private static void RunOption(ConsoleOption opts)
        {
            if (opts.FileSystem.ToUpperInvariant() == "MEMORY")
            {
                fileCabinetService = new FileCabinetMemoryService(recordValidators[opts.Validator.ToUpperInvariant()]);
                inputValidator     = inputValidators[opts.Validator.ToUpperInvariant()];
                Console.WriteLine("Using {0} validation rules.", opts.Validator.ToUpperInvariant());
            }

            if (opts.FileSystem.ToUpperInvariant() == "FILE")
            {
                fileCabinetService = new FileCabinetFileSystemService(recordValidators[opts.Validator.ToUpperInvariant()]);
                inputValidator     = inputValidators[opts.Validator.ToUpperInvariant()];
                Console.WriteLine("Using {0} validation rules.", opts.Validator.ToUpperInvariant());
            }

            if (opts.Watch)
            {
                fileCabinetService = new ServiceMeter(fileCabinetService);
            }

            if (opts.Logger)
            {
                fileCabinetService = new ServiceLogger(fileCabinetService);
            }
        }
        private static void SetFileService()
        {
            FileStream fileStream = new FileStream(Configurator.GetConstantString("DefaultFilesystemFileName"), FileMode.OpenOrCreate, FileAccess.ReadWrite);

            fileCabinetService = new FileCabinetFilesystemService(fileStream);
            Console.WriteLine(Configurator.GetConstantString("UseFile"));
        }
Exemple #3
0
        /// <summary>
        /// Represents the main method.
        /// </summary>
        /// <param name="args">Arguments of command line.</param>
        public static void Main(string[] args)
        {
            Console.WriteLine($"File Cabinet Application, developed by {Program.DeveloperName}");

            // TODO : Implement case intensive arguments
            Parser.Default.ParseArguments <Options>(args)
            .WithParsed(o =>
            {
                if (o.Validation == "default" || o.Validation == default)
                {
                    Console.WriteLine("Using default validation rules.");
                }

                if (o.Validation == "custom")
                {
                    recordValidator = new CustomValidator();
                    Console.WriteLine("Using custom validation rules.");
                }

                // default
                if (o.Storage == "memory")
                {
                    return;
                }

                if (o.Storage == "file")
                {
                    fileCabinetService = new FileCabinetFilesystemService(new FileStream("cabinet-records.db", FileMode.OpenOrCreate));
                }
            });

            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 index = Array.FindIndex(commands, 0, commands.Length, i => i.Item1.Equals(command, StringComparison.InvariantCultureIgnoreCase));
                if (index >= 0)
                {
                    const int parametersIndex = 1;
                    var       parameters      = inputs.Length > 1 ? inputs[parametersIndex] : string.Empty;
                    commands[index].Item2(parameters);
                }
                else
                {
                    PrintMissedCommandInfo(command);
                }
            }while (isRunning);
        }
Exemple #4
0
        /// <summary>
        /// Gathers information about a record.
        /// </summary>
        /// <param name="service">File cabinet service.</param>
        /// <exception cref="ArgumentNullException">Throws when service is null.</exception>
        /// <returns>Record data.</returns>
        public static DataRecord CollectRecordData(IFileCabinetService service)
        {
            if (service is null)
            {
                throw new ArgumentNullException(nameof(service));
            }

            DataRecord       dataRecord = new DataRecord();
            IRecordValidator validator  = service.GetValidator();

            Console.Write("First name: ");
            dataRecord.FirstName = ReadInput(Converter.StringConverter);

            Console.Write("Last Name: ");
            dataRecord.LastName = ReadInput(Converter.StringConverter);

            Console.Write("Date of birth: ");
            dataRecord.DateOfBirth = ReadInput(Converter.DateConverter);

            Console.Write("Access: ");
            dataRecord.Access = ReadInput(Converter.CharConverted);

            Console.Write("Salary: ");
            dataRecord.Salary = ReadInput(Converter.DecimalConverted);

            return(dataRecord);
        }
Exemple #5
0
 private static void SetUpLogger(Options opts)
 {
     if (opts.Log)
     {
         fileCabinetService = new ServiceLogger(fileCabinetService);
     }
 }
Exemple #6
0
 private static void SetUpMeter(Options opts)
 {
     if (opts.Stopwatch)
     {
         fileCabinetService = new ServiceMeter(fileCabinetService);
     }
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SelectCommandHandler"/> class.
 /// DeleteCommandHandler constructor.
 /// </summary>
 /// <param name="cabinetService">fileCabinetService.</param>
 /// <param name="printer">The printer.</param>
 /// <param name="expressionExtensions">expressionExtensions.</param>
 /// <param name="modelWriter">console writer.</param>
 public SelectCommandHandler(IFileCabinetService cabinetService, IExpressionExtensions expressionExtensions, ITablePrinter printer, ModelWriters modelWriter)
     : base(cabinetService)
 {
     this.printer = printer;
     this.expressionExtensions = expressionExtensions;
     this.modelWriter          = modelWriter;
 }
Exemple #8
0
        private static CommandHandlerBase CreateCommandHandlers(IFileCabinetService service)
        {
            var helpCommandHandler        = new HelpCommandHandler();
            var createCommandHandler      = new CreateCommandHandler(service);
            var exitCommandHandler        = new ExitCommandHandler(ChangeRunning, fileStream);
            var exportCommandHandler      = new ExportCommandHandler(service);
            var importCommandHandler      = new ImportCommandHandler(service);
            var purgeCommandHandler       = new PurgeCommandHandler(service);
            var statCommandHandler        = new StatCommandHandler(service);
            var insertCommandHandler      = new InsertCommandHandler(service);
            var deleteCommandHandler      = new DeleteCommandHandler(service);
            var selectCommandHandler      = new SelectCommandHandler(service);
            var updateCommandHandler      = new UpdateCommandHandler(service);
            var printMissedCommandHandler = new PrintMissedCommandHandler();

            helpCommandHandler.SetNext(createCommandHandler);
            createCommandHandler.SetNext(exitCommandHandler);
            exitCommandHandler.SetNext(exportCommandHandler);
            exportCommandHandler.SetNext(importCommandHandler);
            importCommandHandler.SetNext(purgeCommandHandler);
            purgeCommandHandler.SetNext(statCommandHandler);
            statCommandHandler.SetNext(insertCommandHandler);
            insertCommandHandler.SetNext(deleteCommandHandler);
            deleteCommandHandler.SetNext(updateCommandHandler);
            updateCommandHandler.SetNext(selectCommandHandler);
            selectCommandHandler.SetNext(printMissedCommandHandler);
            return(helpCommandHandler);
        }
Exemple #9
0
        private static ICommandHandler CreateCommandHandlers(IFileCabinetService fileCabinetService)
        {
            ICommandHandler createCommandHandler = new CreateCommandHandler(fileCabinetService);
            ICommandHandler updateCommandHandler = new UpdateCommandHandler(fileCabinetService);
            ICommandHandler deleteCommandHandler = new DeleteCommandHandler(fileCabinetService);
            ICommandHandler selectCommand        = new SelectCommandHandler(fileCabinetService, Program.PrinterByFilter);
            ICommandHandler statCommandHandler   = new StatCommandHandler(fileCabinetService);
            ICommandHandler exportCommandHandler = new ExportCommandHandler(fileCabinetService);
            ICommandHandler importCommandHandler = new ImportCommandHandler(fileCabinetService);
            ICommandHandler purgeCommandHandler  = new PurgeCommandHandler(fileCabinetService);
            ICommandHandler helpCommandHandler   = new HelpCommandHandler();
            ICommandHandler exitCommandHandler   = new ExitCommandHandler(Existing);
            ICommandHandler insertCommandHandler = new InsertCommandHandler(fileCabinetService);

            createCommandHandler.SetNext(updateCommandHandler);
            updateCommandHandler.SetNext(deleteCommandHandler);
            deleteCommandHandler.SetNext(selectCommand);
            selectCommand.SetNext(statCommandHandler);
            statCommandHandler.SetNext(exportCommandHandler);
            exportCommandHandler.SetNext(importCommandHandler);
            importCommandHandler.SetNext(purgeCommandHandler);
            purgeCommandHandler.SetNext(helpCommandHandler);
            helpCommandHandler.SetNext(exitCommandHandler);
            exitCommandHandler.SetNext(insertCommandHandler);

            return(createCommandHandler);
        }
Exemple #10
0
 private static void SetDecorators(string[] param, IFileCabinetService service)
 {
     if (string.Equals(param[2], "STOPWATCH", StringComparison.InvariantCultureIgnoreCase) &&
         string.Equals(param[3], "LOGGER", StringComparison.InvariantCultureIgnoreCase))
     {
         Program.fileCabinetService = new ServiceLogger(new ServiceMeter(service));
         Console.WriteLine(LoggerMessage);
         Console.WriteLine(StopwatchMessage);
     }
     else
     {
         if (string.Equals(param[3], "LOGGER", StringComparison.InvariantCultureIgnoreCase))
         {
             Program.fileCabinetService = new ServiceLogger(service);
             Console.WriteLine(LoggerMessage);
         }
         else
         {
             if (string.Equals(param[2], "STOPWATCH", StringComparison.InvariantCultureIgnoreCase))
             {
                 Program.fileCabinetService = new ServiceMeter(service);
                 Console.WriteLine(StopwatchMessage);
             }
             else
             {
                 Program.fileCabinetService = service;
             }
         }
     }
 }
Exemple #11
0
        /// <summary>
        /// Start point for application.
        /// </summary>
        /// <param name="args">Array of command-line keys passed to the program.</param>
        public static void Main(string[] args)
        {
            Console.WriteLine($"File Cabinet Application, developed by {Program.DeveloperName}");
            var handler = new Handler();

            handler.Handle(args);
            fileCabinetService = handler.GetService();
            Console.WriteLine(Program.HintMessage);
            Console.WriteLine();

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

                var commandHandlers = CreateCommandHandlers();

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

                const int parametersIndex = 1;
                string    parameters      = inputs.Length > 1 ? inputs[parametersIndex] : string.Empty;
                commandHandlers.Handle(new AppCommandRequest(command, parameters));
                Console.WriteLine();
            }while (isRunning);
        }
 private static void CreateService()
 {
     if (service.Type.Equals("memory", StringComparison.InvariantCultureIgnoreCase))
     {
         if (service.Validation.Equals("custom", StringComparison.InvariantCultureIgnoreCase))
         {
             fileCabinetService = new FileCabinetMemoryService(new CustomValidator());
         }
         else
         {
             fileCabinetService = new FileCabinetMemoryService(new DefaultValidator());
         }
     }
     else
     {
         if (service.Validation.Equals("custom", StringComparison.InvariantCultureIgnoreCase))
         {
             fileCabinetService = new FileCabinetFilesystemService(new CustomValidator());
         }
         else
         {
             fileCabinetService = new FileCabinetFilesystemService(new DefaultValidator());
         }
     }
 }
Exemple #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ImportCommandHandler"/> class.
 /// </summary>
 /// <param name="cabinetService">The cabinet service.</param>
 /// <param name="xmlValidator">The XSD validator.</param>
 /// <param name="xsdValidatorFile">The XSD validator file.</param>
 /// <param name="modelWriter">console writer.</param>
 public ImportCommandHandler(IFileCabinetService cabinetService, IXmlValidator xmlValidator, string xsdValidatorFile, ModelWriters modelWriter)
     : base(cabinetService)
 {
     this.xsdValidatorFile = xsdValidatorFile;
     this.xmlValidator     = xmlValidator;
     this.modelWriter      = modelWriter;
 }
Exemple #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ServiceLogger"/> class.
 /// </summary>
 /// <param name="service">Service to decorate.</param>
 public ServiceLogger(IFileCabinetService service)
 {
     this.service = service;
     this.writer  = new StreamWriter(Configurator.GetConstantString("DefaultLogFileName"))
     {
         AutoFlush = true,
     };
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CreateCommandHandler"/> class.
 /// </summary>
 /// <param name="fileCabinetService">The file cabinet service.</param>
 /// <param name="inputConverter">The input converter.</param>
 /// <param name="inputValidator">The input validator.</param>
 /// <param name="writeDelegate">The write delegate.</param>
 public CreateCommandHandler(
     IFileCabinetService fileCabinetService, IInputConverter inputConverter, IInputValidator inputValidator, Action <string> writeDelegate)
     : base(fileCabinetService)
 {
     this.converter = inputConverter;
     this.validator = inputValidator;
     write          = writeDelegate;
 }
Exemple #16
0
#pragma warning restore SA1401 // Fields should be private

        /// <summary>
        /// Initializes a new instance of the <see cref="ServiceCommandHandlerBase"/> class.
        /// </summary>
        /// <param name="fileCabinetService">The current service.</param>
        public ServiceCommandHandlerBase(IFileCabinetService fileCabinetService)
        {
            if (fileCabinetService is null)
            {
                throw new ArgumentNullException($"{nameof(fileCabinetService)} cannot be null.");
            }

            this.fileCabinetService = fileCabinetService;
        }
Exemple #17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ServiceLogger"/> class.
        /// </summary>
        /// <param name="service">The service.</param>
        public ServiceLogger(IFileCabinetService service)
        {
            if (service is null)
            {
                throw new ArgumentNullException(nameof(service));
            }

            this.service   = service;
            this.MemEntity = service.MemEntity;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ServiceMeter"/> class.
        /// </summary>
        /// <param name="service">The current service.</param>
        public ServiceMeter(IFileCabinetService service)
        {
            if (service is null)
            {
                throw new ArgumentNullException($"{nameof(service)} cannot be null.");
            }

            this.stopwatch = new Stopwatch();
            this.service   = service;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ServiceCommandHandlerWithSearchProperties"/> class.
        /// </summary>
        /// <param name="fileCabinetService">FileCabinetService.</param>
        protected ServiceCommandHandlerWithSearchProperties(IFileCabinetService fileCabinetService)
            : base(fileCabinetService)
        {
            this.service = fileCabinetService ?? throw new ArgumentNullException(nameof(fileCabinetService));
            var countOfSymbol    = @"{2,}";
            var availableSymbols = @"' .,\\\/";

            this.propertiesRegex = new Regex($" *(?<{RecordGroupName}>(?<{FieldGroupName}>[a-zA-Z]{countOfSymbol}) *= *" +
                                             $"'(?<{ValueGroupName}>[a-zA-Z0-9{availableSymbols}]*)' *(?<{SignGroupName}>($|AND|OR)))+");
        }
Exemple #20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SelectCommandHandler"/> class.
        /// </summary>
        /// <param name="fileCabinetService">The cureent service.</param>
        /// <param name="printer">The current printer.</param>
        public SelectCommandHandler(
            IFileCabinetService fileCabinetService,
            Action <IEnumerable <FileCabinetRecord>, List <string> > printer)
            : base(fileCabinetService)
        {
            if (printer is null)
            {
                throw new ArgumentNullException($"{nameof(printer)} cannot be null.");
            }

            this.printer = printer;
        }
Exemple #21
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ServiceLogger"/> class.
        /// </summary>
        /// <param name="fileCabinetService">Service.</param>
        /// <param name="path">Path.</param>
        public ServiceLogger(IFileCabinetService fileCabinetService, string path)
        {
            this.fileCabinetService = fileCabinetService ?? throw new ArgumentNullException(nameof(fileCabinetService));

            if (path is null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            var stream = File.Exists(path) ? File.OpenWrite(path) : File.Create(path);

            this.writer = new StreamWriter(stream);
        }
Exemple #22
0
        /// <summary>
        /// Method serves to processing parameters application.
        /// </summary>
        /// <param name="args">Parameters for run application.</param>
        public static void ParametersApplication(string[] args)
        {
            foreach (var item in args)
            {
                switch (item.ToUpper(regionalSetting))
                {
                case "--VALIDATION-RULES=CUSTOM":
                    fileCabinetService           = new FileCabinetService(new CustomValidator());
                    validationRule               = "Using custom validation rules.";
                    firstNameValidator           = ValidatorsCustom.FirstNameValidator;
                    dateOfBirthValidator         = ValidatorsCustom.DateOfBirthValidator;
                    succsesfullDealsValidator    = ValidatorsCustom.SuccsesfullDealsValidator;
                    additionCoefficientValidator = ValidatorsCustom.AdditionCoefficientValidator;
                    manegerClassValidator        = ValidatorsCustom.ManegerClassValidator;
                    break;

                case "-V=CUSTOM":
                    fileCabinetService           = new FileCabinetService(new CustomValidator());
                    validationRule               = "Using custom validation rules.";
                    firstNameValidator           = ValidatorsCustom.FirstNameValidator;
                    dateOfBirthValidator         = ValidatorsCustom.DateOfBirthValidator;
                    succsesfullDealsValidator    = ValidatorsCustom.SuccsesfullDealsValidator;
                    additionCoefficientValidator = ValidatorsCustom.AdditionCoefficientValidator;
                    manegerClassValidator        = ValidatorsCustom.ManegerClassValidator;
                    break;

                case "--VALIDATION-RULES=DEFAULT":
                    fileCabinetService           = new FileCabinetService(new DefaultValidator());
                    validationRule               = "Using default validation rules.";
                    firstNameValidator           = ValidatorsDefault.FirstNameValidator;
                    dateOfBirthValidator         = ValidatorsDefault.DateOfBirthValidator;
                    succsesfullDealsValidator    = ValidatorsDefault.SuccsesfullDealsValidator;
                    additionCoefficientValidator = ValidatorsDefault.AdditionCoefficientValidator;
                    manegerClassValidator        = ValidatorsDefault.ManegerClassValidator;
                    break;

                case "-V=DEFAULT":
                    fileCabinetService           = new FileCabinetService(new DefaultValidator());
                    validationRule               = "Using default validation rules.";
                    firstNameValidator           = ValidatorsDefault.FirstNameValidator;
                    dateOfBirthValidator         = ValidatorsDefault.DateOfBirthValidator;
                    succsesfullDealsValidator    = ValidatorsDefault.SuccsesfullDealsValidator;
                    additionCoefficientValidator = ValidatorsDefault.AdditionCoefficientValidator;
                    manegerClassValidator        = ValidatorsDefault.ManegerClassValidator;
                    break;

                default:
                    break;
                }
            }
        }
Exemple #23
0
        /// <summary>
        /// Creates File Cabinet.
        /// </summary>
        private static void CreateFileCabinet()
        {
            IRecordValidator validator = new ValidatorBuilder().CreateDefault();

            if (SettingsApp.FileCabinetType.Equals(typeof(FileCabinetMemoryService)))
            {
                fileCabinetService = new FileCabinetMemoryService(validator, SettingsApp.StartId);
            }
            else if (SettingsApp.FileCabinetType.Equals(typeof(FileCabinetFilesystemService)))
            {
                FileStream fileStream = new FileStream(Settings.FileNameStorage, FileMode.Create, FileAccess.ReadWrite);
                fileCabinetService = new FileCabinetFilesystemService(validator, fileStream, SettingsApp.StartId);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ServiceLogger"/> class.
        /// </summary>
        /// <param name="service">The current service.</param>
        public ServiceLogger(IFileCabinetService service)
        {
            if (service is null)
            {
                throw new ArgumentNullException($"{nameof(service)} cannot be null.");
            }

            this.service = service;

            string path   = "logData.txt";
            var    stream = File.Exists(path) ? File.OpenWrite(path) : File.Create(path);

            this.writer = new StreamWriter(stream);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ServiceLogger"/> class.
        /// </summary>
        /// <param name="service">The current service.</param>
        public ServiceLogger(IFileCabinetService service)
        {
            if (service is null)
            {
                throw new ArgumentNullException($"{nameof(service)} cannot be null.");
            }

            this.service = service;

            string path = @"logData.txt";
            /*E:\GitRepositories\NET.Winter.2020.FileCabinet.Zhurauleu\*/
            var stream = File.Exists(path) ? File.OpenWrite(path) : File.Create(path);

            this.writer = new StreamWriter(stream);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SelectCommandHandler"/> class.
        /// </summary>
        /// <param name="fileCabinetService">FileCabinetService.</param>
        public SelectCommandHandler(IFileCabinetService fileCabinetService)
            : base(fileCabinetService)
        {
            this.selectCommandWithSearchPropertiesRegex = new Regex(
                $"^ *(?<{DisplayedFieldsGroupName}>[a-zA-Z0-9\\W]+) *{WhereSeparator} *" +
                $"(?<{SearchPropertiesGroupName}>[a-zA-Z0-9\\W]+) *$");

            this.selectCommandWithoutSearchPropertiesRegex = new Regex(
                $"(?<{DisplayedFieldsGroupName}>{nameof(FileCabinetRecord.Id).ToUpperInvariant()}|" +
                $"{nameof(FileCabinetRecord.FirstName).ToUpperInvariant()}|" +
                $"{nameof(FileCabinetRecord.LastName).ToUpperInvariant()}|" +
                $"{nameof(FileCabinetRecord.DateOfBirth).ToUpperInvariant()}|" +
                $"{nameof(FileCabinetRecord.Wallet).ToUpperInvariant()}|" +
                $"{nameof(FileCabinetRecord.MaritalStatus).ToUpperInvariant()}|" +
                $"{nameof(FileCabinetRecord.Height).ToUpperInvariant()}|{WordToDisplayAllFields}) *" +
                $"(?<{SignGroupName}>,|$)");
        }
        /// <summary>
        /// Sets the storage rules based on the parameter.
        /// </summary>
        /// <param name="storageRules">Storage rules to set.</param>
        private static void SetStorageRules(string storageRules)
        {
            switch (storageRules)
            {
            case "file":
                FileStream fileStream = new FileStream(FILENAME, FileMode.Create);
                fileCabinetService = new FileCabinetFilesystemService(fileStream, validator);
                serviceType        = "file";

                break;

            default:
                fileCabinetService = new FileCabinetMemoryService(validator);
                serviceType        = "memory";
                break;
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ServiceLogger"/> class.
        /// </summary>
        /// <param name="service">File cabinet service.</param>
        /// <param name="path">The path where the logs will be saved, if null then to the current directory.</param>
        public ServiceLogger(IFileCabinetService service, string path = null)
        {
            if (service is null)
            {
                throw new ArgumentNullException(nameof(service));
            }

            if (string.IsNullOrEmpty(path))
            {
                StringBuilder builder = new StringBuilder();
                builder.Append(Directory.GetCurrentDirectory());
                builder.Append(@"\Logs.txt");
                path = builder.ToString();
            }

            this.service = service;
            this.path    = path;
        }
Exemple #29
0
 private static void SetUpStorage(Options opts)
 {
     if (opts.Storage.Equals("memory", StringComparison.InvariantCultureIgnoreCase))
     {
         fileCabinetService = new FileCabinetMemoryService(recordValidator);
         Console.WriteLine(Source.Resource.GetString("memoryStorage", CultureInfo.InvariantCulture));
     }
     else if (opts.Storage.Equals("file", StringComparison.InvariantCultureIgnoreCase))
     {
         FileStream fileStream;
         fileStream = new FileStream(@"cabinet-records.db", FileMode.Create, FileAccess.ReadWrite);
         var service = fileCabinetService = new FileCabinetFilesystemService(fileStream, recordValidator);
         Console.WriteLine(Source.Resource.GetString("fileStorage", CultureInfo.InvariantCulture));
     }
     else
     {
         throw new ArgumentException(Source.Resource.GetString("invalidStorage", CultureInfo.InvariantCulture));
     }
 }
Exemple #30
0
        private static IFileCabinetService CreateServise(
            string validationRules, ServiceType serviceType, out IInputConverter converter, out IInputValidator validator)
        {
            const string dataFilePath = "cabinet-records.db";

            switch (validationRules)
            {
            case CustomValidationType:
                validator = InputValidatorBuilder.CreateCustom();
                converter = new CustomInputConverter();
                break;

            case DefaultValidationRules:
                validator = InputValidatorBuilder.CreateDefault();
                converter = new DefaultInputConverter();
                break;

            default:
                throw new Exception();
            }

            switch (serviceType)
            {
            case ServiceType.File:
                fileStream         = new FileStream(dataFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                fileCabinetService = (validationRules == CustomValidationType)
                         ? new FileCabinetFilesystemService(fileStream, new ValidatorBuilder().CreateCustom())
                         : new FileCabinetFilesystemService(fileStream, new ValidatorBuilder().CreateDefault());
                break;

            case ServiceType.Memory:
                fileCabinetService = (validationRules == CustomValidationType)
                                ? new FileCabinetMemoryService(new ValidatorBuilder().CreateCustom())
                                : new FileCabinetMemoryService(new ValidatorBuilder().CreateDefault());
                break;

            default:
                throw new Exception();
            }

            return(fileCabinetService);
        }