private async Task <EE> FetchWordExamplesAsync(HttpClient client, String uri) { EE Itemss = null; var response = await client.GetAsync(uri); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); Itemss = JsonConvert.DeserializeObject <EE>(content); } return(Itemss); }
private async void OnNewGameWord(object sender, EventArgs e) { try // exception thrown when jsonA.assoc_word.Count is zero or the Deserialize gives error { if (gstate == gamestate.end) { string sfrS = sfr.Value.ToString(); //word set rating in the Slider control string log = json.word + "," + H1.Text + "," + H2.Text + "," + H3.Text + "," + H4.Text + "," + H5.Text + "," + sfrS; WriteSetAsync2("https://xxxx.azurewebsites.net/api/HttpPOST-CRUD-guessSetRating", log); H1.Text = H2.Text = H3.Text = H4.Text = H5.Text = "- - -"; Guess_label.Text = "**s*e*c*r*e*t w*o*r*d**"; HCount.Text = ""; ExampleS1.Text = "<Example Sentence>"; ExampleS2.Text = "<Example Sentence>"; windex = 0; gstate = gamestate.start; phoneNumberText.Text = ""; sfr.Value = 0.22; letter_counter = 0; } if (gstate == gamestate.start) { //String url = "https://wordsapiv1.p.mashape.com/words/?random=true&frequencymin=7.99"; url = "http://api.wordnik.com:80/v4/words.json/randomWord?hasDictionaryDef=false&minCorpusCount=20000&maxCorpusCount=-1&minDictionaryCount=5&maxDictionaryCount=-1&minLength=4&maxLength=-1&api_key=a2a73e7b926c924fad7001ca3111acd55af2ffabf50eb"; json = (RW) await FetchWordAsync(client, url); Guess_label.Text = underline(json.word); phoneNumberText.Text = "<Type your guess for the secret word here>"; //url = "https://twinword-word-graph-dictionary.p.mashape.com/association/?entry=" + json.word; url = "https://api.twinword.com/api/v4/word/associations/?entry=" + json.word; url2 = "https://wordsapiv1.p.mashape.com/words/" + json.word + "/examples"; try { jsonAAWS = (AAWS) await FetchWordAWSAsync(client1, url); jsonE = (EE) await FetchWordExamplesAsync(client, url2); } catch (Exception ex) { jsonAAWS = null; jsonE = null; gstate = gamestate.end; System.Diagnostics.Debug.WriteLine(ex); //this.DisplayAlert("EXCEPTION", "Exception thrown for " + json.word + jsonE.ToString(), "Yes", "No"); } if (jsonAAWS == null) { gstate = gamestate.end; } else if (jsonAAWS.associations_scored.Count > 0) { gstate = gamestate.ingame; HCount.Text = jsonAAWS.associations_scored.Count.ToString(); aws = orderAWs(jsonAAWS.associations_scored); } else { gstate = gamestate.end; } } if (gstate == gamestate.ingame) { if ((windex < jsonAAWS.associations_scored.Count) && (windex < 5)) { if (windex == 0) { H1.Text = aws[windex]; } else if (windex == 1) { H2.Text = aws[windex]; phoneNumberText.Text = ""; } else if (windex == 2) { H3.Text = aws[windex]; } else if (windex == 3) { H4.Text = aws[windex]; } else if (windex == 4) { H5.Text = aws[windex]; } windex++; } else if (((windex == jsonAAWS.associations_scored.Count) || (windex == 5)) && (jsonE != null) && (jsonE.examples != null) && (jsonE.examples.Count > 0)) { ExampleS1.Text = blankTheWord(jsonE.examples.First(), json.word) + "."; windex++; } else if (((windex == (jsonAAWS.associations_scored.Count) + 1) || (windex == 6)) && (jsonE != null) && (jsonE.examples != null) && (jsonE.examples.Count > 1)) { ExampleS2.Text = blankTheWord(jsonE.examples[1], json.word) + "."; windex++; } else if (letter_counter < json.word.Length) { Guess_label.Text = set_letter_clue(); //based on json.word and letter_counter letter_counter++; } else { gstate = gamestate.end; Guess_label.Text = json.word; } } } catch (Exception ex) { //this.DisplayAlert("EXCEPTION", "Exception thrown for " + json.word + jsonE.ToString(), "Yes", "No"); Console.WriteLine("\nMessage ---\n{0}", ex.Message); System.Diagnostics.Debug.WriteLine(ex); } }