public virtual bool IsResuming(StartArgs startArgs, out ResumeArgs resumeArgs) { if (WasTerminated() && WasSuspended()) { resumeArgs = new ResumeArgs { PreviousExecutionState = ApplicationExecutionState.Terminated, SuspendDate = GetSuspendDate(), }; return(true); } resumeArgs = null; return(false); bool WasTerminated() { return(startArgs.Arguments is ILaunchActivatedEventArgs e && e.PreviousExecutionState == ApplicationExecutionState.Terminated); } bool WasSuspended() { return(ApplicationData.Current.LocalSettings.Values.ContainsKey("Suspend_Data")); } }
private async Task InternalStartAsync(StartArgs startArgs) { await _startSemaphore.WaitAsync(); if (_logStartingEvents) { _logger.Log($"{nameof(PrismApplicationBase)}.{nameof(InternalStartAsync)}({startArgs})", Category.Info, Priority.None); } try { CallOnInitializedOnce(); TestResuming(startArgs); _logger.Log($"[App.OnStart(startKind:{startArgs.StartKind}, startCause:{startArgs.StartCause})]", Category.Info, Priority.None); OnStart(startArgs); _logger.Log($"[App.OnStartAsync(startKind:{startArgs.StartKind}, startCause:{startArgs.StartCause})]", Category.Info, Priority.None); await OnStartAsync(startArgs); Window.Current.Activate(); } catch (Exception ex) { _logger.Log($"ERROR {ex.Message}", Category.Exception, Priority.High); Debugger.Break(); } finally { _startSemaphore.Release(); } }
private async Task InternalStartAsync(StartArgs startArgs) { await _startSemaphore.WaitAsync(); if (_logStartingEvents) { _logger.Log($"{nameof(PrismApplicationBase)}.{nameof(InternalStartAsync)}({startArgs})", Category.Info, Priority.None); } // sometimes activation is rased through the base.onlaunch. We'll fix that. if (Interlocked.Increment(ref _started) > 1 && startArgs.StartKind == StartKinds.Launch) { startArgs.StartKind = StartKinds.Activate; } SetupExtendedSplashScreen(); try { CallOnInitializedOnlyOnce(); var suspensionUtil = new SuspensionUtilities(); if (suspensionUtil.IsResuming(startArgs, out var resumeArgs)) { startArgs.StartKind = StartKinds.ResumeFromTerminate; startArgs.Arguments = resumeArgs; } suspensionUtil.ClearSuspendDate(); _logger.Log($"[App.OnStart(startKind:{startArgs.StartKind}, startCause:{startArgs.StartCause})]", Category.Info, Priority.None); OnStart(startArgs); _logger.Log($"[App.OnStartAsync(startKind:{startArgs.StartKind}, startCause:{startArgs.StartCause})]", Category.Info, Priority.None); await OnStartAsync(startArgs); } finally { _startSemaphore.Release(); } void SetupExtendedSplashScreen() { if (startArgs.StartKind == StartKinds.Launch && startArgs.Arguments is IActivatedEventArgs act && Window.Current.Content is null && !(ExtendedSplashScreenFactory is null)) { try { Window.Current.Content = ExtendedSplashScreenFactory(act.SplashScreen); } catch (Exception ex) { throw new Exception($"Error during {nameof(ExtendedSplashScreenFactory)}.", ex); } } } }
private static void TestResuming(StartArgs startArgs) { if (startArgs.Arguments is ILaunchActivatedEventArgs e && e.PreviousExecutionState == ApplicationExecutionState.Terminated) { if (ApplicationData.Current.LocalSettings.Values.ContainsKey("Suspend_Data")) { startArgs.Arguments = ResumeArgs.Create(ApplicationExecutionState.Terminated); startArgs.StartKind = StartKinds.Resume; } } }
private async Task InternalStartAsync(StartArgs startArgs) { await _startSemaphore.WaitAsync(); try { CallOnInitializedOnce(); TestResuming(startArgs); OnStart(startArgs); await OnStartAsync(startArgs); Window.Current.Activate(); } catch (Exception ex) { Container.Resolve <ILoggerFacade>().Log(ex.ToString(), Category.Exception, Priority.High); } finally { _startSemaphore.Release(); } }
private async Task InternalStartAsync(StartArgs startArgs) { await _startSemaphore.WaitAsync(); Debug.WriteLine($"{nameof(PrismApplicationBase)}.{nameof(InternalStartAsync)}({startArgs})"); try { TestResuming(startArgs); OnStart(startArgs); await OnStartAsync(startArgs); Window.Current.Activate(); } catch (Exception ex) { Debug.WriteLine($"ERROR {ex.Message}"); Debugger.Break(); } finally { _startSemaphore.Release(); } }
public PrismApplicationBase() { InternalInitialize(); _logger.Log("[App.Constructor()]", Category.Info, Priority.None); CoreApplication.Exiting += (s, e) => { var stopArgs = new StopArgs(StopKind.CoreApplicationExiting) { CoreApplicationEventArgs = e }; OnStop(stopArgs); OnStopAsync(stopArgs); }; WindowService.WindowCreatedCallBacks.Add(Guid.Empty, args => { WindowService.WindowCreatedCallBacks.Remove(Guid.Empty); args.Window.Closed += (s, e) => { OnStop(new StopArgs(StopKind.CoreWindowClosed) { CoreWindowEventArgs = e }); OnStopAsync(new StopArgs(StopKind.CoreWindowClosed) { CoreWindowEventArgs = e }).RunSynchronously(); }; SystemNavigationManagerPreview.GetForCurrentView().CloseRequested += async(s, e) => { var deferral = e.GetDeferral(); try { OnStop(new StopArgs(StopKind.CloseRequested) { CloseRequestedPreviewEventArgs = e }); await OnStopAsync(new StopArgs(StopKind.CloseRequested) { CloseRequestedPreviewEventArgs = e }); } finally { deferral.Complete(); } }; }); base.Suspending += async(s, e) => { new SuspensionUtilities().SetSuspendDate(DateTime.Now); var deferral = e.SuspendingOperation.GetDeferral(); try { var stopArgs = new StopArgs(StopKind.Suspending) { SuspendingEventArgs = e }; OnStop(stopArgs); await OnStopAsync(stopArgs); } finally { deferral.Complete(); } }; base.Resuming += async(s, e) => { var resumeArgs = new ResumeArgs { PreviousExecutionState = ApplicationExecutionState.Suspended, }; var startArgs = new StartArgs(resumeArgs, StartKinds.ResumeInMemory); await InternalStartAsync(startArgs); }; }