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; }
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) { var commandInstance = GetCommandFromDescriptor(commandDescriptor); if (commandInstance == null) { var commandResult = CommandResult.ForCommand(commandInstance); commandResult.Exception = new UnknownCommandException(commandDescriptor.Name); return new[] { commandResult }; } results.Add(_commandCoordinator.Handle(saga, commandInstance)); } return results.ToArray(); }
ICommand GetCommandFromDescriptor(CommandDescriptor commandDescriptor) { var commandName = commandDescriptor.Name; if (_commandTypes.ContainsKey(commandName)) { var commandInstance = _serializer.FromJson(_commandTypes[commandName], commandDescriptor.Command) as ICommand; return commandInstance; } return null; }
ICommand GetCommandFromDescriptor(CommandDescriptor commandDescriptor) { var commandName = commandDescriptor.Name; var commandType = _commandTypeManager.GetFromName(commandName); var commandInstance = _serializer.FromJson(commandType, commandDescriptor.Command) as ICommand; return commandInstance; }