public static void FindItemsByTag(ref RequestHandler request, OSMGeometryType typeToFind, bool pathIsContents = false) { var dispatchForType = GetDispatchForType(typeToFind); bool onlyBuildings = false; if (typeToFind == OSMGeometryType.Building) { onlyBuildings = true; } GetBounds(ref request, pathIsContents); for (var i = 0; i < request.XmlPaths.Count; i++) { var xmlPath = request.XmlPaths[i]; if (pathIsContents) { using (XmlReader reader = XmlReader.Create(new StringReader(xmlPath))) { dispatchForType(reader, ref request, i, onlyBuildings); // Only used in testing } } else { using (XmlReader reader = XmlReader.Create(xmlPath)) { dispatchForType(reader, ref request, i); } } } }
public static List <int> GetLineLengthsForFiles(List <string> xmlFilePaths, OSMGeometryType typeToFind, bool readPathAsContents = false) { if (readPathAsContents) { return(Enumerable.Repeat(1000, xmlFilePaths.Count).ToList()); // With tests we pass strings, not paths, so just return arbitrary values } var count = new List <int>(); foreach (var filePath in xmlFilePaths) { try { int linesForFile = File.ReadLines(filePath).Count(); if (typeToFind == OSMGeometryType.Node) // Assume approximately half of the amount of a file is nodes { linesForFile = Convert.ToInt32(linesForFile * 0.55, System.Globalization.CultureInfo.InvariantCulture); } count.Add(linesForFile); } catch { // Usually when file path is unreadable/reachable count.Add(-1); } } return(count); }
// Retur n correct parser for each geometry type private static DispatchDelegate GetDispatchForType(OSMGeometryType typeToFind) { DispatchDelegate dispatchForType; if (typeToFind == OSMGeometryType.Node) { dispatchForType = FindNodesInXML; } else if (typeToFind == OSMGeometryType.Way || typeToFind == OSMGeometryType.Building) { dispatchForType = FindWaysInXML; } else { dispatchForType = null; // Necessary to prevent below paths thinking variable not set } return(dispatchForType); }
public RequestHandler(List <string> providedXMLs, ParseRequest requestedMetaData, OSMGeometryType requestedType, Action <string, double> reportProgress, string workerId) { this.XmlPaths = providedXMLs; this.RequestedMetaData = requestedMetaData; // Setup data holders this.FoundItemIds = new List <string>(); this.FoundData = new Dictionary <OSMTag, List <FoundItem> >(); foreach (OSMTag metaData in requestedMetaData.Requests) { this.FoundData[metaData] = new List <FoundItem>(); } // Setup reporting infrastructure this.WorkerId = workerId; this.ReportProgress = reportProgress; if (providedXMLs[0].Length < 1000) // Don't calculate line lengths when working with tests (e.g. passed by contents not path) { this.LinesPerFile = ProgressReporting.GetLineLengthsForFiles(providedXMLs, requestedType); } }
protected static RequestHandler fetchResultsViaXMLReader(List <string> xml, ParseRequest features, OSMGeometryType typeOfFeature) { var results = new RequestHandler(xml, features, OSMGeometryType.Node, reportProgress, "Test"); ParseViaXMLReader.FindItemsByTag(ref results, typeOfFeature, true); return(results); }