public static void Process(this Exception ex, ErrorHandlingLevels level, string extraMessage = null) { string innerExceptionMessage = ""; if (ex.InnerException != null) { innerExceptionMessage = "INNER EXCEPTION" + Environment.NewLine + ex.InnerException.Message; } switch (level) { case ErrorHandlingLevels.Tray: string trayMessage = string.IsNullOrEmpty(extraMessage) ? ex.Message : extraMessage; AppTray.Message(ToolTipIcon.Error, trayMessage); break; case ErrorHandlingLevels.Modal: string modalMessage = ""; if (!string.IsNullOrEmpty(extraMessage)) { modalMessage += extraMessage + Environment.NewLine + Environment.NewLine; } modalMessage += ex.Message; if (!string.IsNullOrEmpty(innerExceptionMessage)) { modalMessage += Environment.NewLine + Environment.NewLine + innerExceptionMessage; } System.Windows.MessageBox.Show(modalMessage, Settings.Title, MessageBoxButton.OK, MessageBoxImage.Exclamation); break; } lock (_locker) { string path = Path.Combine(Settings.Directory, ERROR_FILE_NAME); string logMessage = DateTime.Now.ToString() + ": "; if (!string.IsNullOrEmpty(extraMessage)) { logMessage += extraMessage + Environment.NewLine + Environment.NewLine; } logMessage += ex.Message + Environment.NewLine + Environment.NewLine + ex.StackTrace; if (!string.IsNullOrEmpty(innerExceptionMessage)) { logMessage += Environment.NewLine + Environment.NewLine + innerExceptionMessage; } logMessage += Environment.NewLine + Environment.NewLine; File.AppendAllText(path, logMessage); } }
public static void UpdateCheck(object updaterStateParam) { lock (_locker) { try { // Костыль для RobotNet, который меняет текущую папку на себя string oldDir = Directory.GetCurrentDirectory(); Directory.SetCurrentDirectory(Settings.Directory); UpdateManager.Instance.CleanUp(); UpdateManager.Instance.CheckForUpdates(); if (UpdateManager.Instance.UpdatesAvailable > 0) { // Показать ли диалоговое окно сразу? var updaterState = (UpdaterState)updaterStateParam; if (!updaterState.IsDialog) { AppTray.Message(System.Windows.Forms.ToolTipIcon.Info, "A new update is available!" + Environment.NewLine + "Click to update.", Settings.TitleUpdate, UPDATE_BALLOON_TIMEOUT); } else { new UpdaterView().ShowDialog(); } } Directory.SetCurrentDirectory(oldDir); } catch (Exception ex) { ex.Process(ErrorHandlingLevels.Silent); } } }