static async Task CreateUIAndLoadBuildingDataAsync( bool prelaunchActivated) { Frame rootFrame = Window.Current.Content as Frame; // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (rootFrame == null) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); Navigator.Frame = rootFrame; // Place the frame in the current Window Window.Current.Content = rootFrame; } if (prelaunchActivated == false) { if (rootFrame.Content == null) { BuildingPersistence.Instance = await BuildingPersistence.LoadAsync(); Type pageType = typeof(MonitorPage); if (BuildingPersistence.Instance == null) { pageType = typeof(SetupBuildingPage); } rootFrame.Navigate(pageType, null); } Window.Current.Activate(); } }
async void OnDataChanged(ApplicationData sender, object args) { await this.Dispatch( async() => { // Something has written our data file so we should reread it. BuildingPersistence.Instance = await BuildingPersistence.LoadAsync(); // If we are showing that building on the screen then we need to refresh. if (this.isLocalBuilding) { // to ensure change notification fires. this.Building = null; this.Building = BuildingPersistence.Instance; } } ); }
/// <summary> /// Big note - we do not deal with cancellation in this background task /// and we should. We should handle the situation both the background /// task being cancelled and also the voice command firing its /// Completed event to do things properly /// </summary> /// <param name="taskInstance"></param> public async void Run(IBackgroundTaskInstance taskInstance) { var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails; if (triggerDetails?.Name == "buildingCommandService") { var deferral = taskInstance.GetDeferral(); // Load up our stored local building configuration if not already loaded. if (BuildingPersistence.Instance == null) { BuildingPersistence.Instance = await BuildingPersistence.LoadAsync(); } // Start building a list of remote building configurations if not already // started.. RemoteLightControlManager.Initialise(BuildingPersistence.Instance.Name); // Get the connection to the 'Cortana' end of this conversation. var voiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails); // We should handle voiceConnection.VoiceCommandCompleted here, we // don't yet. // What command has been issued? var voiceCommand = await voiceConnection.GetVoiceCommandAsync(); // Is this the command that we understand? if (voiceCommand.CommandName == "backgroundSwitchLights") { await this.ProcessCommandAsync(voiceConnection, voiceCommand.SpeechRecognitionResult); await voiceConnection.ReportSuccessAsync(MakeResponse("all done")); } else { // Need to report an error await ReportErrorAsync(voiceConnection, "the command name passed does not match across XML/code"); } deferral.Complete(); } }