public static void Main(string[] args)
        {
            PrintIntroduction();

            LineEditor  editor    = new LineEditor("Bing Dictionary");
            var         dic       = new BingDictionary();
            var         sounder   = new Sounder();
            QueryResult LastQuery = null;

            while (true)
            {
                string line = editor.Edit("> ", string.Empty);
                if (line == null)
                {
                    break;
                }
                else
                {
                    line = line.Trim();
                    if (line.Length == 0)
                    {
                        continue;
                    }
                    else if (line == "-q")
                    {
                        break;
                    }
                    else if (line == "-a" || line == "-b")
                    {
                        if (LastQuery != null)
                        {
                            sounder.PronounceWord(line, LastQuery);
                        }
                        else
                        {
                            Console.WriteLine("No query history.");
                        }
                    }
                    else
                    {
                        LastQuery = dic.SearchWord(line);
                    }
                }
            }
        }
예제 #2
0
 static int Main(string[] args)
 {
     try
     {
         if (args.Length == 0 || args[0] == "/?")
         {
             var fileName = AppDomain.CurrentDomain.SetupInformation.ApplicationName;
             fileName = fileName.Substring(0, fileName.LastIndexOf('.')).ToUpper();
             Usage(fileName);
         }
         else
         {
             var str = string.Empty;
             for (var i = 0; i < args.Length; i++)
             {
                 if (i > 0)
                 {
                     str += " ";
                 }
                 str += args[i];
             }
             var dict   = new BingDictionary();
             var result = dict.SearchWord(str);
             if (result != null)
             {
                 dict.PrintResult(result);
             }
             else
             {
                 Console.WriteLine("无法翻译单词:{0}", str);
             }
         }
     }
     catch (WebException)
     {
         Console.WriteLine("网络连接超时!");
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.ToString());
         return(1);
     }
     return(0);
 }