コード例 #1
0
        public IHttpActionResult Get(Guid id, string direction)
        {
            direction = (direction ?? string.Empty).ToLower();
            using (var uow = ObjectFactory.GetInstance <IUnitOfWork>())
            {
                ActivityDO activityDO = uow.PlanRepository.GetById <ActivityDO>(id);
                if (activityDO == null)
                {
                    throw new MissingObjectException($"Activity with Id {id} doesn't exist");
                }
                switch (direction)
                {
                case "upstream":
                    return(Ok(_activity.GetUpstreamActivities(uow, activityDO).
                              OfType <ActivityDO>().Select(x => Mapper.Map <ActivityDTO>(x)).ToList()));

                case "downstream":
                    return(Ok(_activity.GetDownstreamActivities(uow, activityDO).
                              OfType <ActivityDO>().Select(x => Mapper.Map <ActivityDTO>(x)).ToList()));

                default:
                    return(Ok());
                }
            }
        }
コード例 #2
0
        public async Task ActivityStarted_EventRaisedSuccessfully()
        {
            ActivityDO activityDo = FixtureData.TestActivityStateInProcess();

            activityDo.CrateStorage = JsonConvert.SerializeObject(new ActivityDTO());

            using (var uow = ObjectFactory.GetInstance <IUnitOfWork>())
            {
                uow.ActivityTemplateRepository.Add(activityDo.ActivityTemplate);

                uow.PlanRepository.Add(new PlanDO
                {
                    Name       = "name",
                    PlanState  = PlanState.Executing,
                    ChildNodes = { activityDo }
                });
                uow.SaveChanges();
            }


            Activity    activity    = ObjectFactory.GetInstance <Activity>();
            ContainerDO containerDO = FixtureData.TestContainer1();

            EventManager.EventActionStarted += EventManager_EventActivityStarted;

            using (var uow = ObjectFactory.GetInstance <IUnitOfWork>())
            {
                await activity.Run(uow, activityDo, ActivityExecutionMode.InitialRun, containerDO);
            }

            Assert.IsTrue(_eventReceived, "Unable to receive event about activity start");
        }
コード例 #3
0
        // *************************************************************
        // Workaround to maintain cache integrity in authorization token revoke scenario
        public void RemoveAuthorizationTokenFromCache(ActivityDO activity)
        {
            lock (_loadedNodes)
            {
                foreach (var loadedPlan in _loadedPlans)
                {
                    PlanTreeHelper.Visit(loadedPlan.Root, x =>
                    {
                        var a = x as ActivityDO;

                        if (a != null && a.Id == activity.Id)
                        {
                            a.AuthorizationToken   = null;
                            a.AuthorizationTokenId = null;
                        }
                    });
                }
            }

            _planStorage.UpdateElement(activity.Id, x =>
            {
                var a = x as ActivityDO;

                if (a != null)
                {
                    a.AuthorizationToken   = null;
                    a.AuthorizationTokenId = null;
                }
            });
        }
コード例 #4
0
        public void Process_ActivityUnstarted_ShouldBeCompleted()
        {
            //Arrange
            ActivityDO activityDo = FixtureData.TestActivityUnstarted();

            activityDo.ActivityTemplate.Terminal.Endpoint = "http://localhost:53234/activities/configure";
            activityDo.CrateStorage = JsonConvert.SerializeObject(new ActivityDTO());

            using (var uow = ObjectFactory.GetInstance <IUnitOfWork>())
            {
                uow.ActivityTemplateRepository.Add(activityDo.ActivityTemplate);
                uow.PlanRepository.Add(new PlanDO()
                {
                    Name       = "name",
                    PlanState  = PlanState.Executing,
                    ChildNodes = { activityDo }
                });
                uow.SaveChanges();
            }

            ActivityDTO activityDto = Mapper.Map <ActivityDTO>(activityDo);

            TerminalTransmitterMock.Setup(rc => rc.PostAsync(It.IsAny <Uri>(), It.IsAny <object>(), It.IsAny <string>(), It.IsAny <Dictionary <string, string> >()))
            .Returns(() => Task.FromResult <string>(JsonConvert.SerializeObject(activityDto)));

            ContainerDO containerDO = FixtureData.TestContainer1();

            //Act
            using (var uow = ObjectFactory.GetInstance <IUnitOfWork>())
            {
                var task = _activity.Run(uow, activityDo, ActivityExecutionMode.InitialRun, containerDO);
                //Assert
                Assert.That(task.Status, Is.EqualTo(TaskStatus.RanToCompletion));
            }
        }
コード例 #5
0
        public async Task PrepareToExecute_WithMockedExecute_WithoutPayload()
        {
            ActivityDO activityDo = FixtureData.TestActivityStateInProcess();

            activityDo.CrateStorage = JsonConvert.SerializeObject(new ActivityDTO());

            using (var uow = ObjectFactory.GetInstance <IUnitOfWork>())
            {
                uow.ActivityTemplateRepository.Add(activityDo.ActivityTemplate);
                uow.PlanRepository.Add(new PlanDO()
                {
                    Name       = "sdfsdf",
                    PlanState  = PlanState.Executing,
                    ChildNodes = { activityDo }
                });
                uow.SaveChanges();
            }

            Activity    _activity   = ObjectFactory.GetInstance <Action>();
            ContainerDO containerDO = FixtureData.TestContainer1();

            EventManager.EventActionStarted += EventManager_EventActivityStarted;
            var executeActionMock = new Mock <IActivity>();

            executeActionMock.Setup(s => s.Run(It.IsAny <IUnitOfWork>(), activityDo, It.IsAny <ActivityExecutionMode>(), containerDO)).Returns <Task <PayloadDTO> >(null);

            using (var uow = ObjectFactory.GetInstance <IUnitOfWork>())
            {
                await _activity.Run(uow, activityDo, ActivityExecutionMode.InitialRun, containerDO);
            }

            Assert.IsNull(containerDO.CrateStorage);
            Assert.IsTrue(_eventReceived);
            // Assert.AreEqual(actionDo.ActionState, ActionState.Active);
        }
コード例 #6
0
//
        public static List <PlanNodeDO> TestActivityListParentActivityID12()
        {
            List <ActionListDO> actionLists = new List <ActionListDO>();
//
            var activityTempate = new ActivityTemplateDO()
            {
                Id       = GetTestGuidById(1),
                Version  = "1",
                Terminal = FixtureData.TerminalFive(),
                Name     = "Monitor_DocuSign"
            };
            ActionListDO al_1 = new ActionListDO()
            {
                ParentActivityId = GetTestGuidById(12)
            };
            ActivityDO a_23 = new ActivityDO()
            {
                Id = GetTestGuidById(23),
                ActivityTemplate   = activityTempate,
                ActivityTemplateId = activityTempate.Id,
                CrateStorage       = ""
            };

            al_1.Activities.Add(a_23);

            actionLists.Add(al_1);
            return(new List <PlanNodeDO>()
            {
                a_23
            });
        }
コード例 #7
0
        /**********************************************************************************/

        private void UpdateForeignKeys(ActivityDO activity)
        {
            if (activity.AuthorizationToken != null)
            {
                activity.AuthorizationTokenId = activity.AuthorizationToken.Id;
            }
        }
コード例 #8
0
        public async Task <PayloadDTO> ExecuteChildActivities(ActivityDO curActivityDO, Guid containerId, AuthorizationTokenDO authTokenDO)
        {
            AddCrateMethodInvoked("ExecuteChildActivities");
            var processPayload = new PayloadDTO(Guid.NewGuid());

            return(await Task.FromResult(processPayload));
        }
コード例 #9
0
        private void ReportActivityInvocationError(ActivityDO activity, string error, string containerId, string objectId, Action <string, string, string, string> reportingAction)
        {
            var endpoint = _activityTemplate.GetTerminalUrl(activity.ActivityTemplateId) ?? "<no terminal url>";

            var additionalData = containerId.IsNullOrEmpty() ? " no data " : " Container Id = " + containerId;

            reportingAction(endpoint, additionalData, error, objectId);
        }
コード例 #10
0
        public static void ActivityResponseReceived(ActivityDO activityDo, ActivityResponse responseType)
        {
            var handler = EventActivityResponseReceived;

            if (handler != null)
            {
                handler(activityDo, responseType);
            }
        }
コード例 #11
0
        public async Task Deactivate(ActivityDO curActivityDO)
        {
            using (var uow = ObjectFactory.GetInstance <IUnitOfWork>())
            {
                await CallActivityDeactivate(uow, curActivityDO.Id);

                uow.SaveChanges();
            }
        }
コード例 #12
0
        public static void ActionDispatched(ActivityDO curActivity, Guid processId)
        {
            var handler = EventActionDispatched;

            if (handler != null)
            {
                handler(curActivity, processId);
            }
        }
コード例 #13
0
        public static void ActionActivated(ActivityDO activity)
        {
            var handler = TerminalActionActivated;

            if (handler != null)
            {
                handler(activity);
            }
        }
コード例 #14
0
        public static void ActivityRunRequested(ActivityDO activityDo, ContainerDO containerDO)
        {
            var handler = EventActivityRunRequested;

            if (handler != null)
            {
                handler(activityDo, containerDO);
            }
        }
コード例 #15
0
        public static void ContainerReceived(ContainerDO containerDO, ActivityDO activityDO)
        {
            var handler = EventContainerReceived;

            if (handler != null)
            {
                handler(containerDO, activityDO);
            }
        }
コード例 #16
0
        private void Visit(ActivityDO activity, Action <ActivityDO> callback)
        {
            callback(activity);

            foreach (var child in activity.ChildNodes.OfType <ActivityDO>().ToArray())
            {
                Visit(child, callback);
            }
        }
コード例 #17
0
        public static void ActionStarted(ActivityDO activity, ContainerDO container)
        {
            var handler = EventActionStarted;

            if (handler != null)
            {
                handler(activity, container);
            }
        }
コード例 #18
0
        private static void UpdateActivityProperties(ActivityDO existingActivity, ActivityDO submittedActivity)
        {
            // it is unlikely that we have scenarios when activity template can be changed after activity was created
            //existingActivity.ActivityTemplateId = submittedActivity.ActivityTemplateId;

            existingActivity.Label        = submittedActivity.Label;
            existingActivity.CrateStorage = submittedActivity.CrateStorage;
            existingActivity.Ordering     = submittedActivity.Ordering;
        }
コード例 #19
0
        public void AddCrate_AddCratesDTO_UpdatesActivityCratesStorage()
        {
            ActivityDO activityDO = FixtureData.TestActivity23();

            using (var crateStorage = Hub.Managers.CrateManagerExtensions.GetUpdatableStorage(_crate, activityDO))
            {
                crateStorage.AddRange(FixtureData.CrateStorageDTO());
            }

            Assert.IsNotEmpty(activityDO.CrateStorage);
        }
コード例 #20
0
        public async Task <PayloadDTO> Run(IUnitOfWork uow, ActivityDO curActivityDO, ActivityExecutionMode curActionExecutionMode, ContainerDO curContainerDO)
        {
            if (PlanTreeHelper.Linearize(_planNodes[curActivityDO.Id]).OfType <ActivityDO>().Any(x => x.Id == curActivityDO.Id))
            {
                Processed++;
            }

            await Task.Delay(1);

            return(await _activity.Run(uow, curActivityDO, curActionExecutionMode, curContainerDO));
        }
コード例 #21
0
        private void UpdateActivityProperties(IUnitOfWork uow, ActivityDO submittedActivity)
        {
            var existingAction = uow.PlanRepository.GetById <ActivityDO>(submittedActivity.Id);

            if (existingAction == null)
            {
                throw new Exception("Action was not found");
            }

            UpdateActivityProperties(existingAction, submittedActivity);
            uow.SaveChanges();
        }
コード例 #22
0
        public async Task <ActivityDTO> SaveOrUpdateActivity(ActivityDO submittedActivityData)
        {
            if (submittedActivityData.Id == Guid.Empty)
            {
                return(await SaveOrUpdateActivityCore(submittedActivityData));
            }

            using (await _configureLock.Lock(submittedActivityData.Id))
            {
                return(await SaveOrUpdateActivityCore(submittedActivityData));
            }
        }
コード例 #23
0
ファイル: SubPlan.cs プロジェクト: patel-pragnesh/fr8core-dev
        public void AddActivity(IUnitOfWork uow, ActivityDO curActivityDO)
        {
            var subPlan = uow.PlanRepository.GetById <SubplanDO>(curActivityDO.ParentPlanNodeId.Value);

            if (subPlan == null)
            {
                throw new Exception(string.Format("Unable to find Subplan by id = {0}", curActivityDO.ParentPlanNodeId));
            }

            subPlan.AddChildWithDefaultOrdering(curActivityDO);

            uow.SaveChanges();
        }
コード例 #24
0
        private ActivityTemplateSummaryDTO GetActivityTemplate(ActivityDO ad)
        {
            if (ad.ActivityTemplate != null)
            {
                return(Mapper.Map <ActivityTemplateSummaryDTO>(ad.ActivityTemplate));
            }

            if (ad.ActivityTemplateId == Guid.Empty)
            {
                return(null);
            }

            return(Mapper.Map <ActivityTemplateSummaryDTO>(_activityTemplate.GetByKey(ad.ActivityTemplateId)));
        }
コード例 #25
0
        private void Compare(ActivityDO reference, ActivityDO actual, Action <ActivityDO, ActivityDO> callback)
        {
            callback(reference, actual);

            if (reference.ChildNodes.Count != actual.ChildNodes.Count)
            {
                throw new Exception("Unable to compare nodes with different number of children.");
            }

            for (int i = 0; i < reference.ChildNodes.Count; i++)
            {
                Compare((ActivityDO)reference.ChildNodes[i], (ActivityDO)actual.ChildNodes[i], callback);
            }
        }
コード例 #26
0
        public static ActivityDO PostToChatterTestActivityDO1()
        {
            var actionTemplate = PostToChatterActivityTemplateDO();

            var activityDO = new ActivityDO()
            {
                Id = new Guid("8339DC87-F011-4FB1-B47C-FEC406E4100A"),
                ActivityTemplateId = actionTemplate.Id,
                ActivityTemplate   = actionTemplate,
                CrateStorage       = "",
            };

            return(activityDO);
        }
コード例 #27
0
        private async Task <ActivityDTO> SaveOrUpdateActivityCore(ActivityDO submittedActivity)
        {
            using (var uow = ObjectFactory.GetInstance <IUnitOfWork>())
            {
                await DeactivateActivity(uow, submittedActivity.Id);

                SaveAndUpdateActivity(uow, submittedActivity);

                uow.SaveChanges();

                var result = uow.PlanRepository.GetById <ActivityDO>(submittedActivity.Id);

                return(Mapper.Map <ActivityDTO>(result));
            }
        }
コード例 #28
0
        private ActivityDO CloneActivity(ActivityDO source)
        {
            var clone = (ActivityDO)source.Clone();

            // for backward compatibility
            // if we have encrypted data decrypt it, otherwise leave CrateStorage as is
            if (source.EncryptedCrateStorage != null && source.EncryptedCrateStorage.Length != 0)
            {
                clone.CrateStorage = _encryptionService.DecryptString(source.Fr8AccountId, source.EncryptedCrateStorage);
                // get rid of encrypted data representation to save space in memory.
                clone.EncryptedCrateStorage = null;
            }

            return(clone);
        }
コード例 #29
0
        public async Task <IHttpActionResult> Configure(ActivityDTO curActionDesignDTO, [FromUri] bool force = false)
        {
            ActivityDO curActivityDO = Mapper.Map <ActivityDO>(curActionDesignDTO);
            var        userId        = User.Identity.GetUserId();

            using (var uow = _uowFactory.Create())
            {
                if (_planService.IsPlanActiveOrExecuting(curActionDesignDTO.Id) && !force)
                {
                    return(new LockedHttpActionResult());
                }
                var configuredActivity = await _activityService.Configure(uow, userId, curActivityDO);

                return(Ok(configuredActivity));
            }
        }
コード例 #30
0
        public static bool IsStorageEmpty(this ICrateManager crateManager, ActivityDO activity)
        {
            if (string.IsNullOrWhiteSpace(activity.CrateStorage))
            {
                return(true);
            }

            var proxy = JsonConvert.DeserializeObject <CrateStorageDTO>(activity.CrateStorage);

            if (proxy.Crates == null)
            {
                return(true);
            }

            return(proxy.Crates.Length == 0);
        }