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

Annotation of /trunk/GBPVRProgramDatabaseFixer/Program.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 156 - (hide annotations) (download)
Thu Mar 14 19:25:17 2013 UTC (6 years, 6 months ago) by william
File size: 7199 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 156 //LoadXMLTVFile();
88 william 155 LoadGBPVRDatabase();
89 william 156
90    
91     var programs = sqlite.Programs;
92     var recordings = sqlite.Recordings;
93 william 150 }
94 william 153
95 william 155 static void ConsoleOverwritePreviosLine(string format, params object[] args)
96     {
97     Console.WriteLine(format,args);
98     Console.SetCursorPosition(0, Console.CursorTop - 1);
99     }
100    
101 william 153 static void gLog_ReportProgress(object sender, ReportProgressEventArgs e)
102     {
103 william 155 if (!XMLTV_INSTANCE_CREATED && LOADING_XMLTV_FILE)
104 william 153 {
105 william 155 if (LAST_REPORTED_XMLTV_PROGRESS != e.Progress)
106     {
107     ConsoleOverwritePreviosLine("XMLTV: {0} Loading: {1:00}%", fi_XMLTVFILE.Name, e.Progress);
108     LAST_REPORTED_XMLTV_PROGRESS = e.Progress;
109     if (e.Progress == 100)
110     {
111     Console.WriteLine("XMLTV: {0} Loading: {1:00}%", fi_XMLTVFILE.Name, e.Progress);
112     }
113     }
114 william 153 }
115 william 155 if (!SQLLIST_INSTANCE_CREATED && LOADING_GBPVR_DATABASE)
116     {
117     if (LAST_REPORTED_SQLLITE_PROGRESS != e.Progress)
118     {
119     ConsoleOverwritePreviosLine("SQLLITE: {0} Loading: {1:00}%", fi_XMLTVFILE.Name, e.Progress);
120     LAST_REPORTED_SQLLITE_PROGRESS = e.Progress;
121     if (e.Progress == 100)
122     {
123     Console.WriteLine("SQLLITE: {0} Loading: {1:00}%", fi_XMLTVFILE.Name, e.Progress);
124     }
125     }
126     }
127 william 153 }
128     static void LoadXMLTVFile()
129     {
130 william 155 LOADING_XMLTV_FILE = true;
131 william 153 if (string.IsNullOrEmpty(XMLTV_FILE))
132     {
133     gLog.Error.WriteLine("XMLTV File is either a null or empty string.");
134 william 155 LOADING_XMLTV_FILE = false;
135 william 153 return;
136     }
137     fi_XMLTVFILE = new FileInfo(XMLTV_FILE);
138     if (!fi_XMLTVFILE.Exists)
139     {
140     gLog.Error.WriteLine("Could not find XMLTV File: {0}", fi_XMLTVFILE.FullName);
141 william 155 LOADING_XMLTV_FILE = false;
142 william 153 return;
143     }
144    
145     XMLTV.Create(fi_XMLTVFILE.FullName, new EventHandler<EventArgs>(XMLTV_OnInstanceCreated));
146     while (!XMLTV_INSTANCE_CREATED) { Application.DoEvents(); }
147 william 155 LOADING_XMLTV_FILE = false;
148 william 153 }
149 william 155 static void XMLTV_OnInstanceCreated(object sender, EventArgs e) { XMLTV_INSTANCE_CREATED = true; }
150 william 153
151 william 155 static void LoadGBPVRDatabase()
152     {
153     LOADING_GBPVR_DATABASE = true;
154     if (string.IsNullOrEmpty(GBPVR_DATABASE))
155     {
156     gLog.Error.WriteLine("GBPVR Datbase is either a null or empty string.");
157     LOADING_GBPVR_DATABASE = false;
158     return;
159     }
160     fi_GBPVRDATABASE = new FileInfo(GBPVR_DATABASE);
161     if (!fi_GBPVRDATABASE.Exists)
162     {
163     gLog.Error.WriteLine("Could not find GBPVR Database: {0}", fi_GBPVRDATABASE.FullName);
164     LOADING_GBPVR_DATABASE = false;
165     return;
166     }
167    
168 william 156 sqlite = new SQLLITE(fi_GBPVRDATABASE.FullName, new EventHandler<EventArgs>(SQLLITE_OnInstanceCreated));
169     while (!SQLLIST_INSTANCE_CREATED) { Application.DoEvents(); }
170 william 155 LOADING_GBPVR_DATABASE = false;
171     }
172 william 156 static void SQLLITE_OnInstanceCreated(object sender, EventArgs e) { SQLLIST_INSTANCE_CREATED = true; }
173 william 150 }
174     }

  ViewVC Help
Powered by ViewVC 1.1.22