private void LoadAllFromXmlFileToList(string filePath, ref EdgePipeList edgePipes) { XDocument doc = XDocument.Load(filePath); var edgePipesNode = from eP in doc.Descendants(EDGE_PIPE_ELEM) select eP; foreach (XElement edgePipeNode in edgePipesNode) { int edgePipeId = Int32.Parse(edgePipeNode.Element(ID_ELEM).Value); var edgeRoadsNode = from eR in edgePipeNode.Descendants(EDGE_ROAD_ELEM) select eR; AddEdgePipe(edgePipeId, ref edgePipes); foreach (XElement edgeRoadNode in edgeRoadsNode) { int edgeRoadId = Int32.Parse(edgeRoadNode.Element(ID_ELEM).Value); AddEdgeRoad(edgePipeId, edgeRoadId, Int32.Parse(edgeRoadNode.Element(WIDTH_ELEM).Value), Int32.Parse(edgeRoadNode.Element(FROM_X_ELEM).Value), Int32.Parse(edgeRoadNode.Element(FROM_Y_ELEM).Value), Int32.Parse(edgeRoadNode.Element(TO_X_ELEM).Value), Int32.Parse(edgeRoadNode.Element(TO_Y_ELEM).Value), ref edgePipes); } } }
private void LoadAllFromXmlFileToList(string filePath, EdgePipeList edgePipes, ref IntersectionList intersectionList) { XDocument doc = XDocument.Load(filePath); var intersectionsNode = from i in doc.Descendants(INTERSECTIONS_ELEM) select i; foreach (XElement intersectionNode in intersectionsNode) { int intersectionId = Int32.Parse(intersectionNode.Element(ID_ELEM).Value); var pipesNode = from p in intersectionNode.Descendants(PIPES_ELEM) select p; intersectionList.Add(new Intersection(intersectionId)); Console.WriteLine(pipesNode.ToString()); foreach (XElement pipeNode in pipesNode) { Console.WriteLine(pipeNode.ToString()); int pipeId = Int32.Parse(pipeNode.Element(ID_ELEM).Value); string type = pipeNode.Element(TYPE_ELEM).Value.ToString(); var roads = (from ep in edgePipes select ep.Edges).SelectMany(e => e); intersectionList[intersectionId].AddPipe(roads.FirstOrDefault(r => r.ID == pipeId), stringToIntersectionType(type)); } } }
public EdgePipeList GetAllFromFile(string filePath) { EdgePipeList edgePipes = new EdgePipeList(); LoadAllFromXmlFileToList(filePath, ref edgePipes); return(edgePipes); }
public IntersectionList GetAllFromFile(string filePath, EdgePipeList edgePipes) { IntersectionList intersectionList = new IntersectionList(); LoadAllFromXmlFileToList(filePath, edgePipes, ref intersectionList); return(intersectionList); }
private void AddEdgePipe(int id, ref EdgePipeList edgePipes) { edgePipes.Add(new EdgePipe(id)); }
private void AddEdgeRoad(int edgePipeID, int edgeRoadID, int width, int fromX, int fromY, int toX, int toY, ref EdgePipeList edgePipes) { if (edgePipes.ElementAt(edgePipeID) == null) { return; } var ers = edgePipes.SelectMany(ep => ep.Edges); var fer = ers.FirstOrDefault(er => (er.From.X == fromX && er.To.X == toX) && (er.From.Y == fromY && er.To.Y == toY)); if (ers.Any(er => (er.From.X == fromX && er.To.X == toX) && (er.From.Y == fromY && er.To.Y == toY))) { Console.WriteLine("New ID: " + edgeRoadID + " fromX: " + fromX + " toX: " + toX + " fromY: " + fromY + " toY: " + toY); throw new Exception("Edge already exists ID: " + fer.ID + " fromX: " + fer.From.X + " toX: " + fer.To.X + " fromY: " + fer.From.Y + " toY: " + fer.To.Y); } edgePipes[edgePipeID].AddEdgeRoad(edgeRoadID, width, fromX, fromY, toX, toY); }