public void EventLogger_LoggingTest() { string message = "Error Message"; Exception ex = new Exception("Exception"); string messageFormat = "Message Format: message: {0}, exception: {1}"; ILog log = new EventLogger("ServiceStack.Logging.Tests", "Application"); Assert.IsNotNull(log); log.Debug(message); log.Debug(message, ex); log.DebugFormat(messageFormat, message, ex.Message); log.Error(message); log.Error(message, ex); log.ErrorFormat(messageFormat, message, ex.Message); log.Fatal(message); log.Fatal(message, ex); log.FatalFormat(messageFormat, message, ex.Message); log.Info(message); log.Info(message, ex); log.InfoFormat(messageFormat, message, ex.Message); log.Warn(message); log.Warn(message, ex); log.WarnFormat(messageFormat, message, ex.Message); }
public string Parse(string data) { if (data == null) { throw new ArgumentNullException($"MotParser::Parse"); } string responseMessage; try { using (var gatewaySocket = new MotSocket(GatewayAddress, GatewayPort)) { gatewaySocket._useASCII = this.UseAscii; using (var p = new MotParser(gatewaySocket, data, _inputDataFormat, DebugMode, AllowZeroTQ, DefaultStoreLoc)) { EventLogger.Debug(p.ResponseMessage); responseMessage = p.ResponseMessage; } } } catch (Exception ex) { responseMessage = $"Parser failure, Message: {ex.Message}"; EventLogger.Error(responseMessage); throw; } return(responseMessage); }
/// <summary> /// <c>Startup</c> /// The method caled by Topshelf to start the service running /// </summary> public void Start() { try { if (WatchSocket) { SocketListener = new Hl7SocketListener(ListenerPort, Parse) { RunAsService = true, AllowZeroTQ = AllowZeroTQ, DebugMode = DebugMode }; SocketListener.Go(); } if (WatchFileSystem) { FilesystemListener = new FilesystemListener(GetPlatformOs.Current == PlatformOs.Windows ? WinMonitorDirectory : NixMonitorDirectory, Parse) { RunAsService = true, Listening = true, DebugMode = DebugMode }; FilesystemListener.Go(); } EventLogger.Info("Service started"); } catch (Exception ex) { Console.WriteLine(ex); EventLogger.Error($"Failed to start service: {ex.Message}"); throw; } }
/// <summary> /// <c>WriteMessageToEndpoint</c> /// Send a message back to the originatin g system /// </summary> /// <param name="message"></param> /// <param name="overridePort"></param> /// <param name="wait"></param> public void WriteMessageToEndpoint(string message, int overridePort, bool wait = false) { try { if (overridePort > 0) { var targetIp = IPAddress.Parse(((IPEndPoint)_listenerSocket.RemoteEndPoint).Address.ToString()); using (var localTcpClient = new TcpClient(targetIp.ToString(), overridePort)) { using (var stream = localTcpClient.GetStream()) { stream.Write(System.Text.Encoding.UTF8.GetBytes(message), 0, message.Length); } } return; } if (!wait) { _listenerSocket.WriteReturn(message); } else { _listenerSocket.Write(message); } _listenerSocket.Flush(); } catch (Exception ex) { EventLogger?.Error("Port I/O error sending ACK to {0}. {1}", _listenerSocket.RemoteEndPoint, ex.Message); } }
/// <summary> /// Writes the current FieldList do the passed Socket /// </summary> /// <param name="socket"></param> /// <param name="doLogging"></param> public void Write(MotSocket socket) { if (socket == null) { throw new ArgumentNullException(nameof(socket)); } try { if (QueueWrites) { AddToQueue(); } else { Write(socket, _fieldList); } } catch (Exception ex) { var errorString = $"Failed to write TQ record: {ex.Message}"; EventLogger.Error(errorString); throw new Exception(errorString); } }
private void CreateRecord(string tableAction) { try { _fieldList.Add(new Field("Table", "Prescriber", 10, true, 'a')); _fieldList.Add(new Field("Action", tableAction, 10, true, 'a')); _fieldList.Add(new Field("RxSys_DocID", "", 36, true, 'k')); _fieldList.Add(new Field("LastName", "", 30, true, 'a')); _fieldList.Add(new Field("FirstName", "", 20, true, 'a')); _fieldList.Add(new Field("MiddleInitial", "", 2, false, 'n')); _fieldList.Add(new Field("Address1", "", 40, true, 'w')); _fieldList.Add(new Field("Address2", "", 40, true, 'w')); _fieldList.Add(new Field("City", "", 30, true, 'w')); _fieldList.Add(new Field("State", "", 2, true, 'w')); _fieldList.Add(new Field("Zip", "", 9, true, 'w')); _fieldList.Add(new Field("Phone", "", 10, true, 'w')); _fieldList.Add(new Field("Comments", "", 32767, false, 'n')); _fieldList.Add(new Field("DEA_ID", "", 10, true, 'w')); _fieldList.Add(new Field("TPID", "", 10, false, 'n')); _fieldList.Add(new Field("Specialty", "", 2, false, 'n')); _fieldList.Add(new Field("Fax", "", 10, true, 'w')); _fieldList.Add(new Field("PagerInfo", "", 40, false, 'n')); } catch (Exception ex) { EventLogger.Error($"Prescriber record construction: {ex.Message}"); throw; } }
/// <summary> /// <c>parseDelimited</c> /// </summary> /// Converts motLegacy delimited data format to motLegacy tagged format and passes it to the gateway /// There are two formats in play. One uses binary delimiters and one uses plain text, which is /// undocumented and appears to be used by Qs1. FrameworksLTC uses the binary version /// <param name="v1Data">Indicates documented binary delimited format if true</param> public void Go(bool v1Data = false) { var retVal = PreParseQs1(Data); if (retVal != string.Empty) { Data = retVal; v1Data = true; } retVal = PreParseByteStream(Data); if (retVal != string.Empty) { Data = retVal; } Data = NormalizeDelimiters(Data); var tc = new TableConverter(); char[] fieldDelimiter = { '~' }; char[] recordDelimiter = { '^' }; var table = string.Empty; // Unravel the delimited stream var items = Data.Split(recordDelimiter); string[] fields = null; foreach (var item in items) { try { if (string.IsNullOrEmpty(item)) { continue; } fields = item.Split(fieldDelimiter); table = tc.Parse(fields, v1Data); ParseTagged(table); } catch (Exception ex) { EventLogger.Error(ex.Message); if (fields != null) { foreach (var f in fields) { EventLogger.Debug($"ERROR: ParseDelimited Field: {f}"); } } EventLogger.Debug($"ERROR: ParseDelimited Record: {table}"); throw; } } }
public void EventLoggerLogErrorExceptionAndMessage() { ManualResetEvent handle = new ManualResetEvent(false); try { EventLogger logger = new EventLogger(); Exception ex = new Exception(); logger.Log += (sender, args) => { Assert.AreEqual(EventLoggerEventType.Error, args.EventType); Assert.AreEqual("Error", args.Message); Assert.AreEqual(ex, args.Exception); handle.Set(); }; logger.Error(ex, "Error"); WaitHandle.WaitAll(new WaitHandle[] { handle }); } finally { handle.Close(); } }
public void Go() { try { if (UseSsl) { _workerThread = new Thread(() => _listenerSocket.SecureListenAsync()) { Name = "Encrypted Listener" }; _workerThread.Start(); } else { _workerThread = new Thread(() => _listenerSocket.ListenAsync()) { Name = "Listener" }; _workerThread.Start(); } } catch (Exception ex) { EventLogger.Error($"An error occurred while attempting to start the socket listener: {ex.Message}"); throw; } }
public void EventLoggerLogErrorException() { ManualResetEvent handle = new ManualResetEvent(false); try { EventLogger logger = new EventLogger(); Exception ex = new Exception(); logger.Log += (sender, args) => { Assert.AreEqual(EventLoggerEventType.Error, args.EventType); Assert.AreEqual(string.Empty, args.Message); Assert.AreEqual(ex, args.Exception); handle.Set(); }; logger.Error(ex); WaitHandle.WaitAll(new WaitHandle[] { handle }); } finally { handle.Close(); } }
/// <inheritdoc /> public MotParser(MotSocket outSocket, string inputStream, InputDataFormat inputDataFormat, bool debugMode = false, bool allowZeroTQ = false, string defaultStoreLoc = null, bool autoTruncate = false, bool sendEof = false) : base(inputStream) { GatewaySocket = outSocket ?? throw new ArgumentNullException($@"NULL Socket passed to MotParser"); if (GatewaySocket.Disposed) { throw new ArgumentNullException($"Disposed Socket passed to MotParser"); } SendEof = sendEof; DebugMode = debugMode; AutoTruncate = autoTruncate; AllowZeroTQ = allowZeroTQ; DefaultStoreLoc = defaultStoreLoc; try { RunParser(inputDataFormat, inputStream); } catch { EventLogger.Error($"MotParser failed on input type {inputDataFormat} and data: {inputStream}"); throw; } }
public Hl7SocketListener(int port, StringStringDelegate callback, bool useSsl = false) { _useSsl = useSsl; try { if (port == 0) { throw new ArgumentOutOfRangeException($"Port is 0"); } _stringCallback = callback ?? throw new ArgumentNullException($"callback null"); _listenerSocket = new MotSocket(port, callback) { UseSsl = UseSsl, _useASCII = PreferASCII }; } catch (Exception e) { var errString = $"An error occurred while attempting to start the HL7 Listener: {e.Message}"; EventLogger.Error(errString); throw; } }
/// <summary> /// Write the specified stream and DoLogging. /// </summary> /// <param name="stream">Stream.</param> /// <param name="DoLogging">If set to <c>true</c> do logging.</param> public void Write(NetworkStream stream) { if (stream == null) { throw new ArgumentNullException(nameof(stream)); } try { if (QueueWrites) { AddToQueue(); } else { Write(stream, _fieldList); } } catch (Exception ex) { var errorString = $"Failed to write Prescription record: {ex.Message}"; EventLogger.Error(errorString); throw new Exception(errorString); } }
void GetDiagnosis(string patientId) { if (patientId == null) { throw new ArgumentNullException($"GetDiagnosis"); } string val = string.Empty; string tag; try { var recordSet = Db.ExecuteQuery($"SELECT * FROM vPatientDiagnosis WHERE Patient_ID = '{patientId}';"); if (ValidTable(recordSet)) { foreach (DataRow diagnosisRecord in recordSet.Tables[0].Rows) { // Print the DataType of each column in the table. foreach (DataColumn dxColumn in diagnosisRecord.Table.Columns) { if (TranslationTable.TryGetValue(dxColumn.ColumnName, out var tmp)) { tag = tmp; val = diagnosisRecord[dxColumn.ColumnName].ToString(); switch (dxColumn.ColumnName) { case "condition_description": val += $"Condition: {val}\n"; break; case "Severity": val += $"Severity: {val}"; break; case "Onset_Date": val += $"Onset Date: {val}\n"; break; case "Cessation_Date": val += $"Cessation Date: {val}\n"; break; default: break; } } } } _patient.SetField("DXNotes", val, true); } } catch (Exception ex) { EventLogger.Error($"Failed reading patient diagnosis: {ex.Message}"); throw; } }
private void GetNotes(string rxID) { try { var notes = string.Empty; // Now get all the notes for the record var recordSet = Db.ExecuteQuery($"SELECT * FROM vRxNote WHERE Rx_ID = '{rxID}';"); if (ValidTable(recordSet)) { foreach (DataRow record in recordSet.Tables[0].Rows) { // Print the DataType of each column in the table. foreach (DataColumn column in record.Table.Columns) { if (TranslationTable.TryGetValue(column.ColumnName, out var tmp)) { var tag = tmp; var val = record[column.ColumnName].ToString(); switch (column.ColumnName) { case "Note_ID": notes += $"Condition: {val}\n"; break; case "Note_Type_Code": notes += $"Note Type: {val}\n"; break; case "Create_User": notes += $"Written By: {val}\n"; break; case "Create_Date": notes += $"Date: {val}\n"; break; case "Note_Text": notes += $"Text: {val}\n"; break; default: break; } } } } } _scrip.SetField("Comments", notes, true); } catch (Exception ex) { EventLogger.Error($"Failed to get Rx notes: {ex.Message}"); throw; } }
public void ShutDown() { try { _listenerSocket?.Close(); } catch (Exception ex) { EventLogger.Error($"An error occurred while attempting to stop the HL7 listener: {ex.Message}"); throw; } }
/// <inheritdoc /> // ReSharper disable once UnusedParameter.Local public MotParser(string inputStream, InputDataFormat inputDataFormat, bool autoTruncate = false, bool sendEof = false, bool debugMode = false) : base(inputStream) { try { GatewaySocket = new MotSocket("localhost", 24042); RunParser(inputDataFormat, inputStream); } catch { EventLogger.Error("MotParser failed on input type {0} and data: {1}", inputDataFormat.ToString(), inputStream); throw; } }
/// <summary> /// <c>ParserBase</c> /// Constructor /// </summary> public ParserBase(string inputStream) { EventLogger = LogManager.GetLogger("Mot.Inbound.Lib.Parser"); if (string.IsNullOrEmpty(inputStream)) { var errorString = "inputStream is NULL or Empty"; EventLogger.Error(errorString); throw new ArgumentNullException(errorString); } Data = inputStream; }
/// <summary> /// <c>WriteMessageToFile</c> /// Persist the message to a file /// </summary> /// <param name="message"></param> /// <param name="fileName"></param> public void WriteMessageToFile(string message, string fileName) { try { EventLogger.Info("Received message. Saving to file {0}", fileName); using (var file = new StreamWriter(fileName)) { file.Write(message); } } catch (Exception ex) { EventLogger.Error("Failed to write file {0}, {1}", fileName, ex.Message); } }
private void WaitForPrescriptionRecord() { try { var p = new PollPatient(MotSqlServer, _mutex, GatewayIp, GatewayPort); while (KeepRunning) { p.ReadPatientRecords(); Thread.Sleep(RefreshRate); } } catch (Exception ex) { EventLogger.Error($"Failed in Prescriber {ex.Message}"); } }
/// <summary> /// Constructor with passed Action and optional Autotruncate flag /// </summary> /// <param name="Action"></param> /// <param name="AutoTruncate"></param> public MotPatientRecord(string Action, bool AutoTruncate = false) { recordType = RecordType.Patient; base.AutoTruncate = AutoTruncate; try { _fieldList = new List <Field>(); createRecord(Action); } catch (Exception ex) { var errorString = $"Failed to create Patient record: {ex.Message}"; EventLogger.Error(errorString); throw new Exception(errorString); } }
/// <summary> /// Initializes a new instance of the <see cref="T:Mot.Common.Interface.Lib.MotPrescriptionRecord"/> class. /// </summary> /// <param name="action">Action.</param> /// <param name="autoTruncate">If set to <c>true</c> auto truncate.</param> public MotPrescriptionRecord(string action, bool autoTruncate = false) { recordType = RecordType.Prescription; AutoTruncate = autoTruncate; try { _fieldList = new List <Field>(); CreateRecord(action); } catch (Exception ex) { var errorString = $"Failed to create Prescription record: {ex.Message}"; EventLogger.Error(errorString); throw new Exception(errorString); } }
public void Application_Error() { foreach (var task in IoC.Container.GetNestedContainer().GetAllInstances <IRunOnError>()) { task.Execute(); } // if exception does not comes from IRunOnError(), we hand it to generic error page if (HttpContext.Current.Items[AppConstants.TRANSACTION_ERROR_KEY] == null) { Exception exception = Server.GetLastError(); var dojoLogger = LogManager.GetCurrentClassLogger(); string message = "System error detected. See ErrorMessage column."; EventLogger.Error(dojoLogger, exception, message, typeof(MvcApplication)); Response.Redirect("/Error/Application"); } }
/// <summary> /// <c>parseTagged</c> /// </summary> /// <param name="dataIn"></param> protected void ParseTagged(string dataIn) { try { if (string.IsNullOrEmpty(dataIn) || !dataIn.ToLower().Contains("<record>")) { throw new ArgumentException("Malformed DataIn argument"); } WriteBlockToGateway(dataIn); } catch (Exception e) { var errorStr = $"Tagged Parser Error: {e.Message}"; EventLogger.Error(errorStr); throw new Exception(errorStr); } }
/// <summary> /// Callback method to check in and schedule /// recordings if applicable /// </summary> /// <param name="e"></param> private void ScheduleCallback(object e) { log.Debug("Attempting sync at: " + DateTime.Now.ToString()); if (!isRunning) { lock (thisLock) { this.isRunning = true; this.ScheduleRecordings(); this.isRunning = false; } } else { log.Error("Sync could not be started. Previous sync is still running."); } log.Debug("Sync completed at: " + DateTime.Now.ToString()); }
public void Write(NetworkStream stream) { try { if (QueueWrites) { AddToQueue(); } else { Write(stream, _fieldList); } } catch (Exception ex) { var errorString = $"Failed to write Patient record: {ex.Message}"; EventLogger.Error(errorString); throw new Exception(errorString); } }
public void Write(MotSocket socket, bool doLogging = false) { try { if (QueueWrites) { AddToQueue(); } else { Write(socket, _fieldList); } } catch (Exception ex) { var errorString = $"Failed to write Location record: {ex.Message}"; EventLogger.Error(errorString); throw new Exception(errorString); } }
/// <summary> /// Write /// </summary> /// <param name="socket"></param> /// <param name="doLogging"></param> /// <exception cref="Exception"></exception> public void Write(MotSocket socket) { try { if (QueueWrites) { AddToQueue(); } else { Write(socket, _fieldList); } } catch (Exception ex) { var errorString = string.Format("Failed to write Store record: {0}", ex.Message); EventLogger.Error(errorString); throw new Exception(errorString); } }
/// <inheritdoc /> public MotParser(MotSocket outSocket, string inputStream, bool autoTruncate) : base(inputStream) { GatewaySocket = outSocket ?? throw new ArgumentNullException($@"NULL Socket passed to MotParser"); if (GatewaySocket.Disposed) { throw new ArgumentNullException($@"Disposed Socket passed to MotParser"); } AutoTruncate = autoTruncate; try { ParseByGuess(inputStream); } catch { EventLogger.Error("MotParser failed on input type {0} and data: {1}", "Best Guess", inputStream); throw; } }
private void WriteBlockToGateway(string inboundData) { if (string.IsNullOrEmpty(inboundData)) { throw new ArgumentNullException($"inboundData data Null or Empty"); } if (GatewaySocket == null) { throw new ArgumentNullException($"Invalid Socket Reference"); } try { if (DebugMode) { LogTaggedRecord(inboundData); } if (GatewaySocket.Write(inboundData) == false) { throw new Exception("Parser recieved a 'failed' response from the gateway"); } if (SendEof) { GatewaySocket.Write("<EOF/>"); } if (DebugMode) { EventLogger.Debug(inboundData); } } catch (Exception ex) { EventLogger.Error($"Failed to write to gateway: {ex.Message}"); throw; } }
/// <summary> /// <c>motTimeQtysRecord</c> /// Constructor with a specific action (Add, Change, Delete) and sets the auto truncate option /// </summary> public MotTimesQtysRecord(string action, bool autoTruncate = false) { if (action == null) { throw new ArgumentNullException(nameof(action)); } recordType = RecordType.DoseSchedule; AutoTruncate = autoTruncate; try { _fieldList = new List <Field>(); CreateRecord(action); } catch (Exception ex) { var errorString = $"Failed to create TimeQtys record: {ex.Message}"; EventLogger.Error(errorString); throw new Exception(errorString); } }
public void EventLoggerLogErrorMessage() { ManualResetEvent handle = new ManualResetEvent(false); try { EventLogger logger = new EventLogger(); logger.Log += (sender, args) => { Assert.AreEqual(EventLoggerEventType.Error, args.EventType); Assert.AreEqual("Error", args.Message); Assert.IsNull(args.Exception); handle.Set(); }; logger.Error("Error"); WaitHandle.WaitAll(new WaitHandle[] { handle }); } finally { handle.Close(); } }