示例#1
0
        private static bool CommonValidateInfo <T, K>(T validator, K value) where T : IValidator <K>
        {
            var result = validator.Validate(value);

            if (result.IsValid)
            {
                return(false);
            }

            bool retry = false;

            foreach (var item in result.Errors)
            {
                Consol.WriteLineColor(ConsoleColor.Red, item.ErrorMessage);
                if (item.ErrorCode == Constants.EXIT)
                {
                    throw new ExitException();
                }
                else if (item.ErrorCode == Models.Constants.ErrorCodes.RETRY)
                {
                    retry = true;
                }
            }

            return(retry);
        }
示例#2
0
        public static void Main(string[] args)
        {
            try
            {
                do
                {
                    Console.Clear();
                    Consol.WriteLineColor(ConsoleColor.Cyan, $"[Paşa Yazıcı]");
                    Consol.WriteLineColor(ConsoleColor.Cyan, $"[[email protected]]");
                    Consol.WriteLineColor(ConsoleColor.Cyan, $"[532 654 10 50]\r\n");
                    Consol.WriteLineColor(ConsoleColor.White, $"______________________________________________________________");
                    Consol.WriteLineColor(ConsoleColor.Yellow, ConsoleColor.Red, $"Type \"[{Constants.START}]\" to start the rover.");
                    Consol.WriteLineColor(ConsoleColor.Yellow, ConsoleColor.Red, $"Type \"[{Constants.EXIT}]\" to exit the application.");
                    Consol.WriteLineColor(ConsoleColor.White, $"______________________________________________________________\r\n\r\n");

                    var planetModel = GetParameters();
                    IRoverCommandService planetService = new RoverCommandService(planetModel);
                    var planetResult = planetService.Run();

                    Consol.WriteLineColor(ConsoleColor.White, $"\r\n\r\n_______________________RESULT_________________________________\r\n\r\n");
                    planetResult.ForEach(p =>
                    {
                        switch (p.VerboseType)
                        {
                        case ResultType.Warn:
                            Consol.WriteLineColor(ConsoleColor.Yellow, p.Verbose);
                            break;

                        case ResultType.Error:
                            Consol.WriteLineColor(ConsoleColor.Red, p.Verbose);
                            break;

                        case ResultType.Success:
                            Consol.WriteLineColor(ConsoleColor.Green, p.Verbose);
                            break;

                        case ResultType.Info:
                        default:
                            Consol.WriteLineColor(ConsoleColor.White, p.Verbose);
                            break;
                        }
                    });
                    Consol.WriteLineColor(ConsoleColor.White, $"\r\n\r\n______________________________________________________________\r\n\r\n");
                } while (IsRestart());
            }
            catch (ExitException) { }
            catch (Exception ex)
            {
                Consol.WriteLineColor(ConsoleColor.Red, $"Unhandled exception. [Error: {ex.Message}]");
            }
            finally
            {
                Consol.WriteLineColor(ConsoleColor.White, $"Press any key to exit");
                Console.ReadKey();
            }
        }