18 |
|
|
19 |
|
public partial class main : Form |
20 |
|
{ |
21 |
< |
bool form_closing = false; |
21 |
> |
//bool form_closing = false; |
22 |
|
//private IXMLTVRuntimeInstance xmltv; |
23 |
|
private bool IsUnix |
24 |
|
{ |
34 |
|
} |
35 |
|
|
36 |
|
StringBuilder log_flusher = new StringBuilder(); |
37 |
< |
bool HAVE_CR = false; |
37 |
> |
|
38 |
|
void Log_OnFlush(object sender, LoggerOnFlushEventArgs e) |
39 |
|
{ |
40 |
< |
|
41 |
< |
log_flusher.Append(e.Buffer); |
42 |
< |
if (IsUnix) |
43 |
< |
{ |
44 |
< |
if (e.Buffer == System.Environment.NewLine[0]) |
45 |
< |
{ |
46 |
< |
OnLogFlush(log_flusher.ToString()); |
47 |
< |
log_flusher = new StringBuilder(); |
48 |
< |
} |
49 |
< |
} |
50 |
< |
else |
51 |
< |
{ |
52 |
< |
if (e.Buffer == System.Environment.NewLine[0]) |
53 |
< |
{ |
54 |
< |
HAVE_CR = true; |
55 |
< |
} |
56 |
< |
if (e.Buffer == System.Environment.NewLine[1] && HAVE_CR) |
57 |
< |
{ |
58 |
< |
OnLogFlush(log_flusher.ToString().TrimStart(new char[] { System.Environment.NewLine[1] })); |
59 |
< |
log_flusher = new StringBuilder(); |
60 |
< |
HAVE_CR = false; |
61 |
< |
} |
62 |
< |
} |
63 |
< |
|
40 |
> |
OnLogFlush(e.Buffer); |
41 |
|
} |
42 |
|
//bool txtLog_EnterMouse = false; |
43 |
|
|
53 |
|
{ |
54 |
|
if (this.IsDisposed) { return; } |
55 |
|
Console.Write(logmessage); |
56 |
+ |
UpdateStatus(logmessage); |
57 |
+ |
UpdateLogOutput(logmessage); |
58 |
+ |
Application.DoEvents(); |
59 |
+ |
} |
60 |
+ |
|
61 |
+ |
void UpdateStatus(string logmessage) |
62 |
+ |
{ |
63 |
|
txtStatus.Text = logmessage.Replace(System.Environment.NewLine, ""); |
64 |
+ |
} |
65 |
+ |
void UpdateLogOutput(string logmessage) |
66 |
+ |
{ |
67 |
+ |
if (txtLog.InvokeRequired) |
68 |
+ |
{ |
69 |
+ |
txtLog.Invoke((Action)(delegate { UpdateLogOutput(logmessage); })); |
70 |
+ |
return; |
71 |
+ |
} |
72 |
|
txtLog.AppendText(logmessage); |
81 |
– |
|
82 |
– |
//if (!txtLog_EnterMouse) |
83 |
– |
//{ |
73 |
|
txtLog.SelectionStart = txtLog.Text.Length; //Set the current caret position to the end |
74 |
|
txtLog.ScrollToCaret(); //Now scroll it automatically |
86 |
– |
//} |
87 |
– |
//Thread.Sleep(100); |
88 |
– |
Application.DoEvents(); |
75 |
|
} |
76 |
|
|
77 |
|
//List<IXMLTVChannel> Channels; |
89 |
|
|
90 |
|
void LoadXMLTVShcedule(string schedule_xml) |
91 |
|
{ |
92 |
< |
XMLTV.CreateInstance(schedule_xml, new EventHandler<CancelEventArgs>(xmltv_cancelevent)); |
93 |
< |
var program_count = XMLTV.GetInstance().Programs.Values.Count; |
94 |
< |
var program_list = XMLTV.GetInstance().Programs.Values.ToList().OrderBy(s => s.Start); |
109 |
< |
//Programs = program_list(0, program_count).ToList(); |
110 |
< |
Programs = new List<IXMLTVProgram>(program_list.ToArray()); |
92 |
> |
//XMLTV.CreateInstance(schedule_xml, new EventHandler<CancelEventArgs>(xmltv_cancelevent)); |
93 |
> |
XMLTV.CreateInstance(schedule_xml); |
94 |
> |
XMLTV.OnInstanceCreated += new EventHandler<EventArgs>(XMLTV_OnInstanceCreated); |
95 |
|
} |
96 |
|
|
97 |
< |
void xmltv_cancelevent(object sender, CancelEventArgs e) |
97 |
> |
void XMLTV_OnInstanceCreated(object sender, EventArgs e) |
98 |
|
{ |
99 |
< |
if (form_closing) |
99 |
> |
var instance = XMLTV.GetInstance(); |
100 |
> |
if (instance != null) |
101 |
|
{ |
102 |
< |
e.Cancel = true; |
102 |
> |
var program_count = instance.Programs.Values.Count; |
103 |
> |
var program_list = instance.Programs.Values.ToList().OrderBy(s => s.Start); |
104 |
> |
//Programs = program_list(0, program_count).ToList(); |
105 |
> |
Programs = new List<IXMLTVProgram>(program_list.ToArray()); |
106 |
|
} |
107 |
+ |
CreateControls(); |
108 |
|
} |
109 |
|
|
110 |
+ |
|
111 |
+ |
//void xmltv_cancelevent(object sender, CancelEventArgs e) |
112 |
+ |
//{ |
113 |
+ |
// if (form_closing) |
114 |
+ |
// { |
115 |
+ |
// e.Cancel = true; |
116 |
+ |
// } |
117 |
+ |
//} |
118 |
+ |
|
119 |
|
void CreateControls() |
120 |
|
{ |
121 |
+ |
if (this.InvokeRequired) |
122 |
+ |
{ |
123 |
+ |
this.Invoke((Action)(delegate { CreateControls(); })); |
124 |
+ |
return; |
125 |
+ |
} |
126 |
|
foreach (var program in Programs) |
127 |
|
{ |
128 |
|
ListViewItem li = new ListViewItem(string.Format("{0} {1}", program.Channel.Number, program.Channel.CallSign)); |
144 |
|
if (result != DialogResult.OK) return; |
145 |
|
ClearLocalLog(); |
146 |
|
LoadXMLTVShcedule(xmltv_file_chooser.FileName); |
147 |
< |
CreateControls(); |
147 |
> |
//CreateControls(); |
148 |
|
} |
149 |
|
catch (Exception ex) |
150 |
|
{ |
198 |
|
|
199 |
|
private void main_FormClosing(object sender, FormClosingEventArgs e) |
200 |
|
{ |
201 |
< |
form_closing = true; |
201 |
> |
try |
202 |
> |
{ |
203 |
> |
XMLTV.DestroyInstance(); |
204 |
> |
} |
205 |
> |
catch { } |
206 |
|
} |
207 |
|
|
208 |
|
private void mnuItemClearLocalLog_Click(object sender, EventArgs e) |