private static void GenerateValues(ICommandDispatcher dispatcher, MetadataDefinitionResource original, MetadataDefinitionResource updated)
        {
            if (original.ValuesMatch(updated))
                return;

            dispatcher.Dispatch(new UpdateMetadataDefinitionValuesCommand(updated.Identity, updated.Values));
        }
        private static void GenerateUpdateRegexCommand(ICommandDispatcher dispatcher,MetadataDefinitionResource original, MetadataDefinitionResource updated)
        {
            if (original.RegexMatches(updated))
                return;

            dispatcher.Dispatch(new UpdateMetadataDefinitionRegexCommand(updated.Identity,updated.Regex));
        }
Ejemplo n.º 3
0
 public MetaWeblogHandler(
     ICommandDispatcher commandDispatcher,
     ILogger logger)
 {
     _commandDispatcher = commandDispatcher;
     _logger = logger;
 }
        private static void GenerateChangeDataTypeCommand(ICommandDispatcher dispatcher,MetadataDefinitionResource original, MetadataDefinitionResource updated)
        {
            if (original.DataTypeMatches(updated))
                return;

            dispatcher.Dispatch(new ChangeMetadataDefinitionDataTypeCommand(updated.Identity, updated.DataType));
        }
Ejemplo n.º 5
0
 public FeatureOverridesModule(ICommandDispatcher commandDispatcher)
 {
     _commandDispatcher = commandDispatcher;
     Post["/api/featureoverrides"] = p => CreateFeatureOverride();
     Put["/api/featureoverrides"] = p => UpdateFeatureOverride();
     Delete["/api/featureoverrides"] = p => DeleteFeatureOverride();
 }
Ejemplo n.º 6
0
        public WorkModule(ICommandDispatcher dispatcher, ICommandDeserializer deserializer)
        {
            Post["/work"] = r =>
                                {
                                    object command;
                                    try
                                    {
                                        var reader = new StreamReader(Request.Body);
                                        string str = reader.ReadToEnd();
                                        command = deserializer.Deserialize(str);
                                    }
                                    catch (InvalidCommandObjectException)
                                    {
                                        return new Response().WithStatusCode(HttpStatusCode.BadRequest);
                                    }

                                    try
                                    {
                                        dispatcher.Dispatch(command);
                                        return new Response().WithStatusCode(HttpStatusCode.OK);
                                    }
                                    catch (NoAvailableHandlerException)
                                    {
                                        return new Response().WithStatusCode(HttpStatusCode.NotImplemented);
                                    }
                                };
        }
        private static void GenerateAssociationCommand(ICommandDispatcher dispatcher, MetadataDefinitionGroupResource original, MetadataDefinitionGroupResource updated)
        {
            if (original.DefinitionIdsMatch(updated))
                return;

            dispatcher.Dispatch(new AssociateDefinitionsToMetadataDefinitionGroupCommand(original.Identity, updated.Definitions.Select(x=> x.Id).ToArray()));
        }
        private static void GenerateReLabelCommand(ICommandDispatcher dispatcher, MetadataDefinitionGroupResource original, MetadataDefinitionGroupResource updated)
        {
            if (original.DiscriptionMatches(updated))
                return;

            dispatcher.Dispatch(new ReLabelMetadataDefinitionGroupCommand(updated.Identity, new MetadataDefinitionGroupName(updated.Name), new MetadataDefinitionGroupDescription(updated.Description), updated.Tracking));
        }
Ejemplo n.º 9
0
        public void SetUp()
        {
            _commandDispatcher = Substitute.For<ICommandDispatcher>();
            _boardRepository = Substitute.For<IBoardRepository>();

            _controller = new BoardController(_commandDispatcher, _boardRepository);
        }
 public BoardTaskController(ICommandDispatcher commandDispatcher, IQueryDispatcher queryDispatcher,
     IHyperMediaFactory hyperMediaFactory)
 {
     this.commandDispatcher = commandDispatcher;
     this.queryDispatcher = queryDispatcher;
     this.hyperMediaFactory = hyperMediaFactory;
 }
Ejemplo n.º 11
0
        public WorkModule(ICommandDispatcher dispatcher, ICommandDeserializer deserializer)
        {
            Post["/work"] = r =>
                                {
                                    IUserSession userSession = this.UserSession();

                                    object command;
                                    try
                                    {
                                        var reader = new StreamReader(Request.Body);
                                        string str = reader.ReadToEnd();
                                        command = deserializer.Deserialize(str);
                                    }
                                    catch (InvalidCommandObjectException)
                                    {
                                        throw new BadRequestException("Invalid command object.");
                                    }

                                    try
                                    {
                                        dispatcher.Dispatch(userSession, command);
                                        return null;
                                    }
                                    catch (NoAvailableHandlerException)
                                    {
                                        throw new NotImplementedException("The command does not have a handler.");
                                    }
                                };
        }
Ejemplo n.º 12
0
        public NewUserModule(IPasswordEncryptor passwordEncryptor, ICommandDispatcher commandDispatcher,
                             IReadOnlyRepository readOnlyRepository)
        {
            Post["/user/facebook"] = r =>
                                         {
                                             var newUserRequest = this.Bind<NewUserRequest>();
                                             CheckForExistingFacebookUser(readOnlyRepository, newUserRequest);
                                             DispatchCommand(commandDispatcher, newUserRequest);
                                             return new Response().WithStatusCode(HttpStatusCode.OK);
                                         };

            Post["/user"] = r =>
                                {
                                    var newUserRequest = this.Bind<NewUserRequest>();
                                    CheckForExistingUser(readOnlyRepository, newUserRequest);
                                    commandDispatcher.Dispatch(this.VisitorSession(), new NewUserCommand
                                                                                          {
                                                                                              Email =
                                                                                                  newUserRequest.Email,
                                                                                              EncryptedPassword =
                                                                                                  passwordEncryptor.
                                                                                                  Encrypt(
                                                                                                      newUserRequest.
                                                                                                          Password)
                                                                                          });
                                    return new Response().WithStatusCode(HttpStatusCode.OK);
                                };
        }
Ejemplo n.º 13
0
        private static void GenerateChangeGroupCommand(ICommandDispatcher dispatcher, EntityResource original, EntityResource updated)
        {
            if (original.DefinitionGroup != null && Equals(original.DefinitionGroup.Id, updated.DefinitionGroup.Id))
                return;

            dispatcher.Dispatch(new EntityChangedGroupCommand(updated.Identity, updated.DefinitionGroup.Id));
        }
        public void WhenIIssueACreateElectionCommand()
        {
            //setup the "bus" components
            m_commandDispatcher = new CommandDispatcher();
            m_eventPublisher = new EventDispatcher();

            //register the command handler
            var repository = MockRepository.GenerateStub<IRepository<Election>>();
            m_commandDispatcher.Register(new MakeAnElectionCommandHandler(repository, null));

            //register the event handler
            m_eventPublisher.RegisterHandler<ElectionMadeEvent>(@event => m_electionCreatedEvent = @event);

            //wire-up the domain event to the event publisher
            DomainEvents.Register<ElectionMadeEvent>(@event => m_eventPublisher.Publish(@event));

            //create and send the command
            var command = new MakeAnElection
                              {
                                  AdministratorCode = "AdmCode",
                                  CompanyCode = "CoCode",
                                  ParticipantId = "12345",
                                  ElectionAmount = 1000,
                                  ElectionReason = "election reason",
                              };

            m_commandDispatcher.Dispatch<MakeAnElection>(command);
            
            Assert.Pass();
        }
Ejemplo n.º 15
0
 public Form1(ClaimReader claimReader, ICommandDispatcher dispatcher, IWorkspace workspace)
     : this()
 {
     _claimReader = claimReader;
     _dispatcher = new ExceptionTrapDispatcher(dispatcher);
     this._workspace = workspace;
 }
Ejemplo n.º 16
0
        private static void GenerateReLabelCommand(ICommandDispatcher dispatcher, EntityResource original, EntityResource updated)
        {
            if (original.DiscriptionMatches(updated))
                return;

            dispatcher.Dispatch(new ReLabelEntityCommand(updated.Identity, new EntityName(updated.Name.Trim())));
        }
Ejemplo n.º 17
0
        public UserAccountModule(ICommandDispatcher commandDispatcher, IPasswordEncryptor passwordEncryptor)
        {
            Post["/register"] =
                _ =>
                    {
                        var req = this.Bind<NewUserRequest>();
                        commandDispatcher.Dispatch(this.UserSession(),
                                                   new CreateUser(req.Email, passwordEncryptor.Encrypt(req.Password), req.Name, req.PhoneNumber));
                        return null;
                    };

            Post["/password/requestReset"] =
                _ =>
                {
                    var req = this.Bind<ResetPasswordRequest>();
                    commandDispatcher.Dispatch(this.UserSession(),
                                               new CreatePasswordResetToken(req.Email) );
                    return null;
                };

            Put["/password/reset/{token}"] =
                _ =>
                {
                    return null;
                };
        }
 public CommandQueueSubscriber(string connectionString, string queueName, ICommandDispatcher dispatcher, ILogger logger)
 {
     _dispatcher = dispatcher;
     _logger = logger;
     _client = QueueClient.CreateFromConnectionString(connectionString, queueName);
     _stopEvent = new ManualResetEvent(false);
 }
 public SpeakersController(
     IQueryProcessor queryProcessor,
     ICommandDispatcher commandDispatcher)
 {
     _queryProcessor = queryProcessor;
     _commandDispatcher = commandDispatcher;
 }
        private static void GenerateReLabelDescriptionCommand(ICommandDispatcher dispatcher, MetadataDefinitionResource original, MetadataDefinitionResource updated)
        {
            if (original.DescriptionMatches(updated))
                return;

            dispatcher.Dispatch(new ReLabelMetadataDefinitionDescriptionCommand(updated.Identity, new MetadataDefinitionDescription(updated.Description.Trim())));
        }
Ejemplo n.º 21
0
 public DIContainer(AppSettings settings)
 {
     _settings = settings;
     _dispatcher = new CommandDispatcher(
         GetDefaultHandlers().ToArray(),
         GetPluginHandlers,
         EventDispatcher());
 }
        public OrderCreatorHub(ICommandDispatcher commandDispatcher, ICommandResponseWatcher commandResponseWatcher, IQueryDispatcher queryDispatcher, IConnectionManager connectionManager)
        {
            _commandDispatcher = commandDispatcher;
            _queryDispatcher = queryDispatcher;
            _connectionManager = connectionManager;

            commandResponseWatcher.ResponseReceived += CommandResponseReceived;
        }
Ejemplo n.º 23
0
 public PaymentController(IQueryDispatcher queryDispatcher, ICommandDispatcher commandDispatcher, IAddressProvider addressProvider, ICreditCardService creditCardService, IPayPalService paypalService)
 {
     this._queryDispatcher = queryDispatcher;
     this._commandDispatcher = commandDispatcher;
     this._addressProvider = addressProvider;
     this._creditCardService = creditCardService;
     this._paypalService = paypalService;
 }
Ejemplo n.º 24
0
 public DisasterModule(ICommandDispatcher commandDispatcher)
 {
     Post["/Disasters"] =
         Request =>
             {
                 commandDispatcher.Dispatch(this.UserSession(), this.Bind<CreateNewDisaster>());
                 return null;
             };
 }
Ejemplo n.º 25
0
 public SeverityModule(ICommandDispatcher commandDispatcher)
 {
     Post["/severity"] = r =>
         {
             var voteRequest = this.Bind<VoteOnSeverityRequest>();
             commandDispatcher.Dispatch(this.UserSession(), new VoteOnSeverity(voteRequest.DisasterId, voteRequest.Severity));
             return null;
         };
 }
Ejemplo n.º 26
0
        public ApplicationsModule(ICommandDispatcher commandDispatcher, IQueryDispatcher queryDispatcher)
        {
            _commandDispatcher = commandDispatcher;
            _queryDispatcher = queryDispatcher;

            Get["/api/applications"] = p => GetApplications();
            Post["/api/applications"] = p => PostApplication();
            Put["/api/applications"] = p => PutApplication();
            Delete["/api/applications"] = p => DeleteApplication();
        }
Ejemplo n.º 27
0
 public ResourcesModule(ICommandDispatcher commandDispatcher, IQueryDispatcher queryDispatcher)
 {
     _commandDispatcher = commandDispatcher;
     _queryDispatcher = queryDispatcher;
     Get["/api/resource"] = r => GetResource();
     Get["/api/resources"] = r => GetResources();
     Post["/api/resources"] = r => CreateResource();
     Post["/api/resources/generate"] = r => GenerateResources();
     Put["/api/resources"] = r => UpdateResource();
     Delete["api/resources"] = r => DeleteResource();
 }
Ejemplo n.º 28
0
 public NewUserModule(IPasswordEncryptor passwordEncryptor, ICommandDispatcher commandDispatcher,
                      IReadOnlyRepository readOnlyRepository)
 {
     Post["/user"] = r =>
                         {
                             var newUserRequest = this.Bind<NewUserRequest>();
                             CheckForExistingUser(readOnlyRepository, newUserRequest);
                             DispatchCommand(passwordEncryptor, commandDispatcher, newUserRequest);
                             return new Response().WithStatusCode(HttpStatusCode.OK);
                         };
 }
Ejemplo n.º 29
0
 public Engine(
     ICommandDispatcher commandDispatcher,
     IInputReader reader,
     IOutputWriter writer)
 {
     this.commandDispatcher = commandDispatcher;
     this.reader = reader;
     this.writer = writer;
     this.commandDispatcher.HardwRepository = HardwareRepositoty.Instance;
     this.isRunning = true;
 }
Ejemplo n.º 30
0
        public FeaturesModule(ICommandDispatcher commandDispatcher, IQueryDispatcher queryDispatcher)
        {
            _commandDispatcher = commandDispatcher;
            _queryDispatcher = queryDispatcher;

            Post["/api/features"] = p => CreateFeature();
            Put["/api/features"] = p => UpdateFeature();
            Get["/api/features"] = p => GetFeatures();
            Get["/api/feature"] = p => GetFeature();
            Delete["/api/features"] = p => DeleteFeature();
        }
Ejemplo n.º 31
0
 protected ApiControllerBase(ICommandDispatcher commandDispatcher)
 {
     CommandDispatcher = commandDispatcher;
 }
Ejemplo n.º 32
0
 public LocationController(ITwitterDataService twitterService,
                           ICommandDispatcher commandDispatcher)
 {
     _twitterService    = twitterService;
     _commandDispatcher = commandDispatcher;
 }
Ejemplo n.º 33
0
 public LoginController(ILogger <LoginController> logger, ICommandDispatcher commandDispatcher)
 {
     _logger            = logger;
     _commandDispatcher = commandDispatcher;
 }
Ejemplo n.º 34
0
 public ApiControllerBase(ICommandDispatcher commandDispatcher)
 {
     CommandDispatcher = commandDispatcher;
 }
Ejemplo n.º 35
0
 public UsersController(ICommandDispatcher commandDispatcher, IQueryDispatcher queryDispatcher, ICurrentUserService currentUserService)
 {
     _commandDispatcher  = commandDispatcher;
     _queryDispatcher    = queryDispatcher;
     _currentUserService = currentUserService;
 }
Ejemplo n.º 36
0
 public UtilityController(ICommandDispatcher commands)
 {
     _commands = commands;
 }
Ejemplo n.º 37
0
 public StudentsController(IQueryDispatcher queryDispatcher, ICommandDispatcher commandDispatcher)
 {
     _queryDispatcher   = queryDispatcher;
     _commandDispatcher = commandDispatcher;
 }
Ejemplo n.º 38
0
 public FriendshipsModuleFacade(ICommandDispatcher commandDispatcher, IQueryDispatcher queryDispatcher)
 {
     _commandDispatcher = commandDispatcher;
     _queryDispatcher   = queryDispatcher;
 }
Ejemplo n.º 39
0
 public ValuesController(ICommandDispatcher commandDispatcher)
 {
     _commandDispatcher = commandDispatcher;
 }
Ejemplo n.º 40
0
 public UsersController(IUserService userService, ICommandDispatcher commandDispatcher) : base(commandDispatcher)
 {
     _userService = userService;
 }
Ejemplo n.º 41
0
 public ProductsController(ICommandDispatcher commandDispatcher, IQueryDispatcher queryDispatcher)
 {
     this.commandDispatcher = commandDispatcher;
     this.queryDispatcher   = queryDispatcher;
 }
Ejemplo n.º 42
0
 public AccountController(ICommandDispatcher commandDispatcher) : base(commandDispatcher)
 {
 }
Ejemplo n.º 43
0
 /// <summary>
 /// Assigns the specified domain event dispatcher.
 /// </summary>
 /// <param name="dispatcher">The command dispatcher.</param>
 /// <exception cref="System.ArgumentNullException"></exception>
 public static void Assign(ICommandDispatcher dispatcher)
 {
     _dispatcher = dispatcher;
 }
Ejemplo n.º 44
0
        private static async Task RunDemo()
        {
            ICommandDispatcher dispatcher = _serviceProvider == null?Configure() : _serviceProvider.GetService <ICommandDispatcher>();

            await dispatcher.DispatchAsync(new OutputToConsoleCommand { Message = "Hello Console" });
        }
 public CreateCardEndpoint(ICommandDispatcher commandDispatcher)
 {
     this.commandDispatcher = commandDispatcher ?? throw new ArgumentNullException(nameof(commandDispatcher));
 }
        public async Task <CommandResult <TResult> > DispatchAsync <TResult>(ICommand <TResult> command, CancellationToken cancellationToken)
        {
            await new SynchronizationContextRemover();

            ICommandDispatchContext dispatchContext = _commandScopeManager.Enter();

            try
            {
                CommandResult <TResult> dispatchResult        = null;
                CommandResult           wrappedDispatchResult = null;
                ICommandExecuter        executer   = null;
                ICommandDispatcher      dispatcher = null;
                ICommand unwrappedCommand          = command;
                if (command is NoResultCommandWrapper wrappedCommand)
                {
                    unwrappedCommand = wrappedCommand.Command;
                }

                // we specifically audit BEFORE dispatch as this allows us to capture intent and a replay to
                // occur even if dispatch fails
                // (there is also an audit opportunity after execution completes and I'm considering putting one in
                // on dispatch success)
                await _auditor.AuditPreDispatch(unwrappedCommand, dispatchContext, cancellationToken);

                try
                {
                    Stopwatch stopwatch = _collectMetrics ? Stopwatch.StartNew() : null;
                    Func <ICommandDispatcher> dispatcherFunc = _commandRegistry.GetCommandDispatcherFactory(command);
                    if (dispatcherFunc != null)
                    {
                        dispatcher = dispatcherFunc();
                        if (command != unwrappedCommand)
                        {
                            wrappedDispatchResult = await dispatcher.DispatchAsync(unwrappedCommand, cancellationToken);
                        }
                        else
                        {
                            dispatchResult = await dispatcher.DispatchAsync(command, cancellationToken);
                        }
                        executer = dispatcher.AssociatedExecuter;
                    }
                    await _auditor.AuditPostDispatch(unwrappedCommand, dispatchContext, stopwatch?.ElapsedMilliseconds ?? -1, cancellationToken);

                    if ((dispatchResult != null && dispatchResult.DeferExecution) || (wrappedDispatchResult != null && wrappedDispatchResult.DeferExecution))
                    {
                        return(new CommandResult <TResult>(default(TResult), true));
                    }
                }
                catch (Exception ex)
                {
                    throw new CommandDispatchException(unwrappedCommand, dispatchContext.Copy(), dispatcher?.GetType() ?? GetType(), "Error occurred during command dispatch", ex);
                }

                if (executer == null)
                {
                    executer = AssociatedExecuter;
                }
                return(new CommandResult <TResult>(await executer.ExecuteAsync(command, cancellationToken), false));
            }
            finally
            {
                _commandScopeManager.Exit();
            }
        }
 public WishCompleteItemRequestHandler(ICommandDispatcher commandDispatcher) => _commandDispatcher = commandDispatcher;
Ejemplo n.º 48
0
 public UpdateCurrencyController(ICommandDispatcher commandDispatcher, IQueryRunner queryRunner)
 {
     _commandDispatcher = commandDispatcher;
     _queryRunner       = queryRunner;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ControllerBase"/> class.
 /// </summary>
 /// <param name="commandDispatcher">The command dispatcher.</param>
 /// <param name="queryDispatcher">The query dispatcher.</param>
 public ControllerBase(ICommandDispatcher commandDispatcher, IQueryDispatcher queryDispatcher)
 {
     CommandDispatcher = Guard.ArgumentNotNull(commandDispatcher, nameof(commandDispatcher));
     QueryDispatcher   = Guard.ArgumentNotNull(queryDispatcher, nameof(queryDispatcher));
 }
Ejemplo n.º 50
0
 public LoginController(ICommandDispatcher commandDispatcher, IMemoryCache memoryCache) : base(commandDispatcher)
 {
     _memoryCache = memoryCache;
 }
 public AddWorkoutPlanJob(ICommandDispatcher commandDispatcher)
 {
     _commandDispatcher = commandDispatcher;
 }
 public DriverRoutesController(ICommandDispatcher commandDispatcher) : base(commandDispatcher)
 {
 }
Ejemplo n.º 53
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CarsController"/> class.
 /// </summary>
 /// <param name="commandDispatcher">The command dispatcher.</param>
 /// <param name="queryDispatcher">The query dispatcher.</param>
 public CarsController(ICommandDispatcher commandDispatcher, IQueryDispatcher queryDispatcher)
     : base(commandDispatcher, queryDispatcher)
 {
 }
Ejemplo n.º 54
0
 public CommandExecuter(IQueueClient queueClient, IConfig config, IWorkerRecordStoreService workerRecordStoreService, ICommandDispatcher dispatch, IDirectCommandExecuter directCommandExecuter)
 {
     _queueClient = queueClient;
     _config      = config;
     _workerRecordStoreService = workerRecordStoreService;
     _dispatch = dispatch;
     _directCommandExecuter = directCommandExecuter;
 }
Ejemplo n.º 55
0
 public LearnerMatchAndUpdate(ICommandDispatcher commandDispatcher, ILogger <LearnerMatchAndUpdate> logger)
 {
     _commandDispatcher = commandDispatcher;
     _logger            = logger;
 }
Ejemplo n.º 56
0
 public CategoryController(ICommandDispatcher commandDispatcher, IQueryDispatcher queryDispatcher)
 {
     this.commandDispatcher = commandDispatcher;
     this.queryDispatcher   = queryDispatcher;
 }
Ejemplo n.º 57
0
 public UsersController(IUserServices userServices,
                        ICommandDispatcher commandDispatcher) : base(commandDispatcher)
 {
     _userServices = userServices;
 }
Ejemplo n.º 58
0
 public FollowsController(ICommandDispatcher commandDispatcher) : base(commandDispatcher)
 {
 }
Ejemplo n.º 59
0
 protected BaseController(ICommandDispatcher commandDispatcher)
 {
     CommandDispatcher = commandDispatcher;
 }
Ejemplo n.º 60
0
 public Dispatcher(ICommandDispatcher commandDispatcher,
                   IQueryDispatcher queryDispatcher)
 {
     _commandDispatcher = commandDispatcher;
     _queryDispatcher   = queryDispatcher;
 }