Esempio n. 1
0
        /// <summary>
        /// Apply a command operation
        /// </summary>
        /// <param name="observed">observed operation</param>
        /// <param name="activator">command parameters</param>
        /// <returns>command operation</returns>
        public static CommandOperation DbCommand(this IObservableOperation observed, CommandActivator activator)
        {
            var cmd = new CommandOperation(activator);

            observed.Subscribe(cmd);
            return(cmd);
        }
Esempio n. 2
0
        public void NullCheck()
        {
            IServiceProvider provider = CreateDependencyInjection();

            Assert.Throws <ArgumentNullException>("provider", () => CommandActivator.ConstructCommand(null, typeof(NullCommand)));
            Assert.Throws <ArgumentNullException>("type", () => CommandActivator.ConstructCommand(provider, null));
        }
Esempio n. 3
0
        private void SubmitInput()
        {
            // get current input

            Input input = GetCurrentInput();

            // update command history

            if (_submitHistory.Count == 0 || !_submitHistory.LastOrDefault().Equals(input.ToString().Trim()))
            {
                _submitHistory.Add(input.ToString().TrimEnd());
                _submitHistoryIndex = _submitHistory.Count;
            }

            Out.Standard.WriteLine();

            // resolve command

            CommandResolver resolver = new CommandResolver(input, Commands);

            if (resolver.HasErrors) // if resolution failed with errors, output errors here
            {
                foreach (var err in resolver.Errors)
                {
                    Out.Error.WriteLine(err);
                }
                CommandExecutionComplete(null);
            }
            else
            {
                var cmd = new CommandActivator().Create(resolver, this);
                InputFilters.SetFilterMode(FilterMode.Execution);
                _invoker.Invoke(cmd, false, CommandExecutionComplete);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Apply a command operation
        /// </summary>
        /// <param name="observed">observed operation</param>
        /// <param name="activator">command parameters</param>
        /// <returns>command operation</returns>
        public static CommandOperation DbCommand(this IObservableOperation observed, CommandActivator activator)
        {
            var cmd = new CommandOperation(activator, LogProvider.GetLogger(typeof(CommandOperation).ToString()));

            observed.Subscribe(cmd);
            return(cmd);
        }
 public void SetupCommandActivatorTest()
 {
     keyActivationProvider       = new Mock <IKeyCommandActivationProvider>();
     signatureActivationProvider = new Mock <ISignatureCommandActivationProvider>();
     activator = new CommandActivator(keyActivationProvider.Object, signatureActivationProvider.Object);
     arguments = new ApplicationArguments();
 }
Esempio n. 6
0
        public void CreateCommandWithParameterlessConstructor()
        {
            IServiceProvider provider = CreateDependencyInjection();

            CommandBase command = CommandActivator.ConstructCommand(provider, typeof(NullCommand));

            Assert.IsType <NullCommand>(command);
        }
Esempio n. 7
0
        public void ActivatorRequiresPublicConstructor()
        {
            IServiceProvider provider = CreateDependencyInjection();
            Type             type     = typeof(InvalidCommand);

            Assert.Empty(type.GetConstructors());
            Assert.Throws <InvalidOperationException>(() => CommandActivator.ConstructCommand(provider, type));
        }
Esempio n. 8
0
        public void CreateCommandWithParameterizedConstructor()
        {
            Func <int>       argument = () => 240;
            IServiceProvider provider = CreateDependencyInjection(argument);

            CommandBase command = CommandActivator.ConstructCommand(provider, typeof(DelegateCommand));

            Assert.IsType <DelegateCommand>(command);
        }
Esempio n. 9
0
        /// <summary>
        /// Apply a command operation
        /// </summary>
        /// <param name="observed">observed operation</param>
        /// <param name="act">callback on command activator</param>
        /// <returns>command operation</returns>
        public static CommandOperation DbCommand(this IObservableOperation observed, Action <CommandActivator> act)
        {
            var activator = new CommandActivator();

            act(activator);
            CommandOperation cmd = new CommandOperation(activator);

            observed.Subscribe(cmd);
            return(cmd);
        }
Esempio n. 10
0
        /// <summary>
        /// Apply a command operation
        /// </summary>
        /// <param name="observed">observed operation</param>
        /// <param name="connStr">Name of a connection string defined in the application configuration file</param>
        /// <param name="CommandText">text of the command</param>
        /// <param name="isQuery">indicate if the command is a query</param>
        /// <param name="prepare">callback method to prepare the command</param>
        /// <returns>command operation</returns>
        public static CommandOperation DbCommand(this IObservableOperation observed, string connStr, string CommandText, bool isQuery, Action <IDbCommand, Row> prepare)
        {
            var activator = new CommandActivator();

            activator.ConnStringName = connStr;
            activator.CommandText    = CommandText;
            activator.Prepare        = prepare;
            activator.IsQuery        = isQuery;

            return(observed.DbCommand(activator));
        }
Esempio n. 11
0
        /// <summary>
        /// Apply a database command
        /// </summary>
        /// <param name="connection">Database connection</param>
        /// <param name="CommandText">Text of the command</param>
        /// <param name="isQuery">Indicate if the command is a query</param>
        /// <param name="failOnError">Indicate if the operation must fail on element error</param>
        /// <param name="Prepare">Callback method to prepare the command</param>
        /// <returns>Command operation</returns>
        public static InputCommandOperation Command(IDbConnection connection, string CommandText, bool isQuery, bool failOnError, Action <IDbCommand, Row> Prepare)
        {
            var activator = new CommandActivator();

            activator.Connection  = connection;
            activator.CommandText = CommandText;
            activator.Prepare     = Prepare;
            activator.IsQuery     = isQuery;
            activator.FailOnError = failOnError;

            return(Command(activator));
        }
        private static async Task <CommandResult> RunCommandPipelineAsync(ReadOnlyCollection <string> commandLineArguments, Assembly commandAssembly, IServiceProvider provider, CancellationToken stoppingToken)
        {
            CommandLineArguments args = CommandLineArgumentsParser.Parse(commandLineArguments);
            Type type = CommandSelector.SelectCommand(commandAssembly, args);

            using CommandBase instance = CommandActivator.ConstructCommand(provider, type);
            CommandArgumentsBinder.BindArguments(instance, args);
            CommandOptionsBinder.BindOptions(instance, args);

            CommandResult result = await CommandExecutor.InvokeAsync(instance, stoppingToken);

            return(result);
        }
Esempio n. 13
0
        public static void Initialize(TestContext ctx)
        {
            var registry = new CommandRegistry();

            registry.RegisterCommand <Command>();
            registry.RegisterCommand <WithArgument>();
            registry.RegisterCommand <WithIntArg>();
            registry.RegisterCommand <MultipleArgs>();
            registry.RegisterCommand <WithAlias>();
            registry.RegisterCommand <WithOption>();

            _resolver  = new CommandResolver(registry);
            _activator = new CommandActivator();
        }
Esempio n. 14
0
 public MongoDbUpdateOperation(CommandActivator activator,
                               IMongoDatabase database,
                               string collectionName,
                               Func <Row, MongoDB.Driver.FilterDefinition <T> > filter,
                               Func <Row, MongoDB.Driver.UpdateDefinition <T> > update,
                               MongoDB.Driver.UpdateOptions options = null)
 {
     _activator          = activator;
     this.database       = database;
     this.collectionName = collectionName;
     this.filter         = filter;
     this.update         = update;
     this.options        = options;
 }
        internal CommandLineApplication(
            CommandRegistry registry,
            IContainer container,
            IInterface intfc)
        {
            _registry  = registry;
            _resolver  = new CommandResolver(registry);
            _activator = new CommandActivator(container ?? new SystemActivatorContainer());

            _interface = intfc;
            _interface.CancelExecutionEvent += (sender, e) =>
            {
                if (IsRunning)
                {
                    _currentCancellationTokenSource.Cancel();
                    if (e != null)
                    {
                        e.Cancel = true;
                    }
                }
            };
        }
Esempio n. 16
0
 /// <summary>
 /// Constructor of input command operation
 /// </summary>
 /// <param name="activator"></param>
 public InputCommandOperation(CommandActivator activator)
 {
     _activator = activator;
 }
Esempio n. 17
0
 /// <summary>
 /// Constructor of input command operation
 /// </summary>
 /// <param name="activator"></param>
 public InputCommandOperation(CommandActivator activator, ILogger log)
 {
     _activator = activator;
     this.log   = log;
 }
Esempio n. 18
0
 /// <summary>
 /// Command operation constructor
 /// </summary>
 /// <param name="activator">command parameters</param>
 public CommandOperation(CommandActivator activator, ILogger logger)
 {
     _activator = activator;
     this.log   = logger;
 }
Esempio n. 19
0
        /// <summary>
        /// Apply a database command
        /// </summary>
        /// <param name="activator">command parameters</param>
        /// <returns>command operation</returns>
        public static InputCommandOperation Command(CommandActivator activator)
        {
            var cmd = new InputCommandOperation(activator);

            return(cmd);
        }
 /// <summary>
 /// Command operation constructor
 /// </summary>
 /// <param name="activator">command parameters</param>
 public CommandOperation(CommandActivator activator) => _activator = activator;
Esempio n. 21
0
        /// <summary>
        /// Apply a database command
        /// </summary>
        /// <param name="activator">command parameters</param>
        /// <returns>command operation</returns>
        public static InputCommandOperation Command(CommandActivator activator)
        {
            var cmd = new InputCommandOperation(activator, LogProvider.GetLogger(typeof(InputCommandOperation).ToString()));

            return(cmd);
        }
Esempio n. 22
0
        public void ActivatorDoesNotCatchExceptionThrownInCommandConstructor()
        {
            IServiceProvider provider = CreateDependencyInjection();

            Assert.Throws <NotSupportedException>(() => CommandActivator.ConstructCommand(provider, typeof(BadCommand)));
        }
Esempio n. 23
0
        public void TypeMustBeCommand()
        {
            IServiceProvider provider = CreateDependencyInjection();

            Assert.Throws <ArgumentException>("type", () => CommandActivator.ConstructCommand(provider, typeof(CommandActivatorTests)));
        }