public async void Run(IBackgroundTaskInstance taskInstance) { this._deferral = taskInstance.GetDeferral(); try { taskInstance.Canceled += (s, e) => this.Close(); var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails; if (triggerDetails != null && triggerDetails.Name == "CTime2VoiceCommandService") { this._connection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails); this._connection.VoiceCommandCompleted += (s, e) => this.Close(); var voiceCommand = await this._connection.GetVoiceCommandAsync(); Logger.Info($"Executing voice command '{voiceCommand.CommandName}'."); var applicationStateService = new ApplicationStateService(); await applicationStateService.RestoreStateAsync(); var cTimeService = new CTimeService(new EventAggregator(), applicationStateService, new GeoLocationService()); var stampHelper = new CTimeStampHelper(applicationStateService, cTimeService); var stampHelperCallback = new CTimeStampHelperCallback( this.OnNotLoggedIn, this.SupportsQuestions, this.OnDidNothing, this.OnAlreadyCheckedInWannaCheckOut, this.OnAlreadyCheckedIn, this.OnAlreadyCheckedOutWannaCheckIn, this.OnAlreadyCheckedOut, this.OnSuccess); switch (voiceCommand.CommandName) { case "checkIn": await stampHelper.Stamp(stampHelperCallback, TimeState.Entered); break; case "checkOut": await stampHelper.Stamp(stampHelperCallback, TimeState.Left); break; } } } catch (Exception exception) { Logger.Warn("Exception occured in the voice command service."); Logger.Error(exception); } finally { this.Close(); } }
public void Run(IBackgroundTaskInstance taskInstance) { try { this._deferral = taskInstance.GetDeferral(); taskInstance.Canceled += (s, e) => this.Close(); var triggerDetails = (AppServiceTriggerDetails)taskInstance.TriggerDetails; if (triggerDetails.Name == "com.microsoft.band.observer") { var applicationStateService = new ApplicationStateService(); var cTimeService = new CTimeService(new EventAggregator(), applicationStateService, new GeoLocationService()); var bandService = new Core.Services.Band.BandService(applicationStateService, cTimeService); triggerDetails.AppServiceConnection.RequestReceived += async (sender, e) => { var deferral = e.GetDeferral(); await applicationStateService.RestoreStateAsync(); //Restore session state with every event await e.Request.SendResponseAsync(new ValueSet()); deferral.Complete(); //Handle the tile event outside of the deferral //Otherwise the band will just queue up the tile events //And we want to not allow the user to press buttons multiple times //So we let our own method handle waiting or not await bandService.HandleTileEventAsync(e.Request.Message); }; } } catch (Exception exception) { Logger.Error(exception); this.Close(); } }