public void TestDelegateDecision() { using (var fake = new AutoFake()) { var provider = fake.Resolve <IServiceLocator>(); var transitionRepository = new InMemoryRepository <Transition>(new List <Transition>()); FakeNode node = new FakeNode(); transitionRepository.Add(new Transition() { From = node, Name = "pass" }); A.CallTo(() => provider.GetInstance <IRepository <Transition> >()).Returns(transitionRepository); ServiceLocator.SetLocatorProvider(() => provider); DelegationHelper delegationHelper = new DelegationHelper(); DelegationDef delegationDef = new DelegationDef(); delegationDef.ClassName = "DecisionTest"; ExecutionContext context = new ExecutionContext(null, null, null); context.Node = node; Assert.AreEqual("pass", delegationHelper.DelegateDecision(delegationDef, context).Name); } }
private static void ProcessFork(Fork fork, ExecutionContext executionContext) { Flow flow = executionContext.Flow; var delegationRepository = ServiceLocator.Current.GetInstance <IRepository <DelegationDef> >(); DelegationDef delegation = delegationRepository.Get(fork.ForkDelegationId); if (delegation != null) { var delegationHelper = ServiceLocator.Current.GetInstance <IDelegationHelper>(); delegationHelper.DelegateFork(delegation, executionContext); } else { var transitionRepository = ServiceLocator.Current.GetInstance <IRepository <Transition> >(); var leavingTransitions = transitionRepository.With(w => w.To).Where(q => q.From.Id == fork.Id); foreach (var transition in leavingTransitions) { executionContext.ForkFlow(transition); } } Flow parentFlow = executionContext.Flow; executionContext.Flow = parentFlow; IList <ForkedFlow> forkedFlows = executionContext.ForkedFlows; foreach (var forkedFlow in forkedFlows) { executionContext.RunActionsForEvent(EventType.FORK, fork.Id); executionContext.Flow = forkedFlow.Flow; ProcessTransition(forkedFlow.Transition, executionContext); } }
public Transition DelegateDecision(DelegationDef delegation, ExecutionContext executionContext) { IRepository <Transition> transitionRepository = ServiceLocator.Current.GetInstance <IRepository <Transition> >(); //return transitionRepository.With(s => s.To).SingleOrDefault(s => s.To is EndState); return(transitionRepository.With(s => s.To).SingleOrDefault(s => s.To.Name == "approved holiday fork")); }
private IDictionary <string, object> ParseConfiguration(DelegationDef delegation) { IDictionary <string, object> parameters = new Dictionary <string, object>(); try { string configuration = delegation.Configuration; if (!string.IsNullOrEmpty(configuration)) { XElement xElement = XElement.Parse(configuration); var parameterXmlElements = xElement.Elements("parameter"); foreach (XElement element in parameterXmlElements) { string name = element.Attribute("name").Value; if (string.IsNullOrEmpty(name)) { throw new SystemException("invalid delegation-configuration : " + configuration); } parameters.Add(name, element.Value); } } } catch (Exception t) { Log.Error("can't parse configuration : ", t); throw new SystemException("can't parse configuration : " + t.Message); } return(parameters); }
public void TestDelegateFork() { DelegationHelper delegationHelper = new DelegationHelper(); DelegationDef delegationDef = new DelegationDef(); delegationDef.ClassName = "ForkTest"; ExecutionContext context = new ExecutionContext(null, null, null); delegationHelper.DelegateFork(delegationDef, context); }
public void TestDelegateSerializer() { DelegationHelper delegationHelper = new DelegationHelper(); DelegationDef delegationDef = new DelegationDef(); delegationDef.ClassName = "SerializerTest"; var serializer = delegationHelper.DelegateSerializer(delegationDef); Evaluation result = (Evaluation)serializer.Deserialize("approve"); Assert.AreEqual(Evaluation.APPROVE, result); }
private static void ProcessActivityState(ActivityState destination, ExecutionContext executionContext) { Flow flow = executionContext.Flow; executionContext.RunActionsForEvent(EventType.BEFORE_ACTIVITYSTATE_ASSIGNMENT, destination.Id); IActor actor = null; string role = destination.ActorRoleName; var delegationRepository = ServiceLocator.Current.GetInstance <IRepository <DelegationDef> >(); DelegationDef assignmentDelegation = delegationRepository.Get(destination.AssignmentDelegationId); var delegationHelper = ServiceLocator.Current.GetInstance <IDelegationHelper>(); if (assignmentDelegation != null) { // delegate the assignment of the activity-state actor = delegationHelper.DelegateAssignment(assignmentDelegation, executionContext); if (actor == null) { throw new SystemException("invalid process definition : assigner of activity-state '" + destination.Name + "' returned null instead of a valid actorId"); } //log.Debug("setting actor of flow " + flow + " to " + actorId); } else { // get the assigned actor from the specified attribute instance if (!string.IsNullOrEmpty(role)) { actor = (IActor)executionContext.GetAttribute(role); if (actor == null) { throw new SystemException("invalid process definition : activity-state must be assigned to role '" + role + "' but that attribute instance is null"); } } else { throw new SystemException("invalid process definition : activity-state '" + destination.Name + "' does not have an assigner or a role"); } } flow.ActorId = actor.Id; if ((actor != null) && (assignmentDelegation != null)) { executionContext.StoreRole(actor, destination); } executionContext.AssignedFlows.Add(flow); executionContext.RunActionsForEvent(EventType.AFTER_ACTIVITYSTATE_ASSIGNMENT, destination.Id); }
public void TestDelegateJoin() { DelegationHelper delegationHelper = new DelegationHelper(); DelegationDef delegationDef = new DelegationDef(); delegationDef.ClassName = "JoinTest"; ExecutionContext context = new ExecutionContext(null, null, null); bool reactiveFlow = delegationHelper.DelegateJoin(delegationDef, context); Assert.IsFalse(reactiveFlow); }
public void DelegateFork(DelegationDef delegation, ExecutionContext executionContext) { try { foreach (var forkHandler in ForkHandlers) { if ((string)forkHandler.Metadata.ClassName == delegation.ClassName) { executionContext.Configuration = (ParseConfiguration(delegation)); forkHandler.Value.Fork(executionContext); } } } catch (Exception t) { HandleException(delegation, executionContext, t); } }
private IAuthorizationHandler GetAuthorizationHandler(ProcessDefinition processDefinition) { IAuthorizationHandler authorizationHandler = null; var delegationRepository = ServiceLocator.Current.GetInstance <IRepository <DelegationDef> >(); DelegationDef delegation = delegationRepository.Get(processDefinition.AuthorizationDelegationId); if (delegation != null) { foreach (var handler in AuthorizationHandlers) { if (handler.Metadata.ClassName == delegation.ClassName) { authorizationHandler = handler.Value; } } } return(authorizationHandler); }
public void HelloWorld2() { XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load("Definitions\\HelloWorld2.xml"); using (var unitWork = UnitOfWork.Start()) { ProcessDefinitionCreationContext creationContext = new ProcessDefinitionCreationContext(); ProcessDefinition processDefinition = creationContext.CreateProcessDefinition(xmlDocument); creationContext.ResolveReferences(); Node start = null, end = null; ActivityState activityState = null; foreach (Node node in processDefinition.Nodes) { if (node.Name == "start") { start = node; } else if (node.Name == "first activity state") { activityState = node as ActivityState; } else if (node.Name == "end") { end = node; } } Assert.IsNotNull(start); Assert.IsNotNull(activityState); Assert.IsNotNull(activityState.AssignmentDelegation); DelegationDef delegationDef = activityState.AssignmentDelegation; Assert.AreEqual("ActorAssignment", delegationDef.ClassName); Assert.AreEqual("<cfg><parametername=\"expression\">processInitiator</parameter></cfg>", Regex.Replace(delegationDef.Configuration, @"\s|\t|\n|\r", "")); var processBlockRepository = new EFRepository <ProcessBlock>(); processBlockRepository.Add(processDefinition); unitWork.Flush(); } }
public Transition DelegateDecision(DelegationDef delegation, ExecutionContext executionContext) { Transition selectedTransition = null; try { string transitionName = null; IDecisionHandler decision = null; foreach (var decisionHandler in DecisionHandlers) { if ((string)decisionHandler.Metadata.ClassName == delegation.ClassName) { decision = decisionHandler.Value; executionContext.Configuration = (ParseConfiguration(delegation)); transitionName = decision.Decide(executionContext); } } if (string.IsNullOrEmpty(transitionName)) { throw new SystemException("Decision-delegate for decision '" + executionContext.Node + "' returned null instead of a transition-name : " + decision.GetType().FullName); } try { var transitionRepository = ServiceLocator.Current.GetInstance <IRepository <Transition> >(); selectedTransition = transitionRepository.With(s => s.To) .Query(new Specification <Transition>(s => s.From.Id == executionContext.Node.Id && s.Name == transitionName)).Single(); } catch (Exception t) { throw new SystemException("couldn't find transition '" + transitionName + "' that was selected by the decision-delegate of activity '" + executionContext.Node.Name + "' : " + t.Message); } } catch (Exception t) { HandleException(delegation, executionContext, t); } return(selectedTransition); }
public ISerializer DelegateSerializer(DelegationDef delegation) { try { foreach (var serializer in Serializers) { if ((string)serializer.Metadata.ClassName == delegation.ClassName) { return(serializer.Value); } } } catch (Exception t) { //HandleException(delegation, executionContext, t); } return(null); }
private static void ProcessJoin(Join join, ExecutionContext executionContext) { Flow joiningFlow = executionContext.Flow; joiningFlow.End = DateTime.Now; joiningFlow.ActorId = null; joiningFlow.Node = join; if (joiningFlow.ParentReactivation) { bool parentReactivation = false; IList <Flow> concurrentFlows = executionContext.GetOtherActiveConcurrentFlows(); if (concurrentFlows.Count == 0) { parentReactivation = true; } else { var delegationRepository = ServiceLocator.Current.GetInstance <IRepository <DelegationDef> >(); DelegationDef joinDelegation = delegationRepository.Get(join.JoinDelegationId); if (joinDelegation != null) { var delegationHelper = ServiceLocator.Current.GetInstance <IDelegationHelper>(); parentReactivation = delegationHelper.DelegateJoin(joinDelegation, executionContext); } } if (parentReactivation) { foreach (var concurrentFlow in concurrentFlows) { concurrentFlow.ParentReactivation = false; } Flow parentFlow = joiningFlow.Parent; executionContext.Flow = parentFlow; var transitionRepository = ServiceLocator.Current.GetInstance <IRepository <Transition> >(); var leavingTransition = transitionRepository.With(w => w.To).First(f => f.From.Id == join.Id); ProcessTransition(leavingTransition, executionContext); } } }
public void DelegateAction(DelegationDef delegation, ExecutionContext executionContext) { try { //executionContext.CreateLog(EventType.ACTION); //executionContext.AddLogDetail(new DelegateCallImpl(delegation, typeof(IAction))); foreach (var actionHandler in ActionHanders) { if (actionHandler.Metadata.ClassName == delegation.ClassName) { executionContext.Configuration = (ParseConfiguration(delegation)); actionHandler.Value.Run(executionContext); } } } catch (Exception t) { HandleException(delegation, executionContext, t); } }
public void TestDelegateAction() { DelegationHelper delegationHelper = new DelegationHelper(); DelegationDef delegationDef = new DelegationDef(); delegationDef.ClassName = "ActionTest"; delegationDef.Configuration = "<cfg>" + "<parameter name = \"to\" > previousActor </parameter>" + "<parameter name = \"subject\" > you requested a holiday </parameter>" + "<parameter name = \"message\" > you requested a holiday from ${ start date}" + "to ${ end date}" + "with comment ${ comment}</parameter>" + "</cfg> "; ExecutionContext context = new ExecutionContext(null, null, null); delegationHelper.DelegateAction(delegationDef, context); Assert.IsTrue(context.Configuration.ContainsKey("test")); Assert.AreEqual("1234", context.Configuration["test"]); }
public IActor DelegateAssignment(DelegationDef delegation, ExecutionContext executionContext) { IActor actor = null; try { foreach (var assignmentHandler in AssignmentHandlers) { if ((string)assignmentHandler.Metadata.ClassName == delegation.ClassName) { executionContext.Configuration = (ParseConfiguration(delegation)); actor = assignmentHandler.Value.SelectActor(executionContext); } } } catch (Exception t) { HandleException(delegation, executionContext, t); } return(actor); }
public bool DelegateJoin(DelegationDef delegation, ExecutionContext executionContext) { bool reactivateParent = false; try { foreach (var joinHandler in JoinHandlers) { if ((string)joinHandler.Metadata.ClassName == delegation.ClassName) { executionContext.Configuration = (ParseConfiguration(delegation)); reactivateParent = joinHandler.Value.Join(executionContext); } } } catch (Exception t) { HandleException(delegation, executionContext, t); } return(reactivateParent); }
private void HandleException(DelegationDef delegation, ExecutionContext executionContext, Exception exception) { Log.Debug("handling delegation exception :", exception); string exceptionClassName = exception.GetType().FullName; string delegationClassName = delegation.ClassName; ExceptionHandlingType exceptionHandlingType = delegation.ExceptionHandlingType; if (exceptionHandlingType != 0) { if (exceptionHandlingType == ExceptionHandlingType.IGNORE) { Log.Debug("ignoring '" + exceptionClassName + "' in delegation '" + delegationClassName + "' : " + exception.Message); } else if (exceptionHandlingType == ExceptionHandlingType.LOG) { Log.Debug("logging '" + exceptionClassName + "' in delegation '" + delegationClassName + "' : " + exception.Message); //executionContext.AddLogDetail(new ExceptionReportImpl(exception)); } else if (exceptionHandlingType == ExceptionHandlingType.ROLLBACK) { Log.Debug("rolling back for '" + exceptionClassName + "' in delegation '" + delegationClassName + "' : " + exception.Message); throw new SystemException("rolling back for '" + exceptionClassName + "' in delegation '" + delegationClassName + "' : " + exception.Message); } else { throw new SystemException("unknown exception handler '" + exceptionHandlingType + "' : " + exception.Message); } } else { Log.Debug("'" + exceptionClassName + "' in delegation '" + delegationClassName + "' : " + exception.Message); //executionContext.AddLogDetail(new ExceptionReportImpl(exception)); } }
public bool DelegateJoin(DelegationDef delegation, ExecutionContext executionContext) { return(false); }
public IActor DelegateAssignment(DelegationDef delegation, ExecutionContext executionContext) { throw new NotImplementedException(); }
public ISerializer DelegateSerializer(DelegationDef delegation) { throw new NotImplementedException(); }
public void DelegateAction(DelegationDef delegation, ExecutionContext executionContext) { throw new NotImplementedException(); }
public void DelegateFork(DelegationDef delegation, ExecutionContext executionContext) { }