/// <summary>
 ///     Configure the command with the <see cref="IParserOptions" /> and the <see cref="IConsole" /> of the parser.
 /// </summary>
 /// <param name="parserOptions">The <see cref="IParserOptions" />.</param>
 /// <param name="dependencyResolverScope">The <see cref="IDependencyResolverScope" />.</param>
 /// <param name="commandType">The <see cref="CommandType" /> of the command.</param>
 public virtual void Configure(IParserOptions parserOptions, IDependencyResolverScope dependencyResolverScope,
     CommandType commandType)
 {
     ParserOptions = parserOptions;
     CurrentDependencyResolverScope = dependencyResolverScope;
     CommandType = commandType;
 }
Example #2
0
        protected override object CreateHandlerFromScope <TBusEvent>(IDependencyResolverScope scope, TBusEvent busEvent, Type handlerType, BrokeredMessage brokeredMessage)
        {
            var handler = (IHandleMulticastEvent <TBusEvent>)scope.Resolve(handlerType);

            _propertyInjector.Inject(handler, brokeredMessage);
            return(handler);
        }
Example #3
0
        protected override object CreateHandlerFromScope <TBusEvent>(IDependencyResolverScope scope, TBusEvent busEvent, Type handlerType, NimbusMessage nimbusMessage)
        {
            var handler = (IHandleCompetingEvent <TBusEvent>)scope.Resolve(handlerType);

            _propertyInjector.Inject(handler, nimbusMessage);
            return(handler);
        }
Example #4
0
 /// <summary>
 ///     Configure the command with the <see cref="IParserOptions" /> and the <see cref="IConsole" /> of the parser.
 /// </summary>
 /// <param name="parserOptions">The <see cref="IParserOptions" />.</param>
 /// <param name="dependencyResolverScope">The <see cref="IDependencyResolverScope" />.</param>
 /// <param name="commandType">The <see cref="CommandType" /> of the command.</param>
 public virtual void Configure(IParserOptions parserOptions, IDependencyResolverScope dependencyResolverScope,
                               CommandType commandType)
 {
     ParserOptions = parserOptions;
     CurrentDependencyResolverScope = dependencyResolverScope;
     CommandType = commandType;
 }
 public IOutboundInterceptor[] CreateInterceptors(IDependencyResolverScope scope)
 {
     return _globalOutboundInterceptorTypes
         .Value
         .Select(t => (IOutboundInterceptor) scope.Resolve(t))
         .ToArray();
 }
 public IOutboundInterceptor[] CreateInterceptors(IDependencyResolverScope scope, BrokeredMessage brokeredMessage)
 {
     return _globalOutboundInterceptorTypes
         .Value
         .Select(t => (IOutboundInterceptor) scope.Resolve(t))
         .Do(interceptor => _propertyInjector.Inject(interceptor, brokeredMessage))
         .ToArray();
 }
Example #7
0
        private static HelpCommand GetHelpCommand(IDependencyResolverScope dependencyResolver, IParserOptions parserOptions)
        {
            var commandTypeProvider = dependencyResolver.ResolveDependency <ICommandTypeProvider>();
            var helpCommandType     = commandTypeProvider.GetCommandType(HelpCommand.Name);
            var helpCommand         = helpCommandType.CreateCommand(dependencyResolver, parserOptions) as HelpCommand;

            return(helpCommand);
        }
 public IOutboundInterceptor[] CreateInterceptors(IDependencyResolverScope scope, BrokeredMessage brokeredMessage)
 {
     return(_globalOutboundInterceptorTypes
            .Value
            .Select(t => (IOutboundInterceptor)scope.Resolve(t))
            .Do(interceptor => _propertyInjector.Inject(interceptor, brokeredMessage))
            .ToArray());
 }
        /// <summary>
        /// Create the command from its type.
        /// </summary>
        /// <param name="dependencyResolver">The scoped dependendy resolver.</param>
        /// <param name="parserOptions">The options of the current parser.</param>
        /// <returns></returns>
        public ICommand CreateCommand(IDependencyResolverScope dependencyResolver, IParserOptions parserOptions)
        {
            Guard.NotNull(dependencyResolver, nameof(dependencyResolver));
            Guard.NotNull(parserOptions, nameof(parserOptions));

            var commandActivator = dependencyResolver.ResolveDependency<ICommandActivator>();
            var command = commandActivator.ActivateCommand(Type);
            var commandBase = command as CommandBase;
            commandBase?.Configure(parserOptions, dependencyResolver, this);
            return command;
        }
Example #10
0
        /// <summary>
        /// Create the command from its type.
        /// </summary>
        /// <param name="dependencyResolver">The scoped dependendy resolver.</param>
        /// <param name="parserOptions">The options of the current parser.</param>
        /// <returns></returns>
        public ICommand CreateCommand(IDependencyResolverScope dependencyResolver, IParserOptions parserOptions)
        {
            Guard.NotNull(dependencyResolver, nameof(dependencyResolver));
            Guard.NotNull(parserOptions, nameof(parserOptions));

            var commandActivator = dependencyResolver.ResolveDependency <ICommandActivator>();
            var command          = commandActivator.ActivateCommand(Type);
            var commandBase      = command as CommandBase;

            commandBase?.Configure(parserOptions, dependencyResolver, this);
            return(command);
        }
Example #11
0
        private ICommand ExtractCommandLineOptions(CommandType commandType, IDependencyResolverScope dependencyResolver, IEnumerator <string> argsEnumerator)
        {
            var command = commandType.CreateCommand(dependencyResolver, _parserOptions);

            while (true)
            {
                var argument = GetNextCommandLineItem(argsEnumerator);
                if (argument == null)
                {
                    break;
                }

                if (!(argument.StartsWith(StringComparison.OrdinalIgnoreCase, Constants.OptionStarter)))
                {
                    command.Arguments.Add(argument);
                    continue;
                }

                var    optionText = argument.Substring(1);
                string value      = null;
                var    splitIndex = optionText.IndexOf(Constants.OptionSplitter);
                if (splitIndex > 0)
                {
                    value      = optionText.Substring(splitIndex + 1);
                    optionText = optionText.Substring(0, splitIndex);
                }

                var option = commandType.FindOption(optionText);
                if (option == null)
                {
                    throw new CommandLineParserException(Constants.ExceptionMessages.FormatParserOptionNotFoundForCommand(commandType.Metadata.Name, optionText));
                }

                if (option.OptionType == typeof(bool))
                {
                    value = value ?? bool.TrueString;
                }
                else
                {
                    value = value ?? GetNextCommandLineItem(argsEnumerator);
                }

                if (value == null)
                {
                    throw new CommandLineParserException(Constants.ExceptionMessages.FormatParserOptionValueRequired(commandType.Metadata.Name, optionText));
                }

                option.AssignValue(value, command);
            }
            return(command);
        }
Example #12
0
        public MessageProducer(
            IDependencyResolver dependencyResolver,
            ProducerConfiguration configuration)
        {
            this.configuration = configuration;

            // Create middlewares instances inside a scope to allow scoped injections in producer middlewares
            this.dependencyResolverScope = dependencyResolver.CreateScope();

            var middlewares = this.configuration.MiddlewareConfiguration.Factories
                              .Select(factory => factory(this.dependencyResolverScope.Resolver))
                              .ToList();

            this.middlewareExecutor = new MiddlewareExecutor(middlewares);
        }
        public IInboundInterceptor[] CreateInterceptors(IDependencyResolverScope scope, object handler, object message)
        {
            var globalInterceptors = GetGlobalInterceptorTypes();
            var classLevelInterceptors = GetClassLevelInterceptorTypes(handler);
            var methodLevelInterceptors = GetMethodLevelInterceptorTypes(handler, message);

            var interceptors = new Type[0]
                .Union(globalInterceptors)
                .Union(classLevelInterceptors)
                .Union(methodLevelInterceptors)
                .DistinctBy(t => t.FullName)
                .Select(t => (IInboundInterceptor) scope.Resolve(t, t.FullName))
                .OrderByDescending(i => i.Priority)
                .ThenBy(i => i.GetType().FullName)
                .ToArray();

            return interceptors;
        }
Example #14
0
        public IInboundInterceptor[] CreateInterceptors(IDependencyResolverScope scope, object handler, object message, NimbusMessage nimbusMessage)
        {
            var globalInterceptors      = GetGlobalInterceptorTypes();
            var classLevelInterceptors  = GetClassLevelInterceptorTypes(handler);
            var methodLevelInterceptors = GetMethodLevelInterceptorTypes(handler, message);

            var interceptors = new Type[0]
                               .Union(globalInterceptors)
                               .Union(classLevelInterceptors)
                               .Union(methodLevelInterceptors)
                               .DistinctBy(t => t.FullName)
                               .Select(t => (IInboundInterceptor)scope.Resolve(t))
                               .Do(interceptor => _propertyInjector.Inject(interceptor, nimbusMessage))
                               .OrderByDescending(i => i.Priority)
                               .ThenBy(i => i.GetType().FullName)
                               .ToArray();

            return(interceptors);
        }
Example #15
0
 protected abstract object CreateHandlerFromScope <TBusEvent>(IDependencyResolverScope scope, TBusEvent busEvent, Type handlerType, NimbusMessage nimbusMessage)
     where TBusEvent : IBusEvent;
 public IInboundInterceptor[] CreateInterceptors(IDependencyResolverScope scope, object handler, object message, BrokeredMessage brokeredMessage)
 {
     return new IInboundInterceptor[0];
 }
 public IInboundInterceptor[] CreateInterceptors(IDependencyResolverScope scope, object handler, object message, NimbusMessage nimbusMessage)
 {
     return(new IInboundInterceptor[0]);
 }
Example #18
0
        private CommandResult <ICommand> ParseImpl(IEnumerator <string> argsEnumerator, IDependencyResolverScope dependencyResolver, CommandType commandType)
        {
            var command    = ExtractCommandLineOptions(commandType, dependencyResolver, argsEnumerator);
            var validation = Validate(command, dependencyResolver, commandType.Metadata.Name);

            if (!validation.Item1)
            {
                var helpCommand = GetHelpCommand(dependencyResolver, _parserOptions);
                helpCommand.WriteHelp(commandType);
                return(new CommandResult <ICommand>(command, CommandResultCode.CommandParameterNotValid, validation.Item2));
            }
            return(new CommandResult <ICommand>(command, CommandResultCode.Ok));
        }
Example #19
0
        private static void WriteGlobalHelp(IDependencyResolverScope dependencyResolver, IParserOptions parserOptions)
        {
            var helpCommand = GetHelpCommand(dependencyResolver, parserOptions);

            helpCommand.Execute();
        }
 public IOutboundInterceptor[] CreateInterceptors(IDependencyResolverScope scope, BrokeredMessage message)
 {
     return new IOutboundInterceptor[0];
 }
Example #21
0
        private static Tuple <bool, List <ValidationResult> > Validate(ICommand command, IDependencyResolverScope dependencyResolver, string commandName)
        {
            var validationContext = new ValidationContext(command, null, null);
            var results           = new List <ValidationResult>();

            var isValid = Validator.TryValidateObject(command, validationContext, results, true);

            if (!isValid)
            {
                var console = dependencyResolver.ResolveDependency <IConsole>();
                console.WriteError(Strings.Parser_CommandInvalidArgumentsFormat, commandName);
                foreach (var validation in results)
                {
                    console.WriteError(string.Format(CultureInfo.CurrentUICulture, "-{0} :", validation.ErrorMessage));
                    foreach (var memberName in validation.MemberNames)
                    {
                        console.WriteError(string.Format(CultureInfo.CurrentUICulture, "  -{0}", memberName));
                    }
                }
            }
            return(Tuple.Create(isValid, results));
        }
 public IOutboundInterceptor[] CreateInterceptors(IDependencyResolverScope scope, BrokeredMessage message)
 {
     return(new IOutboundInterceptor[0]);
 }
 public IOutboundInterceptor[] CreateInterceptors(IDependencyResolverScope scope)
 {
     return new IOutboundInterceptor[0];
 }