예제 #1
0
        private String parseDecision(Queue <IXamlElement> token)
        {
            FlowDecision dec = new FlowDecision();
            // [Start] FlowDecision
            IXamlElement elem = token.Dequeue();
            // Reference
            String reference;

            elem.Attributes.TryGetValue("x:Name", out reference);
            dec.Id = reference;
            // True
            String right;

            if (elem.Attributes.TryGetValue("True", out right))
            {
                dec.Right = extractReference(right);
            }
            // False
            String wrong;

            if (elem.Attributes.TryGetValue("False", out wrong))
            {
                dec.Wrong = extractReference(wrong);
            }

            while (!token.Peek().QName.Equals(createQName("FlowDecision")))
            {
                if (token.Peek().QName.Equals(createQName("FlowDecision.True")))
                {
                    token.Dequeue();
                    dec.Right = parseNode(token);
                    token.Dequeue();
                }
                else if (token.Peek().QName.Equals(createQName("FlowDecision.False")))
                {
                    token.Dequeue();
                    dec.Wrong = parseNode(token);
                    token.Dequeue();
                }
                else
                {
                    throw new ParseException(String.Format("Unknown tag found in activity '{0}'", QName), initialTokenCount - token.Count, QName);
                }
            }
            // [End] FlowDecision
            token.Dequeue();

            steps.Add(dec);

            return(dec.Id);
        }
예제 #2
0
        public PetriNet Compile(PetriNet phylum)
        {
            String prefix = phylum.ActivityCount + ".internal.";

            Place p1 = phylum.NewPlace(prefix + "initialized");
            Place p2 = phylum.NewPlace(prefix + "closed");

            if (startNode == null)
            {
                // New Activity
                phylum.ActivityCount += 1;
                int currentID = phylum.ActivityCount;
                // Compile
                new Empty().Compile(phylum);
                // Merge
                phylum.Merge(p1, currentID + ".internal.initialized");
                phylum.Merge(p2, currentID + ".internal.closed");

                return(phylum);
            }

            // Create Steps
            foreach (FlowNode node in steps)
            {
                if (node is FlowStep)
                {
                    FlowStep step       = (FlowStep)node;
                    String   prefixStep = prefix + step.Id + ".";

                    Place stp1 = phylum.NewPlace(prefixStep + "start");
                    Place stp2 = phylum.NewPlace(prefixStep + "next");

                    phylum.ActivityCount += 1;
                    int currentID = phylum.ActivityCount;
                    // Action Activity
                    step.Action.Compile(phylum);
                    // Connect
                    phylum.Merge(stp1, currentID + ".internal.initialized");
                    phylum.Merge(stp2, currentID + ".internal.closed");
                }
                else if (node is FlowDecision)
                {
                    FlowDecision dec        = (FlowDecision)node;
                    String       prefixStep = prefix + dec.Id + ".";

                    Place      dp1           = phylum.NewPlace(prefixStep + "start");
                    Place      condition     = phylum.NewPlace(prefixStep + "condition");
                    Place      right         = phylum.NewPlace(prefixStep + "true");
                    Place      wrong         = phylum.NewPlace(prefixStep + "false");
                    Transition evalCondition = phylum.NewTransition(prefixStep + "evalcondition");
                    Transition startTrue     = phylum.NewTransition(prefixStep + "starttrue");
                    Transition startFalse    = phylum.NewTransition(prefixStep + "startfalse");
                    // Connect
                    phylum.NewArc(dp1, evalCondition);
                    phylum.NewArc(evalCondition, condition);
                    phylum.NewArc(condition, startTrue);
                    phylum.NewArc(condition, startFalse);
                    phylum.NewArc(startTrue, right);
                    phylum.NewArc(startFalse, wrong);
                }
                else if (node is FlowSwitch)
                {
                    FlowSwitch swtch      = (FlowSwitch)node;
                    String     prefixStep = prefix + swtch.Id + ".";

                    Place sp1      = phylum.NewPlace(prefixStep + "start");
                    Place sdefault = phylum.NewPlace(prefixStep + "default");

                    // Inner Petri Net
                    Place lastState = sp1;

                    for (int i = 1; i <= swtch.Branches.Count + 1; i++)
                    {
                        if (i <= swtch.Branches.Count)
                        {
                            Place      cond     = phylum.NewPlace(prefixStep + "condition" + i);
                            Place      state    = phylum.NewPlace(prefixStep + "case" + i);
                            Transition evalCase = phylum.NewTransition(prefixStep + "evalcase" + i);
                            Transition initCase = phylum.NewTransition(prefixStep + "initcase" + i);
                            phylum.NewArc(lastState, evalCase);
                            phylum.NewArc(evalCase, cond);
                            phylum.NewArc(cond, initCase);
                            phylum.NewArc(initCase, state);
                            // LastState
                            lastState = cond;
                        }
                        else
                        {
                            Transition initDefault = phylum.NewTransition(prefixStep + "initdefault");
                            phylum.NewArc(lastState, initDefault);
                            phylum.NewArc(initDefault, sdefault);
                        }
                    }
                }
            }
            // Merge
            // StartNode
            phylum.Merge(p1, prefix + steps.First(e => e.Id.Equals(startNode)).Id + ".start");

            foreach (FlowNode node in steps)
            {
                if (node is FlowStep)
                {
                    FlowStep step       = (FlowStep)node;
                    String   prefixStep = prefix + step.Id + ".";

                    if (step.Next != null)
                    {
                        phylum.Merge(prefixStep + "next", prefix + step.Next + ".start");
                    }
                    else
                    {
                        phylum.Merge(p2, prefixStep + "next");
                    }
                }
                else if (node is FlowDecision)
                {
                    FlowDecision dec            = (FlowDecision)node;
                    String       prefixDecision = prefix + dec.Id + ".";

                    if (dec.Right != null)
                    {
                        phylum.Merge(prefixDecision + "true", prefix + dec.Right + ".start");
                    }
                    else
                    {
                        phylum.Merge(p2, prefixDecision + "true");
                    }

                    if (dec.Wrong != null)
                    {
                        phylum.Merge(prefixDecision + "false", prefix + dec.Wrong + ".start");
                    }
                    else
                    {
                        phylum.Merge(p2, prefixDecision + "false");
                    }
                }
                else if (node is FlowSwitch)
                {
                    FlowSwitch swtch        = (FlowSwitch)node;
                    String     prefixSwitch = prefix + swtch.Id + ".";

                    //Default
                    if (swtch.Default != null)
                    {
                        phylum.Merge(prefixSwitch + "default", prefix + swtch.Default + ".start");
                    }
                    else
                    {
                        phylum.Merge(p2, prefixSwitch + "default");
                    }
                    // Branches
                    for (int i = 1; i <= swtch.Branches.Count; i++)
                    {
                        phylum.Merge(prefixSwitch + "case" + i, prefix + swtch.Branches[i - 1] + ".start");
                    }
                }
            }

            return(phylum);
        }