コード例 #1
0
        public UnhandledExceptionHelper(Calculator calc)
        {
            if (!AppDomain.CurrentDomain.IsDefaultAppDomain())
            {
                throw new InvalidOperationException("This implementation can only be used in the default AppDomain");
            }

            if (!s_initialized)
            {
                s_domains = new Dictionary<AppDomain, AddInToken>();
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            }
            AddInController controller = AddInController.GetAddInController(calc);
            s_domains.Add(controller.AppDomain, controller.Token);
        }
コード例 #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;
        }