示例#1
0
        private static AddInToken ChooseCalculator(Collection <AddInToken> tokens)
        {
            List <AddInToken> unreliableTokens = UnhandledExceptionHelper.GetUnreliableTokens();

            if (tokens.Count == 0)
            {
                Console.WriteLine("No calculators are available");
                return(null);
            }
            Console.WriteLine("Available Calculators: ");
            for (int i = 0; i < tokens.Count; i++)
            {
                String warning = "";
                if (unreliableTokens.Contains(tokens[i]))
                {
                    warning = "{ Possibly Unreliable }";
                }
                Console.WriteLine(String.Format("\t{0}. {1}{2}", (i + 1).ToString(), tokens[i].Name, warning));
            }
            Console.WriteLine("Which calculator do you want to use?");
            String line = Console.ReadLine();
            int    selection;

            if (Int32.TryParse(line, out selection))
            {
                if (selection <= tokens.Count)
                {
                    return(tokens[selection - 1]);
                }
            }
            Console.WriteLine("Invalid selection: {0}. Please choose again.", line);
            return(ChooseCalculator(tokens));
        }
示例#2
0
        private static bool RunCalculator(Calculator calc)
        {
            if (calc == null)
            {
                //No calculators were found, read a line and exit
                Console.ReadLine();
            }
            UnhandledExceptionHelper.LogUnhandledExceptions(calc);
            Console.WriteLine("Available operations: " + calc.Operations);
            Console.WriteLine("Type \"exit\" to exit, type \"reload\" to reload");
            String line = Console.ReadLine();

            while (!line.Equals("exit"))
            {
                if (line.Equals("reload"))
                {
                    return(true);
                }
                //We have a very simple parser, if anything unexpected happens just ask the user to try again.
                try
                {
                    Command c = new Command(line);
                    Console.WriteLine(calc.Operate(new MyOperate(c.Action, c.A, c.B)));
                }
                catch
                {
                    Console.WriteLine("Invalid command: {0}. Commands must be formated: [number] [operation] [number]", line);
                    Console.WriteLine("Available operations: " + calc.Operations);
                }

                line = Console.ReadLine();
            }

            return(false);
        }
示例#3
0
 void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
 {
     UnhandledExceptionHelper.AddTokenToUnreliableList(_token);
 }