Exemple #1
0
        public Instruction Create(List <string> args)
        {
            string cmdName = ParseTools.ExtractCommandName(args);

            var description = library.GetOrNull(cmdName);

            if (description == null)
            {
                throw new UnknownCommandNameException(cmdName);
            }

            var intervalArgumentsDescription
                = ReflectionTools.GetArgumentsDescription(typeof(CommandScheduleSettings));
            var intervalSettingsValues = ReflectionTools.ExtractAndParse(args, intervalArgumentsDescription, typeof(CommandScheduleSettings));
            var intervalSettings       = new CommandScheduleSettings();

            ReflectionTools.Configurate(intervalSettings, intervalSettingsValues);

            var commandConfiguration = ReflectionTools.ExtractAndParse(args, description.Arguments, description.CommandType);

            if (args.Count != 0)
            {
                throw new UnknownArgumentsException(args.ToArray());
            }

            return(new Instruction {
                Locator = new CommandLocator(description.GetRawInstance, commandConfiguration),
                ScheduleSettings = intervalSettings,
            });
        }
Exemple #2
0
 /// <summary>
 /// Executes specified instance. Every time the same instance will be executed.
 /// </summary>
 /// <param name="cmd">Ready to go command instance</param>
 /// <param name="scheduleSettings">Launch settings. Use null for a single sync launch</param>
 public void Execute(ICommand cmd, CommandScheduleSettings scheduleSettings)
 {
     Execute(new Instruction {
         Locator          = new CommandLocator(() => cmd, new Dictionary <PropertyInfo, object>()),
         ScheduleSettings = scheduleSettings ?? new CommandScheduleSettings {
             Count = 1
         }
     });
 }
Exemple #3
0
 /// <summary>
 /// Executes an instance that is accepted from a specified locator.
 /// Locator will be called every time before command execution
 /// </summary>
 /// <param name="scheduleSettings">Launch settings. Use null for a single sync launch</param>
 public void Execute(Func <ICommand> instanceLocator, CommandScheduleSettings scheduleSettings = null)
 {
     Execute(new Instruction {
         Locator          = new CommandLocator(instanceLocator),
         ScheduleSettings = scheduleSettings ?? new CommandScheduleSettings {
             Count = 1
         }
     });
 }
Exemple #4
0
 /// <summary>
 /// Executes a command of a specified type. Сonfiguring is not possible.
 /// </summary>
 /// <param name="scheduleSettings">Launch settings. Use null for a single sync launch</param>
 public void Execute <T>(CommandScheduleSettings scheduleSettings = null) where T : ICommand, new()
 {
     Execute(() => new T(), scheduleSettings);
 }
Exemple #5
0
 /// <summary>
 /// Executes a command of a specified type. Сonfiguring is not possible.
 /// </summary>
 /// <param name="scheduleSettings">Launch settings. Use null for a single sync launch</param>
 public void Execute(Type commandType, CommandScheduleSettings scheduleSettings = null)
 {
     ReflectionTools.ThrowIfItIsNotValidCommand(commandType);
     Execute(() => (ICommand)Activator.CreateInstance(commandType), scheduleSettings);
 }