示例#1
0
文件: Blocks.cs 项目: ljxu1/DWKit
        public override void RegisterFinal(ProcessDefinition pd, List <WorkflowBlock> blocks)
        {
            base.RegisterFinal(pd, blocks);

            //transitions
            var commands = this["Commands"] as List <SimpleCommand>;

            if (commands != null)
            {
                var restrictions = new List <RestrictionDefinition>();
                if (this["_actorRestrictions"] is ActorDefinition)
                {
                    restrictions.Add(RestrictionDefinition.Create(RestrictionType.Allow, (ActorDefinition)this["_actorRestrictions"]));
                }

                foreach (var c in commands)
                {
                    var pdCommand = pd.Commands.Where(pdc => pdc.Name == c.Name).FirstOrDefault();
                    if (pdCommand == null)
                    {
                        pdCommand = CommandDefinition.Create(c.Name);

                        ParameterDefinition pdParameterComment = pd.Parameters.Where(p => p.Name == "Comment").FirstOrDefault();
                        if (pdParameterComment == null)
                        {
                            pdParameterComment = ParameterDefinition.Create("Comment", typeof(string), ParameterPurpose.Temporary, null);
                            pd.Parameters.Add(pdParameterComment);
                        }

                        pdCommand.InputParameters.Add(new ParameterDefinitionReference()
                        {
                            Name      = "Comment",
                            Parameter = pdParameterComment
                        });
                        pd.Commands.Add(pdCommand);
                    }

                    pd.Transitions.Add(new TransitionDefinition()
                    {
                        Name       = string.Format("{0}_{1}_{2}", Name, c.ToBlock.Name, c.Name),
                        Classifier = c.Classifier,
                        From       = (ActivityDefinition)this["_currentActivity"],
                        To         = (ActivityDefinition)c.ToBlock["_currentActivity"],
                        Trigger    = new TriggerDefinition(TriggerType.Command)
                        {
                            Command = pdCommand
                        },
                        Conditions = new List <ConditionDefinition>()
                        {
                            ConditionDefinition.Always
                        },
                        Restrictions = restrictions
                    });
                }
            }
        }
示例#2
0
        public override IEnumerable <TransitionDefinition> ParseTransitions(XElement schemeMedium, IEnumerable <ActorDefinition> actorDefinitions, IEnumerable <CommandDefinition> commandDefinitions, IEnumerable <ActionDefinition> actionDefinitions, IEnumerable <ActivityDefinition> activityDefinitions, IEnumerable <TimerDefinition> timerDefinitions)
        {
            if (schemeMedium == null)
            {
                throw new ArgumentNullException("schemeMedium");
            }
            if (commandDefinitions == null)
            {
                throw new ArgumentNullException("commandDefinitions");
            }
            if (actionDefinitions == null)
            {
                throw new ArgumentNullException("actionDefinitions");
            }
            if (activityDefinitions == null)
            {
                throw new ArgumentNullException("activityDefinitions");
            }
            var transitionElements = schemeMedium.SingleOrDefault("Transitions");

            if (transitionElements == null)
            {
                throw new ArgumentNullException("");
            }

            var commandDefinitionsList  = commandDefinitions.ToList();
            var actionDefinitionsList   = actionDefinitions.ToList();
            var activityDefinitionsList = activityDefinitions.ToList();
            var actorDefinitionsList    = actorDefinitions.ToList();
            var timerDefinitionsList    = timerDefinitions.ToList();

            var transitions = new List <TransitionDefinition>();

            foreach (var transitionElement in transitionElements.Elements().ToList())
            {
                var fromActivity = activityDefinitionsList.Single(ad => ad.Name == GetFrom(transitionElement));
                var toActivity   = activityDefinitionsList.Single(ad => ad.Name == GetTo(transitionElement));

                TriggerDefinition trigger = null;
                var triggersElement       = transitionElement.Element("Triggers");
                if (triggersElement != null)
                {
                    var triggerElement = triggersElement.Element("Trigger");
                    if (triggerElement != null)
                    {
                        trigger = TriggerDefinition.Create(GetType(triggerElement));
                        if (trigger.Type == TriggerType.Command)
                        {
                            (trigger as CommandTriggerDefinition).Command =
                                commandDefinitionsList.Single(cd => cd.Name == GetNameRef(triggerElement));
                        }
                        else if (trigger.Type == TriggerType.Timer)
                        {
                            (trigger as TimerTriggerDefinition).Timer =
                                timerDefinitionsList.Single(cd => cd.Name == GetNameRef(triggerElement));
                        }
                    }
                }

                ConditionDefinition condition = null;
                var conditionsElement         = transitionElement.Element("Conditions");
                if (conditionsElement != null)
                {
                    var conditionElement = conditionsElement.Element("Condition");
                    if (conditionElement != null)
                    {
                        condition = !string.IsNullOrEmpty(GetNameRefNullable(conditionElement))
                                        ? ConditionDefinition.Create(GetType(conditionElement), actionDefinitionsList.Single(ad => ad.Name == GetNameRef(conditionElement)), GetResultOnPreExecution(conditionElement))
                                        : ConditionDefinition.Create(GetType(conditionElement), GetResultOnPreExecution(conditionElement));
                    }
                }

                var transition = TransitionDefinition.Create(GetName(transitionElement), GetClassifier(transitionElement), fromActivity,
                                                             toActivity, trigger, condition);

                var restrictionsElement = transitionElement.Element("Restrictions");
                if (restrictionsElement != null)
                {
                    foreach (var element in restrictionsElement.Elements("Restriction"))
                    {
                        transition.AddRestriction(RestrictionDefinition.Create(GetType(element), actorDefinitionsList.Single(ad => ad.Name == GetNameRef(element))));
                    }
                }

                var onErrorsElement = transitionElement.Element("OnErrors");
                if (onErrorsElement != null)
                {
                    foreach (var element in onErrorsElement.Elements("OnError"))
                    {
                        //TODO Only One Type Of OnErrorHandler
                        transition.AddOnError(OnErrorDefinition.CreateSetActivityOnError(GetName(element), GetNameRef(element), GetPriority(element), GetTypeName(element) /*, GetIsExecuteImplementation(element),GetIsRethrow(element)*/));
                    }
                }
                transitions.Add(transition);
            }


            return(transitions);
        }
示例#3
0
文件: Blocks.cs 项目: ljxu1/DWKit
        public override void RegisterFinal(ProcessDefinition pd, List <WorkflowBlock> blocks)
        {
            //transitions
            var commands = this["Commands"] as List <SimpleCommand>;

            if (commands != null)
            {
                var restrictions = new List <RestrictionDefinition>();
                if (this["_actorRestrictions"] is ActorDefinition)
                {
                    restrictions.Add(RestrictionDefinition.Create(RestrictionType.Allow, (ActorDefinition)this["_actorRestrictions"]));
                }

                foreach (var c in commands)
                {
                    var pdCommand = pd.Commands.Where(pdc => pdc.Name == c.Name).FirstOrDefault();
                    if (pdCommand == null)
                    {
                        pdCommand = CommandDefinition.Create(c.Name);
                        pd.Commands.Add(pdCommand);
                    }

                    if (c.Classifier == TransitionClassifier.Direct)
                    {
                        //CA
                        pd.Transitions.Add(new TransitionDefinition()
                        {
                            Name       = string.Format("{0}_{1}_{2}", Name, c.ToBlock.Name, c.Name),
                            Classifier = c.Classifier,
                            From       = (ActivityDefinition)this["_currentActivity"],
                            To         = (ActivityDefinition)this["_currentActivity"],
                            Trigger    = new TriggerDefinition(TriggerType.Command)
                            {
                                Command = pdCommand
                            },
                            Conditions = new List <ConditionDefinition>()
                            {
                                ConditionDefinition.Always
                            },
                            Restrictions = restrictions
                        });

                        //AC
                        pd.Transitions.Add(new TransitionDefinition()
                        {
                            Name       = string.Format("{0}_{1}_{2}", Name, c.ToBlock.Name, "Auto"),
                            Classifier = c.Classifier,
                            From       = (ActivityDefinition)this["_currentActivity"],
                            To         = (ActivityDefinition)c.ToBlock["_currentActivity"],
                            Trigger    = new TriggerDefinition(TriggerType.Auto),
                            Conditions = new List <ConditionDefinition>()
                            {
                                ConditionDefinition.Create("Action", ActionDefinitionReference.Create("BudgetItemIsLegalEntitySignsComplete", "0", Name), "false", "true")
                            }
                        });
                    }
                    else
                    {
                        pd.Transitions.Add(new TransitionDefinition()
                        {
                            Name       = string.Format("{0}_{1}_{2}", Name, c.ToBlock.Name, c.Name),
                            Classifier = c.Classifier,
                            From       = (ActivityDefinition)this["_currentActivity"],
                            To         = (ActivityDefinition)c.ToBlock["_currentActivity"],
                            Trigger    = new TriggerDefinition(TriggerType.Command)
                            {
                                Command = pdCommand
                            },
                            Conditions = new List <ConditionDefinition>()
                            {
                                ConditionDefinition.Always
                            },
                            Restrictions = restrictions
                        });
                    }
                }
            }
        }