/// <summary>Creates the command handler.</summary>
        /// <returns>CommandHandler that refers to all the commands via chain of responsibility.</returns>
        private static CommandHandlerBase CreateCommandHandler()
        {
            var createHandler = new CreateCommandHandler(fileCabinetService);
            var purgeHandler  = new PurgeCommandHandler(fileCabinetService);
            var statHandler   = new StatCommandHandler(fileCabinetService);
            var exportHandler = new ExportCommandHandler(fileCabinetService);
            var importHandler = new ImportCommandHandler(fileCabinetService);
            var exitHandler   = new ExitCommandHandler(b => isRunning = b);
            var missedHandler = new MissedCommandHandler();
            var insertHandler = new InsertCommandHandler(fileCabinetService);
            var deleteHandler = new DeleteCommandHandler(fileCabinetService);
            var updateHandler = new UpdateCommandHandler(fileCabinetService);
            var selectHandler = new SelectCommandHandler(fileCabinetService);

            exitHandler.SetNext(missedHandler);
            importHandler.SetNext(exitHandler);
            exportHandler.SetNext(importHandler);
            statHandler.SetNext(exportHandler);
            purgeHandler.SetNext(statHandler);
            createHandler.SetNext(purgeHandler);
            updateHandler.SetNext(createHandler);
            deleteHandler.SetNext(updateHandler);
            selectHandler.SetNext(deleteHandler);
            insertHandler.SetNext(selectHandler);
            return(insertHandler);
        }
Example #2
0
        private static ICommandHandler CreateCommandHandlers()
        {
            var recordPrinter = new Action <List <string>, IEnumerable <FileCabinetRecord> >((x, y) => DefaultRecordPrint(x, y));

            var exitHandler          = new ExitCommandHandler(fileStream, Write, (x) => isRunning = x);
            var helpHandler          = new HelpCommandHandler(Write);
            var createHandle         = new CreateCommandHandler(fileCabinetService, converter, validator, Write);
            var insertHandle         = new InsertCommandHandler(fileCabinetService, Write);
            var updateHandler        = new UpdateCommandHandler(fileCabinetService, Write);
            var exportHandler        = new ExportCommandHandler(fileCabinetService, Write);
            var importHandler        = new ImportCommandHandler(fileCabinetService, Write);
            var deleteHandler        = new DeleteCommandHandler(fileCabinetService, Write);
            var statHandler          = new StatCommandHandler(fileCabinetService, Write);
            var purgeHadler          = new PurgeCommandHandler(fileCabinetService, Write);
            var selectHandler        = new SelectCommandHandler(fileCabinetService, recordPrinter);
            var missedCommandHandler = new SimilarCommandHandler(Write);

            helpHandler
            .SetNext(exitHandler)
            .SetNext(statHandler)
            .SetNext(createHandle)
            .SetNext(insertHandle)
            .SetNext(updateHandler)
            .SetNext(deleteHandler)
            .SetNext(exportHandler)
            .SetNext(importHandler)
            .SetNext(purgeHadler)
            .SetNext(selectHandler)
            .SetNext(missedCommandHandler);
            return(helpHandler);
        }
        private static ICommandHandler CreateCommandHandlers()
        {
            ICommandHandler createHandler = new CreateCommandHandler(fileCabinetService);
            ICommandHandler insertHandler = new InsertCommandHandler(fileCabinetService);
            ICommandHandler exitHandler   = new ExitCommandHandler(ChangeProgramState);
            ICommandHandler exportHandler = new ExportCommandHandler(fileCabinetService);
            ICommandHandler helpHandler   = new HelpCommandHandler();
            ICommandHandler importHandler = new ImportCommandHandler(fileCabinetService);
            ICommandHandler purgeHandler  = new PurgeCommandHandler(fileCabinetService);
            ICommandHandler statHandler   = new StatCommandHandler(fileCabinetService);
            ICommandHandler deleteHandler = new DeleteCommandHandler(fileCabinetService);
            ICommandHandler updateHandler = new UpdateCommandHandler(fileCabinetService);
            ICommandHandler selectHandler = new SelectCommandHandler(fileCabinetService);

            helpHandler.SetNext(createHandler).
            SetNext(insertHandler).
            SetNext(importHandler).
            SetNext(exportHandler).
            SetNext(updateHandler).
            SetNext(statHandler).
            SetNext(selectHandler).
            SetNext(deleteHandler).
            SetNext(purgeHandler).
            SetNext(exitHandler);
            return(helpHandler);
        }
Example #4
0
        private static ICommandHandler CreateCommandHandlers()
        {
            var recordPrinter = new DefaultRecordPrinter();
            var createHandler = new CreateCommandHandler(fileCabinetService);
            var selectHandler = new SelectCommandHandler(fileCabinetService);
            var statHandler   = new StatCommandHandler(fileCabinetService);
            var exportHandler = new ExportCommandHandler(fileCabinetService);
            var importHandler = new ImportCommandHandler(fileCabinetService);
            var insertHandler = new InsertCommandHandler(fileCabinetService);
            var deleteHandler = new DeleteCommandHandler(fileCabinetService);
            var updateHandler = new UpdateCommandHandler(fileCabinetService);
            var purgeHandler  = new PurgeCommandHandler(fileCabinetService);
            var helpHandler   = new HelpCommandHandler();
            var exitHandler   = new ExitCommandHandler(ChangeState);

            createHandler.SetNext(insertHandler)
            .SetNext(selectHandler)
            .SetNext(deleteHandler)
            .SetNext(updateHandler)
            .SetNext(statHandler)
            .SetNext(exportHandler)
            .SetNext(importHandler)
            .SetNext(purgeHandler)
            .SetNext(helpHandler)
            .SetNext(exitHandler);

            return(createHandler);
        }
Example #5
0
        private static ICommandHandler CreateCommandHandlers()
        {
            Action <IEnumerable <FileCabinetRecord> > printer;

            printer = DefaultRecordPrint;
            var recordPrinter = new DefaultRecordPrinter();
            var createHandler = new CreateCommandHandler(Program.fileCabinetService);
            var editHandler   = new EditCommandHandler(Program.fileCabinetService);
            var exitHandler   = new ExitCommandHandler(stopProgram);
            var exportHandler = new ExportCommandHandler(Program.fileCabinetService);
            var findHandler   = new FindCommandHandler(
                Program.fileCabinetService, printer);
            var helpHandler   = new HelpCommandHandler();
            var importHandler = new ImportCommandHandler(Program.fileCabinetService);
            var listHandler   = new ListCommandHandler(
                Program.fileCabinetService, printer);
            var purgeHandler   = new PurgeCommandHandler(Program.fileCabinetService);
            var removeHandler  = new RemoveCommandHandler(Program.fileCabinetService);
            var statHandler    = new StatCommandHandler(Program.fileCabinetService);
            var defaultHandler = new DefaultHandler();

            createHandler.SetNext(editHandler);
            editHandler.SetNext(exitHandler);
            exitHandler.SetNext(exportHandler);
            exportHandler.SetNext(findHandler);
            findHandler.SetNext(helpHandler);
            helpHandler.SetNext(importHandler);
            importHandler.SetNext(listHandler);
            listHandler.SetNext(purgeHandler);
            purgeHandler.SetNext(removeHandler);
            removeHandler.SetNext(statHandler);
            statHandler.SetNext(defaultHandler);
            return(createHandler);
        }
Example #6
0
        private static ICommandHandler CreateCommandHandlers()
        {
            var helpHandler   = new HelpCommandHandler();
            var createHandler = new CreateCommandHandler(fileCabinetService, isCustomValidationRules);
            var editHandler   = new EditCommandHandler(fileCabinetService, isCustomValidationRules);
            var exitHandler   = new ExitCommandHandler(setProgramStatus);
            var exporthandler = new ExportCommandHandler(fileCabinetService);
            var findHandler   = new FindCommandHandler(fileCabinetService, DefaultRecordPrint);
            var importHandler = new ImportCommandHandler(fileCabinetService);
            var listHandler   = new ListCommandHandler(fileCabinetService, DefaultRecordPrint);
            var purgeHandler  = new PurgeCommandHandler(fileCabinetService);
            var removeHandler = new RemoveCommandHandler(fileCabinetService);
            var statHandler   = new StatCommandHandler(fileCabinetService);

            helpHandler.SetNext(createHandler);
            createHandler.SetNext(editHandler);
            editHandler.SetNext(exitHandler);
            exitHandler.SetNext(exporthandler);
            exporthandler.SetNext(findHandler);
            findHandler.SetNext(importHandler);
            importHandler.SetNext(listHandler);
            listHandler.SetNext(purgeHandler);
            purgeHandler.SetNext(removeHandler);
            removeHandler.SetNext(statHandler);

            return(helpHandler);
        }
Example #7
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);
        }
Example #8
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);
        }
Example #9
0
        private static ICommandHandler CreateCommandHandlers()
        {
            IRecordPrinter recordPrinter = new DefaultRecordPrinter();

            var create = new CreateCommandHandler(fileCabinetService);
            var exit   = new ExitCommandHandler(Exit);
            var stat   = new StatCommanHandler(fileCabinetService);
            var help   = new PrintHelpCommandHandler();
            var edit   = new EditCommandHandler(fileCabinetService);
            var find   = new FindCommandHandler(fileCabinetService, DefaultRecordPrint);
            var export = new ExportCommandHandler(fileCabinetService);
            var import = new ImportCommandHandler(fileCabinetService);
            var remove = new RemoveCommandHandler(fileCabinetService);
            var purge  = new PurgeCommandHandler(fileCabinetService);

            create.SetNext(exit).SetNext(stat).SetNext(edit).SetNext(find).SetNext(export).SetNext(import).SetNext(remove).SetNext(purge).SetNext(help);

            return(create);
        }
Example #10
0
        private static ICommandHandler CreateCommandHandler()
        {
            var helpHandler   = new HelpCommandHandler();
            var importHandler = new ImportCommandHandler(fileCabinetService);
            var exportHandler = new ExportCommandHandler(fileCabinetService);
            var purgeHandler  = new PurgeCommandHandler(fileCabinetService);
            var statHandler   = new StatCommandHandler(fileCabinetService);
            var exitHandler   = new ExitCommandHandler(IsRunning);
            var insertHandler = new InsertCommandHandler(recordValidator, fileCabinetService);
            var deleteHandler = new DeleteCommandHandler(recordValidator, fileCabinetService);
            var updateHandler = new UpdateCommandHandler(fileCabinetService);
            var selectCommand = new SelectCommandHandler(fileCabinetService);

            helpHandler.SetNext(importHandler).SetNext(exportHandler)
            .SetNext(purgeHandler).SetNext(statHandler).SetNext(exitHandler)
            .SetNext(insertHandler).SetNext(deleteHandler).SetNext(updateHandler)
            .SetNext(selectCommand);

            return(helpHandler);
        }