Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            // Register instances
            _serviceProvider = AutofacSetup.RegisterServices(_serviceProvider);


            // Get starting point
            var calculate = _serviceProvider.GetService <ICalculate>();

            try
            {
                bool run = true;
                while (run)
                {
                    run = calculate.Execute();

                    // Rerun until press esc
                    Console.ForegroundColor = ConsoleColor.Blue;
                    Console.WriteLine("Press ESC to exit or any other key to continue.");
                    if (Console.ReadKey().Key == ConsoleKey.Escape)
                    {
                        run = false;
                    }
                }
            }
            catch (Exception e)
            {
                Console.ForegroundColor = ConsoleColor.DarkRed;

                var isCustomError = e.GetType().GetInterface("IApplicationException") != null;
                if (isCustomError)
                {
                    Console.WriteLine(e.Message);
                }
                else
                {
                    Log.Error(e, e.StackTrace);
                    Console.WriteLine("An unexpected error occured please refer to your Administrator.");
                }
            }

            AutofacSetup.DisposeServices(_serviceProvider);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            _serviceProvider = AutofacSetup.RegisterServices(_serviceProvider);

            var calculateTempratures = _serviceProvider.GetService <ICalculateTempratures>();

            try
            {
                var result = calculateTempratures.Execute();
            }
            catch (Exception e)
            {
                // todo: It should be written in a log file and keep continue to program based on exception type.
                Console.ForegroundColor = ConsoleColor.DarkRed;
                Console.WriteLine(e.Message.ToString());
                Console.WriteLine("Please restart the program.");
            }

            Console.ReadKey();
            AutofacSetup.DisposeServices(_serviceProvider);
        }