/// <summary> /// Catches all unhandled exceptions and logs them in a log file. /// </summary> /// <param name="sender">The unhandled exception sender.</param> /// <param name="e">The unhandled exception data.</param> private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { var exception = (Exception)e.ExceptionObject; _textLogger.WriteLine(exception.Message); _textLogger.WriteLine(exception.StackTrace); }
/// <summary> /// The event handler for OnDataReceive. /// </summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event arguments.</param> private void FicsClient_OnDataReceive(object sender, DataReceivedEventArgs e) { // FICS can sometimes send text with false '$' character which can cause exception due to // unrecognised color symbol. var textWithoutFalseColorSymbols = e.Text.Replace("$", ""); _consoleManager.WriteLine($"$R{FICSConstants.ReceivePrefix}: $c{textWithoutFalseColorSymbols}"); _textLogger.WriteLine($"{FICSConstants.ReceivePrefix}: {e.Text}"); _ficsMode.ProcessMessage(e.Text); }
/// <summary> /// Changes mode to the specified one and logs it on the console. /// </summary> /// <param name="modeType">The CECP mode type.</param> private void ChangeMode(CECPModeType modeType) { _textLogger.WriteLine($"{CECPConstants.EnginePrefix}: Mode changed to {modeType}."); var ficsModeFactory = new CECPModeFactory(); _cecpMode = ficsModeFactory.Create(modeType); _cecpMode.OnSendData += CECPMode_OnSendData; _cecpMode.OnChangeMode += CECPMode_OnChangeMode; }
/// <summary> /// Writes a text on the console and ends it with new line chars. /// </summary> /// <param name="text">The text to write.</param> public void WriteLine(string text) { Console.WriteLine(text); _textLogger.WriteLine($"{CECPConstants.SendPrefix}: {text}"); }