public void SetErrorCode(HResult hr) { if (hr.Succeeded) { ClearStatus(); } else { this.Severity = ErrorSeverity.Error; this.Code = hr.ErrorCodeAsString; this.Description = hr.DetailedMessage; } }
private StatusDialog(Window owner, string title, BackgroundRequest request, HResult hr, string message, string errorPreamble, Action postAction) { instance = this; this.WindowStartupLocation = WindowStartupLocation.CenterOwner; this.Owner = owner; this.Title = title; this.ErrorStatus = new ErrorStatus(); this.ErrorStatus.Preamble = message; this.ErrorStatus.SetStatus(ErrorSeverity.Info, null, null); this.request = request; this.reportProgress = request as IReportProgress; this.DataContext = this; this.originalMessage = message; this.currentMessage = new MessageNode { Preamble = errorPreamble ?? StringResources.UnknownErrorOccurred, PostAction = postAction }; InitializeComponent(); if (request != null) { request.Dispatched += OnRequestDispatched; if (reportProgress != null) { reportProgress.Progress += OnProgressReport; } if (request.IsDispatchComplete) { // We were asked to wait on a request that has already been dispatched. Simulate notification // of the dispatch. Can't call it directly because Close() right now is bad news. this.Dispatcher.BeginInvoke((Action)(() => { this.OnRequestDispatched(request, EventArgs.Empty); }), DispatcherPriority.Background); } } else { SwitchToError(hr, false); } this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, OnCopyExecuted)); }
public void ShowError(string errorPreamble, HResult hr) { StringBuilder sb = new StringBuilder(); if (!string.IsNullOrEmpty(errorPreamble)) { sb.AppendLine(errorPreamble); sb.AppendLine(); } if (!string.IsNullOrEmpty(hr.DetailedMessage)) { sb.Append(hr.DetailedMessage); } else { sb.AppendLine(StringResources.UnknownErrorOccurred); sb.Append(hr.ErrorCodeAsString); } ShowMessageBox(sb.ToString()); }
public ErrorStatus(HResult hr) { this.SetErrorCode(hr); }
private void InternalOnResponseDispatched(HResult result) { Processor.OnRequestDispatched(this); var handler = this.Dispatched; if (handler != null) handler(this, EventArgs.Empty); OnResponseDispatched(result); this.IsDispatchComplete = true; }
// This call is made on the processor's dispatcher thread (presumably the UI). It is guaranteed to be // called exactly once, provided that this request is enqueued and the processor is not shut down before // it gets to it. protected virtual void OnResponseDispatched(HResult result) { }
// Implementations should call this to dispatch the final result of this request. protected virtual void DispatchResponse(HResult result) { lock (lockObject) { if (responseDispatched) return; responseDispatched = true; dispatchedResult = result; if (workDone != null) workDone.Set(); } this.Processor.Dispatcher.BeginInvoke((Action<HResult>)InternalOnResponseDispatched, this.Processor.DispatchPriority, result); }
public static void DisplayWarningMessage(Window owner, string title, HResult hr, string errorPreamble, Action postAction) { DisplayMessageInternal(owner, title, hr, true, errorPreamble, postAction); }
public void ShowError(string errorText) { ShowError(HResult.FromErrorText(errorText)); }
public void ShowError(HResult hr) { ShowError(null, hr); }
private static void DisplayMessageInternal(Window owner, string title, HResult hr, bool isTheHresultAWarning, string errorPreamble, Action postAction) { if (instance == null) { var dialog = new StatusDialog(owner, title, null, hr, null, errorPreamble, postAction); if (isTheHresultAWarning) { dialog.SwitchToError(hr, true); } dialog.ShowDialog(); } else { if (instance.additionalMessages == null) { instance.additionalMessages = new Queue<MessageNode>(); } var newMessage = new MessageNode { Preamble = errorPreamble ?? StringResources.UnknownErrorOccurred, Result = hr, PostAction = postAction, IsWarningMessage = isTheHresultAWarning, }; instance.additionalMessages.Enqueue(newMessage); } }
public void SwitchToError(HResult hr, bool isWarning) { this.ErrorStatus.Preamble = this.currentMessage.Preamble; if (isWarning) { this.ErrorStatus.SetStatus(ErrorSeverity.Warning, hr.DetailedMessage, hr.ErrorCodeAsString); } else { this.ErrorStatus.SetErrorCode(hr); } this.progressBar.Visibility = System.Windows.Visibility.Collapsed; this.cancelButton.Content = StringResources.CloseButtonText; this.canceled = true; this.ProgressiveDisclosure = true; if (AutoDismiss) { Result = hr; this.Dispatcher.BeginInvoke((Action)(() => { this.Close(); }), DispatcherPriority.Background); } }
public static HResult FromErrorText(string errorText, HResult hrOld) { HResult hr = hrOld; hr.detailedErrorMessage = errorText; return hr; }
void LoadWindowState() { bool usingDefault = false; try { if (!File.Exists(this.windowStateFileName)) { usingDefault = true; CreateDefaultWindowState(); } TryLoadWindowState(); } catch (Exception ex) { bool versionMismatch = ex is VersionMismatchException; // Don't let missing/corrupt window state data tip us over. Try the default if we haven't already. if (!usingDefault) { ex = null; try { CreateDefaultWindowState(); TryLoadWindowState(); } catch (Exception ex2) { // This will leave our window blank. Bad, but the file tab will still work. When we have a tools/options/reset window state option, // that will be the solution (or at least the way we can report the problem in a natural way). This would be a weird // situation anyway... ex = ex2; } } if (ex != null || versionMismatch) { this.Dispatcher.BeginInvoke((Action)(() => { var notificationService = this.RootServiceProvider.GetService(typeof(IUserNotificationService)) as IUserNotificationService; if (ex != null) { var loggingService = this.RootServiceProvider.GetService(typeof(ILoggingService)) as ILoggingService; if (loggingService != null) { loggingService.LogException(ex); } if (notificationService != null) { notificationService.ShowError(StringResources.ErrorLoadingWindowState, HResult.FromException(ex)); } } else { if (notificationService != null) { notificationService.ShowMessageBox(StringResources.WindowStateVersionMismatch); } } }), DispatcherPriority.Background); } } }
void ProcessRequests() { this.initResult = this.InitializeBackgroundThread(); this.initHandshakeEvent.Set(); if (this.initResult.Failed) { return; } IBackgroundRequest[] requestList; while (true) { workReadyEvent.Wait(); lock (lockObject) { if (shutdownRequested) { break; } if (!this.ShouldContinueProcessing) { break; } if (this.requests.Count > 0) { requestList = this.requests.ToArray(); this.requests.Clear(); } else { requestList = null; } workReadyEvent.Reset(); } this.DoCustomProcessing(); if (requestList != null) { foreach (var request in requestList) { // Note that these requests may have already been canceled... this is a no-op in that case. request.Execute(); // Allow COM callbacks to arrive between each request if present this.processorThread.Join(0); } requestList = null; } } this.CleanupBackgroundThread(); this.exitHandshakeEvent.Set(); }
void OnOkButtonClicked(object sender, RoutedEventArgs e) { if (this.consoleInEditMode != null) { SetConsoleInEditMode(null, false); return; } var selectedConsole = this.listview.SelectedItem as ConsoleWrapper; if (selectedConsole == null) { return; } if (this.changesMade) { var dupeTable = new Dictionary <string, ConsoleWrapper>(); // Check the console aliases for duplicates foreach (var c in this.Consoles) { ConsoleWrapper dupe; if (dupeTable.TryGetValue(c.Alias, out dupe)) { this.notificationService.ShowError(string.Format(StringResources.ConsoleAliasAlreadyExistsFmt, c.Alias), HResult.FromErrorText(StringResources.ConsoleAliasesMustBeUnique)); this.listview.SelectedItem = c; return; } dupeTable[c.Alias] = c; } // No duplicates... let's try to make the console manager look like what we've got. try { // First, nuke the pure removals foreach (var c in this.removals) { // NOTE: Remove by the real console alias. The user might have changed the local one... this.consoleManager.RemoveConsole(c.RealConsole.Alias); } // Now remove anything that has changed. The replacements list ends up being all consoles that // need to be written, either because they're new, or changed (removed + added). var replacements = new List <ConsoleWrapper>(); foreach (var c in this.Consoles) { if (c.RealConsole != null && (c.RealConsole.Alias != c.Alias || c.RealConsole.Address != c.Address)) { this.consoleManager.RemoveConsole(c.RealConsole.Alias); replacements.Add(c); } else if (c.RealConsole == null) { replacements.Add(c); } } // Re-add everything in replacements list foreach (var c in replacements) { this.consoleManager.AddConsole(c.Alias, c.Address); } // Set the default kit var defaultConsole = this.Consoles.FirstOrDefault(c => c.IsDefault); if (defaultConsole != null) { // NOTE: If the user deletes the default console and doesn't set a new one, the console // manager automatically clears the (now bogus) default console specification. this.consoleManager.SetDefaultConsole(defaultConsole.Alias); } } catch (Exception ex) { this.notificationService.ShowError(HResult.FromException(ex)); // This is somewhat bad... we possibly made *some* of our changes, so chances are that // trying again will end up failing again, even if the user fixed the original problem. // Best hope is to reset the dialog to whatever state the actual list is in. InitConsolesList(); return; } } if (selectedConsole.IsDefault) { this.SpecificKit = null; } else { this.SpecificKit = selectedConsole.Address; } this.SelectedConsole = new ConsoleIdentifier(selectedConsole.Alias, selectedConsole.Address, selectedConsole.IsDefault); // Re-update the outstanding console identifiers ConsoleIdentifier.UpdateOutstandingIdentifiers(this.consoleManager.GetDefaultConsole(), this.consoleManager.GetConsoles()); DialogResult = true; }
void ProcessRequests() { this.initResult = this.InitializeBackgroundThread(); this.initHandshakeEvent.Set(); if (this.initResult.Failed) return; IBackgroundRequest[] requestList; while (true) { workReadyEvent.Wait(); lock (lockObject) { if (shutdownRequested) break; if (!this.ShouldContinueProcessing) break; if (this.requests.Count > 0) { requestList = this.requests.ToArray(); this.requests.Clear(); } else { requestList = null; } workReadyEvent.Reset(); } this.DoCustomProcessing(); if (requestList != null) { foreach (var request in requestList) { // Note that these requests may have already been canceled... this is a no-op in that case. request.Execute(); // Allow COM callbacks to arrive between each request if present this.processorThread.Join(0); } requestList = null; } } this.CleanupBackgroundThread(); this.exitHandshakeEvent.Set(); }