/* Written by Sam Habiel in May 2011 * Licensed under LGPL */ using System; using System.Collections.Generic; using System.Text; using IndianHealthService.BMXNet; using System.Diagnostics; namespace IndianHealthService.ClinicalScheduling { /// /// Class to Log Calls to RPMS/VISTA back and forth. Implements BMXNet.[I]Log interaface. /// Logger is implemented as a Queue Collection of class EventToLog /// public class RPCLogger: Log { /// /// Max size of Log /// const int maxsize = 1000; /// /// Stop Watch to keep track of time between calls. /// Stopwatch _watch; /// /// ctor /// public RPCLogger() { _logger = new List(maxsize); _watch = new Stopwatch(); _watch.Start(); } public bool IsLogging { get; set; } //Event to notify interested controls that we have more data public event EventHandler HaveMoreData; private List _logger; public List Logger { get { return _logger; } } /// /// Data Structure to Log /// public class EventToLog: EventArgs { public DateTime EventTime { get; set; } public long ElapasedTime { get; set; } public string Class { get; set; } public string Category { get; set; } public string Lines { get; set; } public Exception Exception { get; set; } public override string ToString() { return EventTime.TimeOfDay + "\t" + Category + "\t" + Class + "\t" + ElapasedTime + " ms"; } } /// /// Chained to Below /// public void Log(string aClass, string aCategory, params string[] lines) { Log(aClass, aCategory, null, lines); } /// /// Adds Log entry to queue object /// public void Log(string aClass, string aCategory, Exception anException, params string[] lines) { if (_logger.Count >= maxsize - 1) _logger.RemoveAt(_logger.Count - 1); EventToLog _e = new EventToLog { EventTime = DateTime.Now, Class = aClass, Category = aCategory, Lines = String.Join("\r\n", lines), Exception = anException, ElapasedTime = _watch.ElapsedMilliseconds }; _logger.Add(_e); _watch.Reset(); _watch.Start(); //Tell subscribers to this event that we want attention!!!! if (HaveMoreData != null) HaveMoreData(this, _e); } } }