public async void Run(IBackgroundTaskInstance taskInstance) { var deferral = taskInstance.GetDeferral(); var isLocalNetwork = await IsInLocalNetwork(); var service = new SmartHouseService(); if (isLocalNetwork) { var started = IsPhoneCallStarted(); if (started) { PhoneCallStarted(); var model = GetPhoneCallModel(); await service.PhoneCallStarted(model); } else { PhoneCallEnded(); await service.PhoneCallEnded(); } } deferral.Complete(); }
private async Task NowPlaying() { var smartHouse = new SmartHouseService(); await ShowProgressScreen("Of course"); var result = await smartHouse.GetCurrentSong(); await CortanaResponseShowSong(result); }
private async Task TurnOffAirCondition() { var smartHouse = new SmartHouseService(); await ShowProgressScreen("Please wait..."); var result = await smartHouse.TurnOffAirConditioner(); await CompleteMessage($"Air conditioner {result?.Message}"); }
private async Task SmartHouseGetInput() { var smartHouse = new SmartHouseService(); await ShowProgressScreen("Please wait..."); var result = await smartHouse.GetCurrentState(); await CompleteMessage($"Connected input: {result}"); }
private async Task SetSmartHouseSetInput(string input) { var smartHouse = new SmartHouseService(); await ShowProgressScreen($"Setting {input} input"); var result = await smartHouse.SetInput(input); await CompleteMessage(""); }
private async Task SetSmartHouseMode(string mode) { var smartHouse = new SmartHouseService(); await ShowProgressScreen($"Setting {mode} mode"); var result = await smartHouse.SetMode(mode); await CompleteMessage(""); }
private async Task SmartHouseRestartVPN() { var smartHouse = new SmartHouseService(); await ShowProgressScreen("Please Wait..."); var result = await smartHouse.RestartOpenVPN(); await CompleteMessage(""); }
private async Task VolumeDown() { await ShowProgressScreen($"Please wait"); var service = new SmartHouseService(); var data = await service.GetDashboardData(); var newVolume = (data.Volume / 10D) - 2D; await service.SetVolume(newVolume); await CompleteMessage($"Volume is at {newVolume}"); }
private async Task CurrentTempeature() { var smartHouse = new SmartHouseService(); await ShowProgressScreen("Please wait..."); var result = await smartHouse.GetRoomTemperature(); var message = $"Tempearture is at {result.Temperature} deggree, humidity {result.Humidity} percent, and gas is {result.GasValue}."; if (result.GasValue > 250) { message += " Phill, Gas value is high... You smoking to much."; } await CompleteMessage(message); }
private async Task CortanaResponseShowSong(SongResult info) { if (info == null) { await CompleteMessage("Right now... Nothing is playing"); } else if (info.Loved) { var message = $"Now is playing: {info.Song}, from artist {info.Artist}, on album {info.Album}. You liked this song."; await CompleteMessage(message); } else { var message = $"Now is playing: {info.Song}, from artist {info.Artist}, on album {info.Album}. Do you like this song?"; var userPrompt = new VoiceCommandUserMessage(); userPrompt.DisplayMessage = userPrompt.SpokenMessage = message; var userReprompt = new VoiceCommandUserMessage(); var prompt = "Do you like this song?"; userReprompt.DisplayMessage = userReprompt.SpokenMessage = prompt; var response = VoiceCommandResponse.CreateResponseForPrompt(userPrompt, userReprompt); var voiceCommandConfirmation = await voiceServiceConnection.RequestConfirmationAsync(response); if (voiceCommandConfirmation == null) { response = VoiceCommandResponse.CreateResponse(userPrompt); await voiceServiceConnection.ReportSuccessAsync(response); } else if (voiceCommandConfirmation.Confirmed) { var service = new SmartHouseService(); var result = await service.LoveSong(); await CompleteMessage(result?.Message); } else { await CompleteMessage(""); } } }
private static async void StartAlarmClock() { var timeSpan = new TimeSpan(4, 30, 0); Action action = () => { using (var client = new HttpClient()) { client.GetAsync($"http://127.0.0.1:{Port}/api/SmartHouse/TurnOff").Wait(); } Logger.LogInfoMessage("Smart house turn off"); var smartHouse = new SmartHouseService(); var pandoraService = new PandoraService(); pandoraService.Stop(); using (var orvibioService = new OrviboService()) { var turnOffResult = orvibioService.TurnOff(); Logger.LogInfoMessage("orvibioService.TurnOff"); Logger.LogInfoMessage(turnOffResult.Message); Thread.Sleep(TimeSpan.FromMinutes(1)); var turnOnResult = orvibioService.TurnOn(); Logger.LogInfoMessage("orvibioService.TurnOn"); Logger.LogInfoMessage(turnOnResult.Message); } Thread.Sleep(TimeSpan.FromMinutes(3)); smartHouse.RestartOpenVPNService().Wait(); }; var alarmClock = new AlarmClock(DateTime.Today.AddDays(1).Date.AddTicks(timeSpan.Ticks), action); await alarmClock.Start(); }
private async Task ExecuteSmarthouseCommands(string command) { var smartHouse = new SmartHouseService(); switch (command) { case "Turn on": await ShowProgressScreen($"Please wait"); var result = await smartHouse.Run(UWPLib.Model.SmartHouseCommands.TurnOn); await CompleteMessage(result.Message); break; case "Turn off": await ShowProgressScreen($"Please wait"); result = await smartHouse.Run(UWPLib.Model.SmartHouseCommands.TurnOff); await CompleteMessage(result.Message); break; case "Volume up": await VolumeUp(); break; case "Volume down": await VolumeDown(); break; default: LaunchAppInForeground(); break; } }
private async Task ExecutePandoraCommands(string command) { var pandora = new PandoraService(); var smartHouse = new SmartHouseService(); await ShowProgressScreen($"Starting to {command} song"); switch (command) { case "Play": await smartHouse.Run(UWPLib.Model.SmartHouseCommands.Play); await CompleteMessage(""); break; case "Stop": await pandora.Run(SmartHouse.UWPLib.Model.PandoraCommands.Play); await CompleteMessage(""); break; case "Next": await smartHouse.Run(UWPLib.Model.SmartHouseCommands.Next); await CompleteMessage(""); break; case "Love": await smartHouse.LoveSong(); await CompleteMessage(""); break; case "Hate": await pandora.Run(SmartHouse.UWPLib.Model.PandoraCommands.ThumbDown); await CompleteMessage(""); break; case "Boring": await pandora.Run(SmartHouse.UWPLib.Model.PandoraCommands.Tired); await CompleteMessage(""); break; case "Show": var info = await smartHouse.GetCurrentSong(); await CortanaResponseShowSong(info); break; case "NextStation": var nextInfo = await pandora.Run(SmartHouse.UWPLib.Model.PandoraCommands.NextStation); await CompleteMessage(nextInfo?.Message); break; case "PrevStation": var prevInfo = await pandora.Run(SmartHouse.UWPLib.Model.PandoraCommands.PrevStation); await CompleteMessage(prevInfo?.Message); break; default: LaunchAppInForeground(); break; } }
private async Task TurnOnAirCondition() { var smartHouseService = new SmartHouseService(); await smartHouseService.TurnOnAirConditioner(); }