Esempio n. 1
0
 public static ResponseJson.EdgeData getEdgeJsonData(NetworkContainersNS.Edge edge)
 {
     return(new ResponseJson.EdgeData {
         consistency = GraphUtils.getEdgeConsistencyString(edge.consistency),
         sourceVertexId = edge.sourceVertexId,
         sourcePortId = edge.sourcePortId,
         targetVertexId = edge.targetVertexId,
         targetPortId = edge.targetPortId
     });
 }
Esempio n. 2
0
 public static List <string> getUniqueEdgeIds(
     NetworkContainersNS.Graph graph,
     int count
     )
 {
     return(GraphUtils.getUniqueIds(
                (string id) => {
         return graph.edges.ContainsKey(id);
     },
                count
                ));
 }
Esempio n. 3
0
        public static ResponseJson.GraphData getResponseJsonData(NetworkContainersNS.Graph graph)
        {
            ResponseJson.GraphData responseJsonData = new ResponseJson.GraphData {
                vertices = new Dictionary <string, ResponseJson.VertexData>(),
                edges    = new Dictionary <string, ResponseJson.EdgeData>()
            };

            foreach (KeyValuePair <string, NetworkContainersNS.Vertex> vtxEntry in graph.vertices)
            {
                responseJsonData.vertices[vtxEntry.Key] = GraphUtils.getVertexJsonData(vtxEntry.Value);
            }

            foreach (KeyValuePair <string, NetworkContainersNS.Edge> edgeEntry in graph.edges)
            {
                responseJsonData.edges[edgeEntry.Key] = GraphUtils.getEdgeJsonData(edgeEntry.Value);
            }

            return(responseJsonData);
        }
Esempio n. 4
0
        public static void deleteVertex(
            NetworkContainersNS.Graph graph,
            Dictionary <string, ModelClassNS.VertexEdgesInfo> edgesByVertex,
            string vertexId
            )
        {
            if (!graph.vertices.ContainsKey(vertexId))
            {
                throw new System.Exception("Vertex with given id does not exist");
            }

            // Use ToList because C# won't allow the edges by vertex collection to be modified while it is being iterated over
            foreach (string edgeId in edgesByVertex[vertexId].edgesIn.Union(edgesByVertex[vertexId].edgesOut).ToList())
            {
                GraphUtils.deleteEdge(graph, edgesByVertex, edgeId);
            }

            graph.vertices.Remove(vertexId);
            edgesByVertex.Remove(vertexId);
        }
Esempio n. 5
0
        private static ResponseJson.VertexData getVertexJsonData(NetworkContainersNS.Vertex vtx)
        {
            ResponseJson.VertexData jsonVtxData = new ResponseJson.VertexData {
                label = vtx.label,
                geo   = new ResponseJson.GeoData {
                    x = vtx.xLocation,
                    y = vtx.yLocation,
                },
                ports = new Dictionary <string, ResponseJson.GraphPortData>()
            };

            foreach (KeyValuePair <string, NetworkContainersNS.NetworkPort> edgeEntry in vtx.ports)
            {
                jsonVtxData.ports[edgeEntry.Key] = new ResponseJson.GraphPortData {
                    side     = GraphUtils.getPortSideString(edgeEntry.Value.side),
                    position = edgeEntry.Value.position,
                    portType = GraphUtils.getPortTypeString(edgeEntry.Value.type)
                };
            }

            return(jsonVtxData);
        }
Esempio n. 6
0
        public static void createEdge(
            NetworkContainersNS.Graph graph,
            Dictionary <string, ModelClassNS.VertexEdgesInfo> edgesByVertex,
            string newEdgeId,
            string sourceVertexId,
            string sourcePortId,
            string targetVertexId,
            string targetPortId
            )
        {
            // nullable
            string validated = GraphUtils.validateEdge(
                graph,
                edgesByVertex,
                newEdgeId,
                sourceVertexId,
                sourcePortId,
                targetVertexId,
                targetPortId
                );

            if (validated != null)
            {
                throw new System.Exception(validated);
            }

            graph.edges[newEdgeId] = new NetworkContainersNS.Edge {
                consistency    = NetworkContainersNS.ConsistencyType.Consistent,
                sourceVertexId = sourceVertexId,
                sourcePortId   = sourcePortId,
                targetVertexId = targetVertexId,
                targetPortId   = targetPortId,
            };

            edgesByVertex[sourceVertexId].edgesOut.Add(newEdgeId);
            edgesByVertex[targetVertexId].edgesIn.Add(newEdgeId);
        }