public void UnRegisterMessage(IErrorMessage message) { lock (this) { if (errorList.Contains(message)) { LogMessage("Un-Register error: " + message.Text + " From: " + message.Source); if (logFileEnabled) { string s = "-" + DateTime.Now.ToString("h:mm:ss.ff") + " Error=" + message.Text + " Source=" + message.Source; WriteToLogFile(s); } // find the error stats in the hashtable if (errorTable.ContainsKey(message.UniqueID)) { MessageRecord rec = errorTable[message.UniqueID] as MessageRecord; if (rec != null) { rec.Stop(); } } errorList.Remove(message); if (errorList.Count == 0) { lastHandledMessage = null; } updateRequired = true; // myUI.RemoveMessage(message); // UI timer will remove the message itseld SaveErrorTable(); SaveErrorTableTxt(); } } }
public void RegisterMessage(IErrorMessage message) { Debug.Assert(message != null, "ErrorHandler.RegisterMessage() received a message that does not implement IErrorMessage interface"); Debug.Assert(message.Text != null, "ErrorHandler.RegsisterMessage() received a message that has no text assigned!"); // need to verify that message is not already in queue foreach (IErrorMessage msg in errorList) { if (msg.UniqueID == message.UniqueID) { string s = String.Format("The error \"{0}\" is already enqueued!", message.Text); ServiceManager.Tracing.Trace(s); return; } } lock (this) { LogMessage("Register error: " + message.Text + " From: " + message.Source); message.TimeIn = DateTime.Now; if (logFileEnabled) { string s = "+" + DateTime.Now.ToString("h:mm:ss.ff") + " Error=" + message.Text + " Source=" + message.Source; WriteToLogFile(s); } int i; for (i = 0; i < errorList.Count; i++) { if (message.Priority > ((ErrorMessage)errorList[i]).Priority) { break; } } if ((lastHandledMessage != null) && (lastHandledMessage.Source == message.Source)) { i = 0; } errorList.Insert(i, message); // Check time and dat file existing, // If file not existed, imply that start new shift // Clear errortable and start new file, note // If file existed, no action needed // Check time and dat file existing, DateTime tmpDate = new DateTime(); tmpDate = DateTime.Now.AddHours(-6); string newErrorTableFileName = string.Format(errorTableFileNameFormat, tmpDate.ToString("yyyyMMddtt")); if (!File.Exists(errorTableFilePath + errorTableFilePrefix + newErrorTableFileName)) { errorTable.Clear(); errorTableStartDateTime = tmpDate.AddHours(6); errorTableFileName = newErrorTableFileName; } // find the error stats in the hashtable if (errorTable.ContainsKey(message.UniqueID)) { MessageRecord rec = errorTable[message.UniqueID] as MessageRecord; if (rec != null) { rec.Start(); } } else // new error, need to { MessageRecord rec = new MessageRecord(message); errorTable.Add(message.UniqueID, rec); rec.Start(); } updateRequired = true; myUI.EnableTimer(); SaveErrorTable(); SaveErrorTableTxt(); } }