source: Scheduling/trunk/cs/bsdx0200GUISourceCode/RPCLogger.cs@ 1627

Last change on this file since 1627 was 1474, checked in by Sam Habiel, 12 years ago

Finally, v 1.7 to the main repo. I will delete the branch after this.

This commit merges all the BMX4 changes in the Scheduling GUI back to the main trunk.

File size: 3.0 KB
Line 
1/* Written by Sam Habiel in May 2011
2 * Licensed under LGPL */
3
4using System;
5using System.Collections.Generic;
6using System.Text;
7using IndianHealthService.BMXNet;
8using System.Diagnostics;
9
10namespace IndianHealthService.ClinicalScheduling
11{
12 /// <summary>
13 /// Class to Log Calls to RPMS/VISTA back and forth. Implements BMXNet.[I]Log interaface.
14 /// Logger is implemented as a Queue Collection of class EventToLog
15 /// </summary>
16 public class RPCLogger: Log
17 {
18 /// <summary>
19 /// Max size of Log
20 /// </summary>
21 const int maxsize = 1000;
22
23 /// <summary>
24 /// Stop Watch to keep track of time between calls.
25 /// </summary>
26 Stopwatch _watch;
27
28 /// <summary>
29 /// ctor
30 /// </summary>
31 public RPCLogger()
32 {
33 _logger = new List<EventToLog>(maxsize);
34 _watch = new Stopwatch();
35 _watch.Start();
36 }
37
38 public bool IsLogging { get; set; }
39
40 //Event to notify interested controls that we have more data
41 public event EventHandler<EventToLog> HaveMoreData;
42
43 private List<EventToLog> _logger;
44
45 public List<EventToLog> Logger
46 {
47 get { return _logger; }
48 }
49
50 /// <summary>
51 /// Data Structure to Log
52 /// </summary>
53 public class EventToLog: EventArgs
54 {
55 public DateTime EventTime { get; set; }
56 public long ElapasedTime { get; set; }
57 public string Class { get; set; }
58 public string Category { get; set; }
59 public string Lines { get; set; }
60 public Exception Exception { get; set; }
61
62 public override string ToString()
63 {
64 return EventTime.TimeOfDay + "\t" + Category + "\t" + Class + "\t" + ElapasedTime + " ms";
65 }
66 }
67
68 /// <summary>
69 /// Chained to Below
70 /// </summary>
71 public void Log(string aClass, string aCategory, params string[] lines)
72 {
73 Log(aClass, aCategory, null, lines);
74 }
75
76 /// <summary>
77 /// Adds Log entry to queue object
78 /// </summary>
79 public void Log(string aClass, string aCategory, Exception anException, params string[] lines)
80 {
81 if (_logger.Count >= maxsize - 1) _logger.RemoveAt(_logger.Count - 1);
82
83 EventToLog _e = new EventToLog
84 {
85 EventTime = DateTime.Now,
86 Class = aClass,
87 Category = aCategory,
88 Lines = String.Join("\r\n", lines),
89 Exception = anException,
90 ElapasedTime = _watch.ElapsedMilliseconds
91 };
92
93 _logger.Add(_e);
94
95 _watch.Reset();
96 _watch.Start();
97
98 //Tell subscribers to this event that we want attention!!!!
99 if (HaveMoreData != null) HaveMoreData(this, _e);
100 }
101 }
102}
Note: See TracBrowser for help on using the repository browser.