Beispiel #1
0
        public static void DependencyFails(ITaskBuilder builder, bool defaultExecuted, Exception ex)
        {
            "And a non-default task which fails"
            .f(c => builder = ScriptCs.Require <Bau>()
                              .Task("non-default").DependsOn("default")
                              .Do(() =>
            {
                throw new Exception();
            }));

            "And a default task which depends on the non-default task"
            .f(c => builder
               .Task("default").DependsOn("non-default")
               .Do(() => defaultExecuted = true));

            "When I run the builder"
            .f(() => ex = Record.Exception(() => builder.Run()));

            "Then execution should fail"
            .f(() => ex.Should().NotBeNull());

            "And the default task is not executed"
            .f(() => defaultExecuted.Should().BeFalse());

            "And I am informed that the non-default task was executed"
            .f(() => ex.Message.Should().Contain("'non-default' task failed."));
        }
Beispiel #2
0
        public TaskBuilder(ITaskBuilder builder, string name = null)
        {
            Guard.AgainstNullArgument("builder", builder);

            this.builder = builder;
            this.builder.Intern <TTask>(name);
        }
Beispiel #3
0
        public static void DependencyFails(ITaskBuilder builder, bool defaultExecuted, Exception ex)
        {
            "And a non-default task which fails"
                .f(c => builder = ScriptCs.Require<Bau>()
                    .Task("non-default").DependsOn("default")
                        .Do(() =>
                        {
                            throw new Exception();
                        }));

            "And a default task which depends on the non-default task"
                .f(c => builder
                    .Task("default").DependsOn("non-default")
                        .Do(() => defaultExecuted = true));

            "When I run the builder"
                .f(() => ex = Record.Exception(() => builder.Run()));

            "Then execution should fail"
                .f(() => ex.Should().NotBeNull());

            "And the default task is not executed"
                .f(() => defaultExecuted.Should().BeFalse());

            "And I am informed that the non-default task was executed"
                .f(() => ex.Message.Should().Contain("'non-default' task failed."));
        }
Beispiel #4
0
		public TabbedSkin(BasilProject project, ITaskBuilder taskBuilder)
		{
			_project = project;
			_tabsToTools = new System.Collections.Hashtable();

			window = new Gtk.Window ("WeSay");
			window.SetDefaultSize (600, 400);
			window.DeleteEvent += new DeleteEventHandler (WindowDelete);

			HBox hbox = new HBox (false, 0);
			window.Add (hbox);

			Notebook notebook = new Notebook ();
			notebook.SwitchPage += new SwitchPageHandler(OnNotebookSwitchPage);
			hbox.PackStart(notebook, true, true, 0);
			foreach (ITask t in taskBuilder.Tasks)
			{
				VBox container = new VBox();
				t.Container = container;
				int i = notebook.AppendPage(container, new Label(t.Label));
				_tabsToTools.Add(i, t);
			}

			window.ShowAll ();
		}
Beispiel #5
0
 public TaskRunner(ITaskResetter taskResetter, ITaskQueuer taskQueuer, ITaskBuilder taskBuilder, ITaskExecutor taskExecutor)
 {
     _taskResetter = taskResetter;
     _taskQueuer   = taskQueuer;
     _taskBuilder  = taskBuilder;
     _taskExecutor = taskExecutor;
 }
Beispiel #6
0
        public static void MultipleDependencies(ITaskBuilder builder, List<string> executedTasks)
        {
            "Given a non-default task"
                .f(c => builder = ScriptCs.Require<Bau>()
                    .Task("non-default1")
                        .Do(() => (executedTasks = new List<string>()).Add("non-default1")));

            "And a second non-default task"
                .f(() => builder
                    .Task("non-default2")
                        .Do(() => executedTasks.Add("non-default2")));

            "And a default task which depends on both non-default tasks"
                .f(() => builder
                    .Task("default").DependsOn("non-default1", "non-default2")
                        .Do(() => executedTasks.Add("default")));

            "When I run the builder"
                .f(() => builder.Run());

            "Then all three tasks are executed"
                .f(() => executedTasks.Count.Should().Be(3));

            "And the first non-default task is executed first"
                .f(() => executedTasks[0].Should().Be("non-default1"));

            "And the second non-default task is executed second"
                .f(() => executedTasks[1].Should().Be("non-default2"));

            "And the default task is executed third"
                .f(() => executedTasks[2].Should().Be("default"));
        }
Beispiel #7
0
 public TaskRunner(ITaskResetter taskResetter, ITaskQueuer taskQueuer, ITaskBuilder taskBuilder, ITaskExecutor taskExecutor)
 {
     _taskResetter = taskResetter;
     _taskQueuer = taskQueuer;
     _taskBuilder = taskBuilder;
     _taskExecutor = taskExecutor;
 }
Beispiel #8
0
 public TaskService(TasklistDbContext tasklistDbContext, IMapper mapper, ITaskBuilder taskBuilder, IValidator <TaskDto> validator)
 {
     _tasklistDbContext = tasklistDbContext;
     _mapper            = mapper;
     _taskBuilder       = taskBuilder;
     _validator         = validator;
 }
Beispiel #9
0
 public LuaCopyTask(ITaskBuilder taskBuilder, string source, string target)
 {
     _taskBuilder = taskBuilder;
     _taskBuilder
     .With("CopyFromPath", source)
     .With("CopyToPath", target);
 }
Beispiel #10
0
        /// <summary>
        /// Walks through the set of tasks for this target and processes them by handing them off to the TaskBuilder.
        /// </summary>
        /// <returns>
        /// The result of the tasks, based on the last task which ran.
        /// </returns>
        private async Task <WorkUnitResult> ProcessBucket(ITaskBuilder taskBuilder, TargetLoggingContext targetLoggingContext, TaskExecutionMode mode, Lookup lookupForInference, Lookup lookupForExecution)
        {
            WorkUnitResultCode aggregatedTaskResult = WorkUnitResultCode.Success;
            WorkUnitActionCode finalActionCode      = WorkUnitActionCode.Continue;
            WorkUnitResult     lastResult           = new WorkUnitResult(WorkUnitResultCode.Success, WorkUnitActionCode.Continue, null);

            try
            {
                // Grab the task builder so if cancel is called it will have something to operate on.
                _currentTaskBuilder = taskBuilder;

                int currentTask = 0;

                // Walk through all of the tasks and execute them in order.
                for (; (currentTask < _target.Children.Count) && !_cancellationToken.IsCancellationRequested; ++currentTask)
                {
                    ProjectTargetInstanceChild targetChildInstance = _target.Children[currentTask];

                    if (DebuggerManager.DebuggingEnabled)
                    {
                        DebuggerManager.EnterState(targetChildInstance.Location, lookupForExecution.GlobalsForDebugging /* does not matter which lookup we get this from */);
                    }

                    // Execute the task.
                    lastResult = await taskBuilder.ExecuteTask(targetLoggingContext, _requestEntry, _targetBuilderCallback, targetChildInstance, mode, lookupForInference, lookupForExecution, _cancellationToken);

                    if (DebuggerManager.DebuggingEnabled)
                    {
                        DebuggerManager.LeaveState(targetChildInstance.Location);
                    }

                    if (lastResult.ResultCode == WorkUnitResultCode.Failed)
                    {
                        aggregatedTaskResult = WorkUnitResultCode.Failed;
                    }
                    else if (lastResult.ResultCode == WorkUnitResultCode.Success && aggregatedTaskResult != WorkUnitResultCode.Failed)
                    {
                        aggregatedTaskResult = WorkUnitResultCode.Success;
                    }

                    if (lastResult.ActionCode == WorkUnitActionCode.Stop)
                    {
                        finalActionCode = WorkUnitActionCode.Stop;
                        break;
                    }
                }

                if (_cancellationToken.IsCancellationRequested)
                {
                    aggregatedTaskResult = WorkUnitResultCode.Canceled;
                    finalActionCode      = WorkUnitActionCode.Stop;
                }
            }
            finally
            {
                _currentTaskBuilder = null;
            }

            return(new WorkUnitResult(aggregatedTaskResult, finalActionCode, lastResult.Exception));
        }
Beispiel #11
0
        public TabbedSkin(BasilProject project, ITaskBuilder taskBuilder)
        {
            _project     = project;
            _tabsToTools = new System.Collections.Hashtable();

            window = new Gtk.Window("WeSay");
            window.SetDefaultSize(600, 400);
            window.DeleteEvent += new DeleteEventHandler(WindowDelete);

            HBox hbox = new HBox(false, 0);

            window.Add(hbox);

            Notebook notebook = new Notebook();

            notebook.SwitchPage += new SwitchPageHandler(OnNotebookSwitchPage);
            hbox.PackStart(notebook, true, true, 0);
            foreach (ITask t in taskBuilder.Tasks)
            {
                VBox container = new VBox();
                t.Container = container;
                int i = notebook.AppendPage(container, new Label(t.Label));
                _tabsToTools.Add(i, t);
            }

            window.ShowAll();
        }
Beispiel #12
0
        public static void NestedDependencies(ITaskBuilder builder, List <string> executedTasks)
        {
            "Given a non-default task"
            .f(c => builder = ScriptCs.Require <Bau>()
                              .Task("non-default1")
                              .Do(() => (executedTasks = new List <string>()).Add("non-default1")));

            "And a second non-default task which depends on the first non-default task"
            .f(c => builder
               .Task("non-default2").DependsOn("non-default1")
               .Do(() => executedTasks.Add("non-default2")));

            "And a default task which depends on the second non-default task"
            .f(() => builder
               .Task("default").DependsOn("non-default2")
               .Do(() => executedTasks.Add("default")));

            "When I run the builder"
            .f(() => builder.Run());

            "Then all three tasks are executed"
            .f(() => executedTasks.Count.Should().Be(3));

            "And the first non-default task is executed first"
            .f(() => executedTasks[0].Should().Be("non-default1"));

            "And the second non-default task is executed second"
            .f(() => executedTasks[1].Should().Be("non-default2"));

            "And the default task is executed third"
            .f(() => executedTasks[2].Should().Be("default"));
        }
        public void BuildComponentFactory__WhenCallingTaskWith_SoftCopy__ShouldReturnCopyTaskBuilder()
        {
            BuildComponentFactory sut = new BuildComponentFactory();

            ITaskBuilder taskBuilder = sut.Task("SoftCopy");

            Assert.IsInstanceOfType(taskBuilder, typeof(CopyTaskBuilder));
        }
        public void BuildComponentFactory__WhenCallingTaskWith_RunProgram__ShouldReturnRunProcessTaskBuilder()
        {
            BuildComponentFactory sut = new BuildComponentFactory();

            ITaskBuilder taskBuilder = sut.Task("RunProgram");

            Assert.IsInstanceOfType(taskBuilder, typeof(RunProcessTaskBuilder));
        }
 public static ITaskBuilder <TPreviousValue> ErrorWhen <TPreviousValue, TError>(
     this ITaskBuilder <TPreviousValue> previousTaskBuilder,
     Func <TPreviousValue, bool> predicate,
     Func <TPreviousValue, Task <TError> > onError,
     string errorMessage = null)
 {
     return(new ErrorWhenTaskBuilder <TPreviousValue, TError>(previousTaskBuilder, predicate, onError, errorMessage));
 }
        BuildComponentFactory__WhenCallingTaskWith_UpdateSteamWorkshopItem__ShouldReturnUpdateSteamWorkshopItemTaskBuilder()
        {
            BuildComponentFactory sut = new BuildComponentFactory();

            ITaskBuilder taskBuilder = sut.Task("UpdateSteamWorkshopItem");

            Assert.IsInstanceOfType(taskBuilder, typeof(UpdateSteamWorkshopItemTaskBuilder));
        }
Beispiel #17
0
 public QueuedTaskRunner(ITaskQueuer taskQueuer, ITaskBuilder taskBuilder, ITaskExecutor taskExecutor,
                         ISession session, ITriggerUrls triggerUrls)
 {
     _taskQueuer   = taskQueuer;
     _taskBuilder  = taskBuilder;
     _taskExecutor = taskExecutor;
     _session      = session;
     _triggerUrls  = triggerUrls;
 }
Beispiel #18
0
        public static void DefaultTaskExists(ITaskBuilder builder, bool executed)
        {
            "Given a default task"
                .f(() => builder = ScriptCs.Require<Bau>().Do(() => executed = true));

            "When I run the builder"
                .f(() => builder.Run());

            "Then the task is executed"
                .f(() => executed.Should().BeTrue());
        }
Beispiel #19
0
 public MainProgram(
     IAppConfiguration configuration,
     ITaskBuilder taskBuilder,
     IBuildDefinitionReader buildDefinitionReader,
     IBuildReporter buildReporter)
 {
     _configuration         = configuration;
     _buildReporter         = buildReporter;
     _taskBuilder           = taskBuilder;
     _buildDefinitionReader = buildDefinitionReader;
 }
Beispiel #20
0
        public static void DefaultTaskExists(ITaskBuilder builder, bool executed)
        {
            "Given a default task"
            .f(() => builder = ScriptCs.Require <Bau>().Do(() => executed = true));

            "When I run the builder"
            .f(() => builder.Run());

            "Then the task is executed"
            .f(() => executed.Should().BeTrue());
        }
Beispiel #21
0
 public ErrorWhenTaskBuilder(
     ITaskBuilder <TPreviousValue> previousTaskBuilder,
     Func <TPreviousValue, bool> predicate,
     Func <TPreviousValue, Task <TNextValue> > onSuccess,
     Func <TPreviousValue, Task <TError> > onError,
     string errorMessage = null)
 {
     this._previousTaskBuilder = previousTaskBuilder;
     this._predicateAsync      = (p) => Task.Run(() => predicate(p));
     this._onSuccess           = onSuccess;
     this._onError             = onError;
     this._errorMessage        = errorMessage;
 }
Beispiel #22
0
 public CommandsCollection(IConsole console, ITaskManager taskManager, ITaskBuilder taskBuilder, IConverter converter)
 {
     _commands.Add(new DrawHeaderCommand(console));
     _commands.Add(new ClearCommand(console, _commands[0] as DrawHeaderCommand));
     _commands.Add(new HelpCommand(console, this));
     _commands.Add(new AddTaskCommand(console, taskManager, taskBuilder));
     _commands.Add(new RemoveTaskCommand(console, taskManager));
     _commands.Add(new ListTasksCommand(console, taskManager));
     _commands.Add(new ShowTaskCommand(console, taskManager));
     _commands.Add(new EditTaskCommand(console, taskManager, taskBuilder));
     _commands.Add(new SaveListCommand(console, taskManager, converter));
     _commands.Add(new LoadListCommand(console, taskManager, converter));
 }
Beispiel #23
0
        private ITask MakeTask(object buildConfigTask)
        {
            ITaskBuilder taskBuilder = _factory.Task(buildConfigTask.GetType().Name);

            foreach (PropertyInfo prop in buildConfigTask.GetType().GetProperties())
            {
                taskBuilder.With(prop.Name, prop.GetValue(buildConfigTask));
            }

            ITask task = taskBuilder.Build();

            return(task);
        }
Beispiel #24
0
        public static void SingleTask(ITaskBuilder builder, bool executed)
        {
            "Given a non-default task is specified"
            .f(() => builder = ScriptCs.Require <Bau>(new[] { "non-default" }));

            "And a non-default task"
            .f(() => builder.Task("non-default").Do(() => executed = true));

            "When I run the builder"
            .f(() => builder.Run());

            "Then the task is executed"
            .f(() => executed.Should().BeTrue());
        }
Beispiel #25
0
        public static void SingleTask(ITaskBuilder builder, bool executed)
        {
            "Given a non-default task is specified"
                .f(() => builder = ScriptCs.Require<Bau>(new[] { "non-default" }));

            "And a non-default task"
                .f(() => builder.Task("non-default").Do(() => executed = true));

            "When I run the builder"
                .f(() => builder.Run());

            "Then the task is executed"
                .f(() => executed.Should().BeTrue());
        }
Beispiel #26
0
        public static void ANonDefaultTaskExists(ITaskBuilder builder, Exception ex)
        {
            "Given no tasks"
            .f(() => builder = ScriptCs.Require <Bau>().Task("foo").Do(() => { }));

            "When I run the builder"
            .f(() => ex = Record.Exception(() => builder.Run()));

            "Then execution should fail"
            .f(() => ex.Should().NotBeNull());

            "And I am informed that the default task was not found"
            .f(() => ex.Message.Should().Contain("'default' task not found"));
        }
Beispiel #27
0
        public static void NoTasksExist(ITaskBuilder builder, Exception ex)
        {
            "Given no tasks"
                .f(() => builder = ScriptCs.Require<Bau>());

            "When I run the builder"
                .f(() => ex = Record.Exception(() => builder.Run()));

            "Then execution should fail"
                .f(() => ex.Should().NotBeNull());

            "And I am informed that the default task was not found"
                .f(() => ex.Message.Should().Contain("'default' task not found"));
        }
Beispiel #28
0
        public TaskProcessing(ITaskBuilder taskBuilder, TaskProcessingConfiguration taskProcessingConfiguration)
        {
            if (taskBuilder == null)
            {
                throw new ArgumentNullException(nameof(taskBuilder));
            }
            if (taskProcessingConfiguration == null)
            {
                throw new ArgumentNullException(nameof(taskProcessingConfiguration));
            }

            this.taskBuilder = taskBuilder;
            slots            = taskProcessingConfiguration.MaxProcessingTasks;
            RunningTasks     = new Dictionary <int, IRunningTask>();
        }
        public TaskManager(IScheduleRepository scheduleRepository, ITaskRepository taskRepository, IJsonConverter jsonConverter, ITaskBuilder taskBuilder, ITaskProcessing taskProcessing, IServiceMessageProcessor serviceMessageProcessor, IUnitOfWorkFactory unitOfWorkFactory, IContextSettings contextSettings, TaskManagerConfiguration managerConfiguration) : base(managerConfiguration)
        {
            if (scheduleRepository == null)
            {
                throw new ArgumentNullException(nameof(scheduleRepository));
            }
            if (taskRepository == null)
            {
                throw new ArgumentNullException(nameof(taskRepository));
            }
            if (jsonConverter == null)
            {
                throw new ArgumentNullException(nameof(jsonConverter));
            }
            if (taskBuilder == null)
            {
                throw new ArgumentNullException(nameof(taskBuilder));
            }
            if (taskProcessing == null)
            {
                throw new ArgumentNullException(nameof(taskProcessing));
            }
            if (serviceMessageProcessor == null)
            {
                throw new ArgumentNullException(nameof(serviceMessageProcessor));
            }
            if (unitOfWorkFactory == null)
            {
                throw new ArgumentNullException(nameof(unitOfWorkFactory));
            }
            if (contextSettings == null)
            {
                throw new ArgumentNullException(nameof(contextSettings));
            }

            this.scheduleRepository = scheduleRepository;
            this.taskRepository     = taskRepository;
            this.jsonConverter      = jsonConverter;
            this.taskBuilder        = taskBuilder;
            this.taskProcessing     = taskProcessing;
            this.unitOfWorkFactory  = unitOfWorkFactory;
            this.contextSettings    = contextSettings;

            ServiceMessageHandlerId = Guid.NewGuid();
            serviceMessageProcessor.RegisteredServiceMessageHandler(this);

            taskProcessing.OnTaskProcessed += OnTaskProcessed;
        }
Beispiel #30
0
        public static void ExecutingAnInlineTask(ITaskBuilder builder, bool executed)
        {
            "Given a default task with an inline task"
            .f(() => builder = ScriptCs.Require <Bau>().Do(() =>
            {
                var task = new BauCore.BauTask();
                task.Actions.Add(() => executed = true);
                task.Execute();
            }));

            "When I run the builder"
            .f(() => builder.Run());

            "Then the inline task is executed"
            .f(() => executed.Should().BeTrue());
        }
Beispiel #31
0
        public static void ExecutingAnInlineTask(ITaskBuilder builder, bool executed)
        {
            "Given a default task with an inline task"
                .f(() => builder = ScriptCs.Require<Bau>().Do(() =>
                {
                    var task = new BauCore.BauTask();
                    task.Actions.Add(() => executed = true);
                    task.Execute();
                }));

            "When I run the builder"
                .f(() => builder.Run());

            "Then the inline task is executed"
                .f(() => executed.Should().BeTrue());
        }
Beispiel #32
0
        public static void AnotherTaskExists(ITaskBuilder builder, Exception ex)
        {
            "Given a non-existent task is specified"
            .f(() => builder = ScriptCs.Require <Bau>(new[] { "non-existent" }));

            "And another task exists"
            .f(() => builder.Task("foo").Do(() => { }));

            "When I run the builder"
            .f(() => ex = Record.Exception(() => builder.Run()));

            "Then execution should fail"
            .f(() => ex.Should().NotBeNull());

            "And I am informed that the non-existent task was not found"
            .f(() => ex.Message.Should().Contain("'non-existent' task not found"));
        }
Beispiel #33
0
        public static void NoTasksExist(ITaskBuilder builder, Exception ex)
        {
            "Given a non-existent task is specified"
                .f(() => builder = ScriptCs.Require<Bau>(new[] { "non-existent" }));

            "And no tasks"
                .f(() => { });

            "When I run the builder"
                .f(() => ex = Record.Exception(() => builder.Run()));

            "Then execution should fail"
                .f(() => ex.Should().NotBeNull());

            "And I am informed that the non-existent task was not found"
                .f(() => ex.Message.Should().Contain("'non-existent' task not found"));
        }
Beispiel #34
0
        public static void NonexistentDependency(ITaskBuilder builder, Exception ex)
        {
            "Given a default task with a non-existent dependency"
            .f(c => builder = ScriptCs.Require <Bau>()
                              .Task("default").DependsOn("non-existent")
                              .Do(() =>
            {
            }));

            "When I run the builder"
            .f(() => ex = Record.Exception(() => builder.Run()));

            "Then execution should fail"
            .f(() => ex.Should().NotBeNull());

            "And I am informed that the non-existent task was not found"
            .f(() => ex.Message.Should().Contain("'non-existent' task not found"));
        }
Beispiel #35
0
        public static void MultipleTasks(string[] args, ITaskBuilder builder, bool executed1, bool executed2)
        {
            "Given arguments containing 2 non-default tasks"
            .f(() => builder = ScriptCs.Require <Bau>(new[] { "non-default1", "non-default2" }));

            "And a non-default task"
            .f(() => builder.Task("non-default1").Do(() => executed1 = true));

            "And another non-default task"
            .f(() => builder.Task("non-default2").Do(() => executed2 = true));

            "When I run the builder"
            .f(() => builder.Run());

            "Then the first task is executed"
            .f(() => executed1.Should().BeTrue());

            "And the second task is executed"
            .f(() => executed2.Should().BeTrue());
        }
Beispiel #36
0
        public static void MultipleTasks(string[] args, ITaskBuilder builder, bool executed1, bool executed2)
        {
            "Given arguments containing 2 non-default tasks"
                .f(() => builder = ScriptCs.Require<Bau>(new[] { "non-default1", "non-default2" }));

            "And a non-default task"
                .f(() => builder.Task("non-default1").Do(() => executed1 = true));

            "And another non-default task"
                .f(() => builder.Task("non-default2").Do(() => executed2 = true));

            "When I run the builder"
                .f(() => builder.Run());

            "Then the first task is executed"
                .f(() => executed1.Should().BeTrue());

            "And the second task is executed"
                .f(() => executed2.Should().BeTrue());
        }
        public LuaCreateSteamWorkshopItemTask(ITaskBuilder taskBuilder, LuaTable table)
        {
            taskBuilder
            .With("AppId", Convert.ToUInt32(table["app_id"]))
            .With("Title", table["title"])
            .With("DescriptionFilePath", table["description_file"])
            .With("ItemFolderPath", table["item_folder"])
            .With("Visibility", table["visibility"])
            .With("Language", table["language"]);

            LuaTable         tags       = (LuaTable)table["tags"];
            HashSet <string> stringTags = tags?.Values.Cast <string>().ToHashSet();

            if (stringTags != null)
            {
                taskBuilder.With("Tags", stringTags);
            }

            Task = taskBuilder.Build();
        }
Beispiel #38
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="expressionConverter">The <see cref="IExpressionConverter"/> instance.</param>
        /// <param name="taskDataContext">The <see cref="ITaskDataContext"/> instance.</param>
        /// <param name="serverManager">The <see cref="IQueueManager"/> instance.</param>
        /// <param name="queueManager">The <see cref="IServerManager"/> instance.</param>
        /// <param name="loggerFactory">The <see cref="ICommonLoggerFactory"/> instance.</param>
        /// <exception cref="ArgumentNullException"><paramref name="expressionConverter"/> is <see langword="null" />.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="taskDataContext"/> is <see langword="null" />.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="serverManager"/> is <see langword="null" />.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="queueManager"/> is <see langword="null" />.</exception>
        public TaskManager(TaskManagerConfiguration taskManagerConfiguration, ITaskBuilder taskBuilder, IExpressionConverter expressionConverter, ITaskDataContext taskDataContext, IServerManager serverManager, IQueueManager queueManager, ICommonLoggerFactory loggerFactory)
            : base("Task Manager", loggerFactory)
        {
            if (taskManagerConfiguration == null)
            {
                throw new ArgumentNullException(nameof(taskManagerConfiguration));
            }
            if (taskBuilder == null)
            {
                throw new ArgumentNullException(nameof(taskBuilder));
            }
            if (expressionConverter == null)
            {
                throw new ArgumentNullException("expressionConverter");
            }
            if (taskDataContext == null)
            {
                throw new ArgumentNullException("taskDataContext");
            }
            if (serverManager == null)
            {
                throw new ArgumentNullException("serverManager");
            }
            if (queueManager == null)
            {
                throw new ArgumentNullException("queueManager");
            }

            this.taskBuilder         = taskBuilder;
            this.expressionConverter = expressionConverter;
            this.taskDataContext     = taskDataContext;
            this.serverManager       = serverManager;
            this.queueManager        = queueManager;

            activeTasks = new Dictionary <Int64, IRunningTask>();

            maxRerunCount       = taskManagerConfiguration.MaxRerunAttempts;
            maxTasksPerQueue    = taskManagerConfiguration.MaxTaskPerQueue;
            timeShiftAfterCrash = taskManagerConfiguration.TimeShiftAfterCrash;
            taskManagerState    = taskManagerConfiguration.State;
        }
Beispiel #39
0
        public static void ReenablingATask(ITaskBuilder builder, List<string> executedTasks)
        {
            "Given a non-default task which depends on and reenables another non-default task"
                .f(c => builder = ScriptCs.Require<Bau>()
                    .Task("non-default").DependsOn("other-non-default")
                        .Do(() =>
                        {
                            builder.Reenable("other-non-default");
                            executedTasks.Add("non-default");
                        }));

            "And the other non-default task"
                .f(c => builder
                    .Task("other-non-default")
                        .Do(() => (executedTasks ?? (executedTasks = new List<string>())).Add("other-non-default")));

            "And a default task which depends on both non-default tasks"
                .f(() => builder
                    .Task("default").DependsOn("non-default", "other-non-default")
                        .Do(() => executedTasks.Add("default")));

            "When I run the builder"
                .f(() => builder.Run());

            "Then four tasks are executed"
                .f(() => executedTasks.Count.Should().Be(4));

            "And the other non-default task is executed first"
                .f(() => executedTasks[0].Should().Be("other-non-default"));

            "And the non-default task is executed second"
                .f(() => executedTasks[1].Should().Be("non-default"));

            "And the other non-default task is executed third for the second time"
                .f(() => executedTasks[2].Should().Be("other-non-default"));

            "And the default task is executed fourth"
                .f(() => executedTasks[3].Should().Be("default"));
        }
Beispiel #40
0
        public static void ReenablingATask(ITaskBuilder builder, List <string> executedTasks)
        {
            "Given a non-default task which depends on and reenables another non-default task"
            .f(c => builder = ScriptCs.Require <Bau>()
                              .Task("non-default").DependsOn("other-non-default")
                              .Do(() =>
            {
                builder.Reenable("other-non-default");
                executedTasks.Add("non-default");
            }));

            "And the other non-default task"
            .f(c => builder
               .Task("other-non-default")
               .Do(() => (executedTasks ?? (executedTasks = new List <string>())).Add("other-non-default")));

            "And a default task which depends on both non-default tasks"
            .f(() => builder
               .Task("default").DependsOn("non-default", "other-non-default")
               .Do(() => executedTasks.Add("default")));

            "When I run the builder"
            .f(() => builder.Run());

            "Then four tasks are executed"
            .f(() => executedTasks.Count.Should().Be(4));

            "And the other non-default task is executed first"
            .f(() => executedTasks[0].Should().Be("other-non-default"));

            "And the non-default task is executed second"
            .f(() => executedTasks[1].Should().Be("non-default"));

            "And the other non-default task is executed third for the second time"
            .f(() => executedTasks[2].Should().Be("other-non-default"));

            "And the default task is executed fourth"
            .f(() => executedTasks[3].Should().Be("default"));
        }
Beispiel #41
0
        public static void SingleDependency(ITaskBuilder builder, List <string> executedTasks)
        {
            "Given a non-default task"
            .f(c => builder = ScriptCs.Require <Bau>()
                              .Task("non-default")
                              .Do(() => (executedTasks = new List <string>()).Add("non-default")));

            "And a default task which depends on the non-default task"
            .f(() => builder
               .Task("default").DependsOn("non-default")
               .Do(() => executedTasks.Add("default")));

            "When I run the builder"
            .f(() => builder.Run());

            "Then both tasks are executed"
            .f(() => executedTasks.Count.Should().Be(2));

            "And the non-default task is executed first"
            .f(() => executedTasks[0].Should().Be("non-default"));

            "And the default task is executed second"
            .f(() => executedTasks[1].Should().Be("default"));
        }
Beispiel #42
0
        public static void CircularDependency(ITaskBuilder builder, List<string> executedTasks)
        {
            "Given a non-default task which depends on the default task"
                .f(c => builder = ScriptCs.Require<Bau>()
                    .Task("non-default").DependsOn("default")
                        .Do(() => (executedTasks = new List<string>()).Add("non-default")));

            "And a default task which depends on the non-default task"
                .f(c => builder
                    .Task("default").DependsOn("non-default")
                        .Do(() => executedTasks.Add("default")));

            "When I run the builder"
                .f(() => builder.Run());

            "Then both tasks are executed"
                .f(() => executedTasks.Count.Should().Be(2));

            "And the non-default task is executed first"
                .f(() => executedTasks[0].Should().Be("non-default"));

            "And the default task is executed second"
                .f(() => executedTasks[1].Should().Be("default"));
        }
            /// <summary>
            /// Constructor
            /// </summary>
            public MockHost()
            {
                _buildParameters = new BuildParameters();
                _legacyThreadingData = new LegacyThreadingData();

                _configCache = new ConfigCache();
                ((IBuildComponent)_configCache).InitializeComponent(this);

                _loggingService = this;

                _resultsCache = new ResultsCache();
                ((IBuildComponent)_resultsCache).InitializeComponent(this);

                _requestBuilder = new RequestBuilder();
                ((IBuildComponent)_requestBuilder).InitializeComponent(this);

                _taskBuilder = new MockTaskBuilder();
                ((IBuildComponent)_taskBuilder).InitializeComponent(this);

                _targetBuilder = new TargetBuilder();
                ((IBuildComponent)_targetBuilder).InitializeComponent(this);
            }
Beispiel #44
0
        public static void NonexistentDependency(ITaskBuilder builder, Exception ex)
        {
            "Given a default task with a non-existent dependency"
                .f(c => builder = ScriptCs.Require<Bau>()
                    .Task("default").DependsOn("non-existent")
                        .Do(() =>
                        {
                        }));

            "When I run the builder"
                .f(() => ex = Record.Exception(() => builder.Run()));

            "Then execution should fail"
                .f(() => ex.Should().NotBeNull());

            "And I am informed that the non-existent task was not found"
                .f(() => ex.Message.Should().Contain("'non-existent' task not found"));
        }
		public void Generate(IList<PropertyWithName> props, string baseSaveDirectory, RunConfig config)
		{
			var dir = Path.Combine(baseSaveDirectory, config.Directory);
			if(!Directory.Exists(dir))
			{
				Directory.CreateDirectory(dir);
			}

			clientBuilder = config.HttpBuilder;
			taskBuilder = config.TaskBuilder;
			testBuilder = config.TestBuilder;
			variables = config.Variables;

			var cu = CompilationUnit();
			cu = cu.AddUsing("System").WithLeadingTrivia(GeneratorBase.GetLicenseComment());
			cu = cu.AddUsings(new string[]
			{
				"System.Threading.Tasks",
				"Newtonsoft.Json",
				"Newtonsoft.Json.Linq"
			});
			cu = cu.AddUsings(clientBuilder.Namespace);
			cu = cu.AddUsings(testBuilder.Namespaces);

			if(String.Compare(variables.GetValue("IsUWP"), "1", true) == 0)
			{
				cu = cu.AddUsing("System.Runtime.InteropServices");
			}

			var namesp = NamespaceDeclaration(IdentifierName("Sannel.House.ServerSDK.Tests"));

			var @class = ClassDeclaration("ServerContextTests")
				.AddModifiers(Token(SyntaxKind.PublicKeyword),
				Token(SyntaxKind.PartialKeyword));


			foreach(var prop in props)
			{
				@class = addType(prop, @class);
			}

			namesp = namesp.AddMembers(@class);

			cu = cu.AddMembers(namesp).NormalizeWhitespace("\t", true);
			using(var writer = new StreamWriter(File.OpenWrite(Path.Combine(dir, config.FileName))))
			{
				cu.WriteTo(writer);
			}
		}
Beispiel #46
0
        /// <summary>
        /// Processes the target stack until its empty or we hit a recursive break (due to CallTarget etc.)
        /// </summary>
        private async Task ProcessTargetStack(ITaskBuilder taskBuilder)
        {
            // Keep building while we have targets to build and haven't been cancelled.
            bool stopProcessingStack = false;
            while
                (
                !_cancellationToken.IsCancellationRequested &&
                !stopProcessingStack &&
                !_targetsToBuild.IsEmpty
                )
            {
                TargetEntry currentTargetEntry = _targetsToBuild.Peek();
                switch (currentTargetEntry.State)
                {
                    case TargetEntryState.Dependencies:
                        // Ensure we are dealing with a target which actually exists.
                        ProjectErrorUtilities.VerifyThrowInvalidProject
                        (
                        _requestEntry.RequestConfiguration.Project.Targets.ContainsKey(currentTargetEntry.Name),
                        currentTargetEntry.ReferenceLocation,
                        "TargetDoesNotExist",
                        currentTargetEntry.Name
                        );

                        // If we already have results for this target which were not skipped, we can ignore it.  In 
                        // addition, we can also ignore its before and after targets -- if this target has already run, 
                        // then so have they.
                        if (!CheckSkipTarget(ref stopProcessingStack, currentTargetEntry))
                        {
                            // Temporarily remove this entry so we can push our after targets
                            _targetsToBuild.Pop();

                            // Push our after targets, if any.  Our parent is the parent of the target after which we are running.
                            IList<TargetSpecification> afterTargets = _requestEntry.RequestConfiguration.Project.GetTargetsWhichRunAfter(currentTargetEntry.Name);
                            bool didPushTargets = await PushTargets(afterTargets, currentTargetEntry.ParentEntry, currentTargetEntry.Lookup, currentTargetEntry.ErrorTarget, currentTargetEntry.StopProcessingOnCompletion, TargetPushType.AfterTargets);

                            // If we have after targets, the last one to run will inherit the stopProcessing flag and we will reset ours.  If we didn't push any targets, then we shouldn't clear the
                            // flag because it means we are still on the bottom of this CallTarget stack.
                            if ((afterTargets.Count != 0) && didPushTargets)
                            {
                                currentTargetEntry.StopProcessingOnCompletion = false;
                            }

                            // Put us back on the stack
                            _targetsToBuild.Push(currentTargetEntry);

                            // Determine which targets are dependencies.  This will also test to see if the target should be skipped due to condition.
                            // If it is determined the target should skip, the dependency list returned will be empty.
                            IList<TargetSpecification> dependencies = currentTargetEntry.GetDependencies(_projectLoggingContext);

                            // Push our before targets now, unconditionally.  If we have marked that we should stop processing the stack here, which can only
                            // happen if our current target was supposed to stop processing AND we had no after targets, then our last before target should 
                            // inherit the stop processing flag and we will reset it.
                            // Our parent is the target before which we run, just like a depends-on target.
                            IList<TargetSpecification> beforeTargets = _requestEntry.RequestConfiguration.Project.GetTargetsWhichRunBefore(currentTargetEntry.Name);
                            bool pushedTargets = await PushTargets(beforeTargets, currentTargetEntry, currentTargetEntry.Lookup, currentTargetEntry.ErrorTarget, stopProcessingStack, TargetPushType.BeforeTargets);
                            if (beforeTargets.Count != 0 && pushedTargets)
                            {
                                stopProcessingStack = false;
                            }

                            // And if we have dependencies to run, push them now.
                            if (null != dependencies)
                            {
                                await PushTargets(dependencies, currentTargetEntry, currentTargetEntry.Lookup, false, false, TargetPushType.Normal);
                            }
                        }

                        break;

                    case TargetEntryState.Execution:

                        // It's possible that our target got pushed onto the stack for one build and had its dependencies process, then a re-entrant build came in and
                        // actually built this target while we were waiting, so that by the time we get here, it's already been finished.  In this case, just blow it away.
                        if (!CheckSkipTarget(ref stopProcessingStack, currentTargetEntry))
                        {
                            // This target is now actively building.
                            _requestEntry.RequestConfiguration.ActivelyBuildingTargets.Add(currentTargetEntry.Name, _requestEntry.Request.GlobalRequestId);

                            // Execute all of the tasks on this target.
                            await currentTargetEntry.ExecuteTarget(taskBuilder, _requestEntry, _projectLoggingContext, _cancellationToken);
                        }

                        break;

                    case TargetEntryState.ErrorExecution:
                        // Push the error targets onto the stack.  This target will now be marked as completed.
                        // When that state is processed, it will mark its parent for error execution
                        List<TargetSpecification> errorTargets = currentTargetEntry.GetErrorTargets(_projectLoggingContext);
                        try
                        {
                            await PushTargets(errorTargets, currentTargetEntry, currentTargetEntry.Lookup, true, false, TargetPushType.Normal);
                        }
                        catch
                        {
                            if (_requestEntry.RequestConfiguration.ActivelyBuildingTargets.ContainsKey(currentTargetEntry.Name))
                            {
                                _requestEntry.RequestConfiguration.ActivelyBuildingTargets.Remove(currentTargetEntry.Name);
                            }

                            throw;
                        }

                        break;

                    case TargetEntryState.Completed:
                        // The target is complete, we can gather up the results and remove this target
                        // from the stack.
                        TargetResult targetResult = currentTargetEntry.GatherResults();

                        // If this result failed but we are under the influence of the legacy ContinueOnError behavior for a
                        // CallTarget, make sure we don't contribute this failure to the overall success of the build.
                        targetResult.TargetFailureDoesntCauseBuildFailure = _legacyCallTargetContinueOnError;

                        // This target is no longer actively building.
                        _requestEntry.RequestConfiguration.ActivelyBuildingTargets.Remove(currentTargetEntry.Name);

                        _buildResult.AddResultsForTarget(currentTargetEntry.Name, targetResult);

                        TargetEntry topEntry = _targetsToBuild.Pop();
                        if (topEntry.StopProcessingOnCompletion)
                        {
                            stopProcessingStack = true;
                        }

                        PopDependencyTargetsOnTargetFailure(topEntry, targetResult, ref stopProcessingStack);

                        break;

                    default:
                        ErrorUtilities.ThrowInternalError("Unexpected target state {0}", currentTargetEntry.State);
                        break;
                }
            }
        }