diff options
author | sr55 <[email protected]> | 2011-11-20 18:30:43 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2011-11-20 18:30:43 +0000 |
commit | c0c88720f5f59104770be38f0e84d7c2897ef465 (patch) | |
tree | b1a17f7d388203cf99f5eec0665c1806dd1b8221 /win/CS/HandBrakeWPF/App.xaml.cs | |
parent | 24cfd6cf3e18288052533ea385a6d0b648fac139 (diff) |
WinGui: (WPF) Add global exception handler and new wpf exception view.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4361 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS/HandBrakeWPF/App.xaml.cs')
-rw-r--r-- | win/CS/HandBrakeWPF/App.xaml.cs | 96 |
1 files changed, 91 insertions, 5 deletions
diff --git a/win/CS/HandBrakeWPF/App.xaml.cs b/win/CS/HandBrakeWPF/App.xaml.cs index e934546cf..13efba30b 100644 --- a/win/CS/HandBrakeWPF/App.xaml.cs +++ b/win/CS/HandBrakeWPF/App.xaml.cs @@ -1,20 +1,106 @@ -/* App.xaml.cs $
- This file is part of the HandBrake source code.
- Homepage: <http://handbrake.fr>.
- It may be used under the terms of the GNU General Public License. */
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="App.xaml.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+// Interaction logic for App.xaml
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
namespace HandBrakeWPF
{
+ using System;
+ using System.Windows;
+
+ using Caliburn.Micro;
+
+ using HandBrake.ApplicationServices.Exceptions;
+
+ using HandBrakeWPF.ViewModels;
+
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
- public partial class App
+ public partial class App
{
/// <summary>
/// Initializes a new instance of the <see cref="App"/> class.
/// </summary>
public App()
{
+ Application.Current.Dispatcher.UnhandledException += this.Dispatcher_UnhandledException;
+ AppDomain.CurrentDomain.UnhandledException +=
+ new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
+ }
+
+ /// <summary>
+ /// Non-UI Thread expection handler.
+ /// </summary>
+ /// <param name="sender">
+ /// The sender.
+ /// </param>
+ /// <param name="e">
+ /// The UnhandledExceptionEventArgs.
+ /// </param>
+ private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
+ {
+ this.ShowError(e.ExceptionObject);
+ }
+
+ /// <summary>
+ /// Handle unhandled exceptions. UI thread only.
+ /// </summary>
+ /// <param name="sender">
+ /// The sender.
+ /// </param>
+ /// <param name="e">
+ /// The DispatcherUnhandledExceptionEventArgs.
+ /// </param>
+ private void Dispatcher_UnhandledException(
+ object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
+ {
+ this.ShowError(e.Exception);
+ e.Handled = true;
+ }
+
+ /// <summary>
+ /// Show an error dialog for the user.
+ /// </summary>
+ /// <param name="exception">
+ /// The exception.
+ /// </param>
+ private void ShowError(object exception)
+ {
+ try
+ {
+ IWindowManager windowManager = IoC.Get<IWindowManager>();
+ if (windowManager != null)
+ {
+ ErrorViewModel errorView = new ErrorViewModel();
+
+ if (exception.GetType() == typeof(GeneralApplicationException))
+ {
+ GeneralApplicationException applicationException = exception as GeneralApplicationException;
+ if (applicationException != null)
+ {
+ errorView.ErrorMessage = applicationException.Error;
+ errorView.Solution = applicationException.Solution;
+ errorView.Details = applicationException.ActualException.ToString();
+ }
+ }
+ else
+ {
+ errorView.Details = exception.ToString();
+ }
+
+ windowManager.ShowDialog(errorView);
+ }
+ }
+ catch (Exception)
+ {
+ MessageBox.Show("An Unknown Error has occured. \n\n Exception:" + exception, "Unhandled Exception",
+ MessageBoxButton.OK, MessageBoxImage.Error);
+ }
}
}
}
|