EaseFilter Demo Project
EventForm.cs
Go to the documentation of this file.
1 //
3 // (C) Copyright 2012 EaseFilter Technologies Inc.
4 // All Rights Reserved
5 //
6 // This software is part of a licensed software product and may
7 // only be used or copied in accordance with the terms of that license.
8 //
10 
11 using System;
12 using System.Collections.Generic;
13 using System.ComponentModel;
14 using System.Data;
15 using System.Drawing;
16 using System.Linq;
17 using System.Text;
18 using System.IO;
19 using System.Windows.Forms;
20 using System.Diagnostics;
21 using System.Threading;
22 
23 
24 namespace EaseFilter.CommonObjects
25 {
26  public partial class EventForm : Form
27  {
28  static DateTime currentLogDateModified = DateTime.MinValue;
29  static string logFileName = Path.Combine(GlobalConfig.AssemblyPath, GlobalConfig.EventLogFileName);
30  static bool[] selectedDisplayEvents = GlobalConfig.SelectedDisplayEvents;
31 
32  static EventForm eventForm = new EventForm();
33  public delegate void ShowMessageFormDlgt();
34 
35  public EventForm()
36  {
37  InitializeComponent();
38  ResetEventView();
39  }
40 
41  public static void DisplayEventForm()
42  {
43  Thread messageThread = new Thread(new ThreadStart(ShowEventForm));
44  messageThread.Name = "ShowEventFormThread";
45  messageThread.IsBackground = true;
46  messageThread.Start();
47  }
48 
49  private static void ShowEventForm()
50  {
51  var handle = eventForm.Handle;
52 
53  if (eventForm.InvokeRequired)
54  {
55  eventForm.Invoke(new ShowMessageFormDlgt(ShowEventForm));
56  }
57  else
58  {
59  if (!eventForm.Visible)
60  {
61  eventForm.ShowDialog();
62  }
63  else
64  {
65  eventForm.Activate();
66  }
67  }
68  }
69 
70 
71 
72  public void ResetEventView()
73  {
74  listView_EventView.Clear(); //clear control
75  //create column header for ListView
76  //Level Date and Time Source Event ID Message
77  listView_EventView.Columns.Add("Id",50, System.Windows.Forms.HorizontalAlignment.Left);
78  listView_EventView.Columns.Add("Level", 70, System.Windows.Forms.HorizontalAlignment.Left);
79  listView_EventView.Columns.Add("Date and Time", 170, System.Windows.Forms.HorizontalAlignment.Left);
80  listView_EventView.Columns.Add("Source", 150, System.Windows.Forms.HorizontalAlignment.Left);
81  listView_EventView.Columns.Add("EventId",40, System.Windows.Forms.HorizontalAlignment.Left);
82  listView_EventView.Columns.Add("Message", 900, System.Windows.Forms.HorizontalAlignment.Left);
83 
84  errorToolStripMenuItem.Checked = GlobalConfig.SelectedDisplayEvents[(int)EventLevel.Error];
85  warningToolStripMenuItem.Checked = GlobalConfig.SelectedDisplayEvents[(int)EventLevel.Warning];
86  informationToolStripMenuItem.Checked = GlobalConfig.SelectedDisplayEvents[(int)EventLevel.Information];
87  verboseToolStripMenuItem.Checked = GlobalConfig.SelectedDisplayEvents[(int)EventLevel.Verbose];
88  traceToolStripMenuItem.Checked = GlobalConfig.SelectedDisplayEvents[(int)EventLevel.Trace];
89 
90  }
91 
92  public void LoadEventLog()
93  {
94 
95  try
96  {
97  if (!File.Exists(logFileName))
98  {
99  return;
100  }
101 
102  FileInfo fileInfo = new FileInfo(logFileName);
103 
104  ResetEventView();
105 
106  string[] logs = null;
107 
108  EventManager.logFileSyncEvent.WaitOne();
109 
110  logs = File.ReadAllLines(logFileName);
111 
112  EventManager.logFileSyncEvent.Set();
113 
114  List<ListViewItem> items = new List<ListViewItem>();
115 
116  for (int id = 0; id < logs.Length; id++)
117  {
118 
119  try
120  {
121 
122  string log = logs[id];
123 
124  if (string.IsNullOrEmpty(log))
125  {
126  break;
127  }
128 
129 
130  MessageEventArgs arg = EventManager.ConvertSringToEventArg(log);
131 
132  if (arg == null)
133  {
134  continue;
135  }
136 
137  string[] itemStr = new string[listView_EventView.Columns.Count];
138 
139  int itemNum = 0;
140 
141  itemStr[itemNum++] = id.ToString();
142 
143  switch (arg.Type)
144  {
145  case EventLevel.Error: if (!errorToolStripMenuItem.Checked) continue; break;
146  case EventLevel.Warning: if (!warningToolStripMenuItem.Checked) continue; break;
147  case EventLevel.Information: if (!informationToolStripMenuItem.Checked) continue; break;
148  case EventLevel.Verbose: if (!verboseToolStripMenuItem.Checked) continue; break;
149  case EventLevel.Trace: if (!traceToolStripMenuItem.Checked) continue; break;
150  }
151 
152  itemStr[itemNum++] = arg.Type.ToString();
153  itemStr[itemNum++] = EventManager.FormatDateTime(arg.Time);
154  itemStr[itemNum++] = arg.CallerName;
155  itemStr[itemNum++] = arg.EventID.ToString();
156  itemStr[itemNum++] = arg.Message;
157 
158  ListViewItem listItem = new ListViewItem(itemStr, 0);
159 
160  if (arg.Type == EventLevel.Error)
161  {
162  // item.BackColor = Color.Red;
163  listItem.ForeColor = Color.Red;
164  // item.Font = new Font(item.Font,FontStyle.Bold);
165  }
166  else if (arg.Type == EventLevel.Warning)
167  {
168  listItem.BackColor = Color.LightGray;
169  listItem.ForeColor = Color.Yellow;
170  // item.Font = new Font(item.Font, FontStyle.Bold);
171  }
172 
173  items.Add(listItem);
174  }
175  catch (Exception ex)
176  {
177  Debugger.Log(0, "EaseFilter", "ConvertSringToEventArg failed with error:" + ex.Message );
178  }
179  }
180 
181  currentLogDateModified = fileInfo.LastWriteTime;
182 
183  if (items.Count > 0)
184  {
185  var listItems = new ListViewItem[items.Count];
186  for (int i = 0; i < items.Count; i++)
187  {
188  listItems[i] = (ListViewItem)items[i];
189  }
190 
191  listView_EventView.Items.AddRange(listItems);
192  listView_EventView.EnsureVisible(listView_EventView.Items.Count - 1);
193  }
194 
195  }
196  catch (Exception ex)
197  {
198  EventManager.WriteMessage(124, "LoadEventLog", EventLevel.Error, "LoadEventLog failed with error:" + ex.Message);
199  }
200 
201  }
202 
203  private void clearTasksToolStripMenuItem_Click(object sender, EventArgs e)
204  {
205  LoadEventLog();
206  }
207 
208  private void errorToolStripMenuItem_Click(object sender, EventArgs e)
209  {
210  if (errorToolStripMenuItem.Checked)
211  {
212  errorToolStripMenuItem.Checked = false;
213  selectedDisplayEvents[(int)EventLevel.Error] = false;
214  }
215  else
216  {
217  errorToolStripMenuItem.Checked = true;
218  selectedDisplayEvents[(int)EventLevel.Error] = true;
219  }
220 
221  LoadEventLog();
222  }
223 
224  private void warningToolStripMenuItem_Click(object sender, EventArgs e)
225  {
226  if (warningToolStripMenuItem.Checked)
227  {
228  warningToolStripMenuItem.Checked = false;
229  selectedDisplayEvents[(int)EventLevel.Warning] = false;
230  }
231  else
232  {
233  warningToolStripMenuItem.Checked = true;
234  selectedDisplayEvents[(int)EventLevel.Warning] = true;
235  }
236 
237  LoadEventLog();
238  }
239 
240  private void informationToolStripMenuItem_Click(object sender, EventArgs e)
241  {
242  if (informationToolStripMenuItem.Checked)
243  {
244  informationToolStripMenuItem.Checked = false;
245  selectedDisplayEvents[(int)EventLevel.Information] = false;
246  }
247  else
248  {
249  informationToolStripMenuItem.Checked = true;
250  selectedDisplayEvents[(int)EventLevel.Information] = true;
251  }
252 
253  LoadEventLog();
254  }
255 
256  private void verboseToolStripMenuItem_Click(object sender, EventArgs e)
257  {
258  if (verboseToolStripMenuItem.Checked)
259  {
260  verboseToolStripMenuItem.Checked = false;
261  selectedDisplayEvents[(int)EventLevel.Verbose] = false;
262  }
263  else
264  {
265  verboseToolStripMenuItem.Checked = true;
266  selectedDisplayEvents[(int)EventLevel.Verbose] = true;
267  }
268 
269  LoadEventLog();
270  }
271 
272  private void traceToolStripMenuItem_Click(object sender, EventArgs e)
273  {
274  if (traceToolStripMenuItem.Checked)
275  {
276  traceToolStripMenuItem.Checked = false;
277  selectedDisplayEvents[(int)EventLevel.Trace] = false;
278  }
279  else
280  {
281  traceToolStripMenuItem.Checked = true;
282  selectedDisplayEvents[(int)EventLevel.Trace] = true;
283  }
284 
285  LoadEventLog();
286  }
287 
288  private void clearToolStripMenuItem_Click(object sender, EventArgs e)
289  {
290  MessageBoxHelper.PrepToCenterMessageBoxOnForm(this);
291 
292  if (MessageBox.Show("Do you really want to delete all the event messages?", "Delete Message", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.Yes)
293  {
294 
295  File.Delete(logFileName);
296  ResetEventView();
297 
298  }
299  }
300 
301  private void EventForm_Activated(object sender, EventArgs e)
302  {
303  // LoadEventLog();
304  }
305 
306  private void listView_EventView_DoubleClick(object sender, EventArgs e)
307  {
308  ListViewItem item = listView_EventView.SelectedItems[0];
309  string message = (string)item.SubItems[listView_EventView.Columns.Count -1 ].Text;
310 
311  MessageBoxHelper.PrepToCenterMessageBoxOnForm(this);
312  MessageBoxHelper.PrepToCenterMessageBoxOnForm(this);MessageBox.Show(message, "Event Message");
313  }
314 
315  private void EventForm_Load(object sender, EventArgs e)
316  {
317  LoadEventLog();
318  }
319 
320  }
321 }

Social Network


Services Overview

Architect, implement and test file system filter drivers for a wide range of functionality. We can offer several levels of assistance to meet your specific.

Contact Us

You are welcome to contact us for salse or partnership.

Sales: sales@easefilter.com
Support: support@easefilter.com
Info: info@easefilter.com