private async void Button_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) { try { Busy.SetBusy(true, "Checking Usage"); var dataList = await Pronto.DataUsage(); if (dataList.errorList.Count == 0) { dataLimit.Text = dataList.planList[0].ToString(); dataStartDate.Text = dataList.planList[1].ToString(); dataEndDate.Text = dataList.planList[2].ToString(); dataTime.Text = dataList.usageList[0].ToString(); dataUploaded.Text = dataList.usageList[1].ToString(); dataDownloaded.Text = dataList.usageList[2].ToString(); dataTotal.Text = dataList.usageList[3].ToString(); Busy.SetBusy(false); StorageFolder localFolder = ApplicationData.Current.LocalFolder; StorageFile sampleFile = await localFolder.CreateFileAsync("dataUsage.txt", CreationCollisionOption.ReplaceExisting); ////Read the first line of dataFile.txt in LocalFolder and store it in a String //StorageFile sampleFiile = await localFolder.GetFileAsync("dataFittlee.txt"); //IList<string> fileContent = await FileIO.ReadLinesAsync(sampleFiile); // Read complex/large objects var helper = new LocalObjectStorageHelper(); await helper.SaveFileAsync(keyLargeObject, dataList); Pronto.ValueTileUpdater(dataList.usageList[2].ToString()); } else { Busy.SetBusy(false); MainPage.ShowDialog(dataList.errorList[0]); } } catch (System.Exception) { Busy.SetBusy(false); return; } }
public async void Run(IBackgroundTaskInstance taskInstance) { // Create the deferral by requesting it from the task instance serviceDeferral = taskInstance.GetDeferral(); AppServiceTriggerDetails triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails; if (triggerDetails != null && triggerDetails.Name.Equals("VoiceCommandService")) { voiceServiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails); VoiceCommand voiceCommand = await voiceServiceConnection.GetVoiceCommandAsync(); // Perform the appropriate command depending on the operation defined in VCD switch (voiceCommand.CommandName) { case "Login": string loginMessage; bool loginlevel = await Pronto.GetNetworkLevelUsingGoogle(); if (loginlevel) { loginMessage = " You are already Connected "; } else { var networkName = await Network.Pronto.GetNetwoksSSid(); if (networkName.Equals("OK")) { loginMessage = await Pronto.Login(); } else { loginMessage = "You are Not Connected To Vit 2.4G"; } } VoiceCommandUserMessage userLoginMessage = new VoiceCommandUserMessage(); userLoginMessage.DisplayMessage = loginMessage; userLoginMessage.SpokenMessage = loginMessage; VoiceCommandResponse loginResponse = VoiceCommandResponse.CreateResponse(userLoginMessage, null); await voiceServiceConnection.ReportSuccessAsync(loginResponse); break; case "Logout": string logoutMessage; bool level = await Pronto.GetNetworkLevelUsingGoogle(); if (!level) { logoutMessage = " You are already Disconnected "; } else { var networkName = await Network.Pronto.GetNetwoksSSid(); if (networkName.Equals("OK")) { logoutMessage = await Pronto.Logout(); } else { logoutMessage = "You are Not Connected To Vit 2.4G"; } } VoiceCommandUserMessage userLogoutMessage = new VoiceCommandUserMessage(); userLogoutMessage.DisplayMessage = logoutMessage; userLogoutMessage.SpokenMessage = logoutMessage; VoiceCommandResponse logoutResponse = VoiceCommandResponse.CreateResponse(userLogoutMessage, null); await voiceServiceConnection.ReportSuccessAsync(logoutResponse); break; case "Usage": string dataMessage; bool usageLevel = await Pronto.GetNetworkLevelUsingGoogle(); if (!usageLevel) { dataMessage = "Sorry Internet is Unavialable"; } else { var data = await Pronto.DataUsage(); if (data.errorList.Count == 0) { var consumed = data.usageList[2]; dataMessage = string.Format("Your Monthly Data Consumed is :" + consumed); } else { dataMessage = "Sorry" + data.errorList[0]; } } VoiceCommandUserMessage userDataMessage = new VoiceCommandUserMessage(); userDataMessage.DisplayMessage = dataMessage; userDataMessage.SpokenMessage = dataMessage; VoiceCommandResponse dataUsageResponse = VoiceCommandResponse.CreateResponse(userDataMessage, null); await voiceServiceConnection.ReportSuccessAsync(dataUsageResponse); break; default: break; } } // Once the asynchronous method(s) are done, close the deferral serviceDeferral.Complete(); }