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(); } }
private async void OnTileButtonPressed(object sender, BandTileEventArgs<IBandTileButtonPressedEvent> e) { try { Logger.Info("Handling TileButtonPressed event."); //Make sure the client is created //The background task might be stopped after the OnTileOpened event if (this._backgroundTileClient == null) this._backgroundTileClient = await this.GetClientAsync(true); if (e.TileEvent.TileId == BandConstants.TileId) { if (e.TileEvent.ElementId == new StampPageLayout().StampTextButton.ElementId) { await this._backgroundTileClient.NotificationManager.VibrateAsync(VibrationType.NotificationOneTone); bool checkedIn = this._applicationStateService.GetCurrentUser() != null ? await this._cTimeService.IsCurrentlyCheckedIn(this._applicationStateService.GetCurrentUser().Id) : false; var stampHelper = new CTimeStampHelper(this._applicationStateService, this._cTimeService); await stampHelper.Stamp(this, checkedIn ? TimeState.Left : TimeState.Entered); await this.ChangeTileDataToReadyAsync(this._backgroundTileClient); } else if (e.TileEvent.ElementId == new TestConnectionPageLayout().TestTextButton.ElementId) { await this._backgroundTileClient.NotificationManager.VibrateAsync(VibrationType.NotificationTwoTone); } } } catch (Exception exception) { Logger.Error(exception); if (this._backgroundTileClient != null) { var title = CTime2CoreResources.Get("BandService.ApplicationName"); var body = CTime2CoreResources.Get("BandService.ErrorOccurred"); await this._backgroundTileClient.NotificationManager.ShowDialogAsync(BandConstants.TileId, title, body); } } finally { Logger.Info("Handled TileButtonPressed event."); this._backgroundTileEventTaskSource.SetResult(null); } }