/// <summary> /// Attempt to load the controller with the current settings, /// showing the settings dialog if can't load /// </summary> private void TryLoadController() { try { LoadController(); } catch (ControllerConnectionException cex) { Exception ex = cex; // Show the settings dialog if an exception occurrs, // to allow the user to re-configure if necessary. while (true) { var fm = new SettingsWindow(); var result = ExceptionDialog.ShowException("Could not connect to the device. Check application settings and try again", ex, ExceptionSeverity.Warning); // Ignore if (result == ExceptionDialog.ModalResult.Ignore) { break; // Just start the application } bool?_ok = fm.ShowDialog(); bool ok = (_ok.HasValue && _ok.Value); // Cancel, exit application if (!ok) { Shutdown(1); return; } // If settings have changed, we'll need to re-load the controller try { LoadController(); break; // Settings are now valid, don't loop } catch (Exception _ex) { ex = _ex; // For next iteration of the loop } } } }
/// <summary> /// Try and load all engines present /// </summary> private void LoadEngines(ControlWindow controlWindow) { var engineTypes = Engines.ListEngines(); // Load engines & populate tabs foreach (var engineType in engineTypes) { string name = Engines.GetEngineName(engineType); // Try to load the engine HexEngine engine = null; UserControl page = null; try { engine = Engines.LoadEngine(engineType); page = engine.GetControlPage(); } catch (NotImplementedException) { continue; } catch (Exception ex) { string assyName = Plugins.GetAssemblyName(engineType); if (assyName != null) { name += " (" + assyName + ")"; } ExceptionDialog.ShowException(String.Format("Could not load {0}", name), ex, ExceptionSeverity.Error); continue; // Ignore was pressed } // Add tab & page to the control window controlWindow.AddEngine(name, page, engine); } }
void Dispatcher_UnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) { try { Exception outer_ex = e.Exception; Exception ex = e.Exception; // If exception occurred in another thread if (e.Exception is System.Reflection.TargetInvocationException && e.Exception.InnerException != null) { ex = e.Exception.InnerException; outer_ex = e.Exception.InnerException; } if (ex is TimerException) { ex = ex.InnerException; } ExceptionDialog.ShowException(null, ex, ExceptionSeverity.Unhandled); // Re-enable timer if Ignoring the exception if (outer_ex is TimerException && (outer_ex as TimerException).Timer.Enabled == false) { (outer_ex as TimerException).Timer.Start(); connectTimer.Start(); } e.Handled = true; } catch (Exception) { // Fail-safe Shutdown(1); return; } }