public static void LoopToTxt(ref Step[,] canvasMatrix, int threadCol, int indentLevel, int loopHeight, int loopWidth, out string ThreadLog, out string ThreadFunctions) { ThreadLog = ""; ThreadFunctions = ""; string indentString = new string(' ', indentLevel * 4); XmlNode iterations = canvasMatrix[0, 0].StepXmlNode.SelectSingleNode(".//*[@Key='Iterations']"); string iterationsCount, dummy; ConditionXmlToTxt.ParseCondition(iterations, out iterationsCount, out dummy, out dummy, out dummy); Step[,] threadSteps = MatrixTransformations.ResizeArray <Step>(ref canvasMatrix, 1, 0, canvasMatrix.GetLength(0) - 1, canvasMatrix.GetLength(1) - 1); string log, functions; PartialCanvasToTxt.Analyze(ref threadSteps, threadCol, 0, 0, indentLevel + 1, out log, out functions); if (canvasMatrix[0, 0].ToolName == "LoopTool") { ThreadLog = "Loop " + iterationsCount + " times"; } else if (canvasMatrix[0, 0].ToolName == "ParaLoopTool") { ThreadLog = "ParaLoop " + iterationsCount + " branches"; } else { ThreadLog = "LoopToTxt - unrecognized tool name: " + canvasMatrix[0, 0].ToolName; return; } ThreadLog += "\r\n" + indentString + "{" + "\r\n"; ThreadLog += indentString + " " + log.Trim(); ThreadLog += "\r\n" + indentString + "}"; ThreadFunctions = functions; }
public static void LockToTxt(ref Step[,] canvasMatrix, int threadCol, int indentLevel, int lockHeight, int lockWidth, out string ThreadLog, out string ThreadFunctions) { ThreadLog = ""; ThreadFunctions = ""; string indentString = new string(' ', indentLevel * 4); XmlNode expression = canvasMatrix[0, 0].StepXmlNode.SelectSingleNode(".//*[@Key='LockExpression']"); string lockString, dummy; ConditionXmlToTxt.ParseCondition(expression, out lockString, out dummy, out dummy, out dummy); XmlNode timeoutxml = canvasMatrix[0, 0].StepXmlNode.SelectSingleNode(".//*[@Key='TimeoutExpression']"); string timeout = ""; if (timeoutxml != null && timeoutxml.Name != "Null") { timeout = TextfieldToTxt.Parse(timeoutxml); } Step[,] threadSteps = MatrixTransformations.ResizeArray <Step>(ref canvasMatrix, 1, 0, canvasMatrix.GetLength(0) - 1, canvasMatrix.GetLength(1) - 1); string log, functions; PartialCanvasToTxt.Analyze(ref threadSteps, threadCol, 0, 0, indentLevel + 1, out log, out functions); ThreadLog = "lock (" + lockString + ")"; if (timeout.Length > 0) { ThreadLog += " // Timeout: " + timeout + " seconds"; } ThreadLog += "\r\n" + indentString + "{" + "\r\n"; ThreadLog += indentString + " " + log.Trim(); ThreadLog += "\r\n" + indentString + "}"; ThreadFunctions = functions; }
public static void WhileToTxt(ref Step[,] canvasMatrix, int threadCol, int indentLevel, int loopHeight, int loopWidth, out string ThreadLog, out string ThreadFunctions) { ThreadLog = ""; ThreadFunctions = ""; string indentString = new string(' ', indentLevel * 4); XmlNode conditions = canvasMatrix[0, 0].StepXmlNode.SelectSingleNode(".//BinaryExpression[@Key='Condition']/*"); string conditionString, dummy; ConditionXmlToTxt.ParseCondition(conditions, out conditionString, out dummy, out dummy, out dummy); Step[,] threadSteps = MatrixTransformations.ResizeArray <Step>(ref canvasMatrix, 1, 0, canvasMatrix.GetLength(0) - 1, canvasMatrix.GetLength(1) - 1); string log, functions; PartialCanvasToTxt.Analyze(ref threadSteps, threadCol, 0, 0, indentLevel + 1, out log, out functions); bool isDoWhile = bool.Parse(canvasMatrix[0, 0].StepXmlNode.SelectSingleNode(".//Boolean[@Key='IsDoWhile']/@Value").Value); if (isDoWhile) { ThreadLog = "do"; } else { ThreadLog = "while (" + conditionString + ")"; } ThreadLog += "\r\n" + indentString + "{" + "\r\n"; ThreadLog += indentString + " " + log.Trim(); ThreadLog += "\r\n" + indentString + "}"; if (isDoWhile) { ThreadLog += " while (" + conditionString + ")"; } ThreadFunctions = functions; }
public static void CaseToTxt(ref Step[,] canvasMatrix, int threadCol, int indentLevel, int caseHeight, int caseWidth, out string ThreadLog, out string ThreadFunctions) { ThreadLog = ""; ThreadFunctions = ""; string indentString = new string(' ', indentLevel * 4); XmlNodeList conditions = GetConditions(canvasMatrix[0, 0]); string left, right, operatorTxt; var conditionTxt = new string[conditions.Count]; int curcon = 0; foreach (XmlNode condition in conditions) { ConditionXmlToTxt.ParseCondition(condition, out conditionTxt[curcon], out left, out operatorTxt, out right); curcon++; } XmlNode col = canvasMatrix[0, 0].StepXmlNode.SelectSingleNode("List[@Key='Blocks']/StepBlock"); XmlNodeList cols = col.SelectNodes("Array[@Key='OutputConnectors']//*[@Key='Offset']/@Value"); XmlNode hasDefaultXml = canvasMatrix[0, 0].StepXmlNode.SelectSingleNode(".//*[@Key=\"HasDefaultBranch\"]"); int branches = conditions.Count; if (hasDefaultXml != null) { if (hasDefaultXml.Attributes["Value"].Value == "True") { branches++; } } else { //before the case tool could had 1 column branches++; } var logs = new string[conditions.Count + 1]; for (curcon = 0; curcon < branches; curcon++) { Step[,] threadSteps = MatrixTransformations.ResizeArray <Step>(ref canvasMatrix, 1, 0, canvasMatrix.GetLength(0) - 1, canvasMatrix.GetLength(1) - 1); string functions; int column = int.Parse(cols[curcon].Value); PartialCanvasToTxt.Analyze(ref threadSteps, column, 0, 0, indentLevel + 1, out logs[curcon], out functions); ThreadFunctions += "\r\n" + functions; } for (curcon = 0; curcon < branches; curcon++) { if (curcon == 0) { ThreadLog += "if " + conditionTxt[curcon]; } else if (curcon < logs.Length - 1) { ThreadLog += "\r\n" + indentString + "else if " + conditionTxt[curcon]; } else { ThreadLog += "\r\n" + indentString + "else"; } ThreadLog += "\r\n" + indentString + "{" + "\r\n"; ThreadLog += indentString + " " + logs[curcon].Trim(); ThreadLog += "\r\n" + indentString + "}"; } }
public static void SessionToTxt(Step step, int indentLevel, out string ThreadLog, out string ThreadFunctions) { ThreadLog = ""; ThreadFunctions = ""; XmlNodeList parameters = step.StepXmlNode.SelectNodes(".//List[@Key='StartSessionParameters']/*"); XmlNode sessionType = step.StepXmlNode.SelectSingleNode(".//*[@Key='SessionType']/@Value"); XmlNode connectAction = step.StepXmlNode.SelectSingleNode(".//*[@Key='ConnectAction']/@Value"); XmlNode sessionName = step.StepXmlNode.SelectSingleNode(".//*[@Key='SessionName']"); string sessionNameTxt = TextfieldToTxt.Parse(sessionName); string prototype = "("; prototype += "SessionName: " + sessionNameTxt + ", " + "SessionType: " + sessionType.Value + ", " + "ConnectAction: " + connectAction.Value; if (parameters.Count > 0) { prototype += ", "; foreach (XmlNode param in parameters) { string conditionTxt, dummy; ConditionXmlToTxt.ParseCondition(param, out conditionTxt, out dummy, out dummy, out dummy); prototype += conditionTxt; } } XmlNodeList connectionInfoElements = step.StepXmlNode.SelectNodes(".//*[@Key='SessionConnectionInfo']/*"); foreach (XmlNode element in connectionInfoElements) { string name = element.Attributes["Key"].Value; if (name == "NamedParameters") { if (element.ChildNodes.Count > 0) { prototype += ", NamedParameters: ["; int e = 0; foreach (XmlNode nparam in element.ChildNodes) { string value = TextfieldToTxt.Parse(nparam); prototype += value; if (e < element.ChildNodes.Count - 1) { prototype += ", "; } e++; } prototype += "]"; } } else { string value = TextfieldToTxt.Parse(element); prototype += ", " + name + ": " + value; } } prototype += ")"; ThreadLog = prototype; }
public static void CriteriaToTxt(Step step, int indentLevel, out string ThreadLog, out string ThreadFunctions) { ThreadLog = ""; ThreadFunctions = ""; XmlNodeList inputs = step.StepXmlNode.SelectNodes(".//CriteriaLogic/InputProperty"); XmlNodeList outputs = step.StepXmlNode.SelectNodes("//CriteriaLogic/OutputProperty"); string prototype = "("; for (int i = 0; i < inputs.Count; i++) { XmlNode inputxml = inputs[i].SelectSingleNode("./*[@Key='Value']"); string displayName = inputs[i].SelectSingleNode("./*[@Key='DisplayName']/@Value").Value; string input = "null"; if (inputxml.Name != "Null") { input = TextfieldToTxt.Parse(inputxml); } prototype += displayName + ": " + input; if (i < inputs.Count - 1) { prototype += ", "; } } if (inputs.Count > 0 && outputs.Count > 0) { prototype += ", "; } string[] outputNames = new string[outputs.Count]; for (int i = 0; i < outputs.Count; i++) { XmlNode outputxml = outputs[i].SelectSingleNode("./*[@Key='Value']"); string displayName = outputs[i].SelectSingleNode("./*[@Key='DisplayName']/@Value").Value; bool createVariable = bool.Parse(outputs[i].SelectSingleNode("./*[@Key='CreateVariable']/@Value").Value); bool saveResults = bool.Parse(outputs[i].SelectSingleNode("./*[@Key='SaveResults']/@Value").Value); string output = ""; if (outputxml.Name != "Null") { output = TextfieldToTxt.Parse(outputxml); } prototype += "out " + displayName; if (output.Length > 0) { prototype += ": " + output; outputNames[i] = output; } else { outputNames[i] = "{" + displayName + "}"; } if (createVariable == true) { prototype += " /*[Create Variable]*/"; } if (saveResults == true) { prototype += " /*[Save Results]*/"; } if (i < outputs.Count - 1) { prototype += ", "; } } prototype += ")"; ThreadLog = prototype; ThreadFunctions = step.StepName.Replace("_x0020_", "_") + "()"; ThreadFunctions += "\r\n{\r\n" + "/* ------ CriteriaTool ------ */" + "\r\n" + "\r\n"; XmlNodeList criterias = step.StepXmlNode.SelectNodes(".//CriteriaLogic/*[@Key='Expression']"); string assert = "Assert.IsTrue("; for (int i = 0; i < criterias.Count; i++) { string condition, dummy; ConditionXmlToTxt.ParseCondition(criterias[i], out condition, out dummy, out dummy, out dummy); ThreadFunctions += outputNames[i] + " = " + condition + "\r\n"; assert += outputNames[i]; if (i < criterias.Count - 1) { assert += " && "; } } assert += ")"; ThreadFunctions += "\r\n" + assert + "\r\n"; ThreadFunctions += "\r\n"; ThreadFunctions += "}\r\n"; }