diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-12-18 06:44:33 +0200 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-12-18 06:44:33 +0200 |
| commit | 3cdb90407e360a8b820058d8b10651b24bf70599 (patch) | |
| tree | 7b926eb22d0235836bd307aec996ef58f7a77dfa /Software/Visual_Studio | |
| parent | 54ebb63d6bfca47737abd6766cf82245472a6aef (diff) | |
| download | Tango-3cdb90407e360a8b820058d8b10651b24bf70599.tar.gz Tango-3cdb90407e360a8b820058d8b10651b24bf70599.zip | |
Stubs Utils.
Diffstat (limited to 'Software/Visual_Studio')
5 files changed, 90 insertions, 4 deletions
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 @@ <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /> </startup> <runtime> + <legacyCorruptedStateExceptionsPolicy enabled="true" /> + <legacyUnhandledExceptionPolicy enabled="1" /> + <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="Microsoft.IdentityModel.Clients.ActiveDirectory" publicKeyToken="31bf3856ad364e35" culture="neutral" /> 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 /// </summary> 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<String> _ignoredGlobalExceptions; + + public App() : base() + { + _ignoredGlobalExceptions = new HashSet<string>(); + } + 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<ServiceUISettings>(); settings.Save(); } + + private void ExceptionTrapper_ApplicationCrashed(object sender, ApplicationCrashedEventArgs e) + { + e.TryRecover = true; + + List<String> ignoredExceptions = new List<string>() + { + "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 Binary files differnew file mode 100644 index 000000000..20d7bea5e --- /dev/null +++ b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service.UI/Images/machine_icon_none.ico 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 Binary files differindex 95cf615c5..c2ee1e072 100644 --- 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 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 @@ <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> + <PropertyGroup> + <ApplicationIcon>Images\machine_icon_none.ico</ApplicationIcon> + </PropertyGroup> <ItemGroup> <Reference Include="ControlzEx, Version=3.0.2.4, Culture=neutral, processorArchitecture=MSIL"> <HintPath>..\..\packages\ControlzEx.3.0.2.4\lib\net45\ControlzEx.dll</HintPath> @@ -175,13 +178,16 @@ <Resource Include="Images\machine_icon_connected.ico" /> </ItemGroup> <ItemGroup> - <Resource Include="Images\machine_icon_none.png" /> - </ItemGroup> - <ItemGroup> <Resource Include="Images\machine_icon_connected.png" /> <Resource Include="Images\machine_icon_disconnected.ico" /> <Resource Include="Images\machine_icon_disconnected.png" /> </ItemGroup> + <ItemGroup> + <Resource Include="Images\machine_icon_none.ico" /> + </ItemGroup> + <ItemGroup> + <Resource Include="Images\machine_icon_none.png" /> + </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="..\..\packages\MaterialDesignThemes.3.0.1\build\MaterialDesignThemes.targets" Condition="Exists('..\..\packages\MaterialDesignThemes.3.0.1\build\MaterialDesignThemes.targets')" /> <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> |
