public static void Show(UrbanDictionaryResult urban) { if (urban.result_type != "exact" || urban.list.Count == 0) { Server.Print(Template.Text(Category.UrbanDictionary, 0).Replace("+n", urban.org_text)); } else { Server.Print(Template.Text(Category.UrbanDictionary, 1).Replace("+n", urban.org_text)); Server.Print(String.Empty); String[] def = urban.list[0].definition.Split(new String[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); foreach (String str in def) { Server.Print(Template.Text(Category.UrbanDictionary, 2).Replace("+n", str)); } String[] eg = urban.list[0].example.Split(new String[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); if (eg.Length > 0) { Server.Print(String.Empty); Server.Print(Template.Text(Category.UrbanDictionary, 3).Replace("+n", urban.org_text)); Server.Print(String.Empty); foreach (String str in eg) { Server.Print(Template.Text(Category.UrbanDictionary, 4).Replace("+n", str)); } } } }
public static void Lookup(String text) { new Thread(new ThreadStart(() => { String url = "http://www.urbandictionary.com/iphone/search/define?term=" + Uri.EscapeDataString(text); WebRequest request = WebRequest.Create(url); try { using (WebResponse response = request.GetResponse()) using (Stream stream = response.GetResponseStream()) { DataContractJsonSerializer json = new DataContractJsonSerializer(typeof(UrbanDictionaryResult)); UrbanDictionaryResult result = (UrbanDictionaryResult)json.ReadObject(stream); result.org_text = text; RESULTS.Enqueue(result); } } catch { RESULTS.Enqueue(new UrbanDictionaryResult { result_type = String.Empty, org_text = text }); } })).Start(); }