public virtual void Send <TCommand>(TCommand command) where TCommand : ICommand <TAuthenticationToken> { Type commandType = command.GetType(); switch (command.Framework) { case FrameworkType.Akka: Logger.LogInfo(string.Format("A command arrived of the type '{0}' but was marked as coming from the '{1}' framework, so it was dropped.", commandType.FullName, command.Framework)); return; } ICommandValidator <TAuthenticationToken, TCommand> commandValidator = null; try { commandValidator = DependencyResolver.Resolve <ICommandValidator <TAuthenticationToken, TCommand> >(); } catch (Exception exception) { Logger.LogDebug("Locating an ICommandValidator failed.", string.Format("{0}\\Handle({1})", GetType().FullName, commandType.FullName), exception); } if (commandValidator != null && !commandValidator.IsCommandValid(command)) { Logger.LogInfo("The provided command is not valid.", string.Format("{0}\\Handle({1})", GetType().FullName, commandType.FullName)); return; } if (command.AuthenticationToken == null) { command.AuthenticationToken = AuthenticationTokenHelper.GetAuthenticationToken(); } command.CorrelationId = CorrelationIdHelper.GetCorrelationId(); bool isRequired; if (!ConfigurationManager.TryGetSetting(string.Format("{0}.IsRequired", commandType.FullName), out isRequired)) { isRequired = true; } RouteHandlerDelegate commandHandler = Routes.GetSingleHandler(command, isRequired); // This check doesn't require an isRequired check as there will be an exception raised above and handled below. if (commandHandler == null) { Logger.LogDebug(string.Format("The command handler for '{0}' is not required.", commandType.FullName)); return; } Action <IMessage> handler = commandHandler.Delegate; handler(command); }
protected virtual bool PrepareAndValidateCommand <TCommand>(TCommand command, out RouteHandlerDelegate commandHandler) where TCommand : ICommand <TAuthenticationToken> { Type commandType = command.GetType(); if (command.Frameworks != null && command.Frameworks.Contains("Built-In")) { Logger.LogInfo("The provided command has already been processed by the Built-In bus.", string.Format("{0}\\PrepareAndValidateEvent({1})", GetType().FullName, commandType.FullName)); commandHandler = null; return(false); } ICommandValidator <TAuthenticationToken, TCommand> commandValidator = null; try { commandValidator = DependencyResolver.Resolve <ICommandValidator <TAuthenticationToken, TCommand> >(); } catch (Exception exception) { Logger.LogDebug("Locating an ICommandValidator failed.", string.Format("{0}\\Handle({1})", GetType().FullName, commandType.FullName), exception); } if (commandValidator != null && !commandValidator.IsCommandValid(command)) { Logger.LogInfo("The provided command is not valid.", string.Format("{0}\\Handle({1})", GetType().FullName, commandType.FullName)); commandHandler = null; return(false); } PrepareCommand(command); bool isRequired = BusHelper.IsEventRequired(commandType); commandHandler = Routes.GetSingleHandler(command, isRequired); // This check doesn't require an isRequired check as there will be an exception raised above and handled below. if (commandHandler == null) { Logger.LogDebug(string.Format("The command handler for '{0}' is not required.", commandType.FullName)); return(false); } return(true); }
protected virtual bool PrepareAndValidateCommand <TCommand>(TCommand command, out RouteHandlerDelegate commandHandler) where TCommand : ICommand <TAuthenticationToken> { Type commandType = command.GetType(); switch (command.Framework) { case FrameworkType.Akka: Logger.LogInfo(string.Format("A command arrived of the type '{0}' but was marked as coming from the '{1}' framework, so it was dropped.", commandType.FullName, command.Framework)); commandHandler = null; return(false); } ICommandValidator <TAuthenticationToken, TCommand> commandValidator = null; try { commandValidator = DependencyResolver.Resolve <ICommandValidator <TAuthenticationToken, TCommand> >(); } catch (Exception exception) { Logger.LogDebug("Locating an ICommandValidator failed.", string.Format("{0}\\Handle({1})", GetType().FullName, commandType.FullName), exception); } if (commandValidator != null && !commandValidator.IsCommandValid(command)) { Logger.LogInfo("The provided command is not valid.", string.Format("{0}\\Handle({1})", GetType().FullName, commandType.FullName)); commandHandler = null; return(false); } PrepareCommand(command); bool isRequired = BusHelper.IsEventRequired(commandType); commandHandler = Routes.GetSingleHandler(command, isRequired); // This check doesn't require an isRequired check as there will be an exception raised above and handled below. if (commandHandler == null) { Logger.LogDebug(string.Format("The command handler for '{0}' is not required.", commandType.FullName)); return(false); } return(true); }