Ejemplo n.º 1
0
        public void ProcessTransition(TransitionImpl transition, FlowImpl flow, DbSession dbSession)
        {
            NodeImpl destination = (NodeImpl)transition.To;

            flow.Node = destination;

            if (destination is ActivityStateImpl)
            {
                ProcessActivityState((ActivityStateImpl)destination, flow, dbSession);
            }
            else if (destination is ProcessStateImpl)
            {
                //ProcessProcessState((ProcessStateImpl)destination, executionContext, dbSession);
            }
            else if (destination is DecisionImpl)
            {
                ProcessDecision((DecisionImpl)destination, flow, dbSession);
            }
            else if (destination is ForkImpl)
            {
                ProcessFork((ForkImpl)destination, flow, dbSession);
            }
            else if (destination is JoinImpl)
            {
                ProcessJoin((JoinImpl)destination, flow, dbSession);
            }
            else if (destination is EndStateImpl)
            {
                ProcessEndState((EndStateImpl)destination, flow, dbSession);
            }
            else
            {
                throw new SystemException("");
            }
        }
Ejemplo n.º 2
0
        public FlowImpl GetFlow(Int64 flowId, Relations relations, DbSession dbSession)
        {
            FlowImpl flow = null;

            log.Debug("searching for flow '" + flowId + "'...");
            flow = (FlowImpl)dbSession.Load(typeof(FlowImpl), flowId);
            Resolve(flow, relations, dbSession);
            return(flow);
        }
Ejemplo n.º 3
0
        public virtual IFlow GetFlow(Int64 flowId, Relations relations)
        {
            FlowImpl  flow      = null;
            DbSession dbSession = null;

            dbSession = OpenSession();
            flow      = implementation.GetFlow(flowId, relations, dbSession);
            return(flow);
        }
Ejemplo n.º 4
0
        public void ProcessJoin(JoinImpl join, FlowImpl joiningFlow, DbSession dbSession)
        {
            joiningFlow.End     = DateTime.Now;
            joiningFlow.ActorId = null;
            joiningFlow.Node    = join;

            if (false != joiningFlow.ParentReactivation)
            {
                bool  parentReactivation = false;
                IList concurrentFlows    = flowRepository.GetOtherActiveConcurrentFlows(joiningFlow.Id, dbSession);
                if (concurrentFlows.Count == 0)
                {
                    parentReactivation = true;
                }
                else
                {
                    //DelegationImpl joinDelegation = join.JoinDelegation;

                    //if (joinDelegation != null)
                    //{
                    //    IJoinHandler joiner = (IJoinHandler)joinDelegation.GetDelegate();
                    //    IDictionary attributes = joinDelegation.ParseConfiguration();
                    //    parentReactivation = delegationHelper.DelegateJoin(join.JoinDelegation, executionContext);
                    //}
                }

                if (parentReactivation)
                {
                    IEnumerator iter = concurrentFlows.GetEnumerator();
                    while (iter.MoveNext())
                    {
                        FlowImpl concurrentFlow = (FlowImpl)iter.Current;
                        concurrentFlow.ParentReactivation = false;
                    }

                    // reactivate the parent by first setting the parentflow into the executionContext
                    FlowImpl parentFlow = (FlowImpl)joiningFlow.Parent;
                    //executionContext.SetFlow(parentFlow);
                    // and then process the (single, checked at process-archive-parsing-time) leaving transition.
                    ISet leavingTransitions = join.LeavingTransitions;
                    iter = leavingTransitions.GetEnumerator();
                    if (iter.MoveNext())
                    {
                        TransitionImpl leavingTransition = (TransitionImpl)iter.Current;
                        ProcessTransition(leavingTransition, parentFlow, dbSession);
                    }
                    else
                    {
                        // no transition throw exception?
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public void ProcessActivityState(ActivityStateImpl activityState, FlowImpl flow, DbSession dbSession)
        {
            String actorId = null;
            String role    = activityState.ActorRoleName;

            DelegationImpl assignmentDelegation = activityState.AssignmentDelegation;

            if (assignmentDelegation != null)
            {
                var delegateParameters = activityState.AssignmentDelegation.ParseConfiguration();
                actorExpressionResolverService.CurrentScope = flow;
                actorExpressionResolverService.DbSession    = dbSession;
                actorId = actorExpressionResolverService.ResolveArgument(delegateParameters["expression"].ToString()).Id;

                if ((Object)actorId == null)
                {
                    throw new SystemException("invalid process definition : assigner of activity-state '" + activityState.Name + "' returned null instead of a valid actorId");
                }
            }
            else
            {
                if ((Object)role != null)
                {
                    IActor actor = null;
                    var    attr  = attributeRepository.FindAttributeInstanceInScope(role, flow, dbSession);
                    if (attr != null)
                    {
                        actor = (IActor)attr.GetValue();
                    }

                    if (actor == null)
                    {
                        throw new SystemException("invalid process definition : activity-state must be assigned to role '" + role + "' but that attribute instance is null");
                    }
                    actorId = actor.Id;
                }
                else
                {
                    throw new SystemException("invalid process definition : activity-state '" + activityState.Name + "' does not have an assigner or a role");
                }
            }

            flow.ActorId = actorId;

            // If necessary, store the actor in the role
            if ((string.IsNullOrEmpty(role) == false) && (assignmentDelegation != null))
            {
                //executionContext.StoreRole(actorId, activityState);
            }

            // the client of performActivity wants to be Informed of the people in charge of the process
            //executionContext.AssignedFlows.Add(flow);
        }
Ejemplo n.º 6
0
        public ForkedFlow ForkFlow(TransitionImpl transition, FlowImpl parentFlow, IDictionary attributeValues)
        {
            // create the subflow
            FlowImpl subFlow = new FlowImpl(transition.Name, parentFlow, (ProcessBlockImpl)transition.From.ProcessBlock);

            parentFlow.Children.Add(subFlow);

            // save it
            //_dbSession.SaveOrUpdate(subFlow);

            // add the transition and the flow to the set of created sub-flows
            return(new ForkedFlow(transition, subFlow));
        }
Ejemplo n.º 7
0
        private IAuthorizationHandler GetHandlerFromFlowId(Int64 flowId, DbSession dbSession)
        {
            FlowImpl flow = null;

            ;
            try
            {
                flow = (FlowImpl)dbSession.Load(typeof(FlowImpl), flowId);
            }
            catch (ObjectNotFoundException e)
            {
                throw new ArgumentException("couldn't check authorization : flow with id '" + flowId + "' does not exist : " + e.Message);
            }
            return(GetAuthorizationHandler((ProcessDefinitionImpl)flow.ProcessInstance.ProcessDefinition));
        }
Ejemplo n.º 8
0
        public void ProcessDecision(DecisionImpl decision, FlowImpl flow, DbSession dbSession)
        {
            //var delegateParameters = delegationService.ParseConfiguration(decision.DecisionDelegation);

            //IDecisionHandler decisionHandler = (IDecisionHandler)delegationService.GetDelegate(decision.DecisionDelegation);
            var            attributes         = decision.DecisionDelegation.ParseConfiguration();
            string         transiationName    = new EvaluationDecision().Decide(attributes["attribute"].ToString());
            TransitionImpl selectedTransition = this.GetTransition(transiationName, decision, dbSession);

            //// delegate the decision
            //TransitionImpl selectedTransition = delegationHelper.DelegateDecision(decision.DecisionDelegation, executionContext);

            //// process the selected transition
            ProcessTransition(selectedTransition, flow, dbSession);
        }
Ejemplo n.º 9
0
        private void Resolve(FlowImpl flow, Relations relations, DbSession dbSession)
        {
            // resolve the flow
            if (relations != null)
            {
                log.Debug("resolving relations : '" + relations + "' on flow '" + flow + "'");
                relations.Resolve(flow);
            }

            // resolve the flow-details
            IEnumerator iter = flow.Logs.GetEnumerator();

            while (iter.MoveNext())
            {
                LogImpl     logImpl     = (LogImpl)iter.Current;
                IEnumerator detailsIter = logImpl.Details.GetEnumerator();
                while (detailsIter.MoveNext())
                {
                    LogDetailImpl LogDetailImpl = (LogDetailImpl)detailsIter.Current;
                    LogDetailImpl.Resolve(dbSession);
                }
            }

            // resolve the attribute values
            iter = flow.AttributeInstances.GetEnumerator();
            while (iter.MoveNext())
            {
                AttributeInstanceImpl attributeInstance = (AttributeInstanceImpl)iter.Current;
                log.Debug("resolving attribute instance : " + attributeInstance.GetValue());
            }

            // resolve the child-flows
            iter = flow.Children.GetEnumerator();
            while (iter.MoveNext())
            {
                FlowImpl subFlow = (FlowImpl)iter.Current;
                Resolve(subFlow, relations, dbSession);
            }

            // resolve the sub-process-flows
            IProcessInstance subProcessInstance = flow.GetSubProcessInstance();

            if (subProcessInstance != null)
            {
                Resolve((FlowImpl)subProcessInstance.RootFlow, relations, dbSession);
            }
        }
Ejemplo n.º 10
0
        public IList PerformActivity(long flowId, IDictionary attributeValues = null, String transitionName = null, Relations relations = null)
        {
            if (string.IsNullOrEmpty(ActorId))
            {
                throw new AuthorizationException("you can't perform an activity because you are not authenticated");
            }

            IList flows = null;

            try
            {
                using (ISession session = NHibernateHelper.OpenSession())
                {
                    DbSession         dbSession     = new DbSession(session);
                    FlowImpl          flow          = flowRepository.GetFlow(flowId, dbSession);
                    ActivityStateImpl activityState = (ActivityStateImpl)flow.Node;

                    ExecutionContext executionContext = new ExecutionContext();
                    activityState.CheckAccess(attributeValues);

                    attributeService = new AttributeService(flow, dbSession);
                    attributeService.StoreAttributeValue(attributeValues);

                    transitionService = new TransitionService(ActorId, dbSession);
                    TransitionImpl transitionTo = transitionService.GetTransition(transitionName, activityState, dbSession);
                    transitionService.ProcessTransition(transitionTo, flow, dbSession);

                    session.Flush();
                }
            }
            catch (ExecutionException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                throw new SystemException("uncaught exception : " + e.Message, e);
            }
            finally
            {
                //ServiceLocator.Instance.Release(organisationComponent);
            }
            return(flows);
        }
Ejemplo n.º 11
0
        public void ProcessFork(ForkImpl fork, FlowImpl flow, DbSession dbSession)
        {
            // First initialize the children of the flow to be forked
            flow.Children = new ListSet();

            DelegationImpl     delegation  = fork.ForkDelegation;
            IList <ForkedFlow> forkedFlows = new List <ForkedFlow>();

            if (delegation != null)
            {
                //delegationHelper.DelegateFork(fork.ForkDelegation, executionContext);
            }
            else
            {
                // execute the default fork behaviour
                IEnumerator iter = fork.LeavingTransitions.GetEnumerator();
                while (iter.MoveNext())
                {
                    TransitionImpl transition = (TransitionImpl)iter.Current;
                    forkedFlows.Add(this.ForkFlow(transition, flow, null));
                }
            }


            IEnumerator iter2 = forkedFlows.GetEnumerator();

            while (iter2.MoveNext())
            {
                ForkedFlow forkedFlow = (ForkedFlow)iter2.Current;
            }

            // loop over all flows that were forked in the ForkHandler implementation
            iter2 = forkedFlows.GetEnumerator();
            while (iter2.MoveNext())
            {
                ForkedFlow forkedFlow = (ForkedFlow)iter2.Current;

                ProcessTransition(forkedFlow.Transition, forkedFlow.Flow, dbSession);
            }
        }
Ejemplo n.º 12
0
        public FlowImpl GetFlow(long flowId, DbSession dbSession)
        {
            FlowImpl flow = (FlowImpl)dbSession.Load(typeof(FlowImpl), flowId);

            return(flow);
        }
Ejemplo n.º 13
0
 private void ProcessEndState(EndStateImpl endState, FlowImpl flow, DbSession dbSession)
 {
     flow.ActorId = null;
     flow.End     = DateTime.Now;
     flow.Node    = endState;
 }
Ejemplo n.º 14
0
        public AttributeInstanceImpl FindAttributeInstanceInScope(String attributeName, FlowImpl scope, DbSession dbSession)
        {
            AttributeInstanceImpl attributeInstance = null;

            while (attributeInstance == null)
            {
                IList       attributes = this.FindAttributeInstanceByName(attributeName, scope.Id, dbSession);
                IEnumerator iter       = attributes.GetEnumerator();
                if (iter.MoveNext())
                {
                    attributeInstance = (AttributeInstanceImpl)iter.Current;
                    if (iter.MoveNext())
                    {
                        throw new NetBpm.Util.DB.DbException("duplicate value");
                    }
                }
                else
                {
                    if (!scope.IsRootFlow())
                    {
                        scope = (FlowImpl)scope.Parent;
                    }
                    else
                    {
                        log.Warn("couldn't find attribute-instance '" + attributeName + "' in scope of flow '" + scope + "'");
                        break;
                    }
                }
            }
            return(attributeInstance);
        }