Esempio n. 1
0
        private String GenerateExpectedResult(UmlTransition tran)
        {
            String TDexpectedResult = HttpUtility.UrlDecode(tran.GetTaggedValue("TDEXPECTEDRESULT"));
            String aux;
            bool   cycle = false;

            if (tran.GetTaggedValue("TDCYCLETRAN") != null)
            {
                cycle = (tran.GetTaggedValue("TDCYCLETRAN").Equals("true") ? true : false);
            }
            if (!String.IsNullOrEmpty(TDexpectedResult))
            {
                TDexpectedResult = FillTD(TDexpectedResult, cycle);
                aux = HttpUtility.UrlDecode(TDexpectedResult);
                aux = aux.Replace(" | ", "|");
                aux = aux.Replace("| ", "|");
                aux = aux.Replace(" |", "|");
                aux = aux.Replace("|", "." + Environment.NewLine);
                aux = aux + ".";

                return(aux);
            }
            else
            {
                return(" ");
            }
        }
Esempio n. 2
0
        private Boolean GetNewTransition(UmlModel model, List <UmlTransition> list, Transition t, Boolean contem)
        {
            UmlTransition tranSource    = GetUmlTransition(t.SourceState, model, true);
            UmlTransition tranTarget    = GetUmlTransition(t.TargetState, model, false);
            UmlTransition newTransition = new UmlTransition();

            newTransition.Source = tranSource.Source;
            newTransition.Target = tranTarget.Target;
            newTransition.Id     = tranSource.Id;
            foreach (KeyValuePair <String, String> pair in tranTarget.TaggedValues)
            {
                newTransition.SetTaggedValue(pair.Key, pair.Value);
            }
            if (t.CycleTransition)
            {
                newTransition.SetTaggedValue("TDcycleTran", "true");
            }
            if (t.EndCycle)
            {
                newTransition.SetTaggedValue("TDlastCycleTrans", "true");
            }
            list.Add(newTransition);
            contem = true;
            return(contem);
        }
Esempio n. 3
0
        private void OGMA(ClassNode lex)
        {
            model = new UmlModel("script");

            GenerateUseCaseDiagram();

            acdiagram = new UmlActivityDiagram("UseCase0");
            UmlInitialState initial = new UmlInitialState();

            initial.Name = "InitialNode";
            acdiagram.UmlObjects.Add(initial);

            model.AddDiagram(acdiagram);

            LIST_IMPORT(lex.Derivations[0]);
            CLASS(lex.Derivations[1]);

            String currentActionValue = lastAssociation.GetTaggedValue("TDACTION");

            lastAssociation.SetTaggedValue("TDACTION", currentActionValue + "");
            acdiagram.UmlObjects.Add(lastAssociation);

            UmlFinalState final = new UmlFinalState();

            final.Name = "FinalNode";
            acdiagram.UmlObjects.Add(final);
            lastAssociation        = new UmlTransition();
            lastAssociation.Source = lastActivity;
            lastAssociation.Target = (UmlElement)acdiagram.UmlObjects[acdiagram.UmlObjects.Count - 1];
            acdiagram.UmlObjects.Add(lastAssociation);
        }
Esempio n. 4
0
        private String GenerateDescription(UmlTransition tran)
        {
            String aux   = tran.Target.Name + Environment.NewLine + Environment.NewLine;
            bool   cycle = false;

            if (tran.GetTaggedValue("TDCYCLETRAN") != null)
            {
                cycle = (tran.GetTaggedValue("TDCYCLETRAN").Equals("true") ? true : false);
            }
            if (!String.IsNullOrEmpty(aux))
            {
                String TDaction = HttpUtility.UrlDecode(tran.GetTaggedValue("TDACTION"));
                TDaction = FillTD(TDaction, cycle);
                aux     += "- " + TDaction;
                aux      = HttpUtility.UrlDecode(aux);
                aux      = aux.Replace(" | ", "|");
                aux      = aux.Replace("| ", "|");
                aux      = aux.Replace(" |", "|");
                aux      = aux.Replace("|", ";" + Environment.NewLine + "- ");
                aux      = aux + ";";

                return(aux);
            }
            else
            {
                return(" ");
            }
        }
Esempio n. 5
0
        private void ValidateTransitionTags(UmlDiagram diagram, UmlTransition transition)
        {
            String[] validTagNames     = { "TDACTION", "TDEXPECTEDRESULT" };
            String[] mandatoryTagNames = { "TDACTION" };
            String[] optionalTag       = { "TDEXPECTEDRESULT" };

            //Acuse any unexpected tagged value.
            foreach (KeyValuePair <String, String> tagvalue in transition.TaggedValues)
            {
                if (!validTagNames.Contains(tagvalue.Key))
                {
                    log("[WARNING] Unexpected tag {" + tagvalue.Key + "} tagged in transition {" + HttpUtility.UrlDecode(transition.Source.Name + "->" + transition.Target.Name) + "}. Found at {" + HttpUtility.UrlDecode(diagram.Name) + "}.", 2);
                }
            }
            //Acuse any missing tag.
            foreach (String tagvalue in mandatoryTagNames)
            {
                String value = transition.GetTaggedValue(tagvalue);
                if (value == null)
                {
                    log("[ERROR] Missing TDaction in {" + HttpUtility.UrlDecode(transition.Source.Name + "->" + transition.Target.Name) + "}. Found at diagram {" + HttpUtility.UrlDecode(diagram.Name) + "}.", 3);
                }
                else
                {
                    //valid value by tag
                    switch (tagvalue)
                    {
                    case "TDACTION":
                        if (value.Length < 1)
                        {
                            log("[ERROR] Tag {TDaction} has no valid value for transition {" + HttpUtility.UrlDecode(transition.Source.Name + "->" + transition.Target.Name) + "}. Found at diagram {" + HttpUtility.UrlDecode(diagram.Name) + "}.", 3);
                        }
                        break;
                    }
                }
            }
            foreach (String tagvalue in optionalTag)
            {
                String value = transition.GetTaggedValue(tagvalue);
                if (value == null)
                {
                    log("[WARNING] Missing TDexpectedResult in {" + HttpUtility.UrlDecode(transition.Source.Name + "->" + transition.Target.Name) + "}. Found at diagram {" + HttpUtility.UrlDecode(diagram.Name) + "}.", 2);
                }
                else
                {
                    //valid value by tag
                    switch (tagvalue)
                    {
                    case "TDEXPECTEDRESULT":
                        if (value.Length < 1)
                        {
                            log("[WARNING] Tag {TDexpectedResult} has no valid value for transition {" + HttpUtility.UrlDecode(transition.Source.Name + "->" + transition.Target.Name) + "}. Found at diagram {" + HttpUtility.UrlDecode(diagram.Name) + "}.", 2);
                        }

                        break;
                    }
                }
            }
        }
 private Boolean ValidateTDmethod(UmlDiagram diagram, UmlTransition transition, KeyValuePair <String, String> taggedValue)
 {
     if ((taggedValue.Value != "POST") && (taggedValue.Value != "GET"))
     {
         return(false);
     }
     return(true);
 }
        private static String Method(UmlTransition transition, String auxMethod, String line)
        {
            auxMethod = line.Replace("\t", "").Trim().Substring(8);
            auxMethod = auxMethod.Substring(0, auxMethod.Length - 2);

            transition.SetTaggedValue("TDmethod", auxMethod);
            return(auxMethod);
        }
Esempio n. 8
0
        private static string getExpectedResults(UmlTransition transition)
        {
            String result = "  ";

            foreach (var expectResult in transition.listExpectedResults)
            {
                result += HttpUtility.UrlDecode(expectResult.value);
            }
            return(result.Trim());
        }
Esempio n. 9
0
 private Edge GetEquivalentTransition(UmlTransition transition)
 {
     foreach (Edge edge in dg.Edges)
     {
         if ((edge.NodeA.Name.Equals(transition.Source.Name)) && (edge.NodeB.Name.Equals(transition.Target.Name)))
         {
             return(edge);
         }
     }
     return(null);
 }
        private static String Body(UmlTransition transition, String auxBody, String line)
        {
            auxBody = line.Replace("\t", "").Trim().Substring(6);
            auxBody = auxBody.Substring(0, auxBody.Length - 2);
            if (auxBody.Contains("|"))
            {
                auxBody = auxBody.Replace("|", @"\");
            }

            transition.SetTaggedValue("TDbody", auxBody);
            return(auxBody);
        }
        private static String Url(UmlTransition transition, String auxUrl, String line)
        {
            auxUrl = line.Replace("\t", "").Trim().Substring(5);
            auxUrl = auxUrl.Substring(0, auxUrl.Length - 2);

            if (auxUrl.Contains("_"))
            {
                auxUrl = auxUrl.Replace("_", ".");
            }
            transition.SetTaggedValue("TDACTION", auxUrl);
            return(auxUrl);
        }
        private static String Action(UmlTransition transition, String auxAction, String line)
        {
            auxAction = line.Replace("\t", "").Trim().Substring(8);
            auxAction = auxAction.Substring(0, auxAction.Length - 2);

            if (auxAction.Contains("_"))
            {
                auxAction = auxAction.Replace("_", ".");
            }
            transition.SetTaggedValue("TDACTION", auxAction);
            return(auxAction);
        }
Esempio n. 13
0
        private void ELEMENT_DETAILS(ClassNode lex, String tdObject)
        {
            entry.Pop();
            NUMBER(lex.Derivations[1]);
            entry.Pop();
            tdObject += ELEMENT_NAME(lex.Derivations[3]) + "}";
            entry.Pop();
            entry.Pop();

            String tdAction = ACTION(lex.Derivations[6], tdObject);

            if (!tdObject.Split(';') [0].Equals("{window"))
            {
                if (tdObject.Equals(CurrentObject))
                {
                    String currentActionValue = lastAssociation.GetTaggedValue("TDACTION");

                    lastAssociation.SetTaggedValue("TDACTION", currentActionValue + "," + tdAction);
                }
                else
                {
                    UmlActionState newActivity = new UmlActionState();
                    newActivity.Name = CurrentStep + StepPosition;
                    StepPosition++;
                    CurrentObject = tdObject;
                    acdiagram.UmlObjects.Add(newActivity);

                    if (lastAssociation == null)
                    {
                        lastAssociation        = new UmlTransition();
                        lastAssociation.Source = (UmlElement)acdiagram.UmlObjects[0];
                    }
                    else
                    {
                        String currentActionValue = lastAssociation.GetTaggedValue("TDACTION");
                        lastAssociation.SetTaggedValue("TDACTION", currentActionValue + "");
                        acdiagram.UmlObjects.Add(lastAssociation);

                        lastAssociation        = new UmlTransition();
                        lastAssociation.Source = (UmlElement)lastActivity;
                    }

                    lastAssociation.Target = (UmlElement)newActivity;
                    lastAssociation.SetTaggedValue("TDOBJECT", tdObject);
                    lastAssociation.SetTaggedValue("TDACTION", "" + tdAction);

                    lastActivity = newActivity;
                }
            }
        }
Esempio n. 14
0
        public void ValidateFunctionalTest()
        {
            UmlModel model = null; // TODO: Initialize to an appropriate value

            model = new UmlModel("Model X");
            UmlActivityDiagram diagram = new UmlActivityDiagram("");
            //UmlUseCaseDiagram case1 = new UmlUseCaseDiagram();
            UmlInitialState initial     = new UmlInitialState();
            UmlFinalState   final       = new UmlFinalState();
            UmlActionState  action      = new UmlActionState();
            UmlActionState  action1     = new UmlActionState();
            UmlTransition   transition  = new UmlTransition();
            UmlTransition   transition1 = new UmlTransition();
            UmlTransition   transition2 = new UmlTransition();

            initial.Name = "initial0";
            final.Name   = "final0";
            diagram.UmlObjects.Add(initial);
            transition.Source = initial;
            transition.Target = action;
            action.SetTaggedValue("jude.hyperlink", "teste");
            transition1.Source = action;
            transition1.Target = action1;
            transition1.SetTaggedValue("FTaction", "");
            transition1.SetTaggedValue("FTexpectedResult", "Use parameters in the shared step below.");
            transition2.Source = action1;
            transition2.Target = final;
            diagram.UmlObjects.Add(action);
            diagram.UmlObjects.Add(action1);
            diagram.UmlObjects.Add(transition);
            diagram.UmlObjects.Add(transition1);
            diagram.UmlObjects.Add(transition2);
            diagram.UmlObjects.Add(transition2);



            List <KeyValuePair <string, int> > expected = new List <KeyValuePair <string, int> >(); // TODO: Initialize to an appropriate value
            List <KeyValuePair <string, int> > actual   = ValidatorFactory.CreateValidator().Validate(model, "");


            Assert.AreEqual(expected.Count, actual.Count);

            IEnumerator <KeyValuePair <string, int> > e1 = expected.GetEnumerator();
            IEnumerator <KeyValuePair <string, int> > e2 = actual.GetEnumerator();

            while (e1.MoveNext() && e2.MoveNext())
            {
                Assert.AreEqual(e1.Current, e2.Current);
            }
        }
Esempio n. 15
0
        private void PopulateTestCase(String[][] matriz, FiniteStateMachine machine, UmlModel model, TestPlan testPlan, UmlUseCase useCase)
        {
            for (int k = 0; k < matriz.Length; k++)
            {
                testPlan.Name = useCase.Name;
                Transition        t = new Transition();
                List <Transition> listTransition = new List <Transition> ();
                String[]          arraySequence  = matriz[k];
                int maxUseCaseLines = int.MaxValue;
                foreach (String input in arraySequence)
                {
                    t = GetTransition(input, t.TargetState, machine);
                    if (t != null)
                    {
                        listTransition.Add(t);
                        UmlTransition tran = GetUmlTransition(model, t);

                        foreach (KeyValuePair <String, String> pair in tran.TaggedValues)
                        {
                            int aux = GetUsedFilesLineCount(pair.Value);
                            if (maxUseCaseLines > aux)
                            {
                                maxUseCaseLines = aux;
                            }
                        }
                    }
                }

                TestCase testCase = null;
                if (maxUseCaseLines == int.MaxValue)
                {
                    ResetParamFilesPointers();
                }
                else
                {
                    ResetParamFilesPointers(maxUseCaseLines);
                }

                do
                {
                    testCase = FillTestCase(model, useCase, listTransition, testCase);
                    if (testCase != null)
                    {
                        testPlan.TestCases.Add(testCase);
                    }
                    currLine++;
                } while (doAgain && (currLine < maxLine));
            }
        }
        private static String Referer(UmlTransition transition, String auxReferer, String line)
        {
            auxReferer = line.Replace("\t", "").Trim().Substring(9);
            auxReferer = auxReferer.Substring(0, auxReferer.Length - 2);

            if (auxReferer.Length > 0)
            {
                if (auxReferer.Contains("_"))
                {
                    auxReferer = auxReferer.Replace("_", ".");
                }
                transition.SetTaggedValue("TDreferer", auxReferer);
            }
            return(auxReferer);
        }
Esempio n. 17
0
        public static String returnTagTransition(UmlTransition t)
        {
            String tagText = "";

            foreach (String tagKey in t.dictionaryTag.Keys)
            {
                tagText += t.dictionaryTag[tagKey].value;
                tagText  = HttpUtility.UrlDecode(tagText);
            }

            tagText = tagText.Replace("[", Environment.NewLine + " -");
            tagText = tagText.Replace("]", "");

            return(tagText);
        }
Esempio n. 18
0
 private void addTransition()
 {
     if (activity != null)
     {
         if (lastActivity != null)
         {
             UmlTransition tran = new UmlTransition();
             tran.End1 = lastActivity;
             tran.End2 = activity;
             SetTaggedValues(taggedValues, tran);
             actDiagram.UmlObjects.Add(tran);
             lastActivity = null;
             taggedValues = null;
         }
     }
 }
        public static List <Transition> parallelTransitions(UmlTransition t, UmlActivityDiagram actDiagram)
        {
            List <UmlTransition> listUmlTransition = new List <UmlTransition>();
            List <Transition>    listTransition    = new List <Transition>();
            Transition           tran1             = new Transition();

            foreach (UmlTransition tran in actDiagram.UmlObjects.OfType <UmlTransition>())
            {
                if (t.Target.Id.Equals(tran.Source.Id))
                {
                    listUmlTransition.Add(tran);
                }
            }

            Transition tran2 = new Transition();

            tran2.Action  = listUmlTransition[0].GetTaggedValue("TDACTION");
            tran2.Referer = listUmlTransition[0].GetTaggedValue("TDREFERER");
            tran2.Source  = t.Source.Name;
            tran2.Target  = listUmlTransition[0].Target.Name;
            listTransition.Add(tran2);

            UmlTransition transition = listUmlTransition[0];

            tran1.Action  = transition.GetTaggedValue("TDACTION");
            tran1.Referer = transition.GetTaggedValue("TDREFERER");
            tran1.Source  = transition.Target.Name;
            for (int i = 1; i < listUmlTransition.Count; i++)
            {
                transition    = listUmlTransition[i];
                tran1.Action  = transition.GetTaggedValue("TDACTION");
                tran1.Referer = transition.GetTaggedValue("TDREFERER");
                tran1.Target  = transition.Target.Name;
                listTransition.Add(tran1);
                tran1        = new Transition();
                tran1.Source = listTransition[listTransition.Count - 1].Target;
            }
            Transition    tran3         = new Transition();
            UmlTransition transitionAux = getNextState(listTransition[listTransition.Count - 1].Target, actDiagram);

            tran3.Action  = transitionAux.GetTaggedValue("TDACTION");
            tran3.Referer = transitionAux.GetTaggedValue("TDREFERER");
            tran3.Source  = listTransition[listTransition.Count - 1].Target;
            tran3.Target  = transitionAux.Target.Name;
            listTransition.Add(tran3);
            return(listTransition);
        }
        //TODO: Review TDACTION and TDREFERER validation
        private Boolean ValidateTDaction(UmlDiagram diagram, UmlTransition transition, String auxURL, String tagName, String value)
        {
            String auxTD = "";

            auxTD = HttpUtility.UrlDecode(value);
            try {
                auxTD = auxTD.Substring(0, 22);
            } catch {
                return(false);
            }

            if (!auxTD.Equals(auxURL))
            {
                return(false);
            }
            return(true);
        }
Esempio n. 21
0
        /// <summary>
        /// Remove forks and joins of diagram
        /// </summary>
        /// <param name="diagram">targeted diagram to remove fork/join nodes from</param>
        /// <param name="transitions">transitions to be searched and replaced</param>
        private static void RemoveForks(ref UmlActivityDiagram diagram, ref List <UmlTransition> transitions)
        {
            List <UmlFork> forks = (from t in transitions
                                    where t.Target is UmlFork
                                    select(UmlFork) t.Target).Distinct().ToList();

            foreach (UmlFork fork in forks)
            {
                List <UmlTransition> forkLeafs      = transitions.Where(x => x.Source.Equals(fork)).ToList();
                List <UmlTransition> newTransitions = new List <UmlTransition>();
                UmlElement           s = transitions.Where(x => x.Target.Equals(fork)).FirstOrDefault().Source;
                UmlElement           t = null;
                UmlTransition        tran;
                for (int i = 0; i < forkLeafs.Count; i++)
                {
                    t           = forkLeafs[i].Target;
                    tran        = new UmlTransition();
                    tran.Source = s;
                    tran.Target = t;
                    foreach (KeyValuePair <String, String> tag in forkLeafs[i].TaggedValues)
                    {
                        tran.TaggedValues.Add(tag.Key, tag.Value);
                    }
                    tran.TaggedValues.Add("TDPARALELLSTATE", "true");
                    newTransitions.Add(tran);
                    s = t;
                }
                UmlTransition toJoin   = transitions.Where(x => x.Source.Equals(s) && x.Target is UmlJoin).FirstOrDefault();
                UmlJoin       join     = (UmlJoin)toJoin.Target;
                UmlTransition fromJoin = transitions.Where(x => x.Source.Equals(join)).FirstOrDefault();
                tran = new UmlTransition();
                foreach (KeyValuePair <String, String> tag in fromJoin.TaggedValues)
                {
                    tran.TaggedValues.Add(tag.Key, tag.Value);
                }
                tran.Source = s;
                tran.Target = fromJoin.Target;
                newTransitions.Add(tran);

                transitions.RemoveAll(x => x.Target.Equals(fork) || x.Source.Equals(fork));
                transitions.RemoveAll(x => x.Target.Equals(join) || x.Source.Equals(join));
                diagram.UmlObjects.Remove(fork);
                diagram.UmlObjects.Remove(join);
                transitions.AddRange(newTransitions);
            }
        }
Esempio n. 22
0
        /// <summary>
        /// Remove decisions/merge nodes of diagram
        /// </summary>
        /// <param name="diagram">targeted diagram to remove decision/merge nodes from</param>
        /// <param name="transitions">transitions to be searched and replaced</param>
        private static void RemoveDecisions(ref UmlActivityDiagram diagram, ref List <UmlTransition> transitions)
        {
            List <UmlDecision> decs = (from t in transitions
                                       where t.Target is UmlDecision
                                       select(UmlDecision) t.Target).Distinct().ToList();

            while (decs.Count > 0)
            {
                foreach (UmlDecision decision in decs)
                {
                    List <UmlTransition> decisionProspects = transitions.Where(x => x.Source.Equals(decision)).ToList();
                    List <UmlTransition> newTransitions    = new List <UmlTransition>();
                    List <UmlTransition> Ss = transitions.Where(x => x.Target.Equals(decision)).ToList();

                    foreach (UmlTransition sT in Ss)
                    {
                        UmlElement    s = sT.Source;
                        UmlElement    t = null;
                        UmlTransition tran;

                        for (int i = 0; i < decisionProspects.Count; i++)
                        {
                            t           = decisionProspects[i].Target;
                            tran        = new UmlTransition();
                            tran.Source = s;
                            tran.Target = t;
                            foreach (KeyValuePair <string, string> tag in decisionProspects[i].TaggedValues)
                            {
                                tran.TaggedValues.Add(tag.Key, tag.Value);
                            }
                            //tran.TaggedValues.Add("TDParalellState", "true");
                            newTransitions.Add(tran);
                            //s = t;
                        }
                    }
                    transitions.RemoveAll(x => x.Target.Equals(decision) || x.Source.Equals(decision));
                    diagram.UmlObjects.Remove(decision);
                    transitions.AddRange(newTransitions);
                }

                decs = (from t in transitions
                        where t.Target is UmlDecision
                        select(UmlDecision) t.Target).Distinct().ToList();
            }
        }
Esempio n. 23
0
        private void OrderActDiagramTransitions(UmlActivityDiagram actDiagram)
        {
            List <UmlTransition> orderedTransitions = new List <UmlTransition>();
            UmlElement           initialNode        = actDiagram.UmlObjects.OfType <UmlInitialState>().FirstOrDefault();
            UmlTransition        initialTransition  = (actDiagram.UmlObjects.OfType <UmlTransition>().Where(x => x.Source.Equals(initialNode))).FirstOrDefault();
            UmlElement           actual             = initialTransition.Target;

            orderedTransitions.Add(initialTransition);

            for (int i = 0; i < actDiagram.UmlObjects.OfType <UmlTransition>().ToList().Count(); i++)
            {
                UmlTransition transition = (actDiagram.UmlObjects.OfType <UmlTransition>().Where(x => x.Source.Equals(orderedTransitions[i].Target))).FirstOrDefault();
                if (transition != null)
                {
                    orderedTransitions.Add(transition);
                }
            }

            actDiagram.UmlObjects.RemoveAll(IsTransition);
            actDiagram.UmlObjects.AddRange(orderedTransitions);
        }
        /// <summary>
        /// Add a node to the end of the node list.  The new node will get a finish transition and
        /// a continue transition.
        /// </summary>
        /// <param name="node">the node to add</param>
        /// <param name="inboundContinueConstraint">An extra constraint to apply to the continue transition going IN to the added node</param>
        protected void AddNode(StateNode node, IUmlConstraint inboundContinueConstraint = null)
        {
            node.Entered   += HandleNodeEntered;
            node.Exited    += HandleNodeExited;
            node.Dispatcher = Dispatcher;
            node.Faulted   += HandleNodeFaulted;
            node.TimedOut  += HandleNodeTimedOut;

            // add transitions to the final node.
            AddFinalTransitions(node);

            if (_lastCreatedNode != null)
            {
                // Create the Continue transition for the previous node now that it has a consumer.
                UmlTransition continueTransition = _lastCreatedNode.TransitionTo(node);
                continueTransition.Fired += HandleTransitionFired;
                // Use a copy of the default constraint since it will be extended.
                continueTransition.Guard = DefaultContinueConstraint.Copy();
                if (inboundContinueConstraint != null)
                {
                    continueTransition.Guard = continueTransition.Guard.AndWith(inboundContinueConstraint);
                }

                var previousNode = _lastCreatedNode as ConditionalNode;
                if (previousNode != null)
                {
                    previousNode.ContinueTransition = continueTransition;
                    // If the previous node has a ContinueConstraint, then make the new transition inherit it as a guard.
                    // The given constraint must be AND-ed with the machine's guard for all continuation transitions.
                    // It's possible that the ContinueConstraint is not set yet if it is late-bound at runtime.
                    if (previousNode.ContinueConstraint != null)
                    {
                        continueTransition.Guard = continueTransition.Guard.AndWith(previousNode.ContinueConstraint);
                    }
                }
            }

            // Hold a reference to last new node for assembly purposes.
            _lastCreatedNode = node;
        }
Esempio n. 25
0
        private UmlTransition GetUmlTransition(UmlModel model, Transition t)
        {
            UmlTransition tranSource    = GetUmlTransition(t.SourceState, model, true);
            UmlTransition tranTarget    = GetUmlTransition(t.TargetState, model, false);
            UmlTransition newTransition = new UmlTransition();

            newTransition.Source = tranSource.Source;
            newTransition.Target = tranTarget.Target;
            newTransition.Id     = tranSource.Id;
            foreach (KeyValuePair <String, String> pair in tranTarget.TaggedValues)
            {
                newTransition.SetTaggedValue(pair.Key, pair.Value);
            }
            if (t.CycleTransition)
            {
                newTransition.SetTaggedValue("TDcycleTran", "true");
            }
            if (t.EndCycle)
            {
                newTransition.SetTaggedValue("TDlastCycleTrans", "true");
            }
            return(newTransition);
        }
Esempio n. 26
0
        /// <summary>
        /// Converts an activity diagram to a finite state machine.
        /// </summary>
        /// <param name="diagram">Diagram to be converted</param>
        /// <param name="model">Parent model of diagram, used to get sub-diagrams</param>
        /// <returns>a FSM of diagram</returns>
        public static FiniteStateMachine ActivityDiagramToFsm(UmlActivityDiagram diagram, UmlModel model)
        {
            List <UmlTransition> transitions = diagram.UmlObjects.OfType <UmlTransition>().ToList();
            FiniteStateMachine   fsm         = new FiniteStateMachine(diagram.Name);
            State   source         = null;
            State   target         = null;
            String  input          = "";
            String  output         = "";
            Boolean haveHyperlinks = true;
            List <UmlTransition> newTransitions;

            while (haveHyperlinks)
            {
                newTransitions = new List <UmlTransition>();
                foreach (UmlTransition t in transitions)
                {
                    UmlTransition aux = t;
                    if (t.Source.TaggedValues.ContainsKey("jude.hyperlink"))
                    {
                        newTransitions.AddRange(GetTransitionsOfDiagram(model, ref aux, hyperLinkType.Source));
                    }
                    if (t.Target.TaggedValues.ContainsKey("jude.hyperlink"))
                    {
                        newTransitions.AddRange(GetTransitionsOfDiagram(model, ref aux, hyperLinkType.Target));
                    }
                }

                transitions.AddRange(newTransitions);
                transitions = transitions.Distinct().ToList();

                haveHyperlinks = transitions.Where(x => x.Source.TaggedValues.ContainsKey("jude.hyperlink") || x.Target.TaggedValues.ContainsKey("jude.hyperlink")).Count() > 0;
            }

            RemoveForks(ref diagram, ref transitions);
            RemoveDecisions(ref diagram, ref transitions);

            foreach (UmlTransition t in transitions)
            {
                input     = t.GetTaggedValue("TDACTION");
                source    = new State(t.Source.Name);
                source.Id = t.Source.Id;

                if (input != null)
                {
                    target    = new State(t.Target.Name);
                    target.Id = t.Target.Id;
                    output    = "";
                    if (t.GetTaggedValue("TDPARAMETERS") != null)
                    {
                        output = t.GetTaggedValue("TDPARAMETERS");
                    }
                    fsm.AddTransition(new Transition(source, target, input, output));
                }
                if (t.Target is UmlFinalState)
                {
                    fsm.CheckAsFinal(source);
                }
            }

            foreach (Transition t in fsm.Transitions)
            {
                State s = fsm.States
                          .Where(x => x.Name.Equals(t.SourceState.Name))
                          .FirstOrDefault();
                s.Transitions.Add(t);
            }

            fsm = WipeOutOutermost(diagram, fsm);
            fsm.InitialState = getInitial(fsm);
            return(fsm);
        }
Esempio n. 27
0
        public static List <Transition> parallelTransitions(UmlTransition t, UmlActivityDiagram actDiagram)
        {
            List <UmlTransition> listUmlTransition = new List <UmlTransition>();
            List <Transition>    listTransition    = new List <Transition>();
            Transition           tran1             = new Transition();

            foreach (UmlTransition tran in actDiagram.UmlObjects.OfType <UmlTransition>())
            {
                if (t.Target.Id.Equals(tran.Source.Id))
                {
                    listUmlTransition.Add(tran);
                }
            }

            Transition tran2 = new Transition();

            tran2.Input = listUmlTransition[0].GetTaggedValue("TDACTION");
            if (listUmlTransition[0].GetTaggedValue("TDPARAMETERS") == null)
            {
                tran2.Output = "";
            }
            else
            {
                tran2.Output = listUmlTransition[0].GetTaggedValue("TDPARAMETERS");
            }
            tran2.SourceState = getState(t.Source.Name, actDiagram, listTransition);
            tran2.TargetState = getState(listUmlTransition[0].Target.Name, actDiagram, listTransition);;
            listTransition.Add(tran2);

            UmlTransition transition = listUmlTransition[0];

            tran1.Input = transition.GetTaggedValue("TDACTION");
            if (transition.GetTaggedValue("TDPARAMETERS") == null)
            {
                tran1.Output = "";
            }
            else
            {
                tran1.Output = transition.GetTaggedValue("TDPARAMETERS");
            }
            tran1.SourceState = getState(transition.Target.Name, actDiagram, listTransition);
            for (int i = 1; i < listUmlTransition.Count; i++)
            {
                transition  = listUmlTransition[i];
                tran1.Input = transition.GetTaggedValue("TDACTION");
                if (transition.GetTaggedValue("TDPARAMETERS") == null)
                {
                    tran1.Output = "";
                }
                else
                {
                    tran1.Output = transition.GetTaggedValue("TDPARAMETERS");
                }
                tran1.TargetState = getState(transition.Target.Name, actDiagram, listTransition);
                listTransition.Add(tran1);
                tran1             = new Transition();
                tran1.SourceState = listTransition[listTransition.Count - 1].TargetState;
            }
            Transition    tran3         = new Transition();
            UmlTransition transitionAux = getNextState(listTransition[listTransition.Count - 1].TargetState.Name, actDiagram);

            tran3.Input = transitionAux.GetTaggedValue("TDACTION");
            if (transitionAux.GetTaggedValue("TDPARAMETERS") == null)
            {
                tran3.Output = "";
            }
            else
            {
                tran3.Output = transitionAux.GetTaggedValue("TDPARAMETERS");
            }
            tran3.SourceState = listTransition[listTransition.Count - 1].TargetState;
            tran3.TargetState = getState(transitionAux.Target.Name, actDiagram, listTransition);
            listTransition.Add(tran3);
            return(listTransition);
        }
Esempio n. 28
0
        /// <summary>
        /// Converts an activity diagram to a finite state machine.
        /// </summary>
        /// <param name="diagram">Diagram to be converted</param>
        /// <param name="model">Parent model of diagram, used to get sub-diagrams</param>
        /// <returns>a FSM of diagram</returns>
        public FiniteStateMachine ActivityDiagramToFsm(UmlActivityDiagram diagram, UmlModel model)
        {
            List <UmlTransition> transitions = diagram.UmlObjects.OfType <UmlTransition> ().ToList();
            List <UmlTransition> newTransitions;
            //FiniteStateMachine fsm = new FiniteStateMachine(diagram.Name);
            FiniteStateMachine fsm = new FiniteStateMachine();
            State   source         = null;
            State   target         = null;
            String  input          = "";
            String  output         = "";
            Boolean haveHiperlinks = true;

            while (haveHiperlinks)
            {
                newTransitions = new List <UmlTransition> ();
                foreach (UmlTransition t in transitions)
                {
                    UmlTransition aux = new UmlTransition();
                    aux = t;
                    List <UmlTransition> hyperlinkTrans = null;
                    if (t.Source.TaggedValues.ContainsKey("jude.hyperlink"))
                    {
                        hyperlinkTrans = GetTransitionsOfDiagram(model, ref aux, hyperLinkType.Source);
                    }
                    if (hyperlinkTrans != null)
                    {
                        newTransitions.AddRange(hyperlinkTrans);
                    }

                    hyperlinkTrans = null;
                    if (t.Target.TaggedValues.ContainsKey("jude.hyperlink"))
                    {
                        hyperlinkTrans = GetTransitionsOfDiagram(model, ref aux, hyperLinkType.Target);
                    }
                    if (hyperlinkTrans != null)
                    {
                        newTransitions.AddRange(hyperlinkTrans);
                    }
                }

                #region new UmlDecision ID - unsuccessful
                List <UmlDecision> ignoreList = new List <UmlDecision> ();
                foreach (UmlTransition newT in newTransitions)
                {
                    UmlElement src = newT.Source;
                    UmlElement trg = newT.Target;
                    if (src is UmlDecision)
                    {
                        if (!ignoreList.Contains(src))
                        {
                            List <UmlDecision> decs = (from t in newTransitions where t.Source.Name.Equals(src.Name) select(UmlDecision) t.Source).Distinct().ToList();
                            decs.AddRange((from t in newTransitions where t.Target.Name.Equals(src.Name) select(UmlDecision) t.Target).Distinct().ToList());

                            String decID = Guid.NewGuid().ToString();
                            foreach (UmlDecision d in decs)
                            {
                                d.Id = decID;
                            }
                            ignoreList.AddRange(decs);
                        }
                    }
                    if (trg is UmlDecision)
                    {
                        if (!ignoreList.Contains(trg))
                        {
                            List <UmlDecision> decs = (from t in newTransitions where t.Target.Name.Equals(trg.Name) select(UmlDecision) t.Target).Distinct().ToList();
                            decs.AddRange((from t in newTransitions where t.Source.Name.Equals(trg.Name) select(UmlDecision) t.Source).Distinct().ToList());

                            String decID = Guid.NewGuid().ToString();
                            foreach (UmlDecision d in decs)
                            {
                                d.Id = decID;
                            }
                            ignoreList.AddRange(decs);
                        }
                    }
                }
                #endregion

                transitions.AddRange(newTransitions);
                transitions = transitions.Distinct().ToList();

                haveHiperlinks = transitions.Where(x => x.Source.TaggedValues.ContainsKey("jude.hyperlink") || x.Target.TaggedValues.ContainsKey("jude.hyperlink")).Count() > 0;
            }

            RemoveForks(ref diagram, ref transitions);
            RemoveDecisions(ref diagram, ref transitions);

            UmlTransition        auxTran = transitions.Where(x => x.Source is UmlInitialState).FirstOrDefault();
            List <UmlTransition> auxList = new List <UmlTransition> ();
            auxList.Add(auxTran);

            for (int i = 0; i < transitions.Count; i++)
            {
                auxTran = transitions.Where(x => x.Source.Equals(auxTran.Target)).FirstOrDefault();
                if (auxTran != null)
                {
                    auxList.Add(auxTran);
                }
            }

            transitions.Clear();
            transitions.AddRange(auxList);

            foreach (UmlTransition t in transitions)
            {
                input     = t.GetTaggedValue("TDACTION");
                source    = new State(t.Source.Name);
                source.Id = t.Source.Id;

                if (input != null)
                {
                    target    = new State(t.Target.Name);
                    target.Id = t.Target.Id;
                    if ((((UmlActionState)t.Target).ParentLane != null) && !String.IsNullOrEmpty(((UmlActionState)t.Target).ParentLane.Name))
                    {
                        target.TaggedValues.Add("Lane", ((UmlActionState)t.Target).ParentLane.Name);
                    }
                    output = "";
                    if (t.GetTaggedValue("TDEXPECTEDRESULT") != null)
                    {
                        output = t.GetTaggedValue("TDEXPECTEDRESULT");
                    }

                    #region Cycles
                    bool cycleTran = false;
                    if (t.GetTaggedValue("TDCYCLETRAN") != null)
                    {
                        cycleTran = (t.GetTaggedValue("TDCYCLETRAN").Equals("true") ? true : false);
                    }
                    bool lastCycleTrans = false;
                    if (t.GetTaggedValue("TDLASTCYCLETRANS") != null)
                    {
                        //lastCycleTrans = (t.GetTaggedValue("TDCYCLETRAN").Equals("true") ? true : false);
                        lastCycleTrans = (t.GetTaggedValue("TDLASTCYCLETRANS").Equals("true") ? true : false);
                    }
                    Transition trans = new Transition(source, target, input, output, cycleTran, lastCycleTrans);
                    if (t.GetTaggedValue("TDLASTCYCLETRANS") != null)
                    {
                        trans.TaggedValues.Add("TDCYCLETRAN", t.GetTaggedValue("TDCYCLETRAN"));
                    }
                    #endregion

                    foreach (KeyValuePair <String, String> pair in t.TaggedValues)
                    {
                        trans.TaggedValues.Add(pair.Key, pair.Value);
                    }
                    //trans.TaggedValues.Add("TDACTION", t.GetTaggedValue("TDACTION"));
                    //trans.TaggedValues.Add("TDEXPECTEDRESULT", t.GetTaggedValue("TDEXPECTEDRESULT") + "");

                    fsm.AddTransition(trans);
                }

                if (t.Target is UmlFinalState)
                {
                    fsm.CheckAsFinal(source);
                }
            }
            fsm = WipeOutOutermost(diagram, fsm);
            fsm.InitialState = GetFsmInitialState(fsm);
            fsm.Name         = diagram.Name;

            return(fsm);
        }
Esempio n. 29
0
        /// <summary>
        /// Get all transitions of the desired diagram adjusting the initial and final insertion points using <paramref name="t"/>
        /// </summary>
        /// <param name="model">The model where the diagram is</param>
        /// <param name="t">the transation with hyperlink</param>
        /// <param name="tp">the side where the hyperlink is (source or target)</param>
        /// <returns>a list of the transitions</returns>
        private static List <UmlTransition> GetTransitionsOfDiagram(UmlModel model, ref UmlTransition t, hyperLinkType tp)
        {
            List <UmlTransition> subTransitions;
            UmlElement           s;
            String hyperlink = "";

            if (tp == hyperLinkType.Source)
            {
                hyperlink = t.Source.TaggedValues["jude.hyperlink"];
            }
            else
            {
                hyperlink = t.Target.TaggedValues["jude.hyperlink"];
            }

            UmlActivityDiagram subDiagram = model.Diagrams.OfType <UmlActivityDiagram>()
                                            .Where(y => y.Name.Equals(hyperlink))
                                            .FirstOrDefault();

            if (subDiagram == null)
            {
                throw new Exception("Could not find any Activity Diagram named " + hyperlink);
            }

            subTransitions = subDiagram.UmlObjects.OfType <UmlTransition>().ToList();
            List <UmlTransition> fs = null;
            UmlTransition        f  = null;

            if (tp == hyperLinkType.Source)
            {
                fs = subTransitions.Where(x => x.Target is UmlFinalState).ToList();
                f  = fs.ElementAt(0);
            }
            else
            {
                f = subTransitions.Single(x => x.Source is UmlInitialState);
            }

            if (f != null)
            {
                if (tp == hyperLinkType.Source)
                {
                    s = f.Source;
                    for (int i = 1; i < fs.Count; i++)
                    {
                        UmlTransition temp = fs.ElementAt(i);
                        temp.Target = t.Target;
                        foreach (KeyValuePair <string, string> tag in t.TaggedValues)
                        {
                            if (!temp.TaggedValues.ContainsKey(tag.Key))
                            {
                                temp.TaggedValues.Add(tag.Key, tag.Value);
                            }
                        }
                    }
                }
                else
                {
                    s = f.Target;
                }
                foreach (KeyValuePair <string, string> tag in f.TaggedValues)
                {
                    if (!t.TaggedValues.ContainsKey(tag.Key))
                    {
                        t.TaggedValues.Add(tag.Key, tag.Value);
                    }
                }
                subTransitions.Remove(f);
            }
            else
            if (tp == hyperLinkType.Source)
            {
                s = subDiagram.UmlObjects.OfType <UmlFinalState>().FirstOrDefault();
            }
            else
            {
                s = subDiagram.UmlObjects.OfType <UmlInitialState>().FirstOrDefault();
            }

            subTransitions.RemoveAll(x => x.Target is UmlFinalState);
            subTransitions.RemoveAll(x => x.Source is UmlInitialState);
            if (tp == hyperLinkType.Source)
            {
                t.Source = s;
            }
            else
            {
                t.Target = s;
            }

            return(subTransitions);
        }
Esempio n. 30
0
 private void fixName(UmlTransition transition)
 {
     transition.Source.Name = getFriendlyName(transition.Source.Name);
     transition.Target.Name = getFriendlyName(transition.Target.Name);
 }