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); }
public static UmlModel FromLoadRunnerScript(this UmlModel model, String filepath) { filepath = "Action.c"; UmlActivityDiagram activityDiagram = new UmlActivityDiagram("ActivityDiagram"); bool blocoTransaction = false; bool blocoItemData = false; bool blocoSubtransaction = false; bool blocoSaveParameter = false; bool existsLane = false; bool createdLane = false; bool putInitial = false; bool existsThinkTime = false; int i = 0; UmlTransition transition = null; UmlInitialState initial = new UmlInitialState(); UmlFinalState final = new UmlFinalState(); UmlElement antActionState = new UmlActionState(); UmlActionState transaction = null; UmlActionState subtransaction = null; UmlLane lane = null; UmlTransition antTransition = new UmlTransition(); String auxMethod = null; String auxReferer = null; String auxBody = null; String auxUrl = null; String auxAction = null; String auxThinkTime = null; String auxSaveParam = null; String auxSaveParam2 = null; String auxCookies = null; String auxCookies2 = null; String line = null; String auxTDparameters2 = null; String[] auxSubtransaction = null; String[] allLines = File.ReadAllLines(filepath); IEnumerable <String> allLines2 = from String s in allLines where s.Trim() != String.Empty select s; allLines = allLines2.ToArray(); activityDiagram.UmlObjects.Add(initial); for (int k = 0; k < allLines.Length; k++) { line = allLines[k]; #region ThinkTime if (line.Contains("lr_think_time(")) { auxThinkTime = line.Replace("\t", "").Substring(14).Trim(); auxThinkTime = auxThinkTime.Substring(0, auxThinkTime.Length - 2); existsThinkTime = true; } #endregion if (line.Contains("lr_start_transaction(")) { if (line.Contains("lr_start_transaction(\"uc")) { activityDiagram.Name = line.Replace("\t", "").Trim().Substring(22); activityDiagram.Name = activityDiagram.Name.Substring(0, activityDiagram.Name.Length - 3); continue; } blocoTransaction = true; if (allLines[k + 1].Contains("lr_start_sub_transaction(")) { existsLane = true; continue; } } else if (line.Contains("lr_end_transaction(")) { if (line.Contains("lr_end_transaction(\"uc")) { continue; } String auxLine = line.Substring(21); auxLine = auxLine.Substring(0, auxLine.Length - 11); if (auxLine.Equals(lane.Name)) { createdLane = false; } if (!activityDiagram.Lanes.Contains(lane)) { activityDiagram.Lanes.Add(lane); } blocoTransaction = false; existsLane = false; continue; } if (blocoTransaction) { if (line.Contains("lr_start_sub_transaction(")) { blocoSubtransaction = true; } else if (line.Contains("lr_end_sub_transaction(")) { lane.AddElement(subtransaction); blocoSubtransaction = false; continue; } if (existsLane) { if (!createdLane) { lane = new UmlLane(); lane.Index = i; i++; createdLane = true; } if (blocoSubtransaction) { #region SubTransaction if (line.Contains("lr_start_sub_transaction(")) { subtransaction = new UmlActionState(); transition = new UmlTransition(); subtransaction.Name = line.Replace("\t", "").Replace("\"", "").Substring(25); auxSubtransaction = subtransaction.Name.Split(','); auxSubtransaction[0] = auxSubtransaction[0].Substring(0, auxSubtransaction[0].Length).Trim(); auxSubtransaction[1] = auxSubtransaction[1].Substring(0, auxSubtransaction[1].Length - 2).Trim(); subtransaction.Name = auxSubtransaction[0]; if (!activityDiagram.Lanes.Contains(lane)) { lane.Name = auxSubtransaction[1]; } initial.Name = "Initial0"; final.Name = "Final0"; #region PutInitial if (!putInitial) { transition.Source = initial; transition.Target = subtransaction; antActionState = transition.Target; putInitial = true; } else { transition.Source = antActionState; transition.Target = subtransaction; antActionState = transition.Target; } #endregion activityDiagram.UmlObjects.Add(subtransaction); activityDiagram.UmlObjects.Add(transition); } #endregion #region Tagged Values #region URL else if (line.Contains("URL=")) { auxUrl = Url(transition, auxUrl, line); } #endregion #region Action else if (line.Contains("Action=")) { auxAction = Action(transition, auxAction, line); } #endregion #region Referer else if (line.Contains("Referer=")) { auxReferer = Referer(transition, auxReferer, line); } #endregion #region Method else if (line.Contains("Method=")) { auxMethod = Method(transition, auxMethod, line); } #endregion #region Body else if (line.Contains("Body=")) { auxBody = Body(transition, auxBody, line); } #endregion #region Cookies if (line.Contains("web_add_cookie(")) { auxCookies = line.Replace("\t", "").Trim().Substring(16); auxCookies = auxCookies.Substring(0, auxCookies.Length - 3); auxCookies = auxCookies + "|"; auxCookies2 += auxCookies; if (!allLines[k + 1].Contains("web_add_cookie(")) { //SÓ DEVE OCORRER NO FINAL auxCookies2 = auxCookies2.Substring(0, auxCookies2.Length - 1); transition.SetTaggedValue("TDcookies", auxCookies2); } } #endregion #region ItemData else if (line.Contains("ITEMDATA")) { blocoItemData = true; continue; } else if (line.Contains("LAST);") && blocoItemData) { transition.SetTaggedValue("TDparameters", auxTDparameters2); blocoItemData = false; continue; } if (blocoItemData) { auxTDparameters2 = ItemData(line, auxTDparameters2); } #endregion #region ThinkTime if (existsThinkTime) { transition.SetTaggedValue("TDthinkTime", auxThinkTime); existsThinkTime = false; } #endregion #endregion } } else { #region Transaction if (line.Contains("lr_start_transaction(")) { transaction = new UmlActionState(); transition = new UmlTransition(); transaction.Name = line.Replace("\t", "").Trim().Substring(22); transaction.Name = transaction.Name.Substring(0, transaction.Name.Length - 3); if (!(allLines[k + 1].Contains("lr_start_sub_transaction("))) { if (lane.Name == "") { lane.AddElement(transaction); } else { lane = new UmlLane(); lane.Name = ""; lane.Index = i; i++; lane.AddElement(transaction); } } #region PutInitial if (!putInitial) { transition.Source = initial; transition.Target = transaction; antActionState = transition.Target; putInitial = true; } else { transition.Source = antActionState; transition.Target = transaction; antActionState = transition.Target; } #endregion activityDiagram.UmlObjects.Add(transaction); activityDiagram.UmlObjects.Add(transition); } #endregion #region Tagged Values #region URL else if (line.Contains("URL=")) { auxUrl = Url(transition, auxUrl, line); } #endregion #region Action else if (line.Contains("Action=")) { auxAction = Action(transition, auxAction, line); } #endregion #region Referer else if (line.Contains("Referer=")) { auxReferer = Referer(transition, auxReferer, line); } #endregion #region Method else if (line.Contains("Method=")) { auxMethod = Method(transition, auxMethod, line); } #endregion #region Body else if (line.Contains("Body=")) { auxBody = Body(transition, auxBody, line); } #endregion #region Cookies if (line.Contains("web_add_cookie(")) { auxCookies = line.Replace("\t", "").Trim().Substring(16); auxCookies = auxCookies.Substring(0, auxCookies.Length - 3); auxCookies = auxCookies + "|"; auxCookies2 += auxCookies; if (!allLines[k + 1].Contains("web_add_cookie(")) { //SÓ DEVE OCORRER NO FINAL auxCookies2 = auxCookies2.Substring(0, auxCookies2.Length - 1); transition.SetTaggedValue("TDcookies", auxCookies2); } } #endregion #region ItemData else if (line.Contains("ITEMDATA")) { blocoItemData = true; continue; } else if (line.Contains("LAST);") && blocoItemData) { transition.SetTaggedValue("TDparameters", auxTDparameters2); blocoItemData = false; continue; } if (blocoItemData) { auxTDparameters2 = ItemData(line, auxTDparameters2); } #endregion #region ThinkTime if (existsThinkTime) { transition.SetTaggedValue("TDthinkTime", auxThinkTime); existsThinkTime = false; } #endregion #endregion } } #region SaveParameters if (line.Contains("web_reg_save_param(")) { blocoSaveParameter = true; auxSaveParam = line.Replace("\t", "").Trim().Substring(20); auxSaveParam = auxSaveParam.Substring(0, auxSaveParam.Length - 1); auxSaveParam = auxSaveParam + "|"; auxSaveParam2 += auxSaveParam; } else if (line.Contains("LAST);") && blocoSaveParameter) { if (allLines[k + 1].Contains("web_reg_save_param(")) { continue; } else { //SÓ DEVE OCORRER NO FINAL auxSaveParam2 = auxSaveParam2.Substring(0, auxSaveParam2.Length - 1); transition.SetTaggedValue("TDsaveParameters", auxSaveParam2); auxSaveParam2 = null; blocoSaveParameter = false; } } #endregion } transition = new UmlTransition(); transition.Source = antActionState; transition.Target = final; activityDiagram.UmlObjects.Add(transition); activityDiagram.UmlObjects.Add(final); if (activityDiagram.Lanes.Count() > 0) { activityDiagram.Lanes[0].AddElement(initial); lane.AddElement(final); } model.AddDiagram(activityDiagram); return(model); }
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); }