//Compile the code using JDoodle API public async void compile(string code, string Stdin, string lang, string vers) { string contentString; Models.Secrets secrets = new Models.Secrets(); Models.CompileModels.Input input = new Models.CompileModels.Input() { clientId = secrets.JDOODLE_clientId, clientSecret = secrets.JDOODLE_clientSecret, script = code, stdin = Stdin, language = lang, versionIndex = vers, }; HttpClient client = new HttpClient(); string Url = "https://api.jdoodle.com/execute"; var response = await client.PostAsync(Url, new StringContent(JsonConvert.SerializeObject(input), Encoding.UTF8, "application/json")); if (response.IsSuccessStatusCode) { //await DisplayAlert("POST Request Successful", "", "OK"); contentString = await response.Content.ReadAsStringAsync(); await DisplayTextAsync(JObject.Parse(contentString).ToString()); } else { await DisplayAlert("POST Request Failed", "", "OK"); } }
//Uses the Read API on the image to extract text from images images public async void ReadText(string imageFilePath) { try { Models.Secrets secrets = new Models.Secrets(); string subscriptionKey = secrets.READ_subscriptionKey; string uriBase = secrets.READ_endpoint + "/vision/v3.0/read/analyze"; //await DisplayAlert("Start Read API", "Best Of Luck", "Thanks"); HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", subscriptionKey); string url = uriBase; HttpResponseMessage response; string operationLocation; byte[] byteData = GetImageAsByteArray(imageFilePath); using (ByteArrayContent content = new ByteArrayContent(byteData)) { content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); response = await client.PostAsync(url, content); } if (response.IsSuccessStatusCode) { //await DisplayAlert("POST Request Successful", "", "OK"); operationLocation = response.Headers.GetValues("Operation-Location").FirstOrDefault(); } else { string errorString = await response.Content.ReadAsStringAsync(); await DisplayAlert("\n\nResponse:\n{0}\n", JToken.Parse(errorString).ToString(), "OK"); return; } string contentString; int i = 0; do { System.Threading.Thread.Sleep(1000); response = await client.GetAsync(operationLocation); contentString = await response.Content.ReadAsStringAsync(); ++i; }while (i < 60 && contentString.IndexOf("\"status\":\"succeeded\"") == -1); if (i == 60 && contentString.IndexOf("\"status\":\"succeeded\"") == -1) { await DisplayAlert("\nTimeout error.\n", "", "OK"); return; } await DisplayTextAsync(JObject.Parse(contentString).ToString()); } catch (Exception e) { await DisplayAlert("Error", "\n" + e.Message, "OK"); } }
private async void shareButton_Clicked(object sender, EventArgs e) { if (Connectivity.NetworkAccess == NetworkAccess.None) { await DisplayAlert("No Network Available", "Please Connect To Your Wifi Or Turn on Mobile Data", "OK"); } else { string emailContentBody = "Thank you for using CodeCapture.\n\n-----\n\nThe Code you scanned was:\n\n" + saveCode + "\n\n-----\n\nYour Standard Input was:\n\n" + saveStdin + "\n\n-----\n\nThe Result you got was:\n\n" + result; string msgContentBody = "Thank you for using CodeCapture. The Result you got was:\n\n" + result; Models.Secrets secrets = new Models.Secrets(); if (!string.IsNullOrEmpty(emailID.Text)) { try { MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com"); mail.From = new MailAddress(secrets.EMAIL_address); mail.To.Add(emailID.Text.Trim()); mail.Subject = "CodeCapture Scan"; mail.Body = emailContentBody; SmtpServer.Port = 587; SmtpServer.Host = "smtp.gmail.com"; SmtpServer.EnableSsl = true; SmtpServer.UseDefaultCredentials = false; SmtpServer.Credentials = new System.Net.NetworkCredential(secrets.EMAIL_address, secrets.EMAIL_password); SmtpServer.Send(mail); await DisplayAlert("Email Sent Succesfully", "", "OK"); } catch (Exception err) { await DisplayAlert("Failed To Send Email", err.Message, "OK"); } } if (!string.IsNullOrEmpty(phoneNumber.Text)) { try { string accountSid = secrets.TWILIO_accountSID; string authToken = secrets.TWILIO_authToken; TwilioClient.Init(accountSid, authToken); var message = MessageResource.Create( body: msgContentBody, from: new Twilio.Types.PhoneNumber(secrets.TWILIO_phoneNumber), to: new Twilio.Types.PhoneNumber(phoneNumber.Text.Trim()) ); if (!(message.ErrorCode == null)) { await DisplayAlert("Failed To Send SMS", "", "OK"); } else { await DisplayAlert("SMS Sent Succesfully", "", "OK"); } } catch (Exception err) { await DisplayAlert("Failed To Send SMS", err.Message, "OK"); } } } }