Esempio n. 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RemoveCommandHandler"/> class.
 /// </summary>
 /// <param name="service">Type of services.</param>
 public RemoveCommandHandler(IFIleCabinetService service)
     : base(service)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="FindCommandHandler"/> class.
 /// </summary>
 /// <param name="service">Type of services.</param>
 /// <param name="printer">Type of printing.</param>
 public FindCommandHandler(IFIleCabinetService service, Action <IEnumerable <FileCabinetRecord> > printer)
     : base(service)
 {
     this.printer = printer;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CreateCommandHandler"/> class.
 /// </summary>
 /// <param name="service">Type of services.</param>
 public CreateCommandHandler(IFIleCabinetService service)
     : base(service)
 {
 }
Esempio n. 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ExportCommandHandler"/> class.
 /// </summary>
 /// <param name="service">Type of services.</param>
 public ExportCommandHandler(IFIleCabinetService service)
     : base(service)
 {
 }
Esempio n. 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PurgeCommandHandler"/> class.
 /// </summary>
 /// <param name="service">Type of services.</param>
 public PurgeCommandHandler(IFIleCabinetService service)
     : base(service)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="StatCommanHandler"/> class.
 /// </summary>
 /// <param name="service">Type of services.</param>
 public StatCommanHandler(IFIleCabinetService service)
     : base(service)
 {
 }
Esempio n. 7
0
        /// <summary>
        /// Start of execution.
        /// </summary>
        /// <param name="args">Arguments.</param>
        public static void Main(string[] args)
        {
            if (args != null && args.Length != 0)
            {
                ArgsProcessing(args);
            }

            var builder = new ConfigurationBuilder().AddJsonFile("validation-rules.json").Build();

            if (ValidationType != "default" && ValidationType != "custom")
            {
                ValidationType = "default";
            }

            if (ValidationType == "default")
            {
                var config = builder.GetSection("DefaultValidationRules").Get <DefaultValidationRules>();
                validator = new ValidatorBuilder().CreateDefault(config.FirstName.Min, config.FirstName.Max, config.LastName.Min, config.LastName.Max, config.DateOfBirth.YearFrom);
            }
            else
            {
                var config = builder.GetSection("CustomValidationRules").Get <CustomValidationRules>();
                validator = new ValidatorBuilder().CreateCustom(config.FirstName.Min, config.FirstName.Max, config.LastName.Min, config.LastName.Max, config.DateOfBirth.YearFrom);
            }

            if (StorageType == "memory")
            {
                fileCabinetService = new FileCabinetMemoryService(validator);
            }
            else
            {
                using FileStream fileStream = File.Open("cabinet-records.db", FileMode.OpenOrCreate);
                fileStream.Close();
                fileCabinetService = new FileCabinetFilesystemService(fileStream, validator);
            }

            if (UseStopwatch == "on")
            {
                fileCabinetService = new ServiceMeter(fileCabinetService);
            }

            if (UseLogger == "on")
            {
                fileCabinetService = new ServiceLogger(fileCabinetService);
            }

            Console.WriteLine($"File Cabinet Application, developed by {Program.DeveloperName}");
            Console.WriteLine($"Using '{ValidationType}' validation rules");
            Console.WriteLine($"Using '{StorageType}' storage type");
            Console.WriteLine(Program.HintMessage);
            Console.WriteLine();

            do
            {
                Console.Write("> ");
                var       inputs       = Console.ReadLine().Split(' ', 2);
                const int commandIndex = 0;
                var       command      = inputs[commandIndex];

                if (string.IsNullOrEmpty(command))
                {
                    Console.WriteLine(Program.HintMessage);
                    continue;
                }

                var       commandHandler  = CreateCommandHandlers();
                const int parametersIndex = 1;
                var       parameters      = inputs.Length > 1 ? inputs[parametersIndex] : string.Empty;
                commandHandler.Handle(new AppCommandRequest(command, parameters));
            }while (isRunning);
        }
Esempio n. 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ServiceLogger"/> class.
 /// </summary>
 /// <param name="fileCabinetService">File cabinet service.</param>
 public ServiceLogger(IFIleCabinetService fileCabinetService)
 {
     this.fileCabinetService = fileCabinetService;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ServiceCommandHandlerBase"/> class.
 /// </summary>
 /// <param name="service1">Type of services.</param>
 public ServiceCommandHandlerBase(IFIleCabinetService service1)
 {
     service = service1;
 }