Ejemplo n.º 1
0
        static async Task MainAsync(string[] args)
        {
            ITextProcessor textProcessor;

            Console.WriteLine("Select the sample: ");
            Console.WriteLine("1. Calculator");
            Console.WriteLine("2. Calendar");

            switch (Console.ReadLine() ?? "".Trim())
            {
            case "2":
                Console.WriteLine("Starting the calendar...");
                textProcessor = Calendar.CreateTextProcessor();
                break;

            default:
                Console.WriteLine("Starting the calculator...");
                textProcessor = Calculator.CreateTextProcessor();
                break;
            }

            // Creates an empty context
            var context = new RequestContext();

            string inputText;

            do
            {
                Console.WriteLine();
                Console.Write("> ");
                inputText = Console.ReadLine();

                var sw = Stopwatch.StartNew();

                try
                {
                    await textProcessor.ProcessAsync(inputText, context, CancellationToken.None);
                }
                catch (MatchNotFoundException)
                {
                    Console.WriteLine("There's no match for the specified input");
                }
                catch (ArgumentException)
                {
                    break;
                }

                sw.Stop();

#if DEBUG
                Console.WriteLine("Elapsed: {0} ms ({1} ticks)", sw.ElapsedMilliseconds, sw.ElapsedTicks);
#endif
            } while (!string.IsNullOrWhiteSpace(inputText));
        }