Exemplo n.º 1
0
        public PlanDTO CrateTemplate(Guid planId, string userId)
        {
            PlanDO clonedPlan;

            using (var uow = _unitOfWorkFactory.Create())
            {
                var plan = _planService.GetPlanByActivityId(uow, planId);

                clonedPlan = (PlanDO)PlanTreeHelper.CloneWithStructure(plan);
            }

            clonedPlan.PlanState = PlanState.Inactive;

            //linearlize tree structure
            var planTree = clonedPlan.GetDescendants();
            var idsMap   = new Dictionary <Guid, Guid>();

            foreach (var planNodeDO in planTree)
            {
                var oldId = planNodeDO.Id;

                planNodeDO.Id           = Guid.NewGuid();
                planNodeDO.Fr8Account   = null;
                planNodeDO.Fr8AccountId = null;

                var activity = planNodeDO as ActivityDO;

                if (activity != null)
                {
                    activity.AuthorizationToken = null;
                }

                idsMap.Add(oldId, planNodeDO.Id);
            }

            foreach (var activity in planTree.OfType <ActivityDO>())
            {
                activity.CrateStorage = _crateManager.EmptyStorageAsStr(); // UpdateCrateStorage(activity.CrateStorage, idsMap);
            }

            return(PlanMappingHelper.MapPlanToDto(clonedPlan));
        }
Exemplo n.º 2
0
        public async Task <PlanNodeDO> CreateAndConfigure(IUnitOfWork uow, string userId, Guid activityTemplateId, string label = null, string name = null, int?order = null, Guid?parentNodeId = null, bool createPlan = false, Guid?authorizationTokenId = null, PlanVisibility newPlanVisibility = PlanVisibility.Standard)
        {
            if (parentNodeId != null && createPlan)
            {
                throw new ArgumentException("Parent node id can't be set together with create plan flag");
            }

            if (parentNodeId == null && !createPlan)
            {
                throw new ArgumentException("Either Parent node id or create plan flag must be set");
            }

            // to avoid null pointer exception while creating parent node if label is null
            if (name == null)
            {
                name = userId + "_" + activityTemplateId;
            }

            PlanNodeDO parentNode;
            PlanDO     plan = null;

            if (createPlan)
            {
                plan = ObjectFactory.GetInstance <IPlan>().Create(uow, name, ownerId: userId, visibility: newPlanVisibility);

                plan.ChildNodes.Add(parentNode = new SubplanDO
                {
                    StartingSubPlan = true,
                    Name            = name + " #1"
                });
            }
            else
            {
                parentNode = uow.PlanRepository.GetById <PlanNodeDO>(parentNodeId);

                if (parentNode is PlanDO)
                {
                    if (((PlanDO)parentNode).StartingSubplan == null)
                    {
                        parentNode.ChildNodes.Add(parentNode = new SubplanDO
                        {
                            StartingSubPlan = true,
                            Name            = name + " #1"
                        });
                    }
                    else
                    {
                        parentNode = ((PlanDO)parentNode).StartingSubplan;
                    }
                }
            }

            var activity = new ActivityDO
            {
                Id = Guid.NewGuid(),
                ActivityTemplateId   = activityTemplateId,
                CrateStorage         = _crateManager.EmptyStorageAsStr(),
                AuthorizationTokenId = authorizationTokenId
            };

            parentNode.AddChild(activity, order);

            uow.SaveChanges();

            var configuredActivity = await CallActivityConfigure(uow, userId, activity);

            UpdateActivityProperties(uow, configuredActivity);

            if (createPlan)
            {
                return(plan);
            }

            return(activity);
        }