Exemple #1
0
 private void InsertNodesIntoGraph(dynamic dag, StudioGraph graph, string section)
 {
     string nodePositions = dag[section]["SerializedClientData"];
     List<string> nodes = ExtractNodesFromXml(nodePositions);
     foreach (var nodeId in nodes)
         graph.Nodes.Add(new StudioGraphNode
         {
             Id = nodeId,
             Width = 300,
             Height = 100,
             UserData = nodeId
         });
 }
Exemple #2
0
        private StudioGraph CreateStudioGraph(dynamic dag)
        {            
            StudioGraph graph = new StudioGraph();            
            InsertNodesIntoGraph(dag, graph, "Graph");            
            InsertNodesIntoGraph(dag, graph, "WebService");
            // dataset nodes are treated differently because they don't show in the EdgesInternal section.
            Dictionary<string, string> datasetNodes = new Dictionary<string, string>();
            foreach (var moduleNode in dag["Graph"]["ModuleNodes"])
            {
                string nodeId = moduleNode["Id"];
                foreach (var inputPort in moduleNode["InputPortsInternal"])
                    if (inputPort["DataSourceId"] != null && !datasetNodes.Keys.Contains(nodeId)) // this is a dataset node
                        datasetNodes.Add(nodeId, inputPort["DataSourceId"].ToString());
            }

            // normal edges
            foreach (dynamic edge in dag["Graph"]["EdgesInternal"])
            {
                string sourceOutputPort = edge["SourceOutputPortId"].ToString();
                string destInputPort = edge["DestinationInputPortId"].ToString();
                string sourceNode = (sourceOutputPort.Split(':')[0]);
                string destNode = (destInputPort.Split(':')[0]);
                graph.Edges.Add(new StudioGraphEdge
                {
                    DestinationNode = graph.Nodes.Single(n => n.Id == destNode),
                    SourceNode = graph.Nodes.Single(n => n.Id == sourceNode)
                });
            }

            // dataset edges
            foreach (string nodeId in datasetNodes.Keys)
                graph.Edges.Add(new StudioGraphEdge {
                    DestinationNode = graph.Nodes.Single(n => n.Id == nodeId),
                    SourceNode = graph.Nodes.Single(n => n.Id == datasetNodes[nodeId])
                    }
                );

            if (dag["WebService"] != null)
            {
                // web service input edges
                if (dag["WebService"]["Inputs"] != null)
                    foreach (var webSvcInput in dag["WebService"]["Inputs"])
                    {
                        if (webSvcInput["PortId"] != null)
                        {
                            string webSvcModuleId = webSvcInput["Id"].ToString();
                            string connectedModuleId = webSvcInput["PortId"].ToString().Split(':')[0];
                            graph.Edges.Add(new StudioGraphEdge
                            {
                                DestinationNode = graph.Nodes.Single(n => n.Id == connectedModuleId),
                                SourceNode = graph.Nodes.Single(n => n.Id == webSvcModuleId)
                            });                            
                        }
                    }

                // web service output edges
                if (dag["WebService"]["Outputs"] != null)
                    foreach (var webSvcOutput in dag["WebService"]["Outputs"])
                    {
                        if (webSvcOutput["PortId"] != null)
                        {
                            string webSvcModuleId = webSvcOutput["Id"].ToString();
                            string connectedModuleId = webSvcOutput["PortId"].ToString().Split(':')[0];
                            graph.Edges.Add(new StudioGraphEdge
                            {
                                DestinationNode = graph.Nodes.Single(n => n.Id == webSvcModuleId),
                                SourceNode = graph.Nodes.Single(n => n.Id == connectedModuleId)
                            });
                        }
                    }
            }            
            return graph;
        }
Exemple #3
0
        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;
        }