public string UpdateNodesPositions(string jsonGraph, StudioGraph graph)
{
dynamic experimentDag = jss.Deserialize<object>(jsonGraph);
List<string> regularNodes = ExtractNodesFromXml(experimentDag["Graph"]["SerializedClientData"]);
List<string> webServiceNodes = ExtractNodesFromXml(experimentDag["WebService"]["SerializedClientData"]);
StringBuilder newPositions = new StringBuilder();
if (regularNodes.Count > 0)
{
foreach (var node in graph.Nodes.Where(n => regularNodes.Contains(n.Id)))
newPositions.Append("<NodePosition Node='" + node.Id + "' Position='" + node.CenterX + "," + node.CenterY + "," + node.Width + "," + node.Height + "'/>");
string oldPositions = Regex.Match(experimentDag["Graph"]["SerializedClientData"].ToString(), "<NodePositions>(.*)</NodePositions>").Groups[1].Value;
jsonGraph = jsonGraph.Replace(oldPositions, newPositions.ToString());
}
if (webServiceNodes.Count > 0)
{
newPositions.Clear();
foreach (var node in graph.Nodes.Where(n => webServiceNodes.Contains(n.Id)))
newPositions.Append("<NodePosition Node='" + node.Id + "' Position='" + node.CenterX + "," + node.CenterY + "," + node.Width + "," + node.Height + "'/>");
string oldPositions = Regex.Match(experimentDag["WebService"]["SerializedClientData"].ToString(), "<NodePositions>(.*)</NodePositions>").Groups[1].Value;
jsonGraph = jsonGraph.Replace(oldPositions, newPositions.ToString());
}
return jsonGraph;
}