Esempio n. 1
0
        public ConfigServiceControllerTest()
        {
            // arrange
            _stringWriter = new StringWriter();
            Console.SetOut(_stringWriter);
            var loggerService = new ConsoleLoggerService();

            _storageService = new LocalStorageService(Constants.ConfigsFileLocalDirectory);

            // act
            _controller = new ConfigsController(loggerService, _storageService);
        }
Esempio n. 2
0
        // TODO: Refactor unhandled exception handler
        // Where to place universal exception handler ?
        static void UnhandledExceptionTrapper(object sender, UnhandledExceptionEventArgs e)
        {
            ILoggerService loggerService = new ConsoleLoggerService();
            Exception      ex            = e.ExceptionObject as Exception;

            if (ex is CliException)
            {
                loggerService.LogError(ex);
            }
            else if (ex?.InnerException is CliException)
            {
                loggerService.LogError(ex.InnerException);
            }
            else if (ex?.InnerException?.InnerException is CliException)
            {
                loggerService.LogError(ex.InnerException.InnerException);
            }
            else
            {
                loggerService.LogError(ex);
            }
            Environment.Exit(1);
        }
        public static void Main(string[] args)
        {
            ILoggerService logger    = null;
            IAlgorithm     algorithm = null;

            //Read file
            Console.WriteLine("Please provide a file name:");
            var fileName = Console.ReadLine();

            if (String.IsNullOrEmpty(fileName))
            {
                Console.WriteLine("Please provide a file name.");
                return;
            }

            if (!File.Exists(fileName))
            {
                Console.WriteLine($"File {fileName} is not found.");
                Console.ReadKey();
                return;
            }

            var(rules, facts, goal) = ReadFromFile(fileName);

            //Choose output method
            Console.WriteLine("Please choose output method by typing:");
            Console.WriteLine("1. Console");
            Console.WriteLine("2. File");

            var outputSelection = Convert.ToChar(Console.ReadLine());

            if (outputSelection != '1' && outputSelection != '2')
            {
                Console.WriteLine($"{outputSelection} is not a valid output method. Please try again.");
                Console.ReadKey();
                return;
            }

            switch (outputSelection)
            {
            case '1':
                logger = new ConsoleLoggerService();
                break;

            case '2':
                Console.WriteLine("Please provide output file name:");
                var outputFileName = Console.ReadLine();
                if (String.IsNullOrEmpty(outputFileName))
                {
                    Console.WriteLine("Please provide a file name.");
                    return;
                }

                logger = new FileLoggerService(outputFileName);
                break;
            }

            //Choose algorithm
            Console.WriteLine("Please choose the algorithm:");
            Console.WriteLine("1. Forwards chaining");
            Console.WriteLine("2. Backwards chaining");

            var algorithmSelection = Convert.ToChar(Console.ReadLine());

            if (algorithmSelection != '1' && algorithmSelection != '2')
            {
                Console.WriteLine($"{algorithmSelection} is not a algorithm. Please try again.");
                Console.ReadKey();
                return;
            }

            switch (algorithmSelection)
            {
            case '1':
                algorithm = new ForwardsChainingAlgorithm(rules, facts, goal, logger);
                break;

            case '2':
                algorithm = new BackwardsChainingAlgorithm(rules, facts, goal, logger);
                break;
            }

            //Execute
            algorithm.Execute();
            algorithm.Dispose();

            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }