public PlanNodeMock(params PlanDO[] plans) { foreach (var planDo in plans) { _plans.Add(planDo.Id); var plan = planDo; PlanTreeHelper.Visit(planDo, x => PlanNodes[x.Id] = plan); } }
public PlanStorageProviderMonitor(PlanNodeDO planNode) { PlanTreeHelper.Visit(planNode, (x, y) => { x.ParentPlanNodeId = y != null ? y.Id : (Guid?)null; x.ParentPlanNode = y; }); _planNode = planNode; }
public void CanAddPlanWithEmptyDefaultIds() { var provider = new PersistentPlanStorage(null); var cache = new PlanCache(new ExpirationStrategyMock()); var repository = new PlanRepository(new PlanStorage(cache, provider)); var refPlan = GenerateTestPlan(); PlanTreeHelper.Visit(refPlan, x => x.Id = Guid.Empty); repository.Add(refPlan); repository.SaveChanges(); PlanTreeHelper.Visit(refPlan, x => Assert.IsTrue(x.Id != Guid.Empty)); var loadedPlan = provider.LoadPlan(Guid.Empty); AssertEquals(refPlan, loadedPlan); }
private void SaveAndUpdateActivity(IUnitOfWork uow, ActivityDO submittedActiviy) { var isNewActivity = false; PlanTreeHelper.Visit(submittedActiviy, x => { if (x.Id == Guid.Empty) { if (Object.ReferenceEquals(x, submittedActiviy)) { isNewActivity = true; } x.Id = Guid.NewGuid(); } var activityDO = x as ActivityDO; if (activityDO != null && activityDO.ActivityTemplateId == Guid.Empty) { var activityTemplate = activityDO.ActivityTemplate; activityDO.ActivityTemplate = uow .ActivityTemplateRepository .GetQuery() .Single(y => y.Name == activityTemplate.Name && y.Version == activityTemplate.Version && y.Terminal.Name == activityTemplate.Terminal.Name && y.Terminal.Version == activityTemplate.Terminal.Version); activityDO.ActivityTemplateId = activityDO.ActivityTemplate.Id; } }); PlanNodeDO plan; PlanNodeDO originalAction; if (submittedActiviy.ParentPlanNodeId != null) { plan = uow.PlanRepository.Reload <PlanNodeDO>(submittedActiviy.ParentPlanNodeId); if (plan == null) { throw new MissingObjectException($"Parent plan with Id {submittedActiviy.ParentPlanNodeId} doesn't exist"); } originalAction = plan.ChildNodes.FirstOrDefault(x => x.Id == submittedActiviy.Id); //This might mean that this plan's parent was changed if (originalAction == null && !isNewActivity) { originalAction = uow.PlanRepository.GetById <PlanNodeDO>(submittedActiviy.Id); if (originalAction != null) { var originalActionsParent = uow.PlanRepository.Reload <PlanNodeDO>(originalAction.ParentPlanNodeId); originalActionsParent.ChildNodes.Remove(originalAction); originalAction.ParentPlanNodeId = plan.Id; } } } else { originalAction = uow.PlanRepository.Reload <PlanNodeDO>(submittedActiviy.Id); plan = originalAction.ParentPlanNode; } if (originalAction != null) { plan.ChildNodes.Remove(originalAction); // Add child subplans. foreach (var subPlan in originalAction.ChildNodes.OfType <SubplanDO>()) { submittedActiviy.ChildNodes.Add(subPlan); } var originalActions = PlanTreeHelper.Linearize(originalAction) .OfType <ActivityDO>() .ToDictionary(x => x.Id, x => x); foreach (var submitted in PlanTreeHelper.Linearize(submittedActiviy)) { ActivityDO existingActivity; if (originalActions.TryGetValue(submitted.Id, out existingActivity)) { RestoreSystemProperties(existingActivity, (ActivityDO)submitted); } } } if (submittedActiviy.Ordering <= 0) { plan.AddChildWithDefaultOrdering(submittedActiviy); } else { plan.ChildNodes.Add(submittedActiviy); } }