Esempio n. 1
0
 public void Execute(ICommandHandlerContext handlerContext, MethodInfo handlerMethod)
 {
     if (handlerMethod != null)
     {
         handlerMethod.Invoke(handlerContext, new object[] { _commandPayload, _onCompleteCallback });
     }
 }
Esempio n. 2
0
        public ICommandHandlingResult Commit(ICommandHandlerContext context, TAggregateRoot aggregateRoot)
        {
            Contract.Assume(context?.Command != null);
            Contract.Assume(context.Metadata != null);
            Contract.Assume(aggregateRoot?.State != null);

            var command = context.Command;

            // get state tracker from aggregate root state
            var stateTracker = aggregateRoot.State.ExternalStateTracker as IEventProviderStateTracker;

            Contract.Assume(stateTracker?.Revisions != null);

            // make new transaction identity
            TransactionIdentity transactionIdentity = CreateNewTransactionIdentity();

            // create new transaction
            var transaction = new EventProviderTransaction(transactionIdentity, stateTracker.EventProvider, command, aggregateRoot, stateTracker.Revisions, context.Metadata);

            // store transaction
            _eventStore.Commit(transaction);

            // commit state tracker
            stateTracker.Commit();

            // return result
            return(CreateCommandHandlingResult(command, aggregateRoot, transactionIdentity));
        }
        public Task <ICommandHandlingResult> HandleAsync(ICommandHandlerContext context)
        {
            Contract.Requires(context != null);
            Contract.Ensures(Contract.Result <Task <ICommandHandlingResult> >() != null);

            throw new NotImplementedException();
        }
Esempio n. 4
0
 public void Release(ICommandHandlerContext context, object commandHandler)
 {
     if (!(commandHandler is null) && commandHandler is IDisposable disposable)
     {
         disposable.Dispose();
     }
 }
        public ICommandHandlingResult Handle(ICommandHandlerContext <TCommand> context)
        {
            Contract.Requires(context != null);
            Contract.Ensures(Contract.Result <ICommandHandlingResult>() != null);

            throw new NotImplementedException();
        }
        public Task <ICommandHandlingResult> CommitAsync(ICommandHandlerContext context, TAggregateRoot aggregateRoot)
        {
            Contract.Requires(context != null);
            Contract.Requires(aggregateRoot != null);
            Contract.Ensures(Contract.Result <Task <ICommandHandlingResult> >() != null);

            throw new NotImplementedException();
        }
        public override Task <ICommandHandlingResult> HandleAsync(ICommandHandlerContext <TCommand> context)
        {
            var command = context.Command;

            Contract.Assume(command.AggregateRootId != Guid.Empty);

            // create identity from command
            return(HandleAsync(context, new AggregateRootIdentity(command.AggregateRootId)));
        }
        public override void ProcessCommand(ICommand command,
                                            ICommandHandlerContext context)
        {
            InitializeHandler((SlurpAccountsFromHuxleyApiCommand)command,
                              (PelicanContext)context);

            Slurp(ProcessItem,
                  Context,
                  CommandArgument.CompanyFileId);
        }
Esempio n. 9
0
        public void Add(ICommandHandlerContext commandHandlerContext)
        {
            if (commandHandlerContext is null)
            {
                throw new ArgumentNullException(nameof(commandHandlerContext));
            }

            var instance = _commandHandlerActivator.Create(commandHandlerContext);

            _commandHandlers.Add(commandHandlerContext, instance);
        }
        public override ICommandHandlingResult Handle(ICommandHandlerContext <Deposit> context)
        {
            var command = context.Command;

            Contract.Assume(command.Amount > decimal.Zero);

            var domainEvents = AccountAggregateRoot.Create(new Create(Guid.NewGuid(), 50));

            domainEvents.AggregateRoot.Execute(command);

            return(new CommandHandlingResult(command.CommandId));
        }
 public void ProcessCommand(ICommand command,
                            ICommandHandlerContext context)
 {
     var applicationContext = (WhingePoolApplicationContext) context;
     var whinge = JsonConvert.DeserializeObject<WhingeEntity>(command.SerializedCommandArgument);
     applicationContext.WhingesByWhingePoolTable.EnsureInstance(new WhingesByWhingePoolEntity
                                                                {
                                                                    Whinge = whinge.Whinge,
                                                                    WhingePool = whinge.WhingePool.ToUpperInvariant(),
                                                                    Whinger = whinge.Whinger
                                                                });
 }
        public void ProcessCommand(ICommand command,
                                   ICommandHandlerContext context)
        {
            var applicationContext = (WhingePoolApplicationContext) context;
            var whingePool = JsonConvert.DeserializeObject<WhingePoolEntity>(command.SerializedCommandArgument);
            if (string.IsNullOrWhiteSpace(whingePool.Name))
            {
                whingePool.Name = "default";
            }
            whingePool.Name = whingePool.Name.ToUpperInvariant();

            applicationContext.WhingePoolsTable.EnsureInstance(whingePool);
        }
Esempio n. 13
0
        public Task <ICommandHandlingResult> HandleAsync(ICommandHandlerContext context)
        {
            var genericContext = context as ICommandHandlerContext <TCommand>;

            if (genericContext == null)
            {
                return(HandleAsync(new CommandHandlerContext <TCommand>(context)));
            }
            else
            {
                return(HandleAsync(genericContext));
            }
        }
Esempio n. 14
0
        public object Create(ICommandHandlerContext commandHandlerContext)
        {
            if (commandHandlerContext is null)
            {
                throw new ArgumentNullException(nameof(commandHandlerContext));
            }
            if (commandHandlerContext.DeclaringType is null)
            {
                throw new ArgumentNullException(nameof(commandHandlerContext.DeclaringType));
            }

            return(ActivatorUtilities.CreateInstance(_serviceProvider, commandHandlerContext.DeclaringType));
        }
Esempio n. 15
0
        public ICommandHandlingResult Handle(ICommandHandlerContext context)
        {
            var genericContext = context as ICommandHandlerContext <TCommand>;

            if (genericContext == null)
            {
                return(Handle(new CommandHandlerContext <TCommand>(context)));
            }
            else
            {
                return(Handle(genericContext));
            }
        }
        public void ProcessCommand(ICommand command,
                                   ICommandHandlerContext context)
        {
            var applicationContext = (WhingePoolApplicationContext)context;
            var whinge             = JsonConvert.DeserializeObject <WhingeEntity>(command.SerializedCommandArgument);

            applicationContext.WhingesByWhingePoolTable.EnsureInstance(new WhingesByWhingePoolEntity
            {
                Whinge     = whinge.Whinge,
                WhingePool = whinge.WhingePool.ToUpperInvariant(),
                Whinger    = whinge.Whinger
            });
        }
        public void ProcessCommand(ICommand command,
                                   ICommandHandlerContext context)
        {
            var applicationContext = (WhingePoolApplicationContext)context;
            var whingePool         = JsonConvert.DeserializeObject <WhingePoolEntity>(command.SerializedCommandArgument);

            if (string.IsNullOrWhiteSpace(whingePool.Name))
            {
                whingePool.Name = "default";
            }
            whingePool.Name = whingePool.Name.ToUpperInvariant();

            applicationContext.WhingePoolsTable.EnsureInstance(whingePool);
        }
        protected ICommandHandlingResult Handle(ICommandHandlerContext <TCommand> context, AggregateRootIdentity identity)
        {
            Contract.Requires(context != null);
            Contract.Requires(identity != null);
            Contract.Ensures(Contract.Result <ICommandHandlingResult>() != null);

            // use identity to get aggregate root
            TAggregateRoot aggregateRoot = GetAggregateRoot(identity);

            // execute command
            aggregateRoot.Execute(context.Command);

            // commit changes
            return(_repository.Commit(context, aggregateRoot));
        }
        protected async Task <ICommandHandlingResult> HandleAsync(ICommandHandlerContext <TCommand> context, AggregateRootIdentity identity)
        {
            Contract.Requires(context != null);
            Contract.Requires(identity != null);
            Contract.Ensures(Contract.Result <Task>() != null);

            // use identity to get aggregate root
            TAggregateRoot aggregateRoot = await GetAggregateRootAsync(identity);

            // execute command
            aggregateRoot.Execute(context.Command);

            // commit changes
            return(await _repository.CommitAsync(context, aggregateRoot));
        }
        public override void ProcessCommand(ICommand command,
                                            ICommandHandlerContext context)
        {
            InitializeHandler((SlurpCustomersFromHuxleyApiCommand)command,
                              (PelicanContext)context);

            var authorizationService = new AuthorizationService();

            var apiContext = authorizationService.GetAuthorizedContext(Context,
                                                                       CommandArgument.CompanyFileId);

            new CustomerService(apiContext.ApiConfiguration,
                                null,
                                apiContext.KeyService).ForeachItem(apiContext.CompanyFile,
                                                                   apiContext.CompanyFileCredentials,
                                                                   ProcessItem);
        }
        public void ProcessCommand(ICommand command,
                                   ICommandHandlerContext context)
        {
            var applicationContext = (WhingePoolApplicationContext)context;

            var whinge = JsonConvert.DeserializeObject<WhingeEntity>(command.SerializedCommandArgument);

            var whingePool = applicationContext.WhingePoolsTable.RetrieveInstanceByRowKey(whinge.WhingePool);
            if (whingePool == null)
            {
                applicationContext.CommandQueue.EnqueueCommand(new EnsureWhingePoolCommand(new WhingePoolEntity
                                                                                 {
                                                                                     Name = whinge.WhingePool
                                                                                 }));
            }

            applicationContext.CommandQueue.EnqueueCommand(new RecordWhingeAgainstWhingerCommand(whinge));
            applicationContext.CommandQueue.EnqueueCommand(new RecordWhingeAgainstWhingePoolCommand(whinge));
        }
        public void ProcessCommand(ICommand command,
                                   ICommandHandlerContext context)
        {
            var applicationContext = (WhingePoolApplicationContext)context;

            var whinge = JsonConvert.DeserializeObject <WhingeEntity>(command.SerializedCommandArgument);

            var whingePool = applicationContext.WhingePoolsTable.RetrieveInstanceByRowKey(whinge.WhingePool);

            if (whingePool == null)
            {
                applicationContext.CommandQueue.EnqueueCommand(new EnsureWhingePoolCommand(new WhingePoolEntity
                {
                    Name = whinge.WhingePool
                }));
            }

            applicationContext.CommandQueue.EnqueueCommand(new RecordWhingeAgainstWhingerCommand(whinge));
            applicationContext.CommandQueue.EnqueueCommand(new RecordWhingeAgainstWhingePoolCommand(whinge));
        }
Esempio n. 23
0
        private void ExecuteCommandPayload(ICommandHandlerContext handlerContext, ICommandPayload commandPayload, MethodInfo methodHandler, Action onCompleteCallback)
        {
            var handlerContextType = handlerContext.GetType();
            var commandPayloadType = commandPayload.GetType();
            var commandType        = typeof(Command <>);

            Type[] typeArgs = { commandPayloadType };
            commandType = commandType.MakeGenericType(typeArgs);
            var command = (ICommand)Activator.CreateInstance(
                commandType,
                new object[] {
                commandPayload,
                CreateQueuedCompletionCallback(
                    $"{handlerContextType.Name}.{methodHandler.Name}",
                    onCompleteCallback
                    )
            });

            command.Execute(handlerContext, methodHandler);
        }
Esempio n. 24
0
        public void ExecuteCommandPayload(ICommandHandlerContext handlerContext, ICommandPayload commandPayload, Action onCompleteCallback)
        {
            var handlerContextType = handlerContext.GetType();

            if (_methodHandlersByContextType.TryGetValue(handlerContextType, out Dictionary <Type, MethodInfo> methodHandlers))
            {
                var commandPayloadType = commandPayload.GetType();
                if (methodHandlers.ContainsKey(commandPayloadType))
                {
                    ExecuteCommandPayload(handlerContext, commandPayload, methodHandlers[commandPayloadType], onCompleteCallback);
                }
                else
                {
                    throw new Exception($"No command handler for command payload: {commandPayloadType.Name} on type: {handlerContextType.Name}");
                }
            }
            else
            {
                throw new Exception($"No command handlers registered for type: {handlerContextType.Name}");
            }
        }
Esempio n. 25
0
        public override async Task <ICommandHandlingResult> HandleAsync(ICommandHandlerContext <TCommand> context)
        {
            var command = context.Command;

            Contract.Assume(command.AggregateRootId != Guid.Empty);

            // enter aggregate root synchronization
            using (var syncContext = await _synchronizer.EnterAsync(typeof(TAggregateRoot), command.AggregateRootId))
            {
                try
                {
                    // call base class to handle command
                    return(await HandleAsync(context, syncContext.Identity));
                }
                catch
                {
                    // remove aggregate root from cache in case of error
                    _cache.Remove(GetCacheKey(syncContext.Identity));

                    throw;
                }
            }
        }
 internal void ExecuteCommandPayload(ICommandHandlerContext handlerContext, ICommandPayload commandPayload, Action onCompleteCallback)
 {
     _commandManager.ExecuteCommandPayload(handlerContext, commandPayload, onCompleteCallback);
 }
 public CommandHandlerContext(ICommandHandlerContext context)
     : this((TCommand)context.Command, context.Metadata)
 {
     Contract.Requires(context != null);
 }
Esempio n. 28
0
 public abstract Task <ICommandHandlingResult> HandleAsync(ICommandHandlerContext <TCommand> context);
Esempio n. 29
0
 public abstract ICommandHandlingResult Handle(ICommandHandlerContext <TCommand> context);
Esempio n. 30
0
 public override ICommandHandlingResult Handle(ICommandHandlerContext <TCommand> context)
 {
     return(new CommandHandlingResult(context.Command.CommandId));
 }
Esempio n. 31
0
 public override Task <ICommandHandlingResult> HandleAsync(ICommandHandlerContext <TCommand> context)
 {
     return(Task.Run(() => Handle(context)));
 }
        public override ICommandHandlingResult Handle(ICommandHandlerContext <Create> context)
        {
            var domainEvents = AccountAggregateRoot.Create(context.Command);

            return(new CommandHandlingResult(context.Command.CommandId));
        }
 public ITopicSubscription CreateSubscription(ICommandHandlerContext commandHandlerContext, object instance)
 {
     return(new TopicSubscription(commandHandlerContext, instance));
 }