/// <summary> /// Handle an exception. /// </summary> /// <param name="err">The exception to handle.</param> public static void HandleException(Exception err) { if (err == null) { App.MessageUser("Error message is null.", "Error", MessageBoxImage.Error, new string[] { "OK" }); } else { if (App.MessageUser(err.Message, "Error", MessageBoxImage.Error, new string[] { "Details", "OK" }) == "Details") { ErrorDetailsWindow dlg = new ErrorDetailsWindow(); dlg.Error = err; App.ShowDialog(dlg); } } }
/// <summary> /// Initializes a new instance of the ResourcesMonitorViewModel class. /// </summary> public ResourcesMonitorViewModel(IStatusManager statusManager, DialogHandler dialogHandler) { _dialogHandler = dialogHandler; _statusManager = statusManager; Messenger.Default.Register <ClientResponse>(this, response => DispatcherHelper.CheckBeginInvokeOnUI(() => ErrorHandler(response))); Messenger.Default.Register <Exception>(this, exception => DispatcherHelper.CheckBeginInvokeOnUI(() => ErrorHandler(exception))); ApplyIntervalSettingsCommand = new RelayCommand(() => _timer.Change(500, RefreshInterval * 1000)); ErrorCountResetCommand = new RelayCommand(() => ErrorCount = 0); _timer = new System.Threading.Timer(par => { Task.Run(async() => { var statusResponse = await _statusManager.GetStatusAsync(); if (statusResponse.IsSuccessful) { GlobalStore.EndPointIsAlive = true; EndPointStatus.IsAlive = true; EndPointStatus.Status = statusResponse.ResponseObject; } else { GlobalStore.EndPointIsAlive = false; EndPointStatus.IsAlive = false; EndPointStatus.Status = null; } }); }, null, 500, RefreshInterval * 1000); ShowErrorDetailsCommand = new RelayCommand <Error>((error) => { if (error == null) { return; } var edw = new ErrorDetailsWindow(error.Message + Environment.NewLine + error.Details); edw.Show(); }); }