From 02ae577faa0bd4938507061d603e4f9447e2b64f Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Sun, 23 Aug 2020 08:44:31 +0300 Subject: Fixed issue with insights file datetime utc. added insights application exception/crash. added remote actions service. fixed issue with LiteDB hang on application start/exit. reduced insights listener empty frames. --- .../Visual_Studio/PPC/Tango.PPC.UI/App.xaml.cs | 33 +++++++++++-- .../PPCApplication/DefaultPPCApplicationManager.cs | 3 ++ .../RemoteActions/DefaultRemoteActionsService.cs | 54 ++++++++++++++++++++++ .../PPC/Tango.PPC.UI/Tango.PPC.UI.csproj | 6 ++- .../PPC/Tango.PPC.UI/ViewModelLocator.cs | 4 ++ 5 files changed, 94 insertions(+), 6 deletions(-) create mode 100644 Software/Visual_Studio/PPC/Tango.PPC.UI/RemoteActions/DefaultRemoteActionsService.cs (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI') diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/App.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/App.xaml.cs index 16eb656a8..e478dba77 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/App.xaml.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/App.xaml.cs @@ -13,6 +13,7 @@ using Tango.BL; using Tango.Core; using Tango.Core.DI; using Tango.Core.Helpers; +using Tango.Insights; using Tango.Integration.Operation; using Tango.Logging; using Tango.PPC.Common; @@ -29,7 +30,7 @@ namespace Tango.PPC.UI /// public partial class App : Application { - private WpfGlobalExceptionTrapper exceptionTrapper; + public static WpfGlobalExceptionTrapper ExceptionTrapper; public static String[] StartupArgs { get; private set; } private LogManager LogManager = LogManager.Default; @@ -80,9 +81,9 @@ namespace Tango.PPC.UI base.OnStartup(e); - exceptionTrapper = new WpfGlobalExceptionTrapper(); - exceptionTrapper.Initialize(this); - exceptionTrapper.ApplicationCrashed += ExceptionTrapper_ApplicationCrashed; + ExceptionTrapper = new WpfGlobalExceptionTrapper(); + ExceptionTrapper.Initialize(this); + ExceptionTrapper.ApplicationCrashed += ExceptionTrapper_ApplicationCrashed; CoreSettings.DefaultDataSource = new DataSource() { @@ -100,10 +101,21 @@ namespace Tango.PPC.UI private async void GetLastApplicationCrashFromWindows() { - var logItem = await exceptionTrapper.GetLastApplicationCrashEventLog(); + var logItem = await ExceptionTrapper.GetLastApplicationCrashEventLog(60); if (logItem != null) { LogManager.Log(logItem); + + try + { + InsightsManager.Default.InsertApplicationException(new InsightsApplicationException() + { + Time = DateTime.UtcNow, + Exception = logItem.Message, + IsApplicationCrash = true + }); + } + catch { } } } @@ -133,6 +145,17 @@ namespace Tango.PPC.UI LogManager.Log(e.Exception, "Application Crashed!"); LogManager.Log("Trying to recover from application crash..."); + try + { + InsightsManager.Default.InsertApplicationException(new InsightsApplicationException() + { + Time = DateTime.UtcNow, + Exception = e.Exception.ToString() + }); + } + catch + { } + try { if (Application.Current == null) diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs index 54193a793..29f4e65be 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs @@ -476,6 +476,7 @@ namespace Tango.PPC.UI.PPCApplication { var frame = InsightsFrame.CreateEmpty(DateTime.UtcNow); InsightsManager.Default.InsertFrame(frame); + InsightsManager.Default.Dispose(); } catch {} @@ -528,6 +529,7 @@ namespace Tango.PPC.UI.PPCApplication { var frame = InsightsFrame.CreateEmpty(DateTime.UtcNow); InsightsManager.Default.InsertFrame(frame); + InsightsManager.Default.Dispose(); } catch { } @@ -566,6 +568,7 @@ namespace Tango.PPC.UI.PPCApplication { var frame = InsightsFrame.CreateEmpty(DateTime.UtcNow); InsightsManager.Default.InsertFrame(frame); + InsightsManager.Default.Dispose(); } catch { } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/RemoteActions/DefaultRemoteActionsService.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/RemoteActions/DefaultRemoteActionsService.cs new file mode 100644 index 000000000..1b8780f91 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/RemoteActions/DefaultRemoteActionsService.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Tango.Core.DI; +using Tango.Core.Threading; +using Tango.Integration.ExternalBridge; +using Tango.PPC.Common.ExternalBridge; +using Tango.PPC.Common.RemoteActions; +using Tango.PPC.Common.Threading; +using Tango.PPC.Shared.RemoteActions; + +namespace Tango.PPC.UI.RemoteActions +{ + [TangoCreateWhenRegistered] + public class DefaultRemoteActionsService : IRemoteActionsService, IExternalBridgeRequestHandler + { + [TangoInject] + private IDispatcherProvider DispatcherProvider { get; set; } + + public DefaultRemoteActionsService(IPPCExternalBridgeService externalBridge) + { + externalBridge.RegisterRequestHandler(this); + } + + public void OnReceiverDisconnected(ExternalBridgeReceiver receiver) + { + //Do nothing. + } + + [ExternalBridgeRequestHandlerMethod(typeof(SimulateApplicationExceptionRequest), RequestHandlerLoggingMode.LogRequestName)] + public async Task OnSimulateApplicationExceptionRequest(SimulateApplicationExceptionRequest request, String token, ExternalBridgeReceiver receiver) + { + await receiver.SendGenericResponse(new SimulateApplicationExceptionResponse(), token); + + Thread.Sleep(500); + + DispatcherProvider.Invoke(() => + { + if (request.CrashApplication) + { + App.ExceptionTrapper.Disable(); + throw new OutOfMemoryException("This is a simulated exception to cause the application to crash."); + } + else + { + throw new ApplicationException("This is a simulated exception to cause an unhandled application error."); + } + }); + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj b/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj index 569621432..bfb16f10d 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj @@ -181,6 +181,7 @@ + @@ -446,6 +447,9 @@ + + Tango.ColorLib_v4.dll + @@ -717,7 +721,7 @@ if $(ConfigurationName) == Debug copy /Y "$(TargetDir)Packages" "$(TargetDir)" - + \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs index b5da9f066..7011cd3be 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs @@ -24,6 +24,7 @@ using Tango.PPC.Common.Notifications; using Tango.PPC.Common.OS; using Tango.PPC.Common.Performance; using Tango.PPC.Common.Printing; +using Tango.PPC.Common.RemoteActions; using Tango.PPC.Common.RemoteAssistance; using Tango.PPC.Common.RemoteDesktop; using Tango.PPC.Common.RemoteJob; @@ -42,6 +43,7 @@ using Tango.PPC.UI.Navigation; using Tango.PPC.UI.Notifications; using Tango.PPC.UI.PPCApplication; using Tango.PPC.UI.Printing; +using Tango.PPC.UI.RemoteActions; using Tango.PPC.UI.Threading; using Tango.PPC.UI.ViewModels; using Tango.PPC.UI.Views; @@ -94,6 +96,7 @@ namespace Tango.PPC.UI TangoIOC.Default.Unregister(); TangoIOC.Default.Unregister(); TangoIOC.Default.Unregister(); + TangoIOC.Default.Unregister(); if (App.StartupArgs != null && App.StartupArgs.Contains("-webDebug")) { @@ -135,6 +138,7 @@ namespace Tango.PPC.UI TangoIOC.Default.Register(); TangoIOC.Default.Register(); TangoIOC.Default.Register(); + TangoIOC.Default.Register(); TangoIOC.Default.Register(); TangoIOC.Default.Register(); -- cgit v1.3.1