Пример #1
0
        public CommandResult Handle(CommandDescriptor commandDescriptor)
        {
            var commandInstance = GetCommandFromDescriptor(commandDescriptor);
            if (commandInstance == null)
                return new CommandResult { Exception = new UnknownCommandException(commandDescriptor.Name) };

            var result = _commandCoordinator.Handle(commandInstance);
            return result;
        }
Пример #2
0
        public CommandResult Handle(CommandDescriptor commandDescriptor)
        {
            var commandInstance = GetCommandFromDescriptor(commandDescriptor);

            if (commandInstance == null)
            {
                return new CommandResult {
                           Exception = new UnknownCommandException(commandDescriptor.Name)
                }
            }
            ;

            var result = _commandCoordinator.Handle(commandInstance);

            return(result);
        }
Пример #3
0
 public CommandResult Handle(CommandDescriptor descriptor)
 {
     try
     {
         var commandType = _typeDiscoverer.GetCommandTypeByName(descriptor.GeneratedFrom);
         var command     = (ICommand)_serializer.FromJson(commandType, descriptor.Command);
         command.Id = descriptor.Id;
         _commandContextConnectionManager.Register(Context.ConnectionId, command.Id);
         var commandResult = _commandCoordinator.Handle(command);
         return(commandResult);
     }
     catch (Exception ex)
     {
         return(new CommandResult {
             Exception = ex,
             ExceptionMessage = string.Format("Exception occured of type '{0}' with message '{1}'. StackTrace : {2}", ex.GetType().Name, ex.Message, ex.StackTrace)
         });
     }
 }
Пример #4
0
 public CommandResult Handle(CommandDescriptor descriptor)
 {
     try
     {
         var commandType = _typeDiscoverer.GetCommandTypeByName(descriptor.GeneratedFrom);
         var command = (ICommand)_serializer.FromJson(commandType, descriptor.Command);
         command.Id = descriptor.Id;
         _commandContextConnectionManager.Register(Context.ConnectionId, command.Id);
         var commandResult = _commandCoordinator.Handle(command);
         return commandResult;
     }
     catch (Exception ex)
     {
         return new CommandResult {
             Exception = ex,
             ExceptionMessage = string.Format("Exception occured of type '{0}' with message '{1}'. StackTrace : {2}",ex.GetType().Name,ex.Message,ex.StackTrace)
         };
     }
 }
Пример #5
0
        public IEnumerable<CommandResult> HandleForSaga(Guid sagaId, CommandDescriptor[] commandDescriptors)
        {
            var results = new List<CommandResult>();
            var saga = _sagaLibrarian.Get(sagaId);

            // Todo : IMPORTANT : We need to treat this as a unit of work with rollbacks if one or more commands fail and some succeed!!!!!!!!!!! 
            foreach (var commandDescriptor in commandDescriptors)
            {
                ICommand commandInstance = null;
                try
                {
                    commandInstance = GetCommandFromDescriptor(commandDescriptor);
                    results.Add(_commandCoordinator.Handle(saga, commandInstance));
                }
                catch (Exception ex)
                {
                    var commandResult = CommandResult.ForCommand(commandInstance);
                    commandResult.Exception = ex;
                    return new[] { commandResult };
                }
            }

            return results.ToArray();
        }
Пример #6
0
 ICommand GetCommandFromDescriptor(CommandDescriptor commandDescriptor)
 {
     var commandType = _typeDiscoverer.GetCommandTypeByName(commandDescriptor.GeneratedFrom);
     var commandInstance = _serializer.FromJson(commandType, commandDescriptor.Command) as ICommand;
     return commandInstance;
 }