public JsonString(JsonStringType type) { this.Type = type; switch (type) { case JsonStringType.Dict: this.dict = new Dictionary <string, object>(); break; case JsonStringType.Array: this.array = new List <object>(); break; } }
public void ParseInput(string json_str, JsonStringType json_str_type) { JObject json_obj = JObject.Parse(json_str); JObject input = (JObject)json_obj["input"]; JArray nodes = (JArray)input["nodes"]; JArray links = (JArray)input["links"]; foreach (JObject node in nodes) { string id = node["id"].ToString(); int vCPU = int.Parse(node["vCPU"].ToString()); if (json_str_type == JsonStringType.Virtual) { VNG.VirtualNodeDict.Add(id, new VirtualNode(id, vCPU)); } else { PNG.PhysicalNodeDict.Add(id, new PhysicalNode(id, vCPU)); } } foreach (JObject link in links) { string id = link["id"].ToString(); string start_node = link["start_node"].ToString(); string end_node = link["end_node"].ToString(); double bandwidth = double.Parse(link["bandwidth"].ToString()); if (json_str_type == JsonStringType.Virtual) { VNG.VirtualNodeDict[start_node].AdjLinkSet.Add(new VirtualLink(id, bandwidth, start_node, end_node)); VNG.VirtualNodeDict[end_node].AdjLinkSet.Add(new VirtualLink(id, bandwidth, start_node, end_node)); } else { PNG.PhysicalNodeDict[start_node].AdjLinkSet.Add(new PhysicalLink(id, bandwidth, start_node, end_node)); PNG.PhysicalNodeDict[end_node].AdjLinkSet.Add(new PhysicalLink(id, bandwidth, start_node, end_node)); } } }