Пример #1
0
 public CommandController(
     ICommandHandler<CreateProductCommand> createProductCommandHandler,
     ICommandHandler<CreateProductVersionCommand> createProductVersionCommandHandler)
 {
     this.createProductCommandHandler = createProductCommandHandler;
     this.createProductVersionCommandHandler = createProductVersionCommandHandler;
 }
Пример #2
0
 public Game()
 {
     characterQuery = new GetCharacterInfoQueryHandler();
     choiceHandler = new UserChoiceHandler();
     createCharacterHandler = new CreateCharacterHandler();
     userValidator = new DatabaseUserValidator();
 }
Пример #3
0
        static void Main()
        {
            commandFactory = new CommandFactory();
            log = new ConsoleWindowLogger();
            commandHandler = new CommandHandler(commandFactory, log);

            Console.WindowHeight = 40;
            Console.WindowWidth = 120;

            PrintHelp();

            while (true)
            {
                Thread.Sleep(300);
                Console.Write("> ");

                var line = Console.ReadLine();

                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }

                var split = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                commandHandler.TryHandleRequest(split);

                Console.WriteLine();
            }
        }
Пример #4
0
        private static IEnumerable<Match> MatchCommands(CommandParameters parameters, int argCount, CommandHandlerDescriptor descriptor, ICommandHandler handler)
        {
            foreach (var commandDescriptor in descriptor.Commands)
            {
                foreach (var name in commandDescriptor.Names)
                {
                    var names = name.Split(' ');
                    // We check here number of arguments a command can recieve against
                    // arguments provided for the command to identify the correct command
                    // and avoid matching multiple commands.
                    if(commandDescriptor.MethodInfo.GetParameters().Length == argCount - names.Count())
                    {
                        names = parameters.Arguments.ToArray();
                    }

                    if (parameters.Arguments.Take(argCount).SequenceEqual(names, StringComparer.OrdinalIgnoreCase))
                    {
                        yield return new Match
                        {
                            Context = new CommandContext
                            {
                                Arguments = parameters.Arguments.Skip(name.Split(' ').Count()),
                                Command = string.Join(" ", names),
                                CommandDescriptor = commandDescriptor,
                                Input = parameters.Input,
                                Output = parameters.Output,
                                Switches = parameters.Switches,
                            },
                            CommandHandler = handler
                        };
                    }
                }
            }
        }
		public MainCommandHandlerChain(
			IConsole console,
			ICommandHandler[] commandHandlers)
		{
			_console = console;
			_commandHandlers = commandHandlers;
		}
Пример #6
0
 public DocumentWindow(IServiceProvider serviceProvider, Microsoft.Matrix.Core.Documents.Document document)
     : base(serviceProvider)
 {
     if (document == null)
     {
         throw new ArgumentNullException("document");
     }
     this._document = document;
     try
     {
         base.SuspendLayout();
         this.InitializeUserInterface();
         this._documentView = this.CreateDocumentView();
     }
     finally
     {
         base.ResumeLayout(true);
     }
     this._documentView.DocumentChanged += new EventHandler(this.OnDocumentViewDocumentChanged);
     this._viewCommandHandler = this._documentView as ICommandHandler;
     this._viewToolboxClient = this._documentView as IToolboxClient;
     this._viewSelectionContainer = this._documentView as ISelectionContainer;
     IDesigner designer = ((IDesignerHost) serviceProvider.GetService(typeof(IDesignerHost))).GetDesigner(document);
     this._designerCommandHandler = designer as ICommandHandler;
     this._contextCommandHandler = this._document.ProjectItem.Project;
     this.UpdateCaption();
 }
Пример #7
0
 private static IEnumerable<Match> MatchCommands(CommandParameters parameters, int argCount, CommandHandlerDescriptor descriptor, ICommandHandler handler)
 {
     foreach (var commandDescriptor in descriptor.Commands)
     {
         foreach (var name in commandDescriptor.Names)
         {
             var names = name.Split(' ');
             if (parameters.Arguments.Take(argCount).SequenceEqual(names, StringComparer.OrdinalIgnoreCase))
             {
                 yield return new Match
                 {
                     Context = new CommandContext
                     {
                         Arguments = parameters.Arguments.Skip(names.Count()),
                         Command = string.Join(" ", names),
                         CommandDescriptor = commandDescriptor,
                         Input = parameters.Input,
                         Output = parameters.Output,
                         Switches = parameters.Switches,
                     },
                     CommandHandler = handler
                 };
             }
         }
     }
 }
Пример #8
0
 public OrderApiService(
     ICommandHandler<MakeOrderCommand> commmHandler,
     IOrderRepository repository)
 {
     _commmHandler = commmHandler;
     _repository = repository;
 }
Пример #9
0
 public AutoCompleteForm(TextView view, TextControl owner, TextBufferLocation location, ITextAutoCompletionList list)
 {
     this.InitializeComponent();
     this._pickedItem = string.Empty;
     this._list = list;
     foreach (TextAutoCompletionItem item in list.Items)
     {
         this._itemList.Items.Add(item);
     }
     this._view = view;
     this._nextHandler = this._view.AddCommandHandler(this);
     this._owner = owner;
     if (location.ColumnIndex == location.Line.Length)
     {
         this._startLocation = location.Clone();
     }
     else
     {
         using (TextBufferSpan span = this._view.GetWordSpan(location))
         {
             this._startLocation = span.Start.Clone();
         }
     }
     this._timer = new Timer();
     this._timer.Interval = 500;
     this._timer.Tick += new EventHandler(this.OnTimerTick);
 }
Пример #10
0
        public ShellViewModel( ITimerHandler timerHandler, 
                               IPlaybackHandler playbackHandler, 
                               ICommandHandler commandHandler )
        {
            this.TimerHandler = timerHandler;
            this.playbackHandler = playbackHandler;

            this.TimerHandler.TimedEventCompleted += ( se, ea ) =>
            {
                this.playbackHandler.PlayTimedEventComplete( se as TimedEvent );
            };

            commandHandler.CommandRecognized += ( se, ea ) =>
            {
                this.playbackHandler.PlayCommandAccepted();

                var command = se as Command;

                if ( command.Verb == "time" )
                {
                    this.TimerHandler.Start( command.Noun );
                }
                else if ( command.Verb == "clear" )
                {
                    this.TimerHandler.Clear( command.Noun );
                }
            };
        }
Пример #11
0
 public ServiceConsumer(
     ICommandHandler<AddDelegateCommand> addHandler, 
     ICommandHandler<UpdateDelegateCommand> updateHandler)
 {
     this.addHandler = addHandler;
     this.updateHandler = updateHandler;
 }
 public CommandExampleController(
     ICommandHandler<CreateOrderCommand> createOrderhandler,
     ICommandHandler<ShipOrderCommand> shipOrderhandler)
 {
     this.createOrderhandler = createOrderhandler;
     this.shipOrderhandler = shipOrderhandler;
 }
Пример #13
0
        public void Register(ICommandHandler handler)
        {
            if (handler == null) throw new ArgumentNullException(nameof(handler));

            var supportedCommandTypes = handler.GetType()
                .GetInterfaces()
                .Where(iface => iface.IsGenericType && iface.GetGenericTypeDefinition() == typeof(ICommandHandler<>))
                .Select(iface => iface.GetGenericArguments()[0])
                .ToList();
            var registeredType = _handlers.Keys.FirstOrDefault(x => supportedCommandTypes.Contains(x));

            if (registeredType != null)
            {
                var commands = String.Join(", ", supportedCommandTypes.Select(x => x.FullName));
                var registeredHandler = _handlers[registeredType];
                var message = $"The command(s) ('{commands}') handled by the received handler ('{handler}') already has a registered handler ('{registeredHandler}').";

                Logging.Darjeel.TraceError(message);
                throw new ArgumentException(message);
            }

            foreach (var commandType in supportedCommandTypes)
            {
                _handlers.Add(commandType, handler);
            }
        }
Пример #14
0
        public virtual void Invoke(ICommandHandler handler, ICommand command)
        {
            Ensure.That(handler, "handler").IsNotNull();
            Ensure.That(command, "command").IsNotNull();

            var container = ContainerFactory.Invoke(handler.ContainerType);
            handler.Handler.Invoke(container, new object[] { command });
        }
Пример #15
0
 public AccountController(ApplicationUserManager userManager,
     ApplicationSignInManager signInManager,
     ICommandHandler<RegisterUserCommand> registerUserCommandHandler)
 {
     UserManager = userManager;
     SignInManager = signInManager;
     _registerUserCommandHandler = registerUserCommandHandler;
 }
Пример #16
0
 public ValidationService(IRequestResponsePairQueryService requestResponsePairQueryService,
                             IUseCaseQueryService useCaseQueryService,
                             ICommandHandler<CreateUseCaseValidation> commandHandler)
 {
     _requestResponsePairQueryService = requestResponsePairQueryService;
     _useCaseQueryService = useCaseQueryService;
     _commandHandler = commandHandler;
 }
Пример #17
0
 public OrganizationController(ICommandHandler<CreateOrganization, Organization> createOrganization,
     IQueryHandler<GetOrganization, Organization> getOrganization,
     IQueryHandler<ListOrganizations, IEnumerable<Organization>> listOrganizations)
 {
     _createOrganization = createOrganization;
     _getOrganization = getOrganization;
     _listOrganizations = listOrganizations;
 }
 public UserController(ICommandHandler<CreateBasicUser> createUserCommandHandler, ICommandHandler<AddFriendToUser> addFriendCommandHandler, ICommandHandler<DisableUser> disableUserCommandHandler, ICommandHandler<AddWishListItem> addWishListItemCommandHandler, ICommandHandler<EnableUser> enableUserCommandHandler)
 {
     _createUserCommandHandler = createUserCommandHandler;
     _addFriendCommandHandler = addFriendCommandHandler;
     _disableUserCommandHandler = disableUserCommandHandler;
     _addWishListItemCommandHandler = addWishListItemCommandHandler;
     _enableUserCommandHandler = enableUserCommandHandler;
 }
Пример #19
0
 // ----------------------------------------------------------------------
 public GenericCommand( ICommandHandler commandHandler, object context )
 {
     if ( commandHandler == null )
     {
         throw new ArgumentNullException( "commandHandler" );
     }
     this.commandHandler = commandHandler;
     this.context = context;
 }
Пример #20
0
        public CommandDispatcher(
			ICommandHandler[] handlers,
			Func<IEnumerable<ICommandHandler>> pluginHandlerFactory,
			IEventDispatcher eventDispatcher)
        {
            _handlers = handlers;
            _pluginHandlerFactory = pluginHandlerFactory;
            _eventDispatcher = eventDispatcher;
        }
Пример #21
0
        /// <summary>
        /// Registers a handler to be used to process commands.
        /// </summary>
        public void RegisterCommandHandler(ICommandHandler commandHandler)
        {
            if (commandHandler == null) throw new ArgumentNullException("commandHandler");

            if (registeredHandlers.Any(h => h.GetType() == commandHandler.GetType()))
                throw new InvalidOperationException("Handler type " + commandHandler.GetType() + " already registered.");

            registeredHandlers.Add(commandHandler);
        }
Пример #22
0
 public LoginsController
     (
         IRequestHandler<LoginRequest, string> loginHandler,
         ICommandHandler<LogoutRequest> logoutHandler
     )
 {
     this.loginHandler = loginHandler;
     this.logoutHandler = logoutHandler;
 }
        public void Setup()
        {
            command = new TestCommand();
            commandHandler = Substitute.For<ICommandHandler<TestCommand>>();
            
            commandHandlerResolver = Substitute.For<ICommandHandlerResolver>();
            commandHandlerResolver.ResolveCommandHandler<ICommandHandler<TestCommand>>().Returns(commandHandler);

            sut = new CommandBus(commandHandlerResolver);
        }
        private void RegisterCommandHandler(Type commandType, ICommandHandler commandHandler)
        {
            if (_commandHandlerDict.TryAdd(commandType, commandHandler)) return;

            if (_commandHandlerDict.ContainsKey(commandType))
            {
                throw new DuplicatedCommandHandlerException(commandType, commandHandler.GetInnerCommandHandler().GetType());
            }
            throw new ENodeException("Error occurred when registering {0} for {1} command.", commandHandler.GetType().Name, commandType.Name);
        }
Пример #25
0
        public void Construct_MultipleCommandHandlersForSameCommand_ThrowArgumentException()
        {
            // The command bus doesn't currently support multiple command handlers for the same command, make sure that it fails.
            var commandHandlers = new ICommandHandler[] {
                new TestCommandHandler(),
                new TestCommandHandler()
            };

            Assert.Throws<ArgumentException>(() => new CommandExecutor(commandHandlers));
        }
Пример #26
0
        public bool TryGetHandler(Type commandType, out ICommandHandler handler)
        {
            if (_handlers.TryGetValue(commandType, out handler))
            {
                return true;
            }

            Logging.Darjeel.TraceInformation($"Handler not found for command '{commandType.FullName}'.");

            return false;
        }
Пример #27
0
        private static List<ICommandHandler> SortCommandHandlers(ICommandHandler[] commandHandlers)
        {
            // Put command handlers defined in priority assemblies, last. This allows applications
            // to override built-in command handlers.

            var bootstrapper = IoC.Get<AppBootstrapper>();

            return commandHandlers
                .OrderBy(h => bootstrapper.PriorityAssemblies.Contains(h.GetType().Assembly) ? 1 : 0)
                .ToList();
        }
Пример #28
0
 public void RegisterHandler(ICommandHandler<Command> commandHandler)
 {
     if (_handlers.ContainsKey(commandHandler.GetCommandType()))
     {
         throw new InvalidOperationException("Cannot register more than one similar handlers");
     }
     else
     {
         _handlers.Add(commandHandler.GetCommandType(), commandHandler);
     }
 }
        public ApprovalsController(
			IApprovalsViewRepository repository,
			ICurrentUserProvider userProvider,
			ICommandHandler<ApprovePromotionDraftCommand> approveHandler,
            ICommandHandler<RejectPromotionDraftCommand> rejectHandler)
        {
            _repository = repository;
            _userProvider = userProvider;
            _approveHandler = approveHandler;
            _rejectHandler = rejectHandler;
        }
Пример #30
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RollbackMessage"/> class.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <param name="rollbackCommand">The rollback command.</param>
        /// <param name="headers">The headers.</param>
        public RollbackMessage(QueueConsumerConfiguration configuration,
            ICommandHandler<RollbackMessageCommand> rollbackCommand,
            SqlHeaders headers)
        {
            Guard.NotNull(() => configuration, configuration);
            Guard.NotNull(() => rollbackCommand, rollbackCommand);
            Guard.NotNull(() => headers, headers);

            _configuration = configuration;
            _rollbackCommand = rollbackCommand;
            _headers = headers;
        }
Пример #31
0
 /// <summary>
 /// Creates a new <see cref="CliCommand"/> based on a name.
 /// </summary>
 /// <param name="commandName">The command name to look for; case-insensitive; can be <c>null</c>.</param>
 /// <param name="handler">A callback object used when the the user needs to be asked questions or informed about download and IO tasks.</param>
 /// <returns>The requested <see cref="CliCommand"/> or <see cref="DefaultCommand"/> if <paramref name="commandName"/> was <c>null</c>.</returns>
 /// <exception cref="OptionException"><paramref name="commandName"/> is an unknown command.</exception>
 /// <exception cref="IOException">There was a problem accessing a configuration file or one of the stores.</exception>
 /// <exception cref="UnauthorizedAccessException">Access to a configuration file or one of the stores was not permitted.</exception>
 /// <exception cref="InvalidDataException">A configuration file is damaged.</exception>
 public static CliCommand Create(string?commandName, ICommandHandler handler)
 => (commandName ?? "").ToLowerInvariant() switch
 {
     "" => new DefaultCommand(handler),
 public UpdateSemesterCommandHander(ICommandHandler <UpdateEntityCommand, bool> updateEntityHandler)
 {
     this.updateEntityHandler = updateEntityHandler;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="RollbackMessageCommandHandlerDecorator"/> class.
 /// </summary>
 /// <param name="handler">The handler.</param>
 /// <param name="tracer">The tracer.</param>
 public RollbackMessageCommandHandlerDecorator(ICommandHandler <RollbackMessageCommand <long> > handler, ITracer tracer)
 {
     _handler = handler;
     _tracer  = tracer;
 }
Пример #34
0
 /// <inheritdoc/>
 public ImportApps(ICommandHandler handler)
     : base(handler)
 {
     Options.Add("no-download", () => Resources.OptionNoDownload, _ => NoDownload = true);
 }
Пример #35
0
 public CommandConsumer(ICommandHandler <T> commandHandler)
 {
     _commandHandler = commandHandler;
 }
Пример #36
0
 public ResolutionScopeDecorator(ICommandHandler <TCommand> commandHandler,
                                 IDependencyContainer dependencyContainer)
 {
     _commandHandler      = commandHandler;
     _dependencyContainer = dependencyContainer;
 }
Пример #37
0
 public static Task WithCommandHandlerAsync <TCommand>(this IBusClient bus, ICommandHandler <TCommand> handler) where TCommand : ICommand
 => bus.SubscribeAsync <TCommand>(msg => handler.HandleAsync(msg),
                                  ctx => ctx.UseSubscribeConfiguration(cfg =>
                                                                       // Multiple instances of same service should subscribe to same single queue.
                                                                       cfg.FromDeclaredQueue(q => q.WithName(GetQueueName <TCommand>()))));
 public PaymentFailedEventHandler(ICommandHandler <CancelProductBooking> commandHandler,
                                  ILogger <PaymentFailedEventHandler> logger) : base(logger)
 {
     _commandHandler = commandHandler;
 }
 public CreateSemesterCommandHandler(ICommandHandler <EntityCommand, int> createEntityHandler)
 {
     this.createEntityHandler = createEntityHandler;
 }
Пример #40
0
 /// <inheritdoc/>
 public new void SetNext(ICommandHandler commandHandler)
 {
     this.nextHandler = commandHandler ?? throw new ArgumentNullException(nameof(commandHandler));
 }
Пример #41
0
 /// <inheritdoc/>
 public RepairApps([NotNull] ICommandHandler handler) : base(handler)
 {
 }
 public MovieMetadataController(IQueryHandler <GetMovieMetadataQuery, List <DynamicMetadataDto> > getMovieMetadataQueryHandler, ICommandHandler <CreateMovieMetadataCommand, DynamicMetadataDto> createMovieMetadataCommandHandler, ICommandHandler <UpdateMovieMetadataCommand, DynamicMetadataDto> updateMovieMetadataCommandHandler, ICommandHandler <DeleteMovieMetadataCommand, bool> deleteMovieMetadataCommand)
 {
     _getMovieMetadataQueryHandler      = getMovieMetadataQueryHandler;
     _createMovieMetadataCommandHandler = createMovieMetadataCommandHandler;
     _updateMovieMetadataCommandHandler = updateMovieMetadataCommandHandler;
     _deleteMovieMetadataCommand        = deleteMovieMetadataCommand;
 }
Пример #43
0
 public ValidatingCommandHandlerDecorator(ICommandHandler <TCommand> commandHandler, ILogger <ValidatingCommandHandlerDecorator <TCommand> > logger, ICommandValidator <TCommand> commandValidator)
     : base(commandHandler)
 {
     _commandValidator = commandValidator;
     _logger           = logger;
 }
Пример #44
0
 public static Task WithCommandHandlerAsync <TCommand>(this IBusClient bus,
                                                       ICommandHandler <TCommand> handler) where TCommand : ICommand
 => bus.SubscribeAsync <TCommand>(
     msg => handler.HandleAsync(msg),
     ctx => ctx.UseConsumeConfiguration(cfg => cfg.FromQueue(GetQueueName <TCommand>())));
Пример #45
0
 public CommandLoggingDecorator(ICommandHandler <TCommand> handler)
 {
     this.handler = handler;
 }
Пример #46
0
 public AuditLoggingDecorator(ICommandHandler <TCommand> handler)
 {
     _handler = handler;
 }
Пример #47
0
 public void SetSuccessor(ICommandHandler successor)
 {
     this.Successor = successor;
 }
Пример #48
0
 public LogOutParameters(ICommandHandler handler, Action <LocalCommand> onSuccess = null, Action <LocalCommand> onFault = null)
     : base(handler, onSuccess, onFault)
 {
 }
Пример #49
0
 public EndpointTransferredEventHandler(IQueryHandler queryHandler, ICommandHandler commandHandler, ILogger <EndpointTransferredEventHandler> logger) : base(
         queryHandler, commandHandler, logger)
 {
 }
Пример #50
0
 /// <inheritdoc/>
 public AddFeed(ICommandHandler handler)
     : base(handler)
 {
 }
 public EcSec1WriteFormattingDecorator(ICommandHandler <T> decoratedCommand, IEcKeyProvider ecKeyProvider)
 {
     this.decoratedCommand = decoratedCommand;
     this.ecKeyProvider    = ecKeyProvider;
 }
Пример #52
0
 public TransactionalCommandHandlerDecorator(ICommandHandler <T> handler)
 {
     Handler = handler;
 }
Пример #53
0
 public CommandValidationDecorator(ICommandHandler <TCommand> commandHandler)
 {
     this.commandHandler = commandHandler ?? throw new ArgumentNullException(nameof(commandHandler));
 }
Пример #54
0
 public ClientCreateController(ICommandHandler <ClientCreateCommand> createClientCommandHandler)
 {
     _createClientCommandHandler = createClientCommandHandler;
 }
Пример #55
0
 protected virtual void OnBeforeExecuteHandler <TCommand>(ICommandHandler <TCommand> handler, TCommand command)
     where TCommand : ICommand
 {
     // idle, override in ancestor if needed.
 }
Пример #56
0
 public CreateValidFriendlyUrlCommandHandler(
     ICommandHandler <CreateProductCommand> decorated)
 {
     this.decorated = decorated;
 }
Пример #57
0
 public CreateDisciplineCommandHandler(ICommandHandler <EntityCommand, int> createEntityHandler)
 {
     this.createEntityHandler = createEntityHandler;
 }
Пример #58
0
        private bool TryGetControllerCommandHandler <TCommandArgs>(TCommandArgs args, out ICommandHandler <TCommandArgs> commandHandler)
            where TCommandArgs : CommandArgs
        {
            AssertIsForeground();

            Controller controller;

            if (!TryGetController(args, out controller))
            {
                commandHandler = null;
                return(false);
            }

            commandHandler = (ICommandHandler <TCommandArgs>)controller;
            return(true);
        }
Пример #59
0
 public TransactionScopeCommandHandlerDecorator(ICommandHandler <TCommand> decoratee)
 {
     this.decoratee = decoratee;
 }
Пример #60
0
 public CancelOrderConsumer(ICommandHandler <CancelOrder> handler)
 {
     _handler = handler;
 }