public static void Lookup(String text) { new Thread(new ThreadStart(() => { String url = "http://api.wordnik.com//v4/word.json/" + Uri.EscapeDataString(text.ToLower()) + "/definitions?includeRelated=false&includeTags=false&limit=5&sourceDictionaries=all&useCanonical=false"; WebRequest request = WebRequest.Create(url); request.Headers.Add("api_key", "0f69e2f981991cfe0e1351afd6a2d39da10077112d21165be"); try { using (WebResponse response = request.GetResponse()) using (Stream stream = response.GetResponseStream()) { DataContractJsonSerializer json = new DataContractJsonSerializer(typeof(DictionaryResultCollection)); DictionaryResultCollection result = (DictionaryResultCollection)json.ReadObject(stream); result.org_text = text; result.result_type = "exact"; RESULTS.Enqueue(result); } } catch { RESULTS.Enqueue(new DictionaryResultCollection { result_type = String.Empty, org_text = text }); } })).Start(); }
public static void Show(DictionaryResultCollection dict) { if (dict.result_type != "exact" || dict.Count == 0) { Server.Print(Template.Text(Category.Define, 0).Replace("+n", dict.org_text)); } else { Server.Print(Template.Text(Category.Define, 1).Replace("+n", dict.org_text)); Server.Print(String.Empty); foreach (DictionaryResult dr in dict) { Server.Print(Template.Text(Category.Define, 2).Replace("+n", dr.text)); } } }