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

Contents of /trunk/GBPVRProgramDatabaseFixer/Program.cs

Parent Directory Parent Directory | Revision Log Revision Log


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

1 #define OVERRIDE_COMMANDLINE_ARGUMENTS // when defined will override supplied commandline args
2 using System;
3 using System.Collections.Generic;
4 using System.Text;
5 using Enterprise.Logging;
6 using System.Windows.Forms;
7 using System.Diagnostics;
8 using System.IO;
9 using libxmltv.Core;
10
11 namespace GBPVRProgramDatabaseFixer
12 {
13 class Program
14 {
15 static SQLLITE sqlite;
16 static string XMLTV_FILE = "";
17 static string GBPVR_DATABASE = "";
18
19 static bool LOADING_XMLTV_FILE = false;
20 static bool XMLTV_INSTANCE_CREATED = false;
21 static int LAST_REPORTED_XMLTV_PROGRESS = 0;
22
23
24 static bool LOADING_GBPVR_DATABASE = false;
25 static bool SQLLIST_INSTANCE_CREATED = false;
26 static int LAST_REPORTED_SQLLITE_PROGRESS = 0;
27
28 static FileInfo fi_XMLTVFILE;
29 static FileInfo fi_GBPVRDATABASE;
30 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 [Conditional("OVERRIDE_COMMANDLINE_ARGUMENTS")]
51 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 static void Main(string[] args)
66 {
67 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 LoadXMLTVFile();
88 LoadGBPVRDatabase();
89 PerformDatabaseProcessing();
90 }
91
92 static void ConsoleOverwritePreviosLine(string format, params object[] args)
93 {
94 Console.WriteLine(format,args);
95 Console.SetCursorPosition(0, Console.CursorTop - 1);
96 }
97
98 static void gLog_ReportProgress(object sender, ReportProgressEventArgs e)
99 {
100 if (!XMLTV_INSTANCE_CREATED && LOADING_XMLTV_FILE)
101 {
102 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 }
112 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 }
125 static void LoadXMLTVFile()
126 {
127 LOADING_XMLTV_FILE = true;
128 if (string.IsNullOrEmpty(XMLTV_FILE))
129 {
130 gLog.Error.WriteLine("XMLTV File is either a null or empty string.");
131 LOADING_XMLTV_FILE = false;
132 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 LOADING_XMLTV_FILE = false;
139 return;
140 }
141
142 XMLTV.Create(fi_XMLTVFILE.FullName, new EventHandler<EventArgs>(XMLTV_OnInstanceCreated));
143 while (!XMLTV_INSTANCE_CREATED) { Application.DoEvents(); }
144 LOADING_XMLTV_FILE = false;
145 }
146 static void XMLTV_OnInstanceCreated(object sender, EventArgs e) { XMLTV_INSTANCE_CREATED = true; }
147
148 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 sqlite = new SQLLITE(fi_GBPVRDATABASE.FullName, new EventHandler<EventArgs>(SQLLITE_OnInstanceCreated));
166 while (!SQLLIST_INSTANCE_CREATED) { Application.DoEvents(); }
167 LOADING_GBPVR_DATABASE = false;
168 }
169 static void SQLLITE_OnInstanceCreated(object sender, EventArgs e) { SQLLIST_INSTANCE_CREATED = true; }
170
171
172
173 static void PerformDatabaseProcessing()
174 {
175 var programs = sqlite.Programs;
176 var recordings = sqlite.Recordings;
177 }
178 }
179 }

  ViewVC Help
Powered by ViewVC 1.1.22