private void ListenForMessages() { _pipeStream.ReadAsync(_msgBuff, 0, _msgBuff.Length).ContinueWith(t => { if (t.Result == 0) { OnClientDisconnected?.Invoke(this, null); return; } var decodedData = Encoding.Default.GetString(_msgBuff, 0, t.Result); var parsedMessage = PipeMessage.Deserialize(decodedData); switch (parsedMessage.MessageType) { case MessageType.Init: if (!_busy) { _busy = true; SendMessage(new PipeMessage(MessageType.Init, new Dictionary <string, object> { { "error", PipeErrorCode.Success } })); OnClientConnected?.Invoke(this, null); } else { SendMessage(new PipeMessage(MessageType.Init, new Dictionary <string, object> { { "error", PipeErrorCode.PipeBusy } })); } break; case MessageType.TracerError: //TODO: error message OnTracerError?.Invoke(this, new TracerErrorEventArgs( (PipeErrorCode)int.Parse((string)parsedMessage.MessageData["error"]), "")); break; default: OnPipeMessageReceived?.Invoke(this, new PipeMessageEventArgs(parsedMessage)); break; } // Keep reading ListenForMessages(); }); }
private static void InnerLog(string message, MessageVerbosity type, bool isInnerCall, System.Exception e = null) { if (Loaded) { switch (type) { case MessageVerbosity.Debug: Logger.Debug(message); break; case MessageVerbosity.Info: Logger.Info(message); break; case MessageVerbosity.Error: if (isInnerCall) { OnTracerError?.Invoke(message); } if (e != null) { Logger.Error(message, e); } else { Logger.Error(message); } break; } } else { OnTracerError?.Invoke("Tracer is not loaded"); } }