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()); } } }
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"); }
// ************************************************************* // 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; } }); }
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)); } }
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); }
// 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 }); }
/**********************************************************************************/ private void UpdateForeignKeys(ActivityDO activity) { if (activity.AuthorizationToken != null) { activity.AuthorizationTokenId = activity.AuthorizationToken.Id; } }
public async Task <PayloadDTO> ExecuteChildActivities(ActivityDO curActivityDO, Guid containerId, AuthorizationTokenDO authTokenDO) { AddCrateMethodInvoked("ExecuteChildActivities"); var processPayload = new PayloadDTO(Guid.NewGuid()); return(await Task.FromResult(processPayload)); }
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); }
public static void ActivityResponseReceived(ActivityDO activityDo, ActivityResponse responseType) { var handler = EventActivityResponseReceived; if (handler != null) { handler(activityDo, responseType); } }
public async Task Deactivate(ActivityDO curActivityDO) { using (var uow = ObjectFactory.GetInstance <IUnitOfWork>()) { await CallActivityDeactivate(uow, curActivityDO.Id); uow.SaveChanges(); } }
public static void ActionDispatched(ActivityDO curActivity, Guid processId) { var handler = EventActionDispatched; if (handler != null) { handler(curActivity, processId); } }
public static void ActionActivated(ActivityDO activity) { var handler = TerminalActionActivated; if (handler != null) { handler(activity); } }
public static void ActivityRunRequested(ActivityDO activityDo, ContainerDO containerDO) { var handler = EventActivityRunRequested; if (handler != null) { handler(activityDo, containerDO); } }
public static void ContainerReceived(ContainerDO containerDO, ActivityDO activityDO) { var handler = EventContainerReceived; if (handler != null) { handler(containerDO, activityDO); } }
private void Visit(ActivityDO activity, Action <ActivityDO> callback) { callback(activity); foreach (var child in activity.ChildNodes.OfType <ActivityDO>().ToArray()) { Visit(child, callback); } }
public static void ActionStarted(ActivityDO activity, ContainerDO container) { var handler = EventActionStarted; if (handler != null) { handler(activity, container); } }
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; }
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); }
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)); }
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(); }
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)); } }
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(); }
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))); }
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); } }
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); }
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)); } }
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); }
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)); } }
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); }