From 3cdb90407e360a8b820058d8b10651b24bf70599 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Fri, 18 Dec 2020 06:44:33 +0200 Subject: Stubs Utils. --- .../Tango.StubsUtils.Service.UI/App.config | 3 + .../Tango.StubsUtils.Service.UI/App.xaml.cs | 79 ++++++++++++++++++++- .../Images/machine_icon_none.ico | Bin 0 -> 105194 bytes .../Images/machine_icon_none.png | Bin 3171 -> 2607 bytes .../Tango.StubsUtils.Service.UI.csproj | 12 +++- 5 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/Images/machine_icon_none.ico (limited to 'Software/Visual_Studio') diff --git a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/App.config b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/App.config index 6544d52a6..9dfd8545b 100644 --- a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/App.config +++ b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/App.config @@ -4,6 +4,9 @@ + + + diff --git a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/App.xaml.cs b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/App.xaml.cs index c6f57aad6..2f7861a97 100644 --- a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/App.xaml.cs +++ b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/App.xaml.cs @@ -1,10 +1,15 @@ -using System; +using Notifications.Wpf; +using System; using System.Collections.Generic; using System.Configuration; using System.Data; +using System.Globalization; using System.Linq; +using System.Threading; using System.Threading.Tasks; using System.Windows; +using System.Windows.Markup; +using Tango.Logging; using Tango.Settings; namespace Tango.StubsUtils.Service.UI @@ -14,12 +19,84 @@ namespace Tango.StubsUtils.Service.UI /// public partial class App : Application { + private static Mutex mutex = new Mutex(true, "{8F6F0AC4-B9A1-45fd-A8CF-72F0STUBSUTI}"); + + private WpfGlobalExceptionTrapper exceptionTrapper; + private LogManager LogManager = LogManager.Default; + private HashSet _ignoredGlobalExceptions; + + public App() : base() + { + _ignoredGlobalExceptions = new HashSet(); + } + protected override void OnStartup(StartupEventArgs e) { + if (mutex.WaitOne(TimeSpan.Zero, true)) + { + //This is the first instance. Do nothing... + mutex.ReleaseMutex(); + } + else + { + MessageBox.Show("Tango Stubs Service is already running."); + Environment.Exit(0); + } + + //Set culture info. + var enUSCulture = new CultureInfo("en-US"); + + Thread.CurrentThread.CurrentCulture = enUSCulture; + Thread.CurrentThread.CurrentUICulture = enUSCulture; + CultureInfo.DefaultThreadCurrentCulture = enUSCulture; + CultureInfo.DefaultThreadCurrentUICulture = enUSCulture; + + FrameworkElement.LanguageProperty.OverrideMetadata( + typeof(FrameworkElement), + new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag))); + base.OnStartup(e); + exceptionTrapper = new WpfGlobalExceptionTrapper(); + exceptionTrapper.Initialize(this); + exceptionTrapper.ApplicationCrashed += ExceptionTrapper_ApplicationCrashed; + ServiceUISettings settings = SettingsManager.Default.GetOrCreate(); settings.Save(); } + + private void ExceptionTrapper_ApplicationCrashed(object sender, ApplicationCrashedEventArgs e) + { + e.TryRecover = true; + + List ignoredExceptions = new List() + { + "FocusVisualStyle", + "ThreadAbortException", + "A Task's exception(s) were not observed", + "The calling thread must be STA, because many UI components require this." + }; + + LogManager.Log(e.Exception, LogCategory.Critical, "Unexpected Application Error."); + + Application.Current.Dispatcher.Invoke(() => + { + try + { + LogManager.Log("Trying to notify the user about the crash..."); + NotificationManager notification = new NotificationManager(); + notification.Show(new NotificationContent() + { + Title = "Tango Stubs Service", + Message = $"Unexpected Application Error", + Type = NotificationType.Error + }); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error using the notification provider for notifying about application crash."); + } + }); + } } } diff --git a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/Images/machine_icon_none.ico b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/Images/machine_icon_none.ico new file mode 100644 index 000000000..20d7bea5e Binary files /dev/null and b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/Images/machine_icon_none.ico differ diff --git a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/Images/machine_icon_none.png b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/Images/machine_icon_none.png index 95cf615c5..c2ee1e072 100644 Binary files a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/Images/machine_icon_none.png and b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/Images/machine_icon_none.png differ diff --git a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/Tango.StubsUtils.Service.UI.csproj b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/Tango.StubsUtils.Service.UI.csproj index c77c0926e..29519fcab 100644 --- a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/Tango.StubsUtils.Service.UI.csproj +++ b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/Tango.StubsUtils.Service.UI.csproj @@ -36,6 +36,9 @@ prompt 4 + + Images\machine_icon_none.ico + ..\..\packages\ControlzEx.3.0.2.4\lib\net45\ControlzEx.dll @@ -174,14 +177,17 @@ - - - + + + + + + -- cgit v1.3.1