Beispiel #1
0
        protected override async Task OnCommandExecutedAsync(
            IGangCommand command,
            GangState <HostState> state
            )
        {
            await base.OnCommandExecutedAsync(command, state);

            if (!state.HasErrors)
            {
                state = state.AddResult(
                    command.Audit.MemberId,
                    new GangNotify(
                        id: command.GetTypeName(),
                        type: GangNotificationTypes.Success,
                        data: new
                {
                    type = command.GetTypeName(),
                    data = command.Data
                }
                        )
                    );
            }

            var results = state.GetResults(command.Audit);

            foreach (var result in results)
            {
                await Controller.SendCommandAsync(
                    result.Command,
                    result.SendToMemberIds,
                    command.Audit.Version
                    );
            }
        }
Beispiel #2
0
        public Task <GangState <TodosState> > ExecuteAsync(
            GangState <TodosState> state, IGangCommand command)
        {
            ExecuteCalls = ExecuteCalls
                           .Add(new ExecuteCall(
                                    state, command
                                    ));

            return(Task.FromResult(
                       _getResult(state)
                       ));
        }
Beispiel #3
0
        async Task <GangState <TStateData> > IGangCommandExecutor <TStateData>
        .ExecuteAsync(GangState <TStateData> state, IGangCommand command)
        {
            var dataTypeName = command.GetTypeName();

            if (!_handlers.ContainsKey(dataTypeName))
            {
                throw new GangCommandHandlerNotFoundExcetion();
            }

            var handler = _handlers[dataTypeName];

            return(await handler.HandleAsync(state, command));
        }
Beispiel #4
0
 public GangCommandHandlerException(
     IGangCommand command, TargetInvocationException tiex)
     : base("Command failed", tiex)
 {
     Command = command;
 }
Beispiel #5
0
 public static string GetTypeName(
     this IGangCommand command
     )
 {
     return(command.Data.GetType().GetCommandTypeName());
 }
Beispiel #6
0
 public ExecuteCall(GangState <TodosState> state, IGangCommand command)
 {
     State   = state;
     Command = command;
 }