private async void buttSubmit_Clicked(object sender, EventArgs e) { double num; var num_text = txtNumber.Text.Trim(); if (num_text == "pi") { num = pi; } else if (num_text == "e") { num = euler; } else if (!double.TryParse(num_text, out num)) { await DisplayAlert("Invalid", "There was an error parsing the number", "Ok"); return; } int count; if (!int.TryParse(txtIterations.Text, out count)) { await DisplayAlert("Invalid", "There was an error parsing the iterations", "Ok"); return; } ContinuedFractionResponse resp = await WebServiceCom.POSTContinuedFractionRequest(num, count); if (resp == null) { await DisplayAlert("Server Error", "There was an issue communicating the server", "Ok"); return; } else if (!string.IsNullOrWhiteSpace(resp.ServerResponse)) { await DisplayAlert("Bad Request", resp.ServerResponse, "Ok"); return; } else { txtOutput.Text = convertEnumerableToString(resp.qSequence); } }
public async Task <ContinuedFractionResponse> GetContinuedFractionExpansion(ContinuedFractionRequest rqst) { if (string.IsNullOrWhiteSpace(GlobalVariables.CPP_AppPath) || !File.Exists(GlobalVariables.CPP_AppPath)) { throw new NotImplementedException(); } if (rqst.Number == 0 || rqst.Count == 0) { return(new ContinuedFractionResponse() { ServerResponse = "Missing or invalid inputs." }); } string filename = string.Format("{0}.json", Guid.NewGuid().ToString()); //cant use a static filename when the server is processing multiple requests var info = new ProcessStartInfo(GlobalVariables.CPP_AppPath); info.CreateNoWindow = true; info.Arguments = string.Format("{0} {1} {2} /s", rqst.Number, rqst.Count, filename); var p = Process.Start(info); p.WaitForExit(); ContinuedFractionResponse resp = null; if (File.Exists(filename)) { //the c++ program wont output anything if there were problems using (var sr = new StreamReader(filename)) { var jsonString = await sr.ReadToEndAsync(); try { resp = JsonConvert.DeserializeObject <ContinuedFractionResponse>(jsonString); } catch (Exception ex) { resp = new ContinuedFractionResponse() { ServerResponse = ex.Message }; } } //delete the file now to save room when processing multiple requests try { File.Delete(filename); } catch (Exception ex) { } } else { resp = new ContinuedFractionResponse() { ServerResponse = "There was an issue processing the request." }; } return(resp); }