// Search IRDI in files // // public static void SearchForIRDIinEclassFiles(SearchJobData a, Action <double> updateProgress) { if (a == null) { return; } if (a.eclassFiles == null || a.eclassFiles.Count < 1) { return; } if (a.searchIRDIs == null || a.searchIRDIs.Count < 1) { return; } double progressPerFile = 1.0 / a.eclassFiles.Count; // 1st pass: search all content files for IRDI // var unitIrdisToSearch = new List <string>(); for (int fileNdx = 0; fileNdx < a.eclassFiles.Count; fileNdx++) { if (a.eclassFiles[fileNdx].dft != DataFileType.Dictionary && a.eclassFiles[fileNdx].dft != DataFileType.Other) { continue; } long totalSize = 1 + new System.IO.FileInfo(a.eclassFiles[fileNdx].fn).Length; // ReSharper disable EmptyGeneralCatchClause try { using (FileStream fileSteam = File.OpenRead(a.eclassFiles[fileNdx].fn)) { var settings = new XmlReaderSettings(); settings.ConformanceLevel = ConformanceLevel.Document; int numElems = 0; using (XmlReader reader = XmlReader.Create(fileSteam, settings)) { while (reader.Read()) { if (reader.IsStartElement() && reader.Name == "ontoml:property") { // always get the XmlDocument (can either read outer xml or the same as a node) var doc = new XmlDocument(); var node = doc.ReadNode(reader); // very specific: do we have a property with a valid id? if (node.Name == "ontoml:property") { var id = GetAttributeByName(node, "id"); if (id != null && a.searchIRDIs.Contains(id.Trim().ToLower())) { var sItem = CreateSearchItemFromPropertyNode(node, "prop"); if (sItem != null) { a.items.Add(sItem); // not more than max if (a.items.Count > a.maxItems) { a.tooMany = true; break; } // check as well, if a unit is being referenced var ndu = node.SelectSingleNode("domain/unit"); if (ndu != null) { var urefIrdi = GetAttributeByName(ndu, "unit_ref"); if (urefIrdi != null) { unitIrdisToSearch.Add(urefIrdi); } } } } } numElems++; if (numElems % 500 == 0) { long currPos = fileSteam.Position; double frac = Math.Min( 100.0d * progressPerFile * (fileNdx) + (100.0d * currPos) * progressPerFile / totalSize, 100.0); if (updateProgress != null) { updateProgress(frac); } } } } } } } catch { } // ReSharper enable EmptyGeneralCatchClause } // 2st pass: search all unit files only for unit-IRDIs // for (int fileNdx = 0; fileNdx < a.eclassFiles.Count; fileNdx++) { if (a.eclassFiles[fileNdx].dft != DataFileType.Units || unitIrdisToSearch == null || unitIrdisToSearch.Count < 1) { continue; } long totalSize = 1 + new System.IO.FileInfo(a.eclassFiles[fileNdx].fn).Length; // ReSharper disable EmptyGeneralCatchClause try { using (FileStream fileSteam = File.OpenRead(a.eclassFiles[fileNdx].fn)) { var settings = new XmlReaderSettings(); settings.ConformanceLevel = ConformanceLevel.Document; int numElems = 0; using (XmlReader reader = XmlReader.Create(fileSteam, settings)) { while (reader.Read()) { if (reader.IsStartElement() && reader.Name == "unitsml:Unit") { // always get the XmlDocument (can either read outer xml or the same as a node) var doc = new XmlDocument(); var node = doc.ReadNode(reader); // prepare the outer XML var oxml = node.OuterXml.Trim().ToLower(); foreach (var uits in unitIrdisToSearch) { if (uits != null && uits != "" && oxml.Contains(uits.ToLower().Trim())) { foreach (var x in GetChildNodesByName(node, "unitsml:CodeListValue")) { var cln = GetAttributeByName(x, "codeListName"); var ucv = GetAttributeByName(x, "unitCodeValue"); if (cln == "IRDI" && ucv.ToLower().Trim() == uits.ToLower().Trim()) { // read to be added as unit var sItem = new SearchItem("unit", uits, "", node); a.items.Add(sItem); } } } } numElems++; if (numElems % 500 == 0) { long currPos = fileSteam.Position; double frac = Math.Min( 100.0d * progressPerFile * (fileNdx) + (100.0d * currPos) * progressPerFile / totalSize, 100.0); if (updateProgress != null) { updateProgress(frac); } } } } } } } catch { } // ReSharper enable EmptyGeneralCatchClause } }
public static void SearchForTextInEclassFiles(SearchJobData a, Action <double> updateProgress) { if (a == null) { return; } if (a.eclassFiles == null || a.eclassFiles.Count < 1) { return; } double progressPerFile = 1.0 / a.eclassFiles.Count; for (int fileNdx = 0; fileNdx < a.eclassFiles.Count; fileNdx++) { long totalSize = 1 + new System.IO.FileInfo(a.eclassFiles[fileNdx].fn).Length; // ReSharper disable EmptyGeneralCatchClause try { using (FileStream fileSteam = File.OpenRead(a.eclassFiles[fileNdx].fn)) { var settings = new XmlReaderSettings(); settings.ConformanceLevel = ConformanceLevel.Document; int numElems = 0; using (XmlReader reader = XmlReader.Create(fileSteam, settings)) { while (reader.Read()) { if (reader.IsStartElement()) { string searchForType = null; if (reader.Name == "ontoml:class" && a.searchInClasses) { searchForType = "cls"; a.numClass++; } if (reader.Name == "ontoml:datatype" && a.searchInDatatypes) { searchForType = "dt"; a.numDatatype++; } if (reader.Name == "ontoml:property" && a.searchInProperties) { searchForType = "prop"; a.numProperty++; } if (reader.Name == "unitsml:Unit" && a.searchInUnits) { searchForType = "unit"; a.numProperty++; } if (searchForType != null) { // always get the XmlDocument (can either read outer xml or the same as a node) var doc = new XmlDocument(); var node = doc.ReadNode(reader); // contains the text if (node.OuterXml.Trim().ToLower().Contains(a.searchText)) { var sItem = CreateSearchItemFromPropertyNode(node, searchForType); if (sItem != null) { a.items.Add(sItem); // not more than max if (a.items.Count > a.maxItems) { a.tooMany = true; break; } } } } numElems++; if (numElems % 500 == 0) { long currPos = fileSteam.Position; double frac = Math.Min( 100.0d * progressPerFile * (fileNdx) + (100.0d * currPos) * progressPerFile / totalSize, 100.0); if (updateProgress != null) { updateProgress(frac); } } } } } } } catch { } // ReSharper enable EmptyGeneralCatchClause } }