public DefaultBuildEnvironment(IPlan plan, ITargetDescription description, TaskMap<ModuleName, ITarget> taskMap, CancellationToken token) { if (taskMap == null) throw new System.ArgumentNullException("taskMap"); if (description == null) throw new System.ArgumentNullException("description"); if ((object) plan == null) throw new System.ArgumentNullException("plan"); _token = token; _plan = plan; _taskMap = taskMap; _description = description; var externals = new List<SymbolInfo>(); foreach (var name in description.Dependencies) { var d = taskMap[name].Value.Result; if (d.Symbols == null) continue; var origin = new SymbolOrigin.ModuleTopLevel(name, NoSourcePosition.Instance); externals.AddRange(from decl in d.Symbols select new SymbolInfo(decl.Value, origin, decl.Key)); } _externalSymbols = SymbolStore.Create(conflictUnionSource: externals); _compilationEngine = new Engine(); _module = Module.Create(description.Name); }
public ProjectData RemoveTaskLink(TaskLink taskLink) { Debug.Assert(taskLink != null); if (!TaskMap.ContainsKey(taskLink.PredecessorId) || !TaskMap.ContainsKey(taskLink.SuccessorId)) { return(this); } var project = this; var predescessorLinks = Get(TaskFields.PredecessorLinks, taskLink.SuccessorId); predescessorLinks = predescessorLinks.Remove(taskLink); var successorLinks = Get(TaskFields.SuccessorLinks, taskLink.PredecessorId); successorLinks = successorLinks.Remove(taskLink); project = project.SetRaw(TaskFields.PredecessorLinks, taskLink.SuccessorId, predescessorLinks) .SetRaw(TaskFields.SuccessorLinks, taskLink.PredecessorId, successorLinks) .Reset(TaskFields.Predecessors, taskLink.SuccessorId) .Reset(TaskFields.Successors, taskLink.PredecessorId); return(project); }
public bool TaskLinkCausesCycle(TaskLink taskLink) { Debug.Assert(taskLink != null); if (!TaskMap.ContainsKey(taskLink.PredecessorId) || !TaskMap.ContainsKey(taskLink.SuccessorId)) { return(false); } IEnumerable <TaskId> GetPredecessors(TaskId successorId) { var links = Get(TaskFields.PredecessorLinks, successorId); foreach (var link in links) { yield return(link.PredecessorId); } if (successorId == taskLink.SuccessorId) { yield return(taskLink.PredecessorId); } } var queue = new Queue <TaskId>(); foreach (var id in Tasks) { foreach (var predecessorId in GetPredecessors(id)) { queue.Enqueue(predecessorId); while (queue.Count > 0) { var taskId = queue.Dequeue(); if (taskId == id) { return(true); } foreach (var pid in GetPredecessors(taskId)) { queue.Enqueue(pid); } if (taskId == taskLink.SuccessorId) { queue.Enqueue(taskLink.PredecessorId); } } } } return(false); }
public void Register_DuplicateId_ShouldThrowError() { var map = new TaskMap(); var ex = Assert.Throws<Exception>(() => { map.Register("foo", Task.Const(""), new ITaskBehavior[0]); map.Register("foo", Task.Const(""), new ITaskBehavior[0]); }); Assert.That(ex.Message, Is.EqualTo("Task with id [foo] has already been registered")); }
public TaskLink GetTaskLink(TaskId predecessorId, TaskId successorId) { Debug.Assert(!predecessorId.IsDefault); Debug.Assert(!successorId.IsDefault); if (!TaskMap.ContainsKey(predecessorId) || !TaskMap.ContainsKey(successorId)) { return(null); } var links = Get(TaskFields.PredecessorLinks, successorId); return(links.SingleOrDefault(l => l.PredecessorId == predecessorId)); }
public void DeleteTask(string taskId) { string key = string.Empty;; if (TaskMap.TryGetValue(taskId, out key)) { LibTask task = null; if (TaskList.TryGetValue(key, out task)) { task.Timer.Dispose(); TaskList.TryRemove(key, out task); TaskMap.TryRemove(taskId, out key); } } }
public void Compose_IndependentTasks_ShouldGoToTheSameLayer() { var map = new TaskMap(); map.Register("1", FakeFlowable(), new ITaskBehavior[0]); map.Register("2", FakeFlowable(), new ITaskBehavior[0]); // map[new Identity()] = new TaskWithBehaviors(FakeFlowable()); // map[new Identity()] = new TaskWithBehaviors(FakeFlowable()); var result = ComposeWithAllTasksAsFilter(map).ToList(); Assert.That(result, Is.Not.Null); Assert.That(result.Count(), Is.EqualTo(1)); Assert.That(result[0].Items.Count(), Is.EqualTo(2)); }
public void Compose_CircularReference_ShouldThrowException() { Assert.Throws<Exception>(() => { var map = new TaskMap(); var idPrimary = new Identity("primary"); var idSecondary = new Identity("secondary"); map.Register("primary", FakeFlowable(), new ITaskBehavior[] { new DependsOnBehavior(idSecondary) }); map.Register("secondary", FakeFlowable(), new ITaskBehavior[] { new DependsOnBehavior(idPrimary) }); // map[idPrimary] = new TaskWithBehaviors(FakeFlowable(), new DependsOnBehavior(idSecondary)); // map[idSecondary] = new TaskWithBehaviors(FakeFlowable(), new DependsOnBehavior(idPrimary)); ComposeWithAllTasksAsFilter(map); }); }
public void Compose_TaskWithDependency_ShouldGoToDifferentLayer() { var map = new TaskMap(); var idPrimary = new Identity("primary"); var idSecondary = new Identity("secondary"); map.Register("primary", FakeFlowable(), new ITaskBehavior[0]); map.Register("secondary", FakeFlowable(), new ITaskBehavior[] { new DependsOnBehavior(idPrimary) }); var result = ComposeWithAllTasksAsFilter(map).ToList(); Assert.That(result, Is.Not.Null); Assert.That(result.Count(), Is.EqualTo(2)); Assert.That(result[0].Items.Count(), Is.EqualTo(1)); Assert.That(result[1].Items.Count(), Is.EqualTo(1)); Assert.That(result[0].Items[0].Id, Is.EqualTo(idPrimary)); Assert.That(result[1].Items[0].Id, Is.EqualTo(idSecondary)); }
public void InitTask() { if (EnvProvider.Default.ScheduleTaskOpened) //控制仅可初始化一次 { return; } List <LibBusinessTask> taskList = LibBusinessTaskCache.Default.GetCacheItemList(); foreach (LibBusinessTask task in taskList) { AddTask(task); } taskList = InitTempTask(); foreach (LibBusinessTask task in taskList) { if (!TaskMap.ContainsKey(task.TaskId)) //考虑到排程任务后面才打开,已经存在了相关临时业务任务 { AddTask(task); } } EnvProvider.Default.ScheduleTaskOpened = true; }
public void AddTask(LibBusinessTask task, bool needAddDB = false) { int curDate = LibDateUtils.GetCurrentDate(); if (string.IsNullOrEmpty(task.ProgId) || string.IsNullOrEmpty(task.BusinessTaskId)) { return; } //如果指定的日期大于当前日期,无需执行 if (task.TaskType == LibTaskType.None && task.ExecDate != 0 && task.ExecDate > curDate) { return; } //未指定有效执行日期则跳过 if (task.ExecDate == 0 && task.RepeatDateMark == 0) { return; } //无设置执行时间点则跳过 if (task.IntervalTime == 0 && task.ExecTime.Count == 0) { return; } //初始化Timer LibTaskParam param = new LibTaskParam(task); string key = Guid.NewGuid().ToString(); param.Task = new LibTask(new Timer(ExecBusinessTask, param, param.GetTaskDueTime(), Timeout.InfiniteTimeSpan)); TaskList.TryAdd(key, param.Task); TaskMap.TryAdd(task.TaskId, key); if (task.TaskType == LibTaskType.TempTask && needAddDB) { LibDataAccess dataAccess = new LibDataAccess(); dataAccess.ExecuteNonQuery(string.Format("insert into AXPBUSINESSTEMPTASK(TASKID,PROGID,BUSINESSTASKID,EXECDATE,EXECTIME,EXECCONDITION,INTERNALID) values({0},{1},{2},{3},{4},{5},{6})", LibStringBuilder.GetQuotString(task.TaskId), LibStringBuilder.GetQuotString(task.ProgId), LibStringBuilder.GetQuotString(task.BusinessTaskId), task.ExecDate, task.ExecTime[0], LibStringBuilder.GetQuotString(task.ExecCondition), LibStringBuilder.GetQuotString(task.InternalId)), false); } }
public void Compose_WithFilter_ShouldPassOnlyAllowedTasks() { var map = new TaskMap(); var idPrimary = new Identity("primary"); var idSecondary2 = new Identity("secondary2"); map.Register("primary", FakeFlowable(), new ITaskBehavior[0]); map.Register("secondary1", FakeFlowable(), new ITaskBehavior[] { new DependsOnBehavior(idPrimary) }); map.Register("secondary2", FakeFlowable(), new ITaskBehavior[] { new DependsOnBehavior(idPrimary) }); var result = ComposeWithFilter(map, Identities.Empty + idSecondary2).ToList(); Assert.That(result, Is.Not.Null); Assert.That(result.Count(), Is.EqualTo(2)); Assert.That(result[0].Items.Count(), Is.EqualTo(1)); Assert.That(result[1].Items.Count(), Is.EqualTo(1)); Assert.That(result[0].Items[0].Id, Is.EqualTo(idPrimary)); Assert.That(result[1].Items[0].Id, Is.EqualTo(idSecondary2)); }
private IEnumerable<Layer> ComposeWithFilter(TaskMap map, Identities filter) { return new SimpleLayersComposer().Compose(new RegisteredTasks(map.Map, null, Identities.Empty), filter); }
private IEnumerable<Layer> ComposeWithAllTasksAsFilter(TaskMap map) { var startupTaskIds = new Identities(map.Map.Keys.ToArray()); return new SimpleLayersComposer().Compose(new RegisteredTasks(map.Map, null, Identities.Empty), startupTaskIds); }
/// <summary> /// Binds the data. /// </summary> private void BindData() { dcbProducts.SiteID = dcbOrders.SiteID = dcbTaskResult.SiteID = dcbTaskType.SiteID = SiteId; var task = DataManager.Task.SelectById(SiteId, _taskId); if (task != null) { var taskMap = new TaskMap() { ID = task.ID, PlanDurationHours = task.PlanDurationHours, PlanDurationMinutes = task.PlanDurationMinutes, Title = task.Title, StartDate = task.StartDate, EndDate = task.EndDate, MainMemberCompanyID = task.MainMemberCompanyID, MainMemberContactID = task.MainMemberContactID }; ucTaskMembers.Task = taskMap; ucTaskDurations.Task = taskMap; ucMainTaskMember.Task = taskMap; ucSaveTaskDuration.Task = taskMap; txtTitle.Text = task.Title; dcbTaskType.SelectedId = task.TaskTypeID; rdpStartDate.SelectedDate = task.StartDate; rdpEndDate.SelectedDate = task.EndDate; rdpDateOfControl.SelectedDate = task.DateOfControl; rdpDateOfControl.Enabled = (Guid)CurrentUser.Instance.ContactID == task.CreatorID; chxIsImportantTask.Checked = task.IsImportantTask; rntxtPlanDurationHours.Value = task.PlanDurationHours; rntxtPlanDurationMinutes.Value = task.PlanDurationMinutes; ucResponsible.SelectedValue = task.ResponsibleID; ucRadWindowResponsible.SelectedValue = task.ResponsibleID; rcbCreator.Items.Add(new RadComboBoxItem(DataManager.Contact.SelectById(SiteId, task.CreatorID).UserFullName)); rdpResponsibleReminderDate.SelectedDate = task.ResponsibleReminderDate; rdpCreatorReminderDate.SelectedDate = task.CreatorReminderDate; chxIsUrgentTask.Checked = task.IsUrgentTask; SetStatus((TaskStatus)task.TaskStatusID); if (task.TaskResultID.HasValue) { dcbTaskResult.SelectedId = (Guid)task.TaskResultID; } txtDetailedResult.Text = task.DetailedResult; // Workflow var isWorkflow = WorkflowProcessing.IsWorkflow(task.ID); rdpDateOfControl.Enabled = !isWorkflow; if (isWorkflow) { var workflowTemplateElementResults = WorkflowProcessing.WorkflowElementResultsByValue(task.ID); ddlWorkflowResult.Items.Add(new ListItem("Выберите значение", "")); foreach (var workflowTemplateElementResult in workflowTemplateElementResults) { if (!workflowTemplateElementResult.IsSystem) { ddlWorkflowResult.Items.Add(new ListItem(workflowTemplateElementResult.Name, workflowTemplateElementResult.ID.ToString())); } } } var taskType = task.tbl_TaskType; //ucTaskMembers.TypeCategory = (TaskTypeCategory)task.tbl_TaskType.TaskTypeCategoryID; //ucTaskDurations.Visible = plDuration.Visible = (TaskTypeCategory)task.tbl_TaskType.TaskTypeCategoryID == TaskTypeCategory.LongTermTask; //if ((TaskTypeCategory)task.tbl_TaskType.TaskTypeCategoryID == TaskTypeCategory.LongTermTask) //{ // ucTaskDurations.BindData(); // ucSaveTaskDuration.TaskDurations = ucTaskDurations.TaskDurationsList; // ucSaveTaskDuration.BindData(); // ucProgressBar.UpdateProgressBar(CalculateCompletePercent()); //} if (task.OrderID.HasValue) { dcbOrders.SelectedId = (Guid)task.OrderID; } dcbProducts.SelectedIdNullable = task.ProductID; ucTaskMembers.ProductId = task.ProductID; UpdateInterfaceRelatedTaskType(taskType); rntxtActualDurationHours.Value = task.ActualDurationHours; rntxtActualDurationMinutes.Value = task.ActualDurationMinutes; rntxtCompletePercentage.Value = (double?)task.CompletePercentage; CreatorId = task.CreatorID; ResponsibleId = task.ResponsibleID; CheckUpdatePlanDurationRights(taskType); } else { CreatorId = (Guid)CurrentUser.Instance.ContactID; rcbCreator.Items.Add(new RadComboBoxItem(DataManager.Contact.SelectById(SiteId, (Guid)CurrentUser.Instance.ContactID).UserFullName)); ucResponsible.SelectedValue = CurrentUser.Instance.ContactID; ucRadWindowResponsible.SelectedValue = CurrentUser.Instance.ContactID; rdpStartDate.SelectedDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 9, 0, 0, 0); SetStatus(TaskStatus.Planned); ucProgressBar.UpdateProgressBar(0); if (Session["sd"] != null && Session["ed"] != null) { rdpStartDate.SelectedDate = DateTime.Parse(Session["sd"].ToString()); rdpEndDate.SelectedDate = DateTime.Parse(Session["ed"].ToString()); Session["sd"] = Session["ed"] = null; } } }
private void _linkDependencies(TaskMap<ModuleName, ITarget> taskMap, Application instance, ITargetDescription instanceDescription, CancellationToken token) { _LinkDependenciesImpl(this, taskMap, instance, instanceDescription, token); }
internal static void _LinkDependenciesImpl(IPlan plan, TaskMap<ModuleName, ITarget> taskMap, Application instance, ITargetDescription instanceDescription, CancellationToken token) { foreach (var dependency in instanceDescription.Dependencies) { if (instance.IsLinkedTo(dependency)) continue; var dependencyDescription = plan.TargetDescriptions[dependency]; token.ThrowIfCancellationRequested(); var dependencyInstance = new Application(taskMap[dependency].Value.Result.Module); Application.Link(instance, dependencyInstance); _LinkDependenciesImpl(plan, taskMap, dependencyInstance, dependencyDescription, token); } }
protected Task<IBuildEnvironment> GetBuildEnvironmentAsync(TaskMap<ModuleName, ITarget> taskMap, ITargetDescription description, CancellationToken token) { if (description.Dependencies.Count == 0) { var tcs = new TaskCompletionSource<IBuildEnvironment>(); tcs.SetResult(GetBuildEnvironment(taskMap, description, token)); return tcs.Task; } else // Note how the lambda expression doesn't actually depend on the result (directly) // the continue all makes sure that we're not wasting a thread that blocks on Task.Result // GetBuildEnvironment can access the results via the taskMap. return Task.Factory.ContinueWhenAll(description.Dependencies.Select(d => taskMap[d].Value).ToArray(), _ => GetBuildEnvironment(taskMap, description, token)); }
private Task<ITarget> _buildTaskImpl(ITargetDescription targetDescription, TaskMap<ModuleName, ITarget> taskMap, CancellationToken token, ModuleName name) { var desc = TargetDescriptions[name]; var deps = desc.Dependencies.Select( depName => new KeyValuePair<ModuleName, Task<ITarget>>( depName, BuildWithMapAsync( TargetDescriptions[depName], taskMap, token))); var depMap = new Dictionary<ModuleName, Task<ITarget>>(); depMap.AddRange(deps); token.ThrowIfCancellationRequested(); var buildTask = GetBuildEnvironmentAsync(taskMap, desc, token) .ContinueWith(bet => { var instance = new Application( bet.Result.Module); Plan.Trace.TraceEvent( TraceEventType.Verbose, 0, "Linking compile-time dependencies for module {0}.", bet.Result.Module.Name); _linkDependencies(taskMap, instance, targetDescription, token); token .ThrowIfCancellationRequested (); return BuildTargetAsync(bet, desc, depMap, token); }, token); return buildTask.Unwrap(); }
protected Task<ITarget> BuildWithMapAsync(ITargetDescription targetDescription, TaskMap<ModuleName, ITarget> taskMap, CancellationToken token) { return taskMap.GetOrAdd(targetDescription.Name, name => { Plan.Trace.TraceEvent(TraceEventType.Verbose, 0, "Request build of {0} and its dependencies.", targetDescription); return Task.Factory.StartNew(() => _buildTaskImpl(targetDescription, taskMap, token, name), token) .Unwrap(); }); }
protected virtual IBuildEnvironment GetBuildEnvironment(TaskMap<ModuleName, ITarget> taskMap, ITargetDescription description, CancellationToken token) { Plan.Trace.TraceEvent(TraceEventType.Verbose, 0, "Get build environment for {0}.", description); var buildEnvironment = new DefaultBuildEnvironment(this, description, taskMap, token); return buildEnvironment; }