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

Contents of /trunk/GBPVRProgramDatabaseFixer/Program.cs

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.22