public void ShouldSetTheApplicationModeToHelpIfInstructionsContainsHelp()
        {
            var instructions = new ApplicationInstructions(null);
            instructions.Instructions.Add(InstructionType.DisplayHelp, new Instruction());

            Assert.That(instructions.ApplicationMode, Is.EqualTo(ApplicationMode.Help));
        }
        public void Execute(ApplicationInstructions instructions, ApplicationConfiguration configuration)
        {
            Validate.ExecuteAlias(instructions.ExecuteAlias);

            var isTimedMode = instructions.TimedMode || configuration.IsTimedMode;
            var group = TaskCollection.SelectTaskGroup(instructions.ExecuteAlias.Alias);

            Validate.TaskGroup(group);

            try
            {
                PrintStartTime(isTimedMode);

                if (instructions.ParallelMode)
                {
                    ExecuteASync(group, instructions, configuration);
                }
                else
                {
                    ExecuteSync(group, instructions, configuration);
                }
            }
            finally
            {
                PrintEndTime(isTimedMode);
            }
        }
        public void ShouldSetTheApplicationModeToListIfInstructionsContainsListAndNoAlias()
        {
            var instructions = new ApplicationInstructions(null);
            instructions.Instructions.Add(InstructionType.DisplayList, new Instruction());

            Assert.That(instructions.ApplicationMode, Is.EqualTo(ApplicationMode.List));
        }
        public void ShouldSetTheApplicationModeToHelpIfInstructionsContainsGroup()
        {
            var instructions = new ApplicationInstructions(null)
            {
                ExecuteAlias = { Alias = "alias" }
            };

            Assert.That(instructions.ApplicationMode, Is.EqualTo(ApplicationMode.Single));
        }
        private static void ExecuteSync(TaskGroup group, ApplicationInstructions instructions, ApplicationConfiguration configuration)
        {
            var groupInstance = group.ExecuteOnInstance(instructions);

            foreach (var task in group.Tasks)
            {
                task.Execute(configuration, instructions, groupInstance);
            }
        }
        private static void ExecuteASync(TaskGroup group, ApplicationInstructions instructions, ApplicationConfiguration configuration)
        {
            var groupInstance = group.ExecuteOnInstance(instructions);

            Parallel.ForEach(group.Tasks, task =>
            {
                task.Execute(configuration, instructions, groupInstance);
            });
        }
        public void ShouldSetTheApplicationModeToGroupIfInstructionsContainsGroup()
        {
            var instructions = new ApplicationInstructions(null)
            {
                ExecuteAlias = {Alias = "alias"}
            };
            instructions.Instructions.Add(InstructionType.Group, new Instruction());

            Assert.That(instructions.ApplicationMode, Is.EqualTo(ApplicationMode.Group));
        }
示例#8
0
        internal override void Execute(ApplicationConfiguration configuration, ApplicationInstructions instructions,
            object on = null)
        {
            configuration.OnBeforeEachTask(this);

            var instance = on ?? InstanceToExecuteOn(instructions.ConstructorArguments);
            var returnValue = Method.Invoke(instance, instructions.MethodArguments);

            configuration.OnAfterEachTask(this, returnValue);
        }
        public void Execute(ApplicationInstructions instructions, ApplicationConfiguration configuration)
        {
            if (!string.IsNullOrEmpty(instructions.ExecuteAlias.Alias) && instructions.ExecuteAlias.InstructionsFrom == InstructionsFrom.Console)
            {
                throw new ArgumentException("Invalid arguments. Cannot list a task.");
            }

            if (instructions.Instructions.Values.Count(x => x.InstructionsFrom == InstructionsFrom.Console) > 1)
            {
                throw new ArgumentException("Invalid arguments. -l cannot be used with any other switches.");
            }

            PrintTaskList();
            PrintTaskGroupList();
        }
示例#10
0
        internal ApplicationInstructions ToApplicationInstructions(ApplicationConfiguration configuration,
            InstructionsFrom instructionsFrom)
        {
            var appInstructions = new ApplicationInstructions(configuration)
            {
                ExecuteAlias = new ExecutionAlias {Alias = ExecuteAlias, InstructionsFrom = instructionsFrom}
            };

            foreach (var instruction in Instructions)
            {
                appInstructions.Instructions.Add(instruction.InstructionType, instruction);
            }

            return appInstructions;
        }
        public void Execute(ApplicationInstructions instructions, ApplicationConfiguration configuration)
        {
            Validate.ExecuteAlias(instructions.ExecuteAlias);
            var isTimedMode = instructions.TimedMode || configuration.IsTimedMode;

            try
            {
                PrintStartTime(isTimedMode);
                var task = TaskCollection.SelectTask(instructions.ExecuteAlias.Alias);
                task.Execute(configuration, instructions);
            }
            finally
            {
                PrintEndTime(isTimedMode);
            }
        }
        public void Execute(ApplicationInstructions instructions, ApplicationConfiguration configuration)
        {
            if (instructions.Instructions.Values.Count(x => x.InstructionsFrom == InstructionsFrom.Console) > 1)
            {
                throw new ArgumentException("Invalid arguments. -h cannot be used with any other switches.");
            }

            if (string.IsNullOrEmpty(instructions.ExecuteAlias.Alias) || instructions.ExecuteAlias.InstructionsFrom == InstructionsFrom.Configuration)
            {
                Printer.PrintHelp();

                return;
            }

            var task = TaskCollection.SelectTask(instructions.ExecuteAlias.Alias);

            Printer.Info("{0} - {1}", task.UsageExample, task.Description);
        }
 public void ShouldSetTheApplicationModeToHelpIfNoAlias()
 {
     var instructions = new ApplicationInstructions(null);
     Assert.That(instructions.ApplicationMode, Is.EqualTo(ApplicationMode.Help));
 }
示例#14
0
 internal object ExecuteOnInstance(ApplicationInstructions instructions)
 {
     return tasks.ToInstanceToExecuteOn(instructions);
 }
示例#15
0
 internal abstract void Execute(ApplicationConfiguration configuration, ApplicationInstructions instructions,
     object on = null);
 public void Execute(ApplicationInstructions instructions, ApplicationConfiguration configuration)
 {
     Console.WriteLine("Unkown Application ExecuteOn!");
 }
示例#17
0
 internal static object ToInstanceToExecuteOn(this IEnumerable<AbstractTask> collection, ApplicationInstructions instructions)
 {
     return collection.First().InstanceToExecuteOn(instructions.ConstructorArguments);
 }