Пример #1
0
        /// <summary>
        /// Wipe out of the given FSM the outermost states of it, i.e. UmlInitialState and UmlFinalState
        /// </summary>
        /// <param name="diagram">Uml diagram of the given FSM</param>
        /// <param name="fsm">FSM to clean</param>
        /// <returns>cleaned FSM</returns>
        private static FiniteStateMachine WipeOutOutermost(UmlActivityDiagram diagram, FiniteStateMachine fsm)
        {
            UmlFinalState digFinal = diagram.UmlObjects.OfType <UmlFinalState>().FirstOrDefault();

            if (digFinal == null)
            {
                throw new Exception("Activity Diagram " + diagram.Name + " must have a final state.");
            }

            fsm.WipeOutState(new State(digFinal.Name));

            UmlInitialState digInitial = diagram.UmlObjects.OfType <UmlInitialState>().FirstOrDefault();

            if (digInitial == null)
            {
                throw new Exception("Activity Diagram " + diagram.Name + " must have a initial state.");
            }
            if (diagram.UmlObjects.OfType <UmlTransition>().Where(x => x.Target.Equals(digInitial) ||
                                                                  x.Source.Equals(digInitial) &&
                                                                  x.TaggedValues.Count > 0
                                                                  ).Count() == 0)
            {
                fsm.WipeOutState(new State(digInitial.Name));
            }
            return(fsm);
        }
Пример #2
0
        /// <summary>
        /// Wipe out of the given FSM the outermost states of it, i.e. UmlInitialState and UmlFinalState
        /// </summary>
        /// <param name="diagram">Uml diagram of the given FSM</param>
        /// <param name="graph">graph to clean</param>
        /// <returns>cleaned FSM</returns>
        private DirectedGraph WipeOutOutermost(UmlActivityDiagram diagram, DirectedGraph graph)
        {
            UmlFinalState digFinal = diagram.UmlObjects.OfType <UmlFinalState> ().FirstOrDefault();

            if (digFinal == null)
            {
                throw new Exception("Activity Diagram " + diagram.Name + " must have a final state.");
            }

            Node nF = new Node(digFinal.Name, digFinal.Id);

            graph.WipeOutNode(nF);

            UmlInitialState digInitial = diagram.UmlObjects.OfType <UmlInitialState> ().FirstOrDefault();

            if (digInitial == null)
            {
                throw new Exception("Activity Diagram " + diagram.Name + " must have a initial state.");
            }
            if (diagram.UmlObjects.OfType <UmlTransition> ().Where(x => x.Target.Equals(digInitial) ||
                                                                   x.Source.Equals(digInitial) &&
                                                                   x.TaggedValues.Count > 0
                                                                   ).Count() == 0)
            {
                graph.WipeOutNode(new Node(digInitial.Name));
            }
            return(graph);
        }
Пример #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);
        }
Пример #4
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);
            }
        }
Пример #5
0
        private UmlModel FromXmi(XmlDocument doc, ref String name)
        {
            UmlModel    model      = null;
            XmlNodeList modelQuery = doc.SelectNodes("//Objects.UmlModel");

            foreach (XmlNode modelNode in modelQuery)
            {
                model      = new UmlModel();
                model.Id   = modelNode.Attributes["id"].Value;
                model.Name = modelNode.Attributes["name"].Value;
                name       = model.Name;
            }

            #region UseCaseDiagram
            XmlNodeList ucDiagramQuery = doc.SelectNodes("//Diagrams.UmlUseCaseDiagram");
            foreach (XmlNode ucDiagram in ucDiagramQuery)
            {
                UmlUseCaseDiagram umlUseCaseDiagram = new UmlUseCaseDiagram();
                umlUseCaseDiagram.Name = ucDiagram.Attributes["name"].Value;
                umlUseCaseDiagram.Id   = ucDiagram.Attributes["id"].Value;
                #region Actor
                foreach (XmlNode actorNode in ucDiagram.SelectNodes("//Diagrams.UmlUseCaseDiagram[@id='" + umlUseCaseDiagram.Id + "']//Objects.UmlActor"))
                {
                    UmlActor element = new UmlActor();
                    element.Id   = actorNode.Attributes["id"].Value;
                    element.Name = actorNode.Attributes["name"].Value;

                    foreach (XmlNode tag in ucDiagram.SelectNodes("//Diagrams.UmlUseCaseDiagram[@id='" + umlUseCaseDiagram.Id + "']//Objects.UmlActor[@id='" + element.Id + "']//TAG"))
                    {
                        String key   = tag.Attributes["tagName"].Value.ToUpper();
                        String value = tag.Attributes["tagValue"].Value;
                        element.SetTaggedValue(key, value);
                    }
                    umlUseCaseDiagram.UmlObjects.Add(element);
                }
                #endregion
                #region UseCase
                foreach (XmlNode ucNode in ucDiagram.SelectNodes("//Diagrams.UmlUseCaseDiagram[@id='" + umlUseCaseDiagram.Id + "']//Objects.UmlUseCase"))
                {
                    UmlUseCase element = new UmlUseCase();
                    element.Id   = ucNode.Attributes["id"].Value;
                    element.Name = ucNode.Attributes["name"].Value;
                    umlUseCaseDiagram.UmlObjects.Add(element);
                }
                #endregion
                #region Association
                foreach (XmlNode associationNode in ucDiagram.SelectNodes("//Diagrams.UmlUseCaseDiagram[@id='" + umlUseCaseDiagram.Id + "']//Objects.UmlAssociation"))
                {
                    UmlAssociation element = new UmlAssociation();
                    element.Id = associationNode.Attributes["id"].Value;
                    UmlElement end1 = SearchUseCaseDiagramElement(associationNode.Attributes["end1Id"].Value, umlUseCaseDiagram);
                    UmlElement end2 = SearchUseCaseDiagramElement(associationNode.Attributes["end2Id"].Value, umlUseCaseDiagram);
                    element.End1 = end1;
                    element.End2 = end2;
                    umlUseCaseDiagram.UmlObjects.Add(element);
                }
                #endregion
                model.AddDiagram(umlUseCaseDiagram);
            }
            #endregion
            #region ActivityDiagram
            XmlNodeList actDiagramQuery = doc.SelectNodes("//Diagrams.UmlActivityDiagram");
            foreach (XmlNode actDiagram in actDiagramQuery)
            {
                UmlActivityDiagram umlActivityDiagram = new UmlActivityDiagram(actDiagram.Attributes["name"].Value);
                umlActivityDiagram.Id = actDiagram.Attributes["id"].Value;
                #region State Initial
                foreach (XmlNode initialNode in actDiagram.SelectNodes("//Diagrams.UmlActivityDiagram[@id='" + umlActivityDiagram.Id + "']//Objects.UmlInitialState"))
                {
                    UmlInitialState element = new UmlInitialState();
                    element.Id   = initialNode.Attributes["id"].Value;
                    element.Name = initialNode.Attributes["name"].Value;
                    umlActivityDiagram.UmlObjects.Add(element);
                }
                #endregion
                #region Action State
                foreach (XmlNode actionStateNode in actDiagram.SelectNodes("//Diagrams.UmlActivityDiagram[@id='" + umlActivityDiagram.Id + "']//Objects.UmlActionState"))
                {
                    UmlActionState element = new UmlActionState();
                    element.Id   = actionStateNode.Attributes["id"].Value;
                    element.Name = actionStateNode.Attributes["name"].Value;
                    umlActivityDiagram.UmlObjects.Add(element);
                }
                #endregion
                #region State Final
                foreach (XmlNode finalNode in actDiagram.SelectNodes("//Diagrams.UmlActivityDiagram[@id='" + umlActivityDiagram.Id + "']//Objects.UmlFinalState"))
                {
                    UmlFinalState element = new UmlFinalState();
                    element.Id   = finalNode.Attributes["id"].Value;
                    element.Name = finalNode.Attributes["name"].Value;
                    umlActivityDiagram.UmlObjects.Add(element);
                }
                #endregion
                #region Fork
                foreach (XmlNode forkNode in actDiagram.SelectNodes("//Diagrams.UmlActivityDiagram[@id='" + umlActivityDiagram.Id + "']//Objects.UmlFork"))
                {
                    UmlFork element = new UmlFork();
                    element.Id   = forkNode.Attributes["id"].Value;
                    element.Name = forkNode.Attributes["name"].Value;
                    umlActivityDiagram.UmlObjects.Add(element);
                }
                #endregion
                #region Join
                foreach (XmlNode joinNode in actDiagram.SelectNodes("//Diagrams.UmlActivityDiagram[@id='" + umlActivityDiagram.Id + "']//Objects.UmlJoin"))
                {
                    UmlJoin element = new UmlJoin();
                    element.Id   = joinNode.Attributes["id"].Value;
                    element.Name = joinNode.Attributes["name"].Value;
                    umlActivityDiagram.UmlObjects.Add(element);
                }
                #endregion
                #region Decision
                foreach (XmlNode decisionNode in actDiagram.SelectNodes("//Diagrams.UmlActivityDiagram[@id='" + umlActivityDiagram.Id + "']//Objects.UmlDecision"))
                {
                    UmlDecision element = new UmlDecision();
                    element.Id   = decisionNode.Attributes["id"].Value;
                    element.Name = decisionNode.Attributes["name"].Value;
                    umlActivityDiagram.UmlObjects.Add(element);
                }
                #endregion
                #region Transition
                foreach (XmlNode transitionNode in actDiagram.SelectNodes("//Diagrams.UmlActivityDiagram[@id='" + umlActivityDiagram.Id + "']//Objects.UmlTransition"))
                {
                    UmlTransition  element   = new UmlTransition();
                    UmlActionState actSource = SearchActivityDiagramElement(transitionNode.Attributes["stateSourceId"].Value, umlActivityDiagram);
                    UmlActionState actTarget = SearchActivityDiagramElement(transitionNode.Attributes["stateTargetId"].Value, umlActivityDiagram);
                    element.Id     = transitionNode.Attributes["id"].Value;
                    element.Source = actSource;
                    element.Target = actTarget;
                    //Get TAG
                    foreach (XmlNode tag in actDiagram.SelectNodes("//Diagrams.UmlActivityDiagram[@id='" + umlActivityDiagram.Id + "']//Objects.UmlTransition[@id='" + element.Id + "']//TAG"))
                    {
                        String key   = tag.Attributes["tagName"].Value.ToUpper();
                        String value = tag.Attributes["tagValue"].Value;
                        element.SetTaggedValue(key, value);
                    }
                    umlActivityDiagram.UmlObjects.Add(element);
                }
                #endregion
                model.AddDiagram(umlActivityDiagram);
            }
            #endregion
            return(model);
        }
        public static UmlModel FromLoadRunnerScript(this UmlModel model, String filepath)
        {
            filepath = "Action.c";

            UmlActivityDiagram activityDiagram  = new UmlActivityDiagram("ActivityDiagram");
            bool            blocoTransaction    = false;
            bool            blocoItemData       = false;
            bool            blocoSubtransaction = false;
            bool            blocoSaveParameter  = false;
            bool            existsLane          = false;
            bool            createdLane         = false;
            bool            putInitial          = false;
            bool            existsThinkTime     = false;
            int             i                = 0;
            UmlTransition   transition       = null;
            UmlInitialState initial          = new UmlInitialState();
            UmlFinalState   final            = new UmlFinalState();
            UmlElement      antActionState   = new UmlActionState();
            UmlActionState  transaction      = null;
            UmlActionState  subtransaction   = null;
            UmlLane         lane             = null;
            UmlTransition   antTransition    = new UmlTransition();
            String          auxMethod        = null;
            String          auxReferer       = null;
            String          auxBody          = null;
            String          auxUrl           = null;
            String          auxAction        = null;
            String          auxThinkTime     = null;
            String          auxSaveParam     = null;
            String          auxSaveParam2    = null;
            String          auxCookies       = null;
            String          auxCookies2      = null;
            String          line             = null;
            String          auxTDparameters2 = null;

            String[] auxSubtransaction = null;
            String[] allLines          = File.ReadAllLines(filepath);

            IEnumerable <String> allLines2 = from String s in allLines
                                             where s.Trim() != String.Empty
                                             select s;

            allLines = allLines2.ToArray();
            activityDiagram.UmlObjects.Add(initial);

            for (int k = 0; k < allLines.Length; k++)
            {
                line = allLines[k];

                #region ThinkTime
                if (line.Contains("lr_think_time("))
                {
                    auxThinkTime    = line.Replace("\t", "").Substring(14).Trim();
                    auxThinkTime    = auxThinkTime.Substring(0, auxThinkTime.Length - 2);
                    existsThinkTime = true;
                }
                #endregion

                if (line.Contains("lr_start_transaction("))
                {
                    if (line.Contains("lr_start_transaction(\"uc"))
                    {
                        activityDiagram.Name = line.Replace("\t", "").Trim().Substring(22);
                        activityDiagram.Name = activityDiagram.Name.Substring(0, activityDiagram.Name.Length - 3);
                        continue;
                    }

                    blocoTransaction = true;

                    if (allLines[k + 1].Contains("lr_start_sub_transaction("))
                    {
                        existsLane = true;
                        continue;
                    }
                }
                else if (line.Contains("lr_end_transaction("))
                {
                    if (line.Contains("lr_end_transaction(\"uc"))
                    {
                        continue;
                    }
                    String auxLine = line.Substring(21);
                    auxLine = auxLine.Substring(0, auxLine.Length - 11);

                    if (auxLine.Equals(lane.Name))
                    {
                        createdLane = false;
                    }

                    if (!activityDiagram.Lanes.Contains(lane))
                    {
                        activityDiagram.Lanes.Add(lane);
                    }
                    blocoTransaction = false;
                    existsLane       = false;
                    continue;
                }

                if (blocoTransaction)
                {
                    if (line.Contains("lr_start_sub_transaction("))
                    {
                        blocoSubtransaction = true;
                    }
                    else if (line.Contains("lr_end_sub_transaction("))
                    {
                        lane.AddElement(subtransaction);
                        blocoSubtransaction = false;
                        continue;
                    }

                    if (existsLane)
                    {
                        if (!createdLane)
                        {
                            lane = new UmlLane();

                            lane.Index = i;
                            i++;
                            createdLane = true;
                        }
                        if (blocoSubtransaction)
                        {
                            #region SubTransaction
                            if (line.Contains("lr_start_sub_transaction("))
                            {
                                subtransaction = new UmlActionState();
                                transition     = new UmlTransition();

                                subtransaction.Name  = line.Replace("\t", "").Replace("\"", "").Substring(25);
                                auxSubtransaction    = subtransaction.Name.Split(',');
                                auxSubtransaction[0] = auxSubtransaction[0].Substring(0, auxSubtransaction[0].Length).Trim();
                                auxSubtransaction[1] = auxSubtransaction[1].Substring(0, auxSubtransaction[1].Length - 2).Trim();

                                subtransaction.Name = auxSubtransaction[0];

                                if (!activityDiagram.Lanes.Contains(lane))
                                {
                                    lane.Name = auxSubtransaction[1];
                                }
                                initial.Name = "Initial0";
                                final.Name   = "Final0";

                                #region PutInitial
                                if (!putInitial)
                                {
                                    transition.Source = initial;
                                    transition.Target = subtransaction;
                                    antActionState    = transition.Target;
                                    putInitial        = true;
                                }
                                else
                                {
                                    transition.Source = antActionState;
                                    transition.Target = subtransaction;
                                    antActionState    = transition.Target;
                                }
                                #endregion

                                activityDiagram.UmlObjects.Add(subtransaction);
                                activityDiagram.UmlObjects.Add(transition);
                            }
                            #endregion
                            #region Tagged Values
                            #region URL
                            else if (line.Contains("URL="))
                            {
                                auxUrl = Url(transition, auxUrl, line);
                            }
                            #endregion
                            #region Action
                            else if (line.Contains("Action="))
                            {
                                auxAction = Action(transition, auxAction, line);
                            }
                            #endregion
                            #region Referer
                            else if (line.Contains("Referer="))
                            {
                                auxReferer = Referer(transition, auxReferer, line);
                            }
                            #endregion
                            #region Method
                            else if (line.Contains("Method="))
                            {
                                auxMethod = Method(transition, auxMethod, line);
                            }
                            #endregion
                            #region Body
                            else if (line.Contains("Body="))
                            {
                                auxBody = Body(transition, auxBody, line);
                            }
                            #endregion
                            #region Cookies
                            if (line.Contains("web_add_cookie("))
                            {
                                auxCookies = line.Replace("\t", "").Trim().Substring(16);
                                auxCookies = auxCookies.Substring(0, auxCookies.Length - 3);
                                auxCookies = auxCookies + "|";

                                auxCookies2 += auxCookies;
                                if (!allLines[k + 1].Contains("web_add_cookie("))
                                {
                                    //SÓ DEVE OCORRER NO FINAL
                                    auxCookies2 = auxCookies2.Substring(0, auxCookies2.Length - 1);
                                    transition.SetTaggedValue("TDcookies", auxCookies2);
                                }
                            }
                            #endregion
                            #region ItemData
                            else if (line.Contains("ITEMDATA"))
                            {
                                blocoItemData = true;
                                continue;
                            }
                            else if (line.Contains("LAST);") && blocoItemData)
                            {
                                transition.SetTaggedValue("TDparameters", auxTDparameters2);
                                blocoItemData = false;
                                continue;
                            }

                            if (blocoItemData)
                            {
                                auxTDparameters2 = ItemData(line, auxTDparameters2);
                            }
                            #endregion
                            #region ThinkTime
                            if (existsThinkTime)
                            {
                                transition.SetTaggedValue("TDthinkTime", auxThinkTime);
                                existsThinkTime = false;
                            }
                            #endregion
                            #endregion
                        }
                    }
                    else
                    {
                        #region Transaction
                        if (line.Contains("lr_start_transaction("))
                        {
                            transaction      = new UmlActionState();
                            transition       = new UmlTransition();
                            transaction.Name = line.Replace("\t", "").Trim().Substring(22);
                            transaction.Name = transaction.Name.Substring(0, transaction.Name.Length - 3);

                            if (!(allLines[k + 1].Contains("lr_start_sub_transaction(")))
                            {
                                if (lane.Name == "")
                                {
                                    lane.AddElement(transaction);
                                }
                                else
                                {
                                    lane       = new UmlLane();
                                    lane.Name  = "";
                                    lane.Index = i;
                                    i++;
                                    lane.AddElement(transaction);
                                }
                            }

                            #region PutInitial
                            if (!putInitial)
                            {
                                transition.Source = initial;
                                transition.Target = transaction;
                                antActionState    = transition.Target;
                                putInitial        = true;
                            }
                            else
                            {
                                transition.Source = antActionState;
                                transition.Target = transaction;
                                antActionState    = transition.Target;
                            }
                            #endregion

                            activityDiagram.UmlObjects.Add(transaction);
                            activityDiagram.UmlObjects.Add(transition);
                        }
                        #endregion
                        #region Tagged Values
                        #region URL
                        else if (line.Contains("URL="))
                        {
                            auxUrl = Url(transition, auxUrl, line);
                        }
                        #endregion
                        #region Action
                        else if (line.Contains("Action="))
                        {
                            auxAction = Action(transition, auxAction, line);
                        }
                        #endregion
                        #region Referer
                        else if (line.Contains("Referer="))
                        {
                            auxReferer = Referer(transition, auxReferer, line);
                        }
                        #endregion
                        #region Method
                        else if (line.Contains("Method="))
                        {
                            auxMethod = Method(transition, auxMethod, line);
                        }
                        #endregion
                        #region Body
                        else if (line.Contains("Body="))
                        {
                            auxBody = Body(transition, auxBody, line);
                        }
                        #endregion
                        #region Cookies
                        if (line.Contains("web_add_cookie("))
                        {
                            auxCookies = line.Replace("\t", "").Trim().Substring(16);
                            auxCookies = auxCookies.Substring(0, auxCookies.Length - 3);
                            auxCookies = auxCookies + "|";

                            auxCookies2 += auxCookies;
                            if (!allLines[k + 1].Contains("web_add_cookie("))
                            {
                                //SÓ DEVE OCORRER NO FINAL
                                auxCookies2 = auxCookies2.Substring(0, auxCookies2.Length - 1);
                                transition.SetTaggedValue("TDcookies", auxCookies2);
                            }
                        }
                        #endregion
                        #region ItemData
                        else if (line.Contains("ITEMDATA"))
                        {
                            blocoItemData = true;
                            continue;
                        }
                        else if (line.Contains("LAST);") && blocoItemData)
                        {
                            transition.SetTaggedValue("TDparameters", auxTDparameters2);
                            blocoItemData = false;
                            continue;
                        }

                        if (blocoItemData)
                        {
                            auxTDparameters2 = ItemData(line, auxTDparameters2);
                        }
                        #endregion
                        #region ThinkTime
                        if (existsThinkTime)
                        {
                            transition.SetTaggedValue("TDthinkTime", auxThinkTime);
                            existsThinkTime = false;
                        }
                        #endregion
                        #endregion
                    }
                }
                #region SaveParameters
                if (line.Contains("web_reg_save_param("))
                {
                    blocoSaveParameter = true;

                    auxSaveParam = line.Replace("\t", "").Trim().Substring(20);
                    auxSaveParam = auxSaveParam.Substring(0, auxSaveParam.Length - 1);
                    auxSaveParam = auxSaveParam + "|";

                    auxSaveParam2 += auxSaveParam;
                }
                else if (line.Contains("LAST);") && blocoSaveParameter)
                {
                    if (allLines[k + 1].Contains("web_reg_save_param("))
                    {
                        continue;
                    }
                    else
                    {
                        //SÓ DEVE OCORRER NO FINAL
                        auxSaveParam2 = auxSaveParam2.Substring(0, auxSaveParam2.Length - 1);
                        transition.SetTaggedValue("TDsaveParameters", auxSaveParam2);
                        auxSaveParam2      = null;
                        blocoSaveParameter = false;
                    }
                }
                #endregion
            }
            transition        = new UmlTransition();
            transition.Source = antActionState;
            transition.Target = final;

            activityDiagram.UmlObjects.Add(transition);
            activityDiagram.UmlObjects.Add(final);

            if (activityDiagram.Lanes.Count() > 0)
            {
                activityDiagram.Lanes[0].AddElement(initial);
                lane.AddElement(final);
            }

            model.AddDiagram(activityDiagram);

            return(model);
        }
Пример #7
0
        public UmlModel TransformToUml(FiniteStateMachine[] fsms)
        {
            UmlModel          model     = new UmlModel("model");
            UmlUseCaseDiagram ucDiagram = new UmlUseCaseDiagram();

            ucDiagram.Id   = Guid.NewGuid().ToString();
            ucDiagram.Name = "useCase diagram";
            UmlActor user = new UmlActor();

            user.Name = "user";
            user.Id   = Guid.NewGuid().ToString();
            ucDiagram.UmlObjects.Add(user);
            State s = new State();

            foreach (FiniteStateMachine fsm in fsms)
            {
                UmlUseCase useCase = new UmlUseCase();
                useCase.Name = fsm.Name;
                useCase.Id   = Guid.NewGuid().ToString();
                UmlAssociation association = new UmlAssociation();
                association.Id   = Guid.NewGuid().ToString();
                association.End1 = user;
                association.End2 = useCase;

                ucDiagram.UmlObjects.Add(useCase);
                ucDiagram.UmlObjects.Add(association);

                UmlActivityDiagram actDiagram = new UmlActivityDiagram(fsm.Name);

                Transition initialTransition = new Transition();
                State      initialState      = new State();
                initialTransition = (from t in fsm.Transitions where fsm.Transitions.Count(x => x.TargetState.Equals(t.SourceState)) == 0 select t).First();
                UmlInitialState initial       = new UmlInitialState();
                UmlActionState  initialTarget = new UmlActionState();
                UmlTransition   transInitial  = new UmlTransition();
                initial.Name        = initialTransition.SourceState.Name;
                initial.Id          = initialTransition.SourceState.Id;
                initialTarget.Name  = initialTransition.TargetState.Name;
                initialTarget.Id    = initialTransition.TargetState.Id;
                transInitial.Source = initial;
                transInitial.Target = initialTarget;

                actDiagram.UmlObjects.Add(initialTarget);
                actDiagram.UmlObjects.Add(initial);
                actDiagram.UmlObjects.Add(transInitial);

                foreach (State state in fsm.States)
                {
                    List <Transition> listTransition = new List <Transition> ();
                    listTransition = GetTransitions(state, fsm);
                    if (listTransition.Count < 2 && listTransition.Count != 0)
                    {
                        Transition     transitionFSM      = listTransition[0];
                        UmlActionState actionState_Source = new UmlActionState();
                        actionState_Source.Name = transitionFSM.SourceState.Name;
                        actionState_Source.Id   = transitionFSM.SourceState.Id;
                        UmlActionState actionState_Target1 = new UmlActionState();
                        actionState_Target1.Name = transitionFSM.TargetState.Name;
                        actionState_Target1.Id   = transitionFSM.TargetState.Id;
                        UmlTransition trans2 = new UmlTransition();

                        UmlTransition trans1 = new UmlTransition();
                        trans1.Source = actionState_Source;
                        trans1.Target = actionState_Target1;
                        trans1.SetTaggedValue("TDACTION", transitionFSM.Input);
                        trans1.SetTaggedValue("TDEXPECTEDRESULT", transitionFSM.Output);
                        if (!actDiagram.UmlObjects.Contains(trans1))
                        {
                            actDiagram.UmlObjects.Add(trans1);
                        }
                        if (!actDiagram.UmlObjects.Contains(actionState_Source))
                        {
                            actDiagram.UmlObjects.Add(actionState_Source);
                        }
                        if (!actDiagram.UmlObjects.Contains(actionState_Target1))
                        {
                            actDiagram.UmlObjects.Add(actionState_Target1);
                        }
                    }
                    else
                    {
                        //criar decision
                        bool        createDecision = false;
                        UmlDecision decision       = new UmlDecision();
                        foreach (Transition transition in listTransition)
                        {
                            if (createDecision == false)
                            {
                                actDiagram.UmlObjects.Add(decision);
                                createDecision = true;
                            }

                            UmlActionState source = new UmlActionState();
                            UmlActionState target = new UmlActionState();
                            UmlTransition  transitionBeforeDecision = new UmlTransition();
                            UmlTransition  transitionAfterDecision  = new UmlTransition();
                            source.Name = transition.SourceState.Name;
                            source.Id   = transition.SourceState.Id;
                            target.Name = transition.TargetState.Name;
                            target.Id   = transition.TargetState.Id;
                            transitionBeforeDecision.Source = source;
                            transitionBeforeDecision.Target = decision;
                            transitionAfterDecision.Source  = decision;
                            transitionAfterDecision.Target  = target;
                            transitionAfterDecision.SetTaggedValue("TDACTION", transition.Input);
                            transitionAfterDecision.SetTaggedValue("TDEXPECTEDRESULT", transition.Output);
                            actDiagram.UmlObjects.Add(transitionBeforeDecision);
                            actDiagram.UmlObjects.Add(transitionAfterDecision);
                            actDiagram.UmlObjects.Add(source);
                            actDiagram.UmlObjects.Add(target);
                        }
                    }
                }

                State      finalState = new State();
                Transition aux        = new Transition();

                finalState = (from t in fsm.Transitions where fsm.Transitions.Count(x => x.SourceState.Equals(t.TargetState)) == 0 select t.TargetState).First();

                UmlActionState finalSource = new UmlActionState();
                finalSource.Name = finalState.Name;
                finalSource.Id   = finalState.Id;
                UmlFinalState final = new UmlFinalState();
                final.Name = "finalNode";
                final.Id   = Guid.NewGuid().ToString();
                UmlTransition transFinal = new UmlTransition();
                transFinal.Source = finalSource;
                transFinal.Target = final;

                if (!actDiagram.UmlObjects.Contains(finalSource))
                {
                    actDiagram.UmlObjects.Add(finalSource);
                }

                actDiagram.UmlObjects.Add(final);
                actDiagram.UmlObjects.Add(transFinal);
                model.AddDiagram(actDiagram);
                model.AddDiagram(ucDiagram);
            }

            return(model);
        }
Пример #8
0
        public UmlModel Converter(String path, String prm)
        {
            #region Variables
            List <String> functions = new List <string>();
            UmlModel      model     = new UmlModel("55");
            String        line      = "";
            //String test = "";
            String auxAux        = "";;
            String auxMethod     = "";
            String auxReferer    = "";
            String auxBody       = "";
            String parameters    = "";
            String auxCookies    = "";
            String auxCookies2   = "";
            String auxSaveParam  = "";
            String auxSaveParam2 = "";
            String auxThinkTime  = "";
            String auxAction     = "";
            String name          = "";
            String tempoBody     = "";
            //int w = 0;
            bool            trans           = false;
            bool            entro           = false;
            bool            bloco           = false;
            bool            existeLane      = false;
            bool            firstLine       = false;
            bool            putInitial      = false;
            bool            blocoItemData   = false;
            bool            createdLane     = false;
            bool            subbloco        = false;
            bool            existsThinkTime = false;
            bool            blocoExtares    = false;
            bool            comentado       = false;
            bool            blocoBody       = false;
            UmlTransition   transition      = null;
            UmlInitialState initial         = new UmlInitialState();
            UmlFinalState   final           = new UmlFinalState();
            UmlElement      antActionState  = new UmlActionState();
            UmlActionState  actionState     = null;
            UmlActionState  subActionState  = null;
            UmlLane         lane            = null;
            UmlTransition   antTransition   = new UmlTransition();
            UmlFork         fork            = null;
            UmlDecision     decision        = null;
            initial.Name = "Initial0";
            final.Name   = "Final0";
            UmlActivityDiagram activityDiagram = new UmlActivityDiagram("ActivityDiagram");
            activityDiagram.UmlObjects.Add(initial);
            List <String> namesParameter = new List <String>();
            #endregion
            String[] lines   = File.ReadAllLines(path);
            String[] prmFile = File.ReadAllLines(prm);
            #region LoadPrmFile
            Dictionary <String, String> dicPrm = new Dictionary <String, String>();
            String prmName    = "";
            String columnName = "";

            foreach (String linha in prmFile)
            {
                if (linha.Contains("[parameter:"))
                {
                    prmName    = linha.Substring(11);
                    prmName    = prmName.Substring(0, prmName.Length - 1);
                    columnName = String.Empty;
                }

                if (linha.Contains("ColumnName="))
                {
                    columnName = linha.Substring(12);
                    columnName = columnName.Substring(0, columnName.Length - 1);
                    dicPrm.Add(prmName, columnName);
                }
            }

            foreach (String linha in lines)
            {
                if (linha.Trim().StartsWith("//"))
                {
                    continue;
                }


                if (linha.Contains("web_reg_save_param("))
                {
                    String parameter = linha.Replace("\t", "").Trim().Substring(20);
                    parameter = parameter.Substring(0, parameter.Length - 2);
                    namesParameter.Add(parameter);
                }
            }
            #endregion
            for (int i = 0; i < lines.Length; i++)
            {
                line = lines[i].Replace("\t", "").Trim();
                if (line.Trim().StartsWith("//"))
                {
                    continue;
                }

                if (line.Trim().StartsWith("/*"))
                {
                    continue;
                }

                //if (line.Trim().EndsWith("*/") && comentado)
                //{
                //    comentado = false;
                //    continue;
                //}
                //else if (comentado)
                //{
                //    continue;
                //}

                #region ThinkTime
                if (line.Contains("lr_think_time("))
                {
                    auxThinkTime    = line.Replace("\t", "").Substring(14).Trim();
                    auxThinkTime    = auxThinkTime.Substring(0, auxThinkTime.Length - 2);
                    existsThinkTime = true;
                }
                #endregion

                if (!firstLine && line.EndsWith("()"))
                {
                    activityDiagram.Name = line.Replace("\t", "").Trim();
                    activityDiagram.Name = activityDiagram.Name.Substring(0, activityDiagram.Name.Length - 2);
                    firstLine            = true;
                    name = activityDiagram.Name;
                    continue;
                }

                if (line.Contains("lr_start_transaction(\""))
                {
                    lane        = new UmlLane();
                    line        = line.Replace("\t", "").Trim();
                    line        = line.Substring(22);
                    line        = line.Substring(0, line.Length - 3);
                    lane.Name   = line;
                    existeLane  = true;
                    createdLane = true;
                    trans       = true;
                    continue;
                }

                if (trans)
                {
                    #region SaveParam
                    if (line.Contains("web_reg_save_param("))
                    {
                        auxSaveParam   = line.Replace("\t", "").Trim().Substring(20);
                        auxSaveParam   = auxSaveParam.Substring(0, auxSaveParam.Length - 2);
                        auxSaveParam   = auxSaveParam + "|";
                        auxSaveParam2 += auxSaveParam;
                        if (!lines[i + 1].Contains("web_reg_save_param("))
                        {
                            //SÓ DEVE OCORRER NO FINAL
                            // auxSaveParam2 += auxSaveParam2.Substring(0, auxSaveParam2.Length - 1);
                            auxSaveParam2 = ParseParameter(auxSaveParam2, dicPrm, namesParameter);
                            transition.SetTaggedValue("TDsaveParam", auxSaveParam2);
                        }
                    }
                    #endregion
                }

                if (line.Contains("web_custom_request(\"") || line.Contains("web_url(\"") || line.Contains("web_submit_data(\""))
                {
                    actionState    = new UmlActionState();
                    subActionState = new UmlActionState();
                    transition     = new UmlTransition();
                    trans          = false;

                    if (line.Contains("web_custom_request(\""))
                    {
                        line = line.Substring(20);
                        line = line.Substring(0, line.Length - 2);
                        //bloco = true;
                        if (line.Contains("{Server}"))
                        {
                            continue;
                        }
                    }
                    else if (line.Contains("web_url(\""))
                    {
                        line = line.Substring(9);
                        line = line.Substring(0, line.Length - 2);
                        //bloco = true;
                        if (line.Contains("{Server}"))
                        {
                            continue;
                        }
                    }
                    else if (line.Contains("web_submit_data(\""))
                    {
                        line = line.Substring(17);
                        line = line.Substring(0, line.Length - 2);
                        //bloco = true;
                        if (line.Contains("{Server}"))
                        {
                            continue;
                        }
                    }

                    if (createdLane)
                    {
                        createdLane = false;
                        activityDiagram.Lanes.Add(lane);
                    }

                    if (lane != null)
                    {
                        lane.AddElement(actionState);
                    }
                    else if (lane == null)
                    {
                        lane      = new UmlLane();
                        lane.Name = "";
                        lane.AddElement(actionState);
                        activityDiagram.Lanes.Add(lane);
                    }

                    if (!putInitial)
                    {
                        transition.Source = initial;
                        transition.Target = actionState;
                        antActionState    = transition.Target;
                        putInitial        = true;
                    }
                    else
                    {
                        subActionState    = actionState;
                        transition.Source = antActionState;
                        transition.Target = subActionState;
                        antActionState    = transition.Target;
                    }

                    bloco            = true;
                    actionState.Name = line;

                    if (line.Contains("lr_end_transaction(\""))
                    {
                        existeLane = false;
                    }
                    activityDiagram.UmlObjects.Add(transition);
                    activityDiagram.UmlObjects.Add(actionState);
                }

                if (bloco)
                {
                    if (line.Contains("EXTRARES"))
                    {
                        blocoExtares = true;
                    }

                    if (blocoExtares && line.Contains("LAST);"))
                    {
                        blocoExtares = false;
                    }
                    else if (blocoExtares)
                    {
                        continue;
                    }

                    #region URL
                    if (line.Contains("URL="))
                    {
                        auxAux = line.Replace("\t", "").Trim().Substring(5);;
                        auxAux = auxAux.Substring(0, auxAux.Length - 2);

                        if (line.Contains("_"))
                        {
                            auxAux = auxAux.Replace("_", ".");
                        }

                        if (line.Contains("{Server}"))
                        {
                            auxAux = auxAux.Replace("{Server}", "{Server.Server}");
                        }

                        auxAux = ParseParameter(auxAux, dicPrm, namesParameter);
                        transition.SetTaggedValue("TDaction", auxAux);
                    }
                    #endregion
                    #region Action
                    else if (line.Contains("Action="))
                    {
                        auxAction = line.Replace("\t", "").Trim().Substring(8);
                        auxAction = auxAction.Substring(0, auxAction.Length - 2);
                        transition.SetTaggedValue("TDaction", auxAction);
                    }
                    #endregion
                    #region Method
                    else if (line.Contains("Method="))
                    {
                        auxMethod = line.Replace("\t", "").Trim().Substring(8);
                        auxMethod = auxMethod.Substring(0, auxMethod.Length - 2);
                        transition.SetTaggedValue("TDmethod", auxMethod);
                    }
                    #endregion
                    #region Body
                    if (line.Contains("Body="))
                    {
                        auxBody   = line.Replace("\t", "").Trim().Substring(6);
                        auxBody   = auxBody.Substring(0, auxBody.Length - 1);
                        auxBody   = ParseParameter(auxBody, dicPrm, namesParameter);
                        tempoBody = auxBody;
                        blocoBody = true;
                        continue;
                    }

                    if (blocoBody && line.Contains("LAST);"))
                    {
                        //auxBody = auxBody.Substring(0, auxBody.Length - 1);
                        tempoBody = tempoBody.Substring(0, tempoBody.Length - 1);
                        transition.SetTaggedValue("TDbody", tempoBody);
                        tempoBody = "";
                        blocoBody = false;
                    }

                    if (blocoBody)
                    {
                        auxBody    = line.Replace("\t", "").Trim().Substring(1);
                        auxBody    = auxBody.Substring(0, auxBody.Length - 1);
                        auxBody    = ParseParameter(auxBody, dicPrm, namesParameter);
                        tempoBody += auxBody;
                        continue;
                    }
                    #endregion
                    #region Referer
                    else if (line.Contains("Referer="))
                    {
                        auxReferer = line.Replace("\t", "").Trim().Substring(9);
                        auxReferer = auxReferer.Substring(0, auxReferer.Length - 2);

                        if (line.Contains("_"))
                        {
                            auxReferer = auxReferer.Replace("_", ".");
                        }

                        if (line.Contains("{Server}"))
                        {
                            auxReferer = auxReferer.Replace("{Server}", "{Server.Server}");
                        }

                        auxReferer = ParseParameter(auxReferer, dicPrm, namesParameter);

                        if (auxReferer != "")
                        {
                            transition.SetTaggedValue("TDreferer", auxReferer);
                        }
                    }
                    #endregion
                    #region itemData
                    else if (line.Contains("ITEMDATA"))
                    {
                        blocoItemData = true;
                        continue;
                    }
                    else if (line.Contains("LAST);") && blocoItemData)
                    {
                        transition.SetTaggedValue("TDparameters", parameters);
                        blocoItemData = false;
                        parameters    = parameters.Substring(0, parameters.Length - 1);
                        continue;
                    }

                    if (blocoItemData)
                    {
                        parameters = ItemData(line, parameters);
                    }
                    #endregion
                    #region ThinkTime
                    else if (existsThinkTime)
                    {
                        transition.SetTaggedValue("TDthinkTime", auxThinkTime);
                        existsThinkTime = false;
                    }
                    #endregion
                    #region Cookie
                    else if (line.Contains("web_add_cookie("))
                    {
                        auxCookies   = line.Replace("\t", "").Trim().Substring(16);
                        auxCookies   = auxCookies.Substring(0, auxCookies.Length - 3);
                        auxCookies   = auxCookies + "|";
                        auxCookies2 += auxCookies;

                        if (!lines[i + 1].Contains("web_add_cookie("))
                        {
                            //SÓ DEVE OCORRER NO FINAL
                            auxCookies2 = auxCookies2.Substring(0, auxCookies2.Length - 1);
                            transition.SetTaggedValue("TDcookies", auxCookies2);
                        }
                    }
                    #endregion

                    if (line.Contains("LAST);"))
                    {
                        bloco = false;
                    }
                }
            }
            transition        = new UmlTransition();
            transition.Source = antActionState;
            transition.Target = final;
            activityDiagram.UmlObjects.Add(transition);
            activityDiagram.UmlObjects.Add(final);
            model.AddDiagram(activityDiagram);

            return(model);
        }
Пример #9
0
        public UmlModel FromXmi(XmlDocument doc, ref String name)
        {
            UmlModel model = new UmlModel("");
            //uml and astah namespaces
            XmlNamespaceManager nsManager = new XmlNamespaceManager(doc.NameTable);

            nsManager.AddNamespace("JUDE", "http://objectclub.esm.co.jp/Jude/namespace/");
            nsManager.AddNamespace("UML", "org.omg.xmi.namespace.UML");

            XmlNodeList mod = doc.SelectNodes("//UML:Model[@xmi.id]", nsManager);

            foreach (XmlNode node in mod)
            {
                name = node.Attributes["name"].Value;
                break;
            }
            //importing activity diagrams into model.
            XmlNodeList nodesWithActivityDiagrams = doc.SelectNodes("//UML:ActivityGraph[@xmi.id]", nsManager);

            #region Activity Diagram
            if (nodesWithActivityDiagrams.Count != 0)
            {
                foreach (XmlNode node in nodesWithActivityDiagrams)
                {
                    UmlActivityDiagram actDiagram = new UmlActivityDiagram(node.Attributes["name"].Value);
                    actDiagram.Id   = node.Attributes["xmi.id"].Value;
                    actDiagram.Name = node.Attributes["name"].Value;
                    model.AddDiagram(actDiagram);

                    #region Pseudostate
                    foreach (XmlNode pseudoNode in node.SelectNodes("//UML:ActivityGraph[@xmi.id='" + actDiagram.Id + "']//UML:Pseudostate[@xmi.id]", nsManager))
                    {
                        UmlElement element = null;

                        if (pseudoNode.Attributes["kind"].Value.Equals("initial"))
                        {
                            element = new UmlInitialState();
                        }
                        else if (pseudoNode.Attributes["kind"].Value.Equals("fork"))
                        {
                            element = new UmlFork();
                        }
                        else if (pseudoNode.Attributes["kind"].Value.Equals("junction"))
                        {
                            element = new UmlDecision();
                        }
                        else if (pseudoNode.Attributes["kind"].Value.Equals("join"))
                        {
                            element = new UmlJoin();
                        }

                        element.Name = pseudoNode.Attributes["name"].Value;
                        element.Id   = pseudoNode.Attributes["xmi.id"].Value;

                        #region Tagged Values
                        foreach (XmlNode taggedValuesNode in pseudoNode.SelectNodes("//UML:Pseudostate[@xmi.id='" + element.Id + "']//UML:ModelElement.taggedValue//UML:TaggedValue[@xmi.id]", nsManager))
                        {
                            //element.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value, HttpUtility.UrlDecode(taggedValuesNode.Attributes["value"].Value));
                            element.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value, taggedValuesNode.Attributes["value"].Value);
                        }
                        #endregion

                        actDiagram.UmlObjects.Add(element);
                    }
                    #endregion
                    #region ActionState
                    foreach (XmlNode stateNode in node.SelectNodes("//UML:ActivityGraph[@xmi.id='" + actDiagram.Id + "']//UML:ActionState[@xmi.id]", nsManager))
                    {
                        UmlElement state = new UmlActionState();
                        state.Id   = stateNode.Attributes["xmi.id"].Value;
                        state.Name = stateNode.Attributes["name"].Value;

                        #region Tagged Values
                        foreach (XmlNode taggedValuesNode in stateNode.SelectNodes("//UML:ActionState[@xmi.id='" + state.Id + "']//UML:ModelElement.taggedValue//UML:TaggedValue[@xmi.id]", nsManager))
                        {
                            #region Hyperlink
                            if (taggedValuesNode.Attributes["tag"].Value.Equals("jude.hyperlink"))
                            {
                                string nameToken    = "type%3Dmodel%2Cname%3D";
                                string commentToken = "%2Cpath%3D%2Ccomment%3D";
                                int    i1           = taggedValuesNode.Attributes["value"].Value.IndexOf(nameToken) + (nameToken.Length);
                                int    i2           = taggedValuesNode.Attributes["value"].Value.IndexOf(commentToken);
                                String aux_value    = taggedValuesNode.Attributes["value"].Value.Substring(i1, i2 - commentToken.Length + 1);
                                String aux_value2   = taggedValuesNode.Attributes["value"].Value.Substring(i2 + commentToken.Length);

                                state.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value, aux_value);

                                if (!String.IsNullOrEmpty(aux_value2))
                                {
                                    state.SetTaggedValue("cycles", aux_value2);
                                }

                                foreach (XmlNode jude in node.SelectNodes("//JUDE:Diagram[@xmi.id='" + aux_value + "']//UML:ActivityGraph", nsManager))
                                {
                                    string idActivityGraph = jude.Attributes["xmi.idref"].Value;
                                    foreach (XmlNode item in node.SelectNodes("//UML:ActivityGraph[xmi.id='" + idActivityGraph + "']", nsManager))
                                    {
                                        state.SetTaggedValue("jude.hyperlink", item.Attributes["name"].Value);
                                    }
                                }
                                foreach (XmlNode item in node.SelectNodes("//JUDE:ActivityDiagram[@xmi.id='" + aux_value + "']//UML:ActivityGraph", nsManager))
                                {
                                    string idActivityGraph = item.Attributes["xmi.idref"].Value;
                                    foreach (XmlNode item1 in node.SelectNodes("//UML:ActivityGraph[@xmi.id='" + idActivityGraph + "']", nsManager))
                                    {
                                        state.SetTaggedValue("jude.hyperlink", item1.Attributes["name"].Value);
                                    }
                                }
                            }
                            #endregion
                            else
                            {
                                string tag = taggedValuesNode.Attributes["tag"].Value;
                                string var = null;
                                try
                                {
                                    var = taggedValuesNode.Attributes["value"].Value;
                                }
                                catch (Exception)
                                {
                                    state.SetTaggedValue(tag, "");
                                }
                                if (var != null)
                                {
                                    state.SetTaggedValue(tag, var);
                                }
                            }
                        }
                        #endregion

                        actDiagram.UmlObjects.Add(state);
                    }
                    #endregion
                    #region FinalState
                    foreach (XmlNode finalStateNode in node.SelectNodes("//UML:ActivityGraph[@xmi.id='" + actDiagram.Id + "']//UML:FinalState[@xmi.id]", nsManager))
                    {
                        UmlElement finalState = new UmlFinalState();
                        finalState.Name = finalStateNode.Attributes["name"].Value;
                        finalState.Id   = finalStateNode.Attributes["xmi.id"].Value;

                        #region Tagged Values
                        foreach (XmlNode taggedValuesNode in finalStateNode.SelectNodes("//UML:FinalState[@xmi.id='" + finalState.Id + "']//UML:ModelElement.taggedValue//UML:TaggedValue[@xmi.id]", nsManager))
                        {
                            //finalState.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value, HttpUtility.UrlDecode(taggedValuesNode.Attributes["value"].Value));
                            finalState.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value, taggedValuesNode.Attributes["value"].Value);
                        }
                        #endregion

                        actDiagram.UmlObjects.Add(finalState);
                    }
                    #endregion
                    #region Transition
                    //UmlTransition
                    foreach (XmlNode transitionNode in node.SelectNodes("//UML:ActivityGraph[@xmi.id='" + actDiagram.Id + "']//UML:Transition[@xmi.id]", nsManager))
                    {
                        UmlTransition transition = new UmlTransition();

                        transition.Id   = transitionNode.Attributes["xmi.id"].Value;
                        transition.Name = transitionNode.Attributes["name"].Value;
                        // Tagged Values
                        foreach (XmlNode tagValuesNode in transitionNode.SelectNodes("//UML:ActivityGraph[@xmi.id='" + actDiagram.Id + "']//UML:Transition[@xmi.id='" + transition.Id + "']//UML:TaggedValue", nsManager))
                        {
                            try
                            {
                                //transition.SetTaggedValue(tagValuesNode.Attributes["tag"].Value, HttpUtility.UrlDecode(tagValuesNode.Attributes["value"].Value));
                                transition.SetTaggedValue(tagValuesNode.Attributes["tag"].Value.ToUpper(), tagValuesNode.Attributes["value"].Value);
                            }
                            catch
                            {
                                transition.SetTaggedValue(tagValuesNode.Attributes["tag"].Value.ToUpper(), "");
                            }
                        }
                        // Transition Source
                        foreach (XmlNode transitionSource in transitionNode.SelectNodes("//UML:ActivityGraph[@xmi.id='" + actDiagram.Id + "']//UML:Transition[@xmi.id='" + transition.Id + "']//UML:Transition.source//UML:StateVertex", nsManager))
                        {
                            UmlElement element = actDiagram.GetElementById(transitionSource.Attributes["xmi.idref"].Value);
                            transition.Source = element;
                        }
                        // Transition Target
                        foreach (XmlNode transitionTarget in transitionNode.SelectNodes("//UML:ActivityGraph[@xmi.id='" + actDiagram.Id + "']//UML:Transition[@xmi.id='" + transition.Id + "']//UML:Transition.target//UML:StateVertex", nsManager))
                        {
                            UmlElement element = actDiagram.GetElementById(transitionTarget.Attributes["xmi.idref"].Value);
                            transition.Target = element;
                        }
                        actDiagram.UmlObjects.Add(transition);
                    }
                    #endregion
                    #region Lanes
                    XmlNodeList partition   = node.SelectNodes("//UML:ActivityGraph[@xmi.id='" + actDiagram.Id + "']//UML:Partition[@xmi.id]", nsManager);
                    bool        isDimension = false;

                    if (partition.Count != 0)
                    {
                        foreach (XmlNode dimensionNode in partition)
                        {
                            if (isDimension == false)
                            {
                                isDimension = true;
                                UmlLane dimension = new UmlLane();
                                dimension.Id   = dimensionNode.Attributes["xmi.id"].Value;
                                dimension.Name = dimensionNode.Attributes["name"].Value;
                                foreach (XmlNode laneNode in dimensionNode.SelectNodes("//UML:ActivityGraph[@xmi.id='" + actDiagram.Id + "']//UML:Partition[@xmi.id='" + dimension.Id + "']//JUDE:ModelElement", nsManager))
                                {
                                    XmiImporter importer = new XmiImporter();
                                    UmlLane     lane     = importer.CreateLane(dimension.Id, node, laneNode.Attributes["xmi.idref"].Value, actDiagram, nsManager);
                                    actDiagram.UmlObjects.Add(lane);
                                    actDiagram.Lanes.Add(lane);
                                    dimension.ListLane.Add(lane);
                                }
                            }
                        }
                    }
                    #endregion
                }
            }
            #endregion

            //importing usecase diagrams into model.
            XmlNodeList nodesWithUseCaseDiagrams = doc.SelectNodes("//UML:UseCase[@xmi.id]", nsManager);
            XmlNodeList nodesWithActorDiagrams   = doc.SelectNodes("//UML:Actor[@xmi.id]", nsManager);

            #region UseCase Diagrams
            //   if (nodesWithUseCaseDiagrams.Count != 0 && nodesWithActorDiagrams.Count != 0)
            {
                XmlNodeList modelElements = doc.SelectNodes("//UML:Model[@xmi.id]", nsManager);

                foreach (XmlNode node in modelElements)
                {
                    UmlUseCaseDiagram useCaseDiagram = new UmlUseCaseDiagram();
                    useCaseDiagram.Id   = node.Attributes["xmi.id"].Value;
                    useCaseDiagram.Name = node.Attributes["name"].Value;
                    model.AddDiagram(useCaseDiagram);
                    #region Actor
                    foreach (XmlNode actorNode in node.SelectNodes("//UML:Actor[@xmi.id]", nsManager))
                    {
                        UmlActor actor = new UmlActor();
                        actor.Id   = actorNode.Attributes["xmi.id"].Value;
                        actor.Name = actorNode.Attributes["name"].Value;

                        #region Tagged Values
                        foreach (XmlNode taggedValuesNode in actorNode.SelectNodes("//UML:Actor[@xmi.id='" + actor.Id + "']//UML:ModelElement.taggedValue//UML:TaggedValue[@xmi.id]", nsManager))
                        {
                            #region Hyperlink
                            if (taggedValuesNode.Attributes["tag"].Value.Equals("jude.hyperlink"))
                            {
                                string aux_value = taggedValuesNode.Attributes["value"].Value.Substring(22);
                                aux_value = aux_value.Substring(0, aux_value.Length - 23);
                                actor.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value, aux_value);
                                foreach (XmlNode jude in node.SelectNodes("//JUDE:Diagram[@xmi.id='" + aux_value + "']//UML:ActivityGraph", nsManager))
                                {
                                    string idActivityGraph = jude.Attributes["xmi.idref"].Value;
                                    foreach (XmlNode item in node.SelectNodes("//UML:ActivityGraph[xmi.id='" + idActivityGraph + "']", nsManager))
                                    {
                                        actor.SetTaggedValue("jude.hyperlink", item.Attributes["name"].Value);
                                    }
                                }
                                foreach (XmlNode item in node.SelectNodes("//JUDE:ActivityDiagram[@xmi.id='" + aux_value + "']//UML:ActivityGraph", nsManager))
                                {
                                    string idActivityGraph = item.Attributes["xmi.idref"].Value;
                                    foreach (XmlNode item1 in node.SelectNodes("//UML:ActivityGraph[@xmi.id='" + idActivityGraph + "']", nsManager))
                                    {
                                        actor.SetTaggedValue("jude.hyperlink", item1.Attributes["name"].Value);
                                    }
                                }
                            }
                            #endregion
                            else
                            {
                                try
                                {
                                    //actor.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value, HttpUtility.UrlDecode(taggedValuesNode.Attributes["value"].Value));
                                    actor.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value.ToUpper(), taggedValuesNode.Attributes["value"].Value);
                                }
                                catch
                                {
                                    actor.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value.ToUpper(), "");
                                }
                            }
                        }
                        #endregion
                        useCaseDiagram.UmlObjects.Add(actor);
                    }
                    #endregion
                    #region UseCase
                    foreach (XmlNode useCaseNode in node.SelectNodes("//UML:UseCase[@xmi.id]", nsManager))
                    {
                        UmlUseCase useCase = new UmlUseCase();
                        useCase.Id   = useCaseNode.Attributes["xmi.id"].Value;
                        useCase.Name = useCaseNode.Attributes["name"].Value;

                        #region Tagged Values
                        foreach (XmlNode taggedValuesNode in node.SelectNodes("//UML:UseCase[@xmi.id='" + useCase.Id + "']//UML:ModelElement.taggedValue//UML:TaggedValue[@xmi.id]", nsManager))
                        {
                            #region Hyperlink
                            if (taggedValuesNode.Attributes["tag"].Value.Equals("jude.hyperlink"))
                            {
                                string aux_value = taggedValuesNode.Attributes["value"].Value.Substring(22);
                                aux_value = aux_value.Substring(0, aux_value.Length - 23);
                                foreach (XmlNode jude in node.SelectNodes("//JUDE:Diagram[@xmi.id='" + aux_value + "']//UML:ActivityGraph", nsManager))
                                {
                                    string idActivityGraph = jude.Attributes["xmi.idref"].Value;
                                    foreach (XmlNode item in node.SelectNodes("//UML:ActivityGraph[xmi.id='" + idActivityGraph + "']", nsManager))
                                    {
                                        useCase.SetTaggedValue("jude.hyperlink", item.Attributes["name"].Value);
                                    }
                                }

                                foreach (XmlNode item in node.SelectNodes("//JUDE:ActivityDiagram[@xmi.id='" + aux_value + "']//UML:ActivityGraph", nsManager))
                                {
                                    string idActivityGraph = item.Attributes["xmi.idref"].Value;
                                    foreach (XmlNode item1 in node.SelectNodes("//UML:ActivityGraph[@xmi.id='" + idActivityGraph + "']", nsManager))
                                    {
                                        useCase.SetTaggedValue("jude.hyperlink", item1.Attributes["name"].Value);
                                    }
                                }
                            }
                            #endregion
                            else
                            {
                                try
                                {
                                    //useCase.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value, HttpUtility.UrlDecode(taggedValuesNode.Attributes["value"].Value));
                                    useCase.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value.ToUpper(), taggedValuesNode.Attributes["value"].Value);
                                }
                                catch
                                {
                                    useCase.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value.ToUpper(), "");
                                }
                            }
                        }
                        #endregion
                        useCaseDiagram.UmlObjects.Add(useCase);
                    }
                    #endregion
                    #region Association
                    foreach (XmlNode associationNode in node.SelectNodes("//UML:Association[@xmi.id]", nsManager))
                    {
                        UmlAssociation association = new UmlAssociation();
                        association.Id   = associationNode.Attributes["xmi.id"].Value;
                        association.Name = associationNode.Attributes["name"].Value;

                        bool putEnd1 = false;

                        foreach (XmlNode associationEndNode in associationNode.SelectNodes("//UML:Association[@xmi.id='" + association.Id + "']//UML:AssociationEnd//UML:AssociationEnd.participant//UML:Classifier[@xmi.idref]", nsManager))
                        {
                            foreach (UmlElement element in useCaseDiagram.UmlObjects.OfType <UmlElement>())
                            {
                                if (!putEnd1)
                                {
                                    if (element.Id.Equals(associationEndNode.Attributes["xmi.idref"].Value))
                                    {
                                        association.End1 = element;
                                        putEnd1          = true;
                                    }
                                }
                                else
                                {
                                    if (element.Id.Equals(associationEndNode.Attributes["xmi.idref"].Value))
                                    {
                                        association.End2 = element;
                                    }
                                }
                            }
                        }

                        #region Tagged Values
                        foreach (XmlNode taggedValuesNode in node.SelectNodes("//UML:Association[@xmi.id='" + association.Id + "']//UML:ModelElement.taggedValue//UML:TaggedValue[@xmi.id]", nsManager))
                        {
                            try
                            {
                                //association.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value, HttpUtility.UrlDecode(taggedValuesNode.Attributes["value"].Value));
                                association.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value, taggedValuesNode.Attributes["value"].Value);
                            }
                            catch
                            {
                                association.SetTaggedValue(taggedValuesNode.Attributes["tag"].Value, "");
                            }
                        }
                        #endregion
                        useCaseDiagram.UmlObjects.Add(association);
                    }

                    #endregion
                    #region Include
                    foreach (XmlNode includeNode in node.SelectNodes("//UML:Include[@xmi.id]", nsManager))
                    {
                        UmlAssociation association = new UmlAssociation();
                        association.Id   = includeNode.Attributes["xmi.id"].Value;
                        association.Name = includeNode.Attributes["name"].Value;
                        association.Stereotypes.Add("Include");

                        XmlNode begin = includeNode.SelectSingleNode("//UML:Include[@xmi.id='" + association.Id + "']//UML:Include.base//UML:UseCase[@xmi.idref]", nsManager);
                        XmlNode end   = includeNode.SelectSingleNode("//UML:Include[@xmi.id='" + association.Id + "']//UML:Include.addition//UML:UseCase[@xmi.idref]", nsManager);

                        foreach (UmlElement element in useCaseDiagram.UmlObjects.OfType <UmlElement>())
                        {
                            if (element.Id.Equals(begin.Attributes["xmi.idref"].Value))
                            {
                                association.End1 = element;
                            }
                            else if (element.Id.Equals(end.Attributes["xmi.idref"].Value))
                            {
                                association.End2 = element;
                            }
                        }
                        useCaseDiagram.UmlObjects.Add(association);
                    }
                    #endregion
                    #region Extend
                    foreach (XmlNode extendNode in node.SelectNodes("//UML:Extend[@xmi.id]", nsManager))
                    {
                        UmlAssociation association = new UmlAssociation();
                        association.Id   = extendNode.Attributes["xmi.id"].Value;
                        association.Name = extendNode.Attributes["name"].Value;
                        association.Stereotypes.Add("Extend");

                        XmlNode end   = extendNode.SelectSingleNode("//UML:Extend[@xmi.id='" + association.Id + "']//UML:Extend.base//UML:UseCase[@xmi.idref]", nsManager);
                        XmlNode begin = extendNode.SelectSingleNode("//UML:Extend[@xmi.id='" + association.Id + "']//UML:Extend.extension//UML:UseCase[@xmi.idref]", nsManager);

                        foreach (UmlElement element in useCaseDiagram.UmlObjects.OfType <UmlElement>())
                        {
                            if (element.Id.Equals(begin.Attributes["xmi.idref"].Value))
                            {
                                association.End1 = element;
                            }
                            else if (element.Id.Equals(end.Attributes["xmi.idref"].Value))
                            {
                                association.End2 = element;
                            }
                        }
                        useCaseDiagram.UmlObjects.Add(association);
                    }
                    #endregion
                }
            }
            #endregion
            return(model);
        }
Пример #10
0
        /// <summary>
        /// Converts a list of URLs into a UML Model.
        /// </summary>
        public UmlModel generateXmlFromNavigationData(List <String> lista)
        {
            List <String>      listaUrl = new List <string>();
            UmlModel           model    = new UmlModel("Activity+Diagram0");
            UmlActivityDiagram diagram  = new UmlActivityDiagram("Activity0");

            model.AddDiagram(diagram);
            UmlInitialState initial = new UmlInitialState()
            {
                Name = "Initial0"
            };
            UmlTransition transition = new UmlTransition();

            transition.End1 = initial;
            diagram.UmlObjects.Add(initial);
            diagram.UmlObjects.Add(transition);

            UmlLane lane = new UmlLane();

            for (int i = 0; i < lista.Count; i++)
            {
                String url      = Filter.iShttps(lista[i]);
                String urlParam = url;

                if (Filter.isGet(url) == true)
                {
                    transition.SetTaggedValue(new UmlTag(null, "TDmethod"), "GET");
                }

                urlParam = Filter.filtraParam(urlParam);
                url      = Filter.TDactionValue;

                transition.SetTaggedValue(new UmlTag(null, "TDaction"), url);
                string urlFilter = Filter.filtrarNome(url);
                listaUrl.Add(urlFilter);
                UmlElement element = new UmlActionState()
                {
                    Name = urlFilter + Filter.contadorUrl(listaUrl, urlFilter)
                };
                lane.Name = "Partition" + i;
                lane.Elements.Add(element);
                transition.End2 = element;

                if (!urlParam.Equals(""))
                {
                    transition.SetTaggedValue(new UmlTag(null, "TDparameter"), urlParam);
                }

                transition.SetTaggedValue(new UmlTag(null, "TDthinkTime"), "5");

                UmlTransition t = new UmlTransition();
                t.End1     = element;
                transition = t;

                diagram.UmlObjects.Add(element);
                diagram.UmlObjects.Add(t);
            }

            UmlFinalState final = new UmlFinalState()
            {
                Name = "Final0"
            };

            transition.End2 = final;
            diagram.UmlObjects.Add(final);

            diagram.UmlObjects.Add(lane);
            return(model);
        }