/// <summary>Lifecycle suspend.</summary> /// <param name="sender">The source of the suspend request.</param> /// <param name="e">Details about the suspend request.</param> private async void OnSuspending(object sender, SuspendingEventArgs e) { LoggingService.LogInfo($"OnSuspending {e.SuspendingOperation.ToString()}", Windows.Foundation.Diagnostics.LoggingLevel.Information); // This is the most accurate thing that we can tell the user. // There is no way to know if the app is being terminated or just suspended for fun. if (_notPrelaunchSuspend) { LoggingService.LogInfo("App is suspending.", Windows.Foundation.Diagnostics.LoggingLevel.Information); } else { LoggingService.LogInfo("OnSuspending - Prelaunch", Windows.Foundation.Diagnostics.LoggingLevel.Information); } // If the deferral is not obtained the suspension proceeds at the end of this method. // With the deferral there is still a 5 second time limit to completing suspension code. // The deferral allows code to be awaited in this method. var deferral = e.SuspendingOperation.GetDeferral(); var completer = new TaskCompletionSource <object>(); AddSessionTask(completer.Task); await BroadcasterService.Instance.Suspending.Invoke(completer, true, true); await completer.Task; _networking?.Suspend(); DatapointService.Instance.Suspend(); WebSocketConnection.Instance.Suspend(); VirtualDeviceService.Stop(); deferral.Complete(); }
/// <summary> /// The most important method => starts the party! Initiates everything that needs to be intiates /// </summary> /// <returns>Task that indicated when it's done</returns> public async Task StartSession() { using (var db = new MainDbContext()) { db.Database.Migrate(); } WebSocketConnection.Instance.TryStart(); await StartOrKillNetworkManagerBasedOnSettings(); VirtualDeviceService.UpdateBasedONSettings(); }
/// <summary>Ends session, deletes database and unsets all credentials.</summary> /// <returns></returns> public async Task SignOut() { await EndSession(); SettingsService.Instance.UnsetCreds(); SettingsService.Instance.ResetDatabaseAndPostSettings(); VirtualDeviceService.UpdateBasedONSettings(); await StartOrKillNetworkManagerBasedOnSettings(); // Delete the database. var localFolder = ApplicationData.Current.LocalFolder; await(await localFolder.GetItemAsync(MainDbContext.FileName)).DeleteAsync(); }
private async void OnResuming(object sender, object e) { LoggingService.LogInfo($"OnResuming ", Windows.Foundation.Diagnostics.LoggingLevel.Information); var completer = new TaskCompletionSource <object>(); AddSessionTask(completer.Task); await BroadcasterService.Instance.Resuming.Invoke(completer, true, true); await completer.Task; _networking?.Resume(); DatapointService.Instance.Resume(); WebSocketConnection.Instance.Resume(); VirtualDeviceService.UpdateBasedONSettings(); }