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

Annotation of /trunk/GBPVRProgramDatabaseFixer/Program.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 157 - (hide annotations) (download)
Thu Mar 14 19:36:01 2013 UTC (6 years, 6 months ago) by william
File size: 7319 byte(s)

1 william 154 #define OVERRIDE_COMMANDLINE_ARGUMENTS // when defined will override supplied commandline args
2 william 153 using System;
3 william 150 using System.Collections.Generic;
4     using System.Text;
5 william 153 using Enterprise.Logging;
6     using System.Windows.Forms;
7     using System.Diagnostics;
8     using System.IO;
9     using libxmltv.Core;
10 william 150
11     namespace GBPVRProgramDatabaseFixer
12     {
13     class Program
14     {
15 william 156 static SQLLITE sqlite;
16 william 153 static string XMLTV_FILE = "";
17     static string GBPVR_DATABASE = "";
18 william 155
19     static bool LOADING_XMLTV_FILE = false;
20 william 153 static bool XMLTV_INSTANCE_CREATED = false;
21 william 155 static int LAST_REPORTED_XMLTV_PROGRESS = 0;
22 william 153
23    
24 william 155 static bool LOADING_GBPVR_DATABASE = false;
25     static bool SQLLIST_INSTANCE_CREATED = false;
26     static int LAST_REPORTED_SQLLITE_PROGRESS = 0;
27    
28 william 153 static FileInfo fi_XMLTVFILE;
29 william 155 static FileInfo fi_GBPVRDATABASE;
30 william 153 static void CreateLog()
31     {
32     string log_path = Application.StartupPath;
33     string log_filename = string.Format("{0}.log", typeof(Program).Assembly.GetName().Name);
34     gLog.CreateLog(string.Format(@"{0}\{1}", log_path, log_filename), false, LogLevel.kLogLevel_All);
35     #if DEBUG
36     LogLevel gLevel = gLog.LogLevel;
37     gLevel |= LogLevel.kLogLevel_VerboseDebug;
38     gLevel |= LogLevel.kLogLevel_Debug;
39     gLog.SetLogLevel(gLevel);
40     #else
41     LogLevel gLevel = LogLevel.kLogLevel_Default; // set the default log level: Info, Warn, Error, Debug
42     // it is OK for kLogLevel_Debug to be set in Release mode ... must of the chatty messages are from kLogLevel_VerboseDebug
43     gLevel &= ~LogLevel.kLogLevel_Debug; // ensure this is not set, ever in release mode
44     gLevel &= ~LogLevel.kLogLevel_VerboseDebug; // ensure this is not set, ever in release mode
45     gLog.SetLogLevel(gLevel);
46     #endif
47     gLog.ReportProgressEvent += new EventHandler<ReportProgressEventArgs>(gLog_ReportProgress);
48     }
49    
50 william 154 [Conditional("OVERRIDE_COMMANDLINE_ARGUMENTS")]
51 william 153 static void CreateDebugCommandlineArgs(ref List<string> cargs)
52     {
53     cargs = new List<string>();
54     cargs.Add(string.Format("--xmltv_file=\"{0}\"", @"c:\EPG Guide\Guide\tvguide.xml"));
55     cargs.Add(string.Format("--gbprv_db=\"{0}\"", @"c:\Program Files (x86)\Devnz\GBPVR\gbpvr.db3"));
56     }
57    
58     static List<string> CreateCommandlineArgs(string[] args)
59     {
60     List<string> cargs = new List<string>(args);
61     CreateDebugCommandlineArgs(ref cargs);
62     return cargs;
63     }
64    
65 william 150 static void Main(string[] args)
66     {
67 william 153 CreateLog();
68     var cargs = CreateCommandlineArgs(args);
69     foreach (var carg in cargs)
70     {
71     if (carg.ToLower().Contains("--xmltv_file="))
72     {
73     XMLTV_FILE = carg.Replace("--xmltv_file=", "").Replace("\"","");
74     gLog.Info.WriteLine("XMLTV FILE: '{0}'", XMLTV_FILE);
75     }
76     else if (carg.ToLower().Contains("--gbprv_db="))
77     {
78     GBPVR_DATABASE = carg.Replace("--gbprv_db=", "").Replace("\"", "");
79     gLog.Info.WriteLine("GBPVR DATABASE: '{0}'", GBPVR_DATABASE);
80     }
81     else
82     {
83     gLog.Warn.WriteLine("Unknown commandline option: {0}", carg);
84     }
85     }
86    
87 william 157 LoadXMLTVFile();
88 william 155 LoadGBPVRDatabase();
89 william 157 PerformDatabaseProcessing();
90 william 150 }
91 william 153
92 william 155 static void ConsoleOverwritePreviosLine(string format, params object[] args)
93     {
94     Console.WriteLine(format,args);
95     Console.SetCursorPosition(0, Console.CursorTop - 1);
96     }
97    
98 william 153 static void gLog_ReportProgress(object sender, ReportProgressEventArgs e)
99     {
100 william 155 if (!XMLTV_INSTANCE_CREATED && LOADING_XMLTV_FILE)
101 william 153 {
102 william 155 if (LAST_REPORTED_XMLTV_PROGRESS != e.Progress)
103     {
104     ConsoleOverwritePreviosLine("XMLTV: {0} Loading: {1:00}%", fi_XMLTVFILE.Name, e.Progress);
105     LAST_REPORTED_XMLTV_PROGRESS = e.Progress;
106     if (e.Progress == 100)
107     {
108     Console.WriteLine("XMLTV: {0} Loading: {1:00}%", fi_XMLTVFILE.Name, e.Progress);
109     }
110     }
111 william 153 }
112 william 155 if (!SQLLIST_INSTANCE_CREATED && LOADING_GBPVR_DATABASE)
113     {
114     if (LAST_REPORTED_SQLLITE_PROGRESS != e.Progress)
115     {
116     ConsoleOverwritePreviosLine("SQLLITE: {0} Loading: {1:00}%", fi_XMLTVFILE.Name, e.Progress);
117     LAST_REPORTED_SQLLITE_PROGRESS = e.Progress;
118     if (e.Progress == 100)
119     {
120     Console.WriteLine("SQLLITE: {0} Loading: {1:00}%", fi_XMLTVFILE.Name, e.Progress);
121     }
122     }
123     }
124 william 153 }
125     static void LoadXMLTVFile()
126     {
127 william 155 LOADING_XMLTV_FILE = true;
128 william 153 if (string.IsNullOrEmpty(XMLTV_FILE))
129     {
130     gLog.Error.WriteLine("XMLTV File is either a null or empty string.");
131 william 155 LOADING_XMLTV_FILE = false;
132 william 153 return;
133     }
134     fi_XMLTVFILE = new FileInfo(XMLTV_FILE);
135     if (!fi_XMLTVFILE.Exists)
136     {
137     gLog.Error.WriteLine("Could not find XMLTV File: {0}", fi_XMLTVFILE.FullName);
138 william 155 LOADING_XMLTV_FILE = false;
139 william 153 return;
140     }
141    
142     XMLTV.Create(fi_XMLTVFILE.FullName, new EventHandler<EventArgs>(XMLTV_OnInstanceCreated));
143     while (!XMLTV_INSTANCE_CREATED) { Application.DoEvents(); }
144 william 155 LOADING_XMLTV_FILE = false;
145 william 153 }
146 william 155 static void XMLTV_OnInstanceCreated(object sender, EventArgs e) { XMLTV_INSTANCE_CREATED = true; }
147 william 153
148 william 155 static void LoadGBPVRDatabase()
149     {
150     LOADING_GBPVR_DATABASE = true;
151     if (string.IsNullOrEmpty(GBPVR_DATABASE))
152     {
153     gLog.Error.WriteLine("GBPVR Datbase is either a null or empty string.");
154     LOADING_GBPVR_DATABASE = false;
155     return;
156     }
157     fi_GBPVRDATABASE = new FileInfo(GBPVR_DATABASE);
158     if (!fi_GBPVRDATABASE.Exists)
159     {
160     gLog.Error.WriteLine("Could not find GBPVR Database: {0}", fi_GBPVRDATABASE.FullName);
161     LOADING_GBPVR_DATABASE = false;
162     return;
163     }
164    
165 william 156 sqlite = new SQLLITE(fi_GBPVRDATABASE.FullName, new EventHandler<EventArgs>(SQLLITE_OnInstanceCreated));
166     while (!SQLLIST_INSTANCE_CREATED) { Application.DoEvents(); }
167 william 155 LOADING_GBPVR_DATABASE = false;
168     }
169 william 156 static void SQLLITE_OnInstanceCreated(object sender, EventArgs e) { SQLLIST_INSTANCE_CREATED = true; }
170 william 157
171    
172    
173     static void PerformDatabaseProcessing()
174     {
175     var programs = sqlite.Programs;
176     var recordings = sqlite.Recordings;
177     }
178 william 150 }
179     }

  ViewVC Help
Powered by ViewVC 1.1.22