private Boolean GetNewTransition(UmlModel model, List <UmlTransition> list, Transition t, Boolean contem) { UmlTransition tranSource = GetUmlTransition(t.SourceState, model, true); UmlTransition tranTarget = GetUmlTransition(t.TargetState, model, false); UmlTransition newTransition = new UmlTransition(); newTransition.Source = tranSource.Source; newTransition.Target = tranTarget.Target; newTransition.Id = tranSource.Id; foreach (KeyValuePair <String, String> pair in tranTarget.TaggedValues) { newTransition.SetTaggedValue(pair.Key, pair.Value); } if (t.CycleTransition) { newTransition.SetTaggedValue("TDcycleTran", "true"); } if (t.EndCycle) { newTransition.SetTaggedValue("TDlastCycleTrans", "true"); } list.Add(newTransition); contem = true; return(contem); }
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); }
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); } }
private static String Method(UmlTransition transition, String auxMethod, String line) { auxMethod = line.Replace("\t", "").Trim().Substring(8); auxMethod = auxMethod.Substring(0, auxMethod.Length - 2); transition.SetTaggedValue("TDmethod", auxMethod); return(auxMethod); }
private static String Url(UmlTransition transition, String auxUrl, String line) { auxUrl = line.Replace("\t", "").Trim().Substring(5); auxUrl = auxUrl.Substring(0, auxUrl.Length - 2); if (auxUrl.Contains("_")) { auxUrl = auxUrl.Replace("_", "."); } transition.SetTaggedValue("TDACTION", auxUrl); return(auxUrl); }
private static String Action(UmlTransition transition, String auxAction, String line) { auxAction = line.Replace("\t", "").Trim().Substring(8); auxAction = auxAction.Substring(0, auxAction.Length - 2); if (auxAction.Contains("_")) { auxAction = auxAction.Replace("_", "."); } transition.SetTaggedValue("TDACTION", auxAction); return(auxAction); }
private static String Body(UmlTransition transition, String auxBody, String line) { auxBody = line.Replace("\t", "").Trim().Substring(6); auxBody = auxBody.Substring(0, auxBody.Length - 2); if (auxBody.Contains("|")) { auxBody = auxBody.Replace("|", @"\"); } transition.SetTaggedValue("TDbody", auxBody); return(auxBody); }
private UmlTransition GetUmlTransition(UmlModel model, Transition t) { UmlTransition tranSource = GetUmlTransition(t.SourceState, model, true); UmlTransition tranTarget = GetUmlTransition(t.TargetState, model, false); UmlTransition newTransition = new UmlTransition(); newTransition.Source = tranSource.Source; newTransition.Target = tranTarget.Target; newTransition.Id = tranSource.Id; foreach (KeyValuePair <String, String> pair in tranTarget.TaggedValues) { newTransition.SetTaggedValue(pair.Key, pair.Value); } if (t.CycleTransition) { newTransition.SetTaggedValue("TDcycleTran", "true"); } if (t.EndCycle) { newTransition.SetTaggedValue("TDlastCycleTrans", "true"); } return(newTransition); }
private static String Referer(UmlTransition transition, String auxReferer, String line) { auxReferer = line.Replace("\t", "").Trim().Substring(9); auxReferer = auxReferer.Substring(0, auxReferer.Length - 2); if (auxReferer.Length > 0) { if (auxReferer.Contains("_")) { auxReferer = auxReferer.Replace("_", "."); } transition.SetTaggedValue("TDreferer", auxReferer); } return(auxReferer); }
/// <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); }
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 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); }
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); }
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); }
/// <summary> /// /// </summary> /// <param name="node"></param> /// <returns></returns> public string parse(GroupNode node) { string scrpt = ""; try { if (node != null) { tabHelper.incrementTabs(); bool containsDtBnk = false; bool containsCondition = false; int iterations = 0; string dataBank = ""; string loopCondition = ""; string stepScrpt = buildStep(node.GroupName); foreach (UmlTransition transition in node.Transitions) { /* * 1 - buildStep() * 2 - buildDataBank() * 3 - buildLoop() * 4 - verifyObject() * 5 - buildObjScript() * 6 - addThink() */ Dictionary <TagNames, string> tags = extractTransitionTags(transition); try { if (string.IsNullOrEmpty(loopCondition)) { loopCondition = tags[TagNames.TDLoopCondition]; containsCondition = !string.IsNullOrEmpty(loopCondition); } if (iterations == 0) { iterations = Convert.ToInt32(tags[TagNames.TDIterations]); } if (!containsDtBnk) { string actions_Assert = tags[TagNames.TDAction] + ",{;" + tags[TagNames.TDAssert] + "}"; extractDataBanks(actions_Assert).ForEach(S => dataBank += S); containsDtBnk = !string.IsNullOrEmpty(dataBank); } } catch (FormatException e) { } catch (Exception e) { } //realiza a construcao do script para as tags desta transicao scrpt += parse(tags); } //subgrupos string subScrpt = ""; string cond = ""; for (int j = 0; j < node.SubGroups.Count; j++) { GroupNode sub = node.SubGroups[j]; //caso a primeira transicao seja loopcond, remove UmlTransition transition = null; if (j == 0 && sub.Transitions.Count > 0) { transition = node.SubGroups[0].Transitions[0]; cond = transition.GetTaggedValue("TDLOOPCONDITION"); transition.SetTaggedValue("TDLOOPCONDITION", ""); } subScrpt += parse(sub); if (!string.IsNullOrEmpty(cond) && transition != null) { transition.SetTaggedValue("TDLOOPCONDITION", cond); } } //caso tenha subgrupos e tenha loop na primeira transicao if (node.SubGroups.Count > 0) { try { UmlTransition transition = node.SubGroups[0].Transitions[0]; Dictionary <TagNames, string> tags = extractTransitionTags(transition); string loopCond = ""; try { loopCond = tags[TagNames.TDLoopCondition]; } catch (Exception e) { } //caso tenha condicao para o loop, adiciona no while o subscript if (!string.IsNullOrEmpty(loopCond)) { subScrpt = buildWhile(loopCond, subScrpt); } } catch (Exception e) { } } scrpt += subScrpt; //verifica entre estas transicoes se deve adicionar um loop... if (iterations > 0) { scrpt = buildFor(iterations, scrpt); } //caso tenha que adicionar as transicoes no databank if (containsDtBnk) { scrpt = dataBank + scrpt; } //step's loop if (containsCondition) { scrpt = buildWhile(loopCondition, scrpt); } scrpt = string.Format(stepScrpt, scrpt); } } catch (Exception e) { scrpt = ""; } finally { tabHelper.decrementTabs(); } return(scrpt); }
/// <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); }