public RoadNode(int id, RoadNodeRole role, RoadNodeState state) { _id = id; _state = state; _role = role; _links = new List <RoadLink>(); }
public RoadNode(int id, RoadNodeRole role, RoadNodeState state) { _id = id; _state = state; _role = role; _links = new List<RoadLink>(); }
/// <summary> /// Parse source road map XML document /// </summary> /// <param name="sourceXml">road map XML document</param> /// <returns>parsed RoadMap object</returns> public static RoadMap ParseRoadMapXml(XmlDocument sourceXml) { if (sourceXml == null) { return(null); } RoadMap roadMap = new RoadMap(); if (ValidateSchema(sourceXml)) { XmlNode graph = sourceXml.SelectNodes("/graph").Item(0); XmlNodeList nodes = graph.SelectNodes("node"); foreach (XmlNode node in nodes) { RoadNodeRole nodeRole = RoadNodeRole.Normal; if (node.Attributes["role"] != null && node.Attributes["role"].Value == "start") { nodeRole = RoadNodeRole.Start; } else if (node.Attributes["role"] != null && node.Attributes["role"].Value == "finish") { nodeRole = RoadNodeRole.Finish; } RoadNodeState nodeState = RoadNodeState.Ok; if (node.Attributes["status"] != null && node.Attributes["status"].Value == "crash") { nodeState = RoadNodeState.Crash; } int nodeId = Convert.ToInt32(node.Attributes["id"].Value); RoadNode roadNode = new RoadNode(nodeId, nodeRole, nodeState); XmlNodeList links = node.SelectNodes("link"); foreach (XmlNode link in links) { int linkRef = Convert.ToInt32(link.Attributes["ref"].Value); int linkWeight = Convert.ToInt32(link.Attributes["weight"].Value); RoadLink roadLink = new RoadLink(linkWeight, linkRef); roadNode.Links.Add(roadLink); } roadMap.Nodes.Add(roadNode); } } return(roadMap); }