aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/App.xaml.cs
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-02-12 12:53:46 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-02-12 12:53:46 +0200
commit8231c057a4073e7397dbb1d953c43a76d8187e72 (patch)
tree1c40c8497aac2f10f919ab732af0c357493ca320 /Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/App.xaml.cs
parent2bef1ef7fb1d5cd57e2af3f47a648e512cfcd4f2 (diff)
downloadTango-8231c057a4073e7397dbb1d953c43a76d8187e72.tar.gz
Tango-8231c057a4073e7397dbb1d953c43a76d8187e72.zip
Implemented global exception trapping on machine studio.
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/App.xaml.cs')
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/App.xaml.cs57
1 files changed, 57 insertions, 0 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/App.xaml.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/App.xaml.cs
index 50e57aab1..ffc8068a5 100644
--- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/App.xaml.cs
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/App.xaml.cs
@@ -2,10 +2,14 @@
using System.Collections.Generic;
using System.Configuration;
using System.Data;
+using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using Tango.Integration.Observables;
+using Tango.Logging;
+using Tango.MachineStudio.UI.Windows;
+using Tango.Settings;
namespace Tango.MachineStudio.UI
{
@@ -14,9 +18,62 @@ namespace Tango.MachineStudio.UI
/// </summary>
public partial class App : Application
{
+ private WpfGlobalExceptionTrapper exceptionTrapper;
+
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
+
+ LogManager.Categories.Clear();
+ LogManager.Categories.AddRange(SettingsManager.Default.MachineStudio.LoggingCategories);
+
+ if (LogManager.Categories.Count == 0)
+ {
+ LogManager.Categories.Add(LogCategory.Critical);
+ LogManager.Categories.Add(LogCategory.Error);
+ LogManager.Categories.Add(LogCategory.General);
+ LogManager.Categories.Add(LogCategory.Warning);
+ }
+
+ LogManager.RegisterLogger(new VSOutputLogger());
+ LogManager.RegisterLogger(new FileLogger());
+
+ exceptionTrapper = new WpfGlobalExceptionTrapper();
+ exceptionTrapper.Initialize(this);
+ exceptionTrapper.ApplicationCrashed += ExceptionTrapper_ApplicationCrashed;
}
+
+ #region Global Exception Trapping
+
+ /// <summary>
+ /// Handles the ApplicationCrashed event of the ExceptionTrapper.
+ /// </summary>
+ /// <param name="sender">The source of the event.</param>
+ /// <param name="e">The <see cref="ApplicationCrashedEventArgs"/> instance containing the event data.</param>
+ private void ExceptionTrapper_ApplicationCrashed(object sender, ApplicationCrashedEventArgs e)
+ {
+ ExceptionWindow exWin = new ExceptionWindow(e.Exception);
+ exWin.ShowDialog();
+
+ switch (exWin.Resolution)
+ {
+ case ExceptionResolutions.Ignore:
+ e.TryRecover = true;
+ break;
+ case ExceptionResolutions.Restart:
+ e.TryRecover = false;
+ LogManager.Log("User selection was to restart the application. Restarting...");
+ Process.Start(Application.ResourceAssembly.Location);
+ Environment.Exit(0);
+ break;
+ case ExceptionResolutions.Shutdown:
+ e.TryRecover = false;
+ LogManager.Log("User selection was to shutdown the application. Restarting...");
+ Environment.Exit(0);
+ break;
+ }
+ }
+
+ #endregion
}
}