private async void metroBtnSearchForAWord_Click(object sender, EventArgs e) { if (!(metroTxtWordToSearch.Text == "")) { WordDefinition wordDefinition = null; metroPanelLoad.Visible = true; wordDefinition = await Task.Run(() => service.Define(metroTxtWordToSearch.Text)); rtxtWordDefn.Text = String.Format("Word Searched: \n\t{0}\n\nTotal No of Definition: {1}\n", wordDefinition.Word, wordDefinition.Definitions.Length); int c = 0; foreach (Definition definition in wordDefinition.Definitions) { rtxtWordDefn.Text += String.Format("{0}) Dictionary: {1}\n\t Definition: {2}\n\n", ++c, definition.Dictionary, definition.WordDefinition); } metroPanelLoad.Visible = false; } }
public static void Define( [Required(Description = "Word to define")] string word, [Optional("", Description = "Dictionary identifier")] string dict, [Optional("", Description = "The url of the proxy server to use for http requests")] string proxy, [Optional("", Description = "The user name to use when the connecting to a proxy server that requires authentication")] string proxyusername, [Optional("", Description = "The password to use when the connecting to a proxy server that requires authentication")] string proxypassword, [Optional("", Description = "The domain to use when the connecting to a proxy server that requires authentication")] string proxydomain ) { try { DictService svc = new DictService(); SetupProxyServer(svc, proxy, proxyusername, proxypassword, proxydomain); WordDefinition wd; if (String.IsNullOrEmpty(dict)) { wd = svc.Define(word); } else { wd = svc.DefineInDict(dict, word); } if (wd.Definitions.Length == 0) { Console.WriteLine("No definitions for {0} found.", word); return; } foreach (Definition d in wd.Definitions) { Console.WriteLine("From {0}:", d.Dictionary.Name); Console.WriteLine(d.WordDefinition); Console.WriteLine(); } } catch (System.Exception e) { Console.WriteLine("Error: {0}", e.Message); } }