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

Contents of /trunk/GBPVRProgramDatabaseFixer/Program.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 156 - (show annotations) (download)
Thu Mar 14 19:25:17 2013 UTC (6 years, 8 months ago) by william
File size: 7199 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
90
91 var programs = sqlite.Programs;
92 var recordings = sqlite.Recordings;
93 }
94
95 static void ConsoleOverwritePreviosLine(string format, params object[] args)
96 {
97 Console.WriteLine(format,args);
98 Console.SetCursorPosition(0, Console.CursorTop - 1);
99 }
100
101 static void gLog_ReportProgress(object sender, ReportProgressEventArgs e)
102 {
103 if (!XMLTV_INSTANCE_CREATED && LOADING_XMLTV_FILE)
104 {
105 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 }
115 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 }
128 static void LoadXMLTVFile()
129 {
130 LOADING_XMLTV_FILE = true;
131 if (string.IsNullOrEmpty(XMLTV_FILE))
132 {
133 gLog.Error.WriteLine("XMLTV File is either a null or empty string.");
134 LOADING_XMLTV_FILE = false;
135 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 LOADING_XMLTV_FILE = false;
142 return;
143 }
144
145 XMLTV.Create(fi_XMLTVFILE.FullName, new EventHandler<EventArgs>(XMLTV_OnInstanceCreated));
146 while (!XMLTV_INSTANCE_CREATED) { Application.DoEvents(); }
147 LOADING_XMLTV_FILE = false;
148 }
149 static void XMLTV_OnInstanceCreated(object sender, EventArgs e) { XMLTV_INSTANCE_CREATED = true; }
150
151 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 sqlite = new SQLLITE(fi_GBPVRDATABASE.FullName, new EventHandler<EventArgs>(SQLLITE_OnInstanceCreated));
169 while (!SQLLIST_INSTANCE_CREATED) { Application.DoEvents(); }
170 LOADING_GBPVR_DATABASE = false;
171 }
172 static void SQLLITE_OnInstanceCreated(object sender, EventArgs e) { SQLLIST_INSTANCE_CREATED = true; }
173 }
174 }

  ViewVC Help
Powered by ViewVC 1.1.22