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 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 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"); }
public static ActionListDO TestActivityListHealth1() { //string envelopeId = "F02C3D55-F6EF-4B2B-B0A0-02BF64CA1E09"; var containerDO = new ContainerDO { Id = TestContainer_Id_1(), State = 1, Name = "test name", PlanId = TestPlanHealthDemo().Id }; using (var crateStorage = ObjectFactory.GetInstance <ICrateManager>().UpdateStorage(() => containerDO.CrateStorage)) { crateStorage.Add(GetEnvelopeIdCrate()); } return(new ActionListDO { // Id = 88, // Name = "list1", // ActionListType = ActionListType.Immediate, // SubPlanID = 50, // CurrentActivity = TestActionHealth1(), // Process = processDo }); }
private void ConfigureProcess(ContainerDO container) { container.Name = _name; container.PlanId = _ptId; container.State = State.Executing; container.CrateStorage = JsonConvert.SerializeObject(CrateStorageSerializer.Default.ConvertToDto(new CrateStorage(_crates))); }
public static ContainerDO TestContainer() { var containerDO = new ContainerDO(); containerDO.Id = TestContainerGuid(); containerDO.State = 1; return(containerDO); }
public static void ContainerReceived(ContainerDO containerDO, ActivityDO activityDO) { var handler = EventContainerReceived; if (handler != null) { handler(containerDO, activityDO); } }
public static ContainerDO TestHealthDemoContainer1() { var containerDO = new ContainerDO(); containerDO.Id = TestContainer_Id_49(); containerDO.PlanId = TestPlan2().Id; containerDO.State = State.Executing; return(containerDO); }
public static ContainerDO TestContainer1() { var containerDO = new ContainerDO(); containerDO.Id = TestContainer_Id_49(); containerDO.PlanId = TestPlan2().Id; containerDO.State = 1; return(containerDO); }
public static void ContainerExecutionCompleted(ContainerDO containerDO) { var handler = EventContainerExecutionCompleted; if (handler != null) { handler(containerDO); } }
public static void ActivityRunRequested(ActivityDO activityDo, ContainerDO containerDO) { var handler = EventActivityRunRequested; if (handler != null) { handler(activityDo, containerDO); } }
public static void ContainerCreated(ContainerDO containerDO) { var handler = EventContainerCreated; if (handler != null) { handler(containerDO); } }
public static void ProcessRequestReceived(ContainerDO containerDO) { var handler = EventProcessRequestReceived; if (handler != null) { handler(containerDO); } }
public static void ActionStarted(ActivityDO activity, ContainerDO container) { var handler = EventActionStarted; if (handler != null) { handler(activity, container); } }
public static void ContainerLaunched(ContainerDO launchedContainer) { var handler = EventContainerLaunched; if (handler != null) { handler(launchedContainer); } }
public static void ProcessingTerminatedPerActivityResponse(ContainerDO containerDO, ActivityResponse resposneType) { var handler = EventProcessingTerminatedPerActivityResponse; if (handler != null) { handler(containerDO, resposneType); } }
// public static ActionListDO TestActivityList6() { ContainerDO containerDO = FixtureData.TestContainer1(); containerDO.CrateStorage = ""; return(new ActionListDO { // Id = 2, // ActionListType = ActionListType.Immediate, // ActionListState = ActionListState.Unstarted, // Process = processDO }); }
public async Task Continue(IUnitOfWork uow, ContainerDO container) { if (container == null) { throw new ArgumentNullException(nameof(container)); } if (container.State != State.Suspended) { throw new ApplicationException($"Attempted to Continue a Container {container.Id} that wasn't in pending state. Container state is {container.State}."); } //continue from where we left await Run(uow, container); }
private void ContainerExecutionCompleted(ContainerDO containerDO) { var factDO = new FactDO() { PrimaryCategory = "Container Execution", SecondaryCategory = "Container", Activity = "Launched", ObjectId = containerDO.Id.ToString(), Fr8UserId = _security.GetCurrentUser(), CreatedByID = _security.GetCurrentUser(), Data = string.Join(Environment.NewLine, "Container Id: " + containerDO.Id, "Plan Id: " + containerDO.PlanId) }; SaveAndLogFact(factDO); }
private void ProcessingTerminatedPerActivityResponse(ContainerDO containerDO, ActivityResponse resposneType) { var factDO = new FactDO() { PrimaryCategory = "Container Execution", SecondaryCategory = "Container", Activity = "Terminated", Status = resposneType.ToString(), ObjectId = containerDO.Id.ToString(), CreatedByID = _security.GetCurrentUser(), Fr8UserId = _security.GetCurrentUser(), Data = string.Join(Environment.NewLine, "Container Id: " + containerDO.Name) }; SaveAndLogFact(factDO); }
private static object ExtractOperationStateData( ContainerDO container, Func <OperationalStateCM, object> extractor) { var crateStorageDTO = CrateStorageFromStringConverter.Convert(container.CrateStorage); var crateStorage = CrateStorageSerializer.Default.ConvertFromDto(crateStorageDTO); var cm = crateStorage .CrateContentsOfType <OperationalStateCM>() .SingleOrDefault(); if (cm == null) { return(null); } return(extractor(cm)); }
/**********************************************************************************/ // Functions /**********************************************************************************/ public ExecutionSession(IUnitOfWork uow, OperationalStateCM.ActivityCallStack callStack, ContainerDO container, IActivity activity, ICrateManager crateManager, IUtilizationMonitoringService utilizationMonitoringService, IActivityExecutionRateLimitingService activityRateLimiter) { _uow = uow; _callStack = callStack; _container = container; _activity = activity; _crate = crateManager; _utilizationMonitoringService = utilizationMonitoringService; _activityRateLimiter = activityRateLimiter; }
public async Task Run_WithMockedExecute_WithPayload() { ActivityDO activityDo = FixtureData.TestActivityStateInProcess(); activityDo.CrateStorage = JsonConvert.SerializeObject(new ActivityDTO() { Label = "Test Action" }); 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(); } IActivity _activity = ObjectFactory.GetInstance <IActivity>(); ContainerDO containerDO = FixtureData.TestContainer1(); EventManager.EventActionStarted += EventManager_EventActivityStarted; using (var uow = ObjectFactory.GetInstance <IUnitOfWork>()) { var terminalClientMock = new Mock <ITerminalTransmitter>(); terminalClientMock.Setup(s => s.CallActivityAsync <PayloadDTO>(It.IsAny <string>(), It.IsAny <IEnumerable <KeyValuePair <string, string> > >(), It.IsAny <Fr8DataDTO>(), It.IsAny <string>())) .Returns(Task.FromResult(new PayloadDTO(containerDO.Id) { CrateStorage = JsonConvert.DeserializeObject <CrateStorageDTO>(activityDo.CrateStorage) })); ObjectFactory.Configure(cfg => cfg.For <ITerminalTransmitter>().Use(terminalClientMock.Object)); var payload = await _activity.Run(uow, activityDo, ActivityExecutionMode.InitialRun, containerDO); Assert.IsNotNull(payload); } Assert.IsTrue(_eventReceived); }
private void LogEventProcessLaunched(ContainerDO launchedContainer) { using (var uow = ObjectFactory.GetInstance <IUnitOfWork>()) { var plan = uow.PlanRepository.GetById <PlanDO>(launchedContainer.PlanId); var fact = new FactDO { Fr8UserId = plan.Fr8AccountId, Data = launchedContainer.Id.ToStr(), ObjectId = launchedContainer.Id.ToStr(), PrimaryCategory = "Container Execution", SecondaryCategory = "Container", Activity = "Launched" }; SaveAndLogFact(fact); } }
private void EventManagerOnEventProcessRequestReceived(ContainerDO containerDO) { using (var uow = ObjectFactory.GetInstance <IUnitOfWork>()) { var plan = uow.PlanRepository.GetById <PlanDO>(containerDO.PlanId); var fact = new FactDO { Fr8UserId = plan.Fr8AccountId, Data = containerDO.Id.ToStr(), ObjectId = containerDO.Id.ToStr(), PrimaryCategory = "Process Access", SecondaryCategory = "Process", Activity = "Requested" }; SaveAndLogFact(fact); } }
/// <summary> /// New Process object /// </summary> /// <param name="planId"></param> /// <param name="envelopeId"></param> /// <returns></returns> public ContainerDO Create(IUnitOfWork uow, PlanDO curPlan, params Crate[] curPayload) { var containerDO = new ContainerDO { Id = Guid.NewGuid() }; containerDO.PlanId = curPlan.Id; containerDO.Name = curPlan.Name; containerDO.State = State.Unstarted; using (var crateStorage = _crate.UpdateStorage(() => containerDO.CrateStorage)) { if (curPayload?.Length > 0) { foreach (var crate in curPayload) { if (crate != null && !crate.IsOfType <OperationalStateCM>()) { crateStorage.Add(crate); } } } var operationalState = new OperationalStateCM(); operationalState.CallStack.PushFrame(new OperationalStateCM.StackFrame { NodeName = "Starting subplan", NodeId = curPlan.StartingSubPlanId, }); crateStorage.Add(Crate.FromContent("Operational state", operationalState)); } uow.ContainerRepository.Add(containerDO); uow.SaveChanges(); EventManager.ContainerCreated(containerDO); return(containerDO); }
private void LogEventActivityStarted(ActivityDO curActivity, ContainerDO containerInExecution) { FactDO fact; using (var uow = ObjectFactory.GetInstance <IUnitOfWork>()) { var plan = containerInExecution != null?uow.PlanRepository.GetById <PlanDO>(containerInExecution.PlanId) : null; fact = new FactDO { Fr8UserId = (containerInExecution != null) ? plan.Fr8AccountId : "unknown", Data = (containerInExecution != null) ? containerInExecution.Id.ToStr() : "unknown", ObjectId = curActivity.Id.ToStr(), PrimaryCategory = "Process Execution", SecondaryCategory = "Action", Activity = "Started" }; } SaveAndLogFact(fact); }
public void TrackActivityExecution(ActivityDO activity, ContainerDO container) { lock (_activityExecutionReports) { ActivityExecutionRate report; var user = ExtractUser(activity, container); if (!_activityExecutionReports.TryGetValue(user, out report)) { report = new ActivityExecutionRate { UserId = user }; _activityExecutionReports.Add(user, report); } report.ActivitiesExecuted++; } }
private void ActivityRunRequested(ActivityDO activityDo, ContainerDO containerDO) { try { using (var uow = ObjectFactory.GetInstance <IUnitOfWork>()) { var template = _activityTemplate.GetByKey(activityDo.ActivityTemplateId); var factDO = new FactDO() { PrimaryCategory = "Container", SecondaryCategory = "Activity", Activity = "Process Execution", Status = "Activity Execution Initiating", ObjectId = activityDo.Id.ToString(), Fr8UserId = _security.GetCurrentUser(), CreatedByID = _security.GetCurrentUser(), Data = string.Join(Environment.NewLine, "Activity Name: " + template?.Name) }; SaveAndLogFact(factDO); // Create user notifications about activity execution var _pusherNotifier = ObjectFactory.GetInstance <IPusherNotifier>(); _pusherNotifier.NotifyUser(new NotificationMessageDTO() { NotificationType = NotificationType.GenericInfo, Subject = "Executing Activity", Message = "For Plan: " + containerDO.Name + "\nContainer: " + containerDO.Id.ToString(), ActivityName = template.Label, Collapsed = true, }, activityDo.Fr8Account.Id); } } catch (Exception exception) { EventManager.UnexpectedError(exception); } }
public void Store(IUnitOfWork uow) { StoreTemplate(uow); var container = uow.ContainerRepository.GetQuery().FirstOrDefault(x => x.Name == _name); var add = container == null; if (add) { container = new ContainerDO() { Id = Guid.NewGuid() }; } ConfigureProcess(container); if (add) { uow.ContainerRepository.Add(container); } }