예제 #1
0
        // private static UmlModelImporter java;
        /// <summary>
        /// Converts given model to an array of FiniteStateMachine.
        /// </summary>
        public static FiniteStateMachine[] TransformToFsm(UmlModel model)
        {
            model2 = new UmlModel("");
            model2 = model;
            List <FiniteStateMachine> machines       = new List <FiniteStateMachine>();
            UmlUseCaseDiagram         useCaseDiagram = model.Diagrams.OfType <UmlUseCaseDiagram>().FirstOrDefault();

            if (useCaseDiagram == null)
            {
                throw new Exception("No use case diagram found. Cannot continue.");
            }
            foreach (UmlUseCase useCase in useCaseDiagram.UmlObjects.OfType <UmlUseCase>())
            {
                UmlActivityDiagram activityDiagram = model.Diagrams
                                                     .OfType <UmlActivityDiagram>()
                                                     .Where(x => x.Name == useCase.Name)
                                                     .FirstOrDefault();

                //if (activityDiagram == null)
                //{
                //    throw new Exception("Could not find any Activity Diagram named " + useCase.Name);
                //}
                if (activityDiagram != null && ContainsInclude(useCaseDiagram, useCase) == false)
                {
                    FiniteStateMachine generatedMachine = new FiniteStateMachine(useCase.Name);
                    generatedMachine = ActivityDiagramToFsm(activityDiagram, model);
                    machines.Add(generatedMachine);
                }
            }
            return(machines.ToArray());
        }
예제 #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="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);
        }
예제 #3
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);
        }
예제 #4
0
        private void ValidateDuplicatedActivitiesRecCall(UmlActivityDiagram actDiagram, UmlModel model, List <String> listActionForSingleUseCase, UmlUseCase useCase)
        {
            List <String> repeatedActivities = new List <String>();

            foreach (UmlActionState act in actDiagram.UmlObjects.OfType <UmlActionState>())
            {
                if (!String.IsNullOrEmpty(act.GetTaggedValue("jude.hyperlink")))
                {
                    UmlActivityDiagram actDiagramSub = model.Diagrams.OfType <UmlActivityDiagram>().Where(x => x.Name.Equals(act.Name)).FirstOrDefault();
                    ValidateDuplicatedActivitiesRecCall(actDiagramSub, model, listActionForSingleUseCase, useCase);
                }
                else
                {
                    if (!(act is UmlInitialState || act is UmlFinalState))
                    {
                        if (!listActionForSingleUseCase.Contains(act.Name))
                        {
                            listActionForSingleUseCase.Add(act.Name);
                        }
                        else
                        {
                            if (!repeatedActivities.Contains(act.Name))
                            {
                                log("[ERROR] Action state { " + HttpUtility.UrlDecode(act.Name) + " } has its name duplicated. Found at { " + HttpUtility.UrlDecode(useCase.Name) + " } diagram.", 3);
                                repeatedActivities.Add(act.Name);
                            }
                        }
                    }
                }
            }
        }
예제 #5
0
 private static State getInitial(UmlActivityDiagram actDiagram, List <State> listState)
 {
     foreach (UmlInitialState initial in actDiagram.UmlObjects.OfType <UmlInitialState>())
     {
         foreach (UmlTransition tr in actDiagram.UmlObjects.OfType <UmlTransition>())
         {
             if (tr.Source.Id.Equals(initial.Id))
             {
                 if (tr.Target.GetTaggedValue("jude.hyperlink") == null)
                 {
                     return(getState(listState, tr.Target.Name));
                 }
                 else
                 {
                     UmlActivityDiagram activityDiagram = model2.Diagrams
                                                          .OfType <UmlActivityDiagram>()
                                                          .Where(x => x.Name == tr.Target.GetTaggedValue("jude.hyperlink"))
                                                          .FirstOrDefault();
                     State v = getInitial(activityDiagram, listState);
                     return(v);
                 }
             }
         }
     }
     return(null);
 }
예제 #6
0
        private static State getState(String name, UmlActivityDiagram actdiagram, List <Transition> transitions)
        {
            foreach (UmlElement act in actdiagram.UmlObjects.OfType <UmlElement>())
            {
                if (act.Name.Equals(name))
                {
                    State sSource = new State();
                    sSource.Name = act.Name;
                    sSource.Id   = act.Id;

                    foreach (Transition item in transitions)
                    {
                        if (item.SourceState.Equals(sSource.Name))
                        {
                            Transition t = new Transition();
                            t.SourceState = sSource;
                            State      sTarget = new State();
                            UmlElement element = new UmlActionState();
                            element      = getTransition(act).Target;
                            sTarget.Id   = element.Id;
                            sTarget.Name = element.Name;
                            sSource.Transitions.Add(t);
                        }
                    }
                    return(sSource);
                }
            }
            return(null);
        }
예제 #7
0
 public static UmlActionState getLaneLastState(UmlLane lane, UmlActivityDiagram activityDiagram)
 {
     foreach (UmlActionState act in lane.GetElements().OfType <UmlActionState>())
     {
         if (!(act is UmlFinalState))
         {
             foreach (UmlTransition t in activityDiagram.UmlObjects.OfType <UmlTransition>())
             {
                 if (t.Source.Id.Equals(act.Id))
                 {
                     if (t.Target is UmlFinalState)
                     {
                         return(act);
                     }
                     else if (t.Target is UmlActionState)
                     {
                         if (!((UmlActionState)t.Target).ParentLane.Equals(act.ParentLane))
                         {
                             return(act);
                         }
                     }
                 }
             }
         }
     }
     return(null);
 }
예제 #8
0
파일: Ogma.cs 프로젝트: plets-x1/plets-x1
        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);
        }
예제 #9
0
 private UmlActionState SearchActivityDiagramElement(string id, UmlActivityDiagram umlActivityDiagram)
 {
     foreach (UmlActionState act in umlActivityDiagram.UmlObjects.OfType <UmlActionState> ())
     {
         if (act.Id.Equals(id))
         {
             return(act);
         }
     }
     return(null);
 }
예제 #10
0
 private static void getRequests(UmlActivityDiagram actDiagram, List <Request> requests, UmlModel model)
 {
     foreach (UmlActionState act in actDiagram.UmlObjects.OfType <UmlActionState>())
     {
         try
         {
             if (!((act is UmlInitialState) || (act is UmlFinalState) || (act is UmlPseudoState)))
             {
                 String diagramName = act.TaggedValues["jude.hyperlink"];
                 foreach (UmlActivityDiagram actDiagram2 in model.Diagrams.OfType <UmlActivityDiagram>())
                 {
                     if (actDiagram2.Name.Equals(diagramName))
                     {
                         getRequests(actDiagram2, requests, model);
                     }
                 }
             }
         }
         catch
         {
             bool exist = false;
             foreach (var item in requests)
             {
                 if (item.Name.Equals(act.Name))
                 {
                     exist = true;
                 }
             }
             if (!exist)
             {
                 Request r = new Request();
                 r.Name        = act.Name;
                 r.Transitions = getTransitions(act, actDiagram);
                 if (r.Transitions.Count > 1)
                 {
                     foreach (Transition item in r.Transitions)
                     {
                         Request request = new Request();
                         request.Name = item.Source;
                         request.Transitions.Add(item);
                         requests.Add(request);
                     }
                 }
                 else
                 {
                     requests.Add(r);
                 }
             }
         }
     }
 }
예제 #11
0
        private void ValidateDuplicatedActivities(UmlModel model, UmlDiagram diagram)
        {
            UmlUseCaseDiagram ucDiagram = (UmlUseCaseDiagram)diagram;

            foreach (UmlUseCase useCase in ucDiagram.UmlObjects.OfType <UmlUseCase>())
            {
                UmlActivityDiagram actDiagram = model.Diagrams.OfType <UmlActivityDiagram>().Where(x => x.Name.Equals(useCase.Name)).FirstOrDefault();
                if (actDiagram != null && ContainsInclude(ucDiagram, useCase) == false)
                {
                    List <String> listActionForSingleUseCase = new List <String>();
                    ValidateDuplicatedActivitiesRecCall(actDiagram, model, listActionForSingleUseCase, useCase);
                }
            }
        }
예제 #12
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);
            }
        }
예제 #13
0
 public static UmlActionState getDiagramLastState(UmlActivityDiagram activityDiagram)
 {
     foreach (UmlActionState act in activityDiagram.UmlObjects.OfType <UmlActionState>())
     {
         foreach (UmlTransition t in activityDiagram.UmlObjects.OfType <UmlTransition>())
         {
             if (t.Target is UmlFinalState)
             {
                 return((UmlActionState)t.Source);
             }
         }
     }
     return(null);
 }
예제 #14
0
 private static void getParallelState(UmlActivityDiagram actDiagram, List <Request> requests, UmlModel model)
 {
     foreach (UmlActionState act in actDiagram.UmlObjects.OfType <UmlActionState>())
     {
         try
         {
             if (!((act is UmlInitialState) || (act is UmlFinalState)))
             {
                 String diagramName = act.TaggedValues["jude.hyperlink"];
                 foreach (UmlActivityDiagram actDiagram2 in model.Diagrams.OfType <UmlActivityDiagram>())
                 {
                     if (actDiagram2.Name.Equals(diagramName))
                     {
                         getParallelState(actDiagram2, requests, model);
                     }
                 }
             }
         }
         catch
         {
             foreach (UmlTransition t in actDiagram.UmlObjects.OfType <UmlTransition>())
             {
                 if (t.Source is UmlFork)
                 {
                     foreach (Request req in requests)
                     {
                         if (req.Name.Equals(t.Target.Name))
                         {
                             req.ParallelState = true;
                             break;
                         }
                     }
                 }
                 else if (t.Target is UmlJoin)
                 {
                     foreach (Request req in requests)
                     {
                         if (req.Name.Equals(t.Source.Name))
                         {
                             req.ParallelState = true;
                             break;
                         }
                     }
                 }
             }
         }
     }
 }
예제 #15
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.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);
        }
예제 #16
0
        private void ToOATS(XmlDocument xmiDoc)
        {
            String  toTestRegex = "{click},{setText;[data1.username]},{pressTab}";
            Boolean testedRegex = RegexTest(toTestRegex);

            UmlModel    model    = new UmlModel("");
            XmiImporter importer = new XmiImporter();
            String      name     = "";

            model = importer.FromXmi(xmiDoc, ref name);

            string[] parts = xmiDoc.BaseURI.Split(new char[] { '/' });
            string   fName = parts[parts.Length - 1];

            fName = fName.Substring(0, fName.IndexOf('.'));
            filterToActDiagOnly(ref model);
            try
            {
                foreach (UmlActivityDiagram actDiag in model.Diagrams)
                {
                    tabs = 0;
                    UmlToGraphOATS umlToGraphOATS = new UmlToGraphOATS();
                    //sw = new StreamWriter(Configuration.getInstance().getConfiguration(Configuration.Fields.workspacepath) + fname + "_OATS.java");
                    //sw = new StreamWriter(Configuration.getInstance().getConfiguration(Configuration.Fields.workspacepath) + actDiag.Name + "_OATS.java");
                    sw = new StreamWriter(".//TestOutput//script.java");

                    dg = umlToGraphOATS.ActivityDiagramToGraph(actDiag, model);
                    OrderEdges(dg);
                    OrderActDiagramTransitions(actDiag);
                    currState  = dg.RootNode;
                    curActDiag = actDiag;
                    S();
                    sw.Close();
                    // break;
                }
            }
            catch (Exception e)
            {
                String message = e.Message;
                if (sw != null)
                {
                    sw.Close();
                }
                throw;
            }
        }
예제 #17
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);
            }
        }
예제 #18
0
 private static UmlTransition getNextState(String act, UmlActivityDiagram actDiagram)
 {
     foreach (UmlTransition transition in actDiagram.UmlObjects.OfType <UmlTransition>())
     {
         if (transition.Source.Name.Equals(act))
         {
             foreach (UmlTransition tran in actDiagram.UmlObjects.OfType <UmlTransition>())
             {
                 if (transition.Target.Id.Equals(tran.Source.Id))
                 {
                     return(tran);
                 }
             }
         }
     }
     return(null);
 }
예제 #19
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();
            }
        }
예제 #20
0
        private static List <Transition> getTransitions(UmlActionState act, UmlActivityDiagram actDiagram)
        {
            List <Transition> list = new List <Transition>();

            foreach (UmlTransition t in actDiagram.UmlObjects.OfType <UmlTransition>())
            {
                if (t.Source.Id.Equals(act.Id))
                {
                    if (t.Source is UmlActionState && t.Target is UmlFork)
                    {
                        list.AddRange(parallelTransitions(t, actDiagram));
                    }
                    else if (t.Source is UmlActionState && t.Target is UmlActionState)
                    {
                        if (!(t.Source is UmlPseudoState))
                        {
                            Transition transition = new Transition();
                            transition.Action = t.GetTaggedValue("TDACTION");
                            transition.Body   = t.GetTaggedValue("TDBODY");
                            if (t.GetTaggedValue("TDCOOKIES") != null)
                            {
                                transition.Cookies = getCookies(t.GetTaggedValue("TDTDCOOKIES"));
                            }
                            transition.EstimatedTime = Convert.ToDouble(t.GetTaggedValue("TDEXPTIME"));
                            transition.Method        = t.GetTaggedValue("TDMETHOD");
                            if (t.GetTaggedValue("TDPARAMETERS") != null)
                            {
                                transition.Parameters = getParameters(t.GetTaggedValue("TDTDPARAMETERS"));
                            }
                            transition.Referer = t.GetTaggedValue("TDREFERER");
                            if (t.GetTaggedValue("TDSAVEPARAMETERS") != null)
                            {
                                transition.SaveParameters = getSaveParameters(t.GetTaggedValue("TDSAVEPARAMETERS"));
                            }
                            transition.ThinkTime = Convert.ToDouble(t.GetTaggedValue("TDTHINKTIME"));
                            transition.Source    = t.Source.Name;
                            transition.Target    = t.Target.Name;
                            list.Add(transition);
                        }
                    }
                }
            }
            return(list);
        }
예제 #21
0
        public void ParseXmiToOATS(string XmiPath, string OATSPath)
        {
            UmlModel    model  = new UmlModel("");
            XmlDocument xmiDoc = new XmlDocument();

            xmiDoc.Load(XmiPath);
            XmiImporter importer = new XmiImporter();
            String      name     = "";

            model = importer.FromXmi(xmiDoc, ref name);


            if (model.Diagrams.Count(X => X is UmlActivityDiagram) > 1)
            {
                throw new Exception("Only one Activity diagram allowed! (For now)");
            }
            try
            {
                UmlToFsm umlToFsm = new UmlToFsm();
                foreach (UmlActivityDiagram actDiag in model.Diagrams)
                {
                    tabs = 0;
                    sw   = new StreamWriter(OATSPath + "\\script.java");
                    fsm  = umlToFsm.ActivityDiagramToFsm(actDiag, model);
                    //fsm.
                    currState  = fsm.InitialState;
                    curActDiag = actDiag;
                    S();
                    sw.Close();
                    break;//only one
                }
            }
            catch (Exception ex)
            {
                if (sw != null)
                {
                    sw.Close();
                }
                throw ex;
            }
        }
예제 #22
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);
        }
예제 #23
0
        public DirectedGraph[] TransformToGraph(UmlModel model)
        {
            List <DirectedGraph> graphs         = new List <DirectedGraph> ();
            UmlUseCaseDiagram    useCaseDiagram = model.Diagrams.OfType <UmlUseCaseDiagram> ().FirstOrDefault();

            if (useCaseDiagram == null)
            {
                throw new Exception("No use case diagram found. Cannot continue.");
            }
            foreach (UmlUseCase useCase in useCaseDiagram.UmlObjects.OfType <UmlUseCase> ())
            {
                String             aux             = useCase.GetTaggedValue("jude.hyperlink");
                UmlActivityDiagram activityDiagram = null;

                if (aux != null)
                {
                    activityDiagram = model.Diagrams
                                      .OfType <UmlActivityDiagram> ()
                                      .Where(x => x.Name == aux)
                                      .FirstOrDefault();
                }
                else
                {
                    activityDiagram = model.Diagrams
                                      .OfType <UmlActivityDiagram> ()
                                      .Where(x => x.Name == useCase.Name)
                                      .FirstOrDefault();
                }
                if (activityDiagram != null && ContainsInclude(useCaseDiagram, useCase) == false)
                {
                    DirectedGraph graph = new DirectedGraph();
                    graph = ActivityDiagramToGraph(activityDiagram, model);
                    GetUseCaseTaggedValues(useCase, graph);
                    //graph.NameUseCase = useCaseDiagram.Name;
                    graphs.Add(graph);
                }
            }
            return(graphs.ToArray());
        }
        private Boolean HasCircularReference(Stack <UmlActivityDiagram> visitedDiagrams, UmlModel model, UmlActivityDiagram actDiagram)
        {
            listLog = new List <string> ();
            foreach (UmlActionState state in visitedDiagrams.Peek().UmlObjects.OfType <UmlActionState> ())
            {
                if (state.GetTaggedValue("jude.hyperlink") == null)
                {
                    continue;
                }

                UmlActivityDiagram referenced = model.Diagrams.Where(x => x is UmlActivityDiagram && x.Name.Equals(state.GetTaggedValue("jude.hyperlink"))).FirstOrDefault() as UmlActivityDiagram;

                if (referenced == null)
                {
                    continue;
                }

                if (visitedDiagrams.Contains(referenced))
                {
                    string temp = "[ERROR] Circular reference found at {" + referenced.Name + "}.";
                    if (!listLog.Contains(temp))
                    {
                        listLog.Add(temp);
                    }
                    return(true);
                }

                visitedDiagrams.Push(referenced);

                if (HasCircularReference(visitedDiagrams, model, referenced))
                {
                    return(true);
                }
                visitedDiagrams.Pop();
            }

            return(false);
        }
예제 #25
0
        public UmlLane CreateLane(String idDimension, XmlNode node, String id, UmlActivityDiagram actDiagram, XmlNamespaceManager nsManager)
        {
            UmlLane lane = new UmlLane();

            foreach (XmlNode element in node.SelectNodes("//UML:Partition[@xmi.id='" + id + "']", nsManager))
            {
                String aux_lane_name = element.Attributes["name"].Value;
                lane.Id = element.Attributes["xmi.id"].Value;
                if (aux_lane_name.Contains("+"))
                {
                    aux_lane_name = aux_lane_name.Replace("+", "");
                    if (aux_lane_name.Equals(""))
                    {
                        lane.Name = "";
                    }
                    else
                    {
                        lane.Name = element.Attributes["name"].Value;
                    }
                }
                else
                {
                    lane.Name = element.Attributes["name"].Value;
                }

                if (!idDimension.Equals(lane.Id))
                {
                    foreach (XmlNode modelElementNode in element.SelectNodes("//UML:Partition[@xmi.id='" + lane.Id + "']//JUDE:ModelElement", nsManager))
                    {
                        if (actDiagram.GetElementById(modelElementNode.Attributes["xmi.idref"].Value) != null)
                        {
                            lane.AddElement(actDiagram.GetElementById(modelElementNode.Attributes["xmi.idref"].Value));
                        }
                    }
                }
            }
            return(lane);
        }
예제 #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);
        }
예제 #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);
        }
예제 #28
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 List <UmlTransition> GetTransitionsOfDiagram(UmlModel model, ref UmlTransition t, hyperLinkType tp)
        {
            List <UmlTransition> subTransitions;
            UmlElement           s;
            String hyperlink = "";
            int    c         = 0;

            if (tp == hyperLinkType.Source)
            {
                if (t.Source.TaggedValues.ContainsKey("cycles"))
                {
                    c = Convert.ToInt32(t.Source.GetTaggedValue("cycles"));
                }
                hyperlink = t.Source.TaggedValues["jude.hyperlink"];
            }
            else
            {
                if (t.Target.TaggedValues.ContainsKey("cycles"))
                {
                    c = Convert.ToInt32(t.Target.GetTaggedValue("cycles"));
                }
                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();
            }

            UmlTransition initialT = subTransitions.SingleOrDefault(x => x.Source is UmlInitialState);

            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;
            }

            #region cycles

            List <UmlTransition> hyperlinkTrans2 = new List <UmlTransition> ();
            if (c > 1)
            {
                List <UmlTransition> temp            = subTransitions;
                UmlElement           firstFirstState = null;
                UmlElement           prevLastState   = null;
                UmlElement           lastSate        = null;
                UmlTransition        lastTran        = null;
                for (int i = 0; i < c; i++)
                {
                    UmlElement currFirstState = null;
                    foreach (UmlTransition trans in temp)
                    {
                        UmlTransition cycleTran = new UmlTransition();
                        UmlElement    src       = (UmlElement)Activator.CreateInstance(trans.Source.GetType());
                        UmlElement    targ      = (UmlElement)Activator.CreateInstance(trans.Target.GetType());
                        if (i != 0)
                        {
                            src.Name  = trans.Source.Name + "_" + i;
                            targ.Name = trans.Target.Name + "_" + i;
                        }
                        else
                        {
                            src.Name  = trans.Source.Name;
                            targ.Name = trans.Target.Name;
                        }
                        src.Id = trans.Source.Id;
                        //src.Id = Guid.NewGuid().ToString();
                        //targ.Name = trans.Target.Name + "_" + i;
                        targ.Id = trans.Target.Id;
                        //targ.Id = Guid.NewGuid().ToString();
                        foreach (KeyValuePair <String, String> tag in trans.TaggedValues)
                        {
                            cycleTran.SetTaggedValue(tag.Key, tag.Value + "$@#ITERATION@#" + i);
                        }
                        cycleTran.SetTaggedValue("TDCYCLETRAN", "true");
                        cycleTran.Source = src;
                        cycleTran.Target = targ;
                        hyperlinkTrans2.Add(cycleTran);
                        lastTran = cycleTran;
                        if (currFirstState == null)
                        {
                            currFirstState = src;
                        }
                        lastSate = targ;
                    }
                    if (prevLastState != null)
                    {
                        UmlTransition cycleTran = new UmlTransition();
                        if (initialT != null)
                        {
                            foreach (KeyValuePair <String, String> tag in initialT.TaggedValues)
                            {
                                // cycleTran.SetTaggedValue(tag.Key, tag.Value + ". Iteration " + i);
                                cycleTran.SetTaggedValue(tag.Key, tag.Value + "$@#ITERATION@#" + i);
                            }
                            cycleTran.SetTaggedValue("TDCYCLETRAN", "true");
                            cycleTran.SetTaggedValue("TDLASTCYCLETRANS", "true");
                        }

                        cycleTran.Source = prevLastState;
                        cycleTran.Target = currFirstState;
                        if (cycleTran.TaggedValues.Count > 0)
                        {
                            hyperlinkTrans2.Add(cycleTran);
                            lastTran = cycleTran;
                        }
                    }
                    if (currFirstState != null)
                    {
                        if (firstFirstState == null)
                        {
                            firstFirstState = currFirstState;
                        }
                    }
                    prevLastState = lastSate;
                }

                if (tp == hyperLinkType.Source)
                {
                    t.Source = lastSate;
                    t.SetTaggedValue("TDLASTCYCLETRANS", "true");
                }
                else
                {
                    t.Target = firstFirstState;
                }
                t.SetTaggedValue("TDCYCLETRAN", "true");
                subTransitions = hyperlinkTrans2;
            }
            #endregion

            return(subTransitions);
        }
예제 #29
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);
        }
예제 #30
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);
        }