/[xmltv_parser]/trunk/GBPVRProgramDatabaseFixer/SQLLITE.cs
ViewVC logotype

Diff of /trunk/GBPVRProgramDatabaseFixer/SQLLITE.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/GBPVRProgramDatabaseFixer/SQLLITE.cs	2013/03/14 21:40:19	162
+++ trunk/GBPVRProgramDatabaseFixer/SQLLITE.cs	2013/03/15 16:53:40	163
@@ -6,11 +6,25 @@
 using System.Data.SQLite;
 using System.Diagnostics;
 using Enterprise.Logging;
-
+using libxmltv;
 namespace GBPVRProgramDatabaseFixer
 {
-    internal class SQLLITE
+    public interface ISQLLITE
+    {
+        List<SQLLITE.IPROGRAMME> Programs { get; }
+        List<SQLLITE.IRECORDING_SCHEDULE> Recordings { get; }
+        List<SQLLITE.ICHANNEL> Channels { get; }
+        IDateTimeRange GetProgramsDateRange(List<SQLLITE.IPROGRAMME> programs);
+        List<SQLLITE.IPROGRAMME> FilterProgramsByDateRange(List<SQLLITE.IPROGRAMME> programs, IDateTimeRange range);
+
+    }
+    public class SQLLITE : ISQLLITE
     {
+        public static ISQLLITE Create(string database, EventHandler<EventArgs> OnInstanceCreated)
+        {
+            return new SQLLITE(database, OnInstanceCreated);
+        }
+
         #region DATABASE DEFINITIONS
 
         public interface ICHANNEL
@@ -217,7 +231,7 @@
         }
 
         //public SQLLite() { }
-        public SQLLITE(string database, EventHandler<EventArgs> OnInstanceCreated) 
+        protected SQLLITE(string database, EventHandler<EventArgs> OnInstanceCreated) 
         {
             this.OnInstanceCreated = OnInstanceCreated;
             //CreateConnection(database);
@@ -243,11 +257,48 @@
             if (OnInstanceCreated != null) { OnInstanceCreated.Invoke(sender, e); }
         }
 
-        #region SQLLite 
         private string Database;
+        #region ISQLLITE members        
         public List<IPROGRAMME> Programs { get; private set; }
         public List<IRECORDING_SCHEDULE> Recordings { get; private set; }
         public List<ICHANNEL> Channels { get; private set; }
+
+        public IDateTimeRange GetProgramsDateRange(List<SQLLITE.IPROGRAMME> programs)
+        {
+            var list = new List<IPROGRAMME>(programs.ToArray());
+            DateTime first = new DateTime();
+            DateTime last = new DateTime();
+            first = list.OrderBy(s => s.start_time).ToList().First().start_time;            
+            last = list.OrderBy(s => s.start_time).ToList().Last().start_time;
+            gLog.Info.WriteLine("\tFirst: {0} = ({1})", first.ToString("yyyy/MM/dd HH:mm:ss.fffffff"), first.ToDateTimeString());
+            gLog.Info.WriteLine("\tLast: {0} = ({1})", last.ToString("yyyy/MM/dd HH:mm:ss.fffffff"), last.ToDateTimeString());
+            var range = DateTimeRange.Create(first, last);
+            return range;
+        }
+
+        public List<SQLLITE.IPROGRAMME> FilterProgramsByDateRange(List<SQLLITE.IPROGRAMME> programs, IDateTimeRange range)
+        {
+            List<SQLLITE.IPROGRAMME> list = new List<IPROGRAMME>(programs.ToArray());
+            list = list.OrderBy(s => s.start_time).ToList();
+            List<SQLLITE.IPROGRAMME> list2 = new List<IPROGRAMME>();
+            if (range == null)
+            {
+                gLog.Warn.WriteLine("The DateTimeRange passed in is null...returning the original program list");
+                return list;
+            }
+            //gLog.Warn.WriteLine("FilterProgramsByDateRange has not been implemented");
+           
+            foreach (var program in list)
+            {
+                if (program.start_time >= range.Start && 
+                    program.start_time <= range.End)
+                {
+                    list2.Add(program);
+                }
+            }
+            list2 = list2.OrderBy(s => s.channel_oid).ThenBy(s => s.start_time).ToList();
+            return list2;
+        }
         #endregion
 
 

 

  ViewVC Help
Powered by ViewVC 1.1.22