/[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

revision 162 by william, Thu Mar 14 20:26:05 2013 UTC revision 163 by william, Fri Mar 15 16:53:40 2013 UTC
# Line 6  using System.Text; Line 6  using System.Text;
6  using System.Data.SQLite;  using System.Data.SQLite;
7  using System.Diagnostics;  using System.Diagnostics;
8  using Enterprise.Logging;  using Enterprise.Logging;
9    using libxmltv;
10  namespace GBPVRProgramDatabaseFixer  namespace GBPVRProgramDatabaseFixer
11  {  {
12      internal class SQLLITE      public interface ISQLLITE
13        {
14            List<SQLLITE.IPROGRAMME> Programs { get; }
15            List<SQLLITE.IRECORDING_SCHEDULE> Recordings { get; }
16            List<SQLLITE.ICHANNEL> Channels { get; }
17            IDateTimeRange GetProgramsDateRange(List<SQLLITE.IPROGRAMME> programs);
18            List<SQLLITE.IPROGRAMME> FilterProgramsByDateRange(List<SQLLITE.IPROGRAMME> programs, IDateTimeRange range);
19    
20        }
21        public class SQLLITE : ISQLLITE
22      {      {
23            public static ISQLLITE Create(string database, EventHandler<EventArgs> OnInstanceCreated)
24            {
25                return new SQLLITE(database, OnInstanceCreated);
26            }
27    
28          #region DATABASE DEFINITIONS          #region DATABASE DEFINITIONS
29    
30          public interface ICHANNEL          public interface ICHANNEL
# Line 217  namespace GBPVRProgramDatabaseFixer Line 231  namespace GBPVRProgramDatabaseFixer
231          }          }
232    
233          //public SQLLite() { }          //public SQLLite() { }
234          public SQLLITE(string database, EventHandler<EventArgs> OnInstanceCreated)          protected SQLLITE(string database, EventHandler<EventArgs> OnInstanceCreated)
235          {          {
236              this.OnInstanceCreated = OnInstanceCreated;              this.OnInstanceCreated = OnInstanceCreated;
237              //CreateConnection(database);              //CreateConnection(database);
# Line 243  namespace GBPVRProgramDatabaseFixer Line 257  namespace GBPVRProgramDatabaseFixer
257              if (OnInstanceCreated != null) { OnInstanceCreated.Invoke(sender, e); }              if (OnInstanceCreated != null) { OnInstanceCreated.Invoke(sender, e); }
258          }          }
259    
         #region SQLLite  
260          private string Database;          private string Database;
261            #region ISQLLITE members        
262          public List<IPROGRAMME> Programs { get; private set; }          public List<IPROGRAMME> Programs { get; private set; }
263          public List<IRECORDING_SCHEDULE> Recordings { get; private set; }          public List<IRECORDING_SCHEDULE> Recordings { get; private set; }
264          public List<ICHANNEL> Channels { get; private set; }          public List<ICHANNEL> Channels { get; private set; }
265    
266            public IDateTimeRange GetProgramsDateRange(List<SQLLITE.IPROGRAMME> programs)
267            {
268                var list = new List<IPROGRAMME>(programs.ToArray());
269                DateTime first = new DateTime();
270                DateTime last = new DateTime();
271                first = list.OrderBy(s => s.start_time).ToList().First().start_time;            
272                last = list.OrderBy(s => s.start_time).ToList().Last().start_time;
273                gLog.Info.WriteLine("\tFirst: {0} = ({1})", first.ToString("yyyy/MM/dd HH:mm:ss.fffffff"), first.ToDateTimeString());
274                gLog.Info.WriteLine("\tLast: {0} = ({1})", last.ToString("yyyy/MM/dd HH:mm:ss.fffffff"), last.ToDateTimeString());
275                var range = DateTimeRange.Create(first, last);
276                return range;
277            }
278    
279            public List<SQLLITE.IPROGRAMME> FilterProgramsByDateRange(List<SQLLITE.IPROGRAMME> programs, IDateTimeRange range)
280            {
281                List<SQLLITE.IPROGRAMME> list = new List<IPROGRAMME>(programs.ToArray());
282                list = list.OrderBy(s => s.start_time).ToList();
283                List<SQLLITE.IPROGRAMME> list2 = new List<IPROGRAMME>();
284                if (range == null)
285                {
286                    gLog.Warn.WriteLine("The DateTimeRange passed in is null...returning the original program list");
287                    return list;
288                }
289                //gLog.Warn.WriteLine("FilterProgramsByDateRange has not been implemented");
290              
291                foreach (var program in list)
292                {
293                    if (program.start_time >= range.Start &&
294                        program.start_time <= range.End)
295                    {
296                        list2.Add(program);
297                    }
298                }
299                list2 = list2.OrderBy(s => s.channel_oid).ThenBy(s => s.start_time).ToList();
300                return list2;
301            }
302          #endregion          #endregion
303    
304    

Legend:
Removed from v.162  
changed lines
  Added in v.163

  ViewVC Help
Powered by ViewVC 1.1.22