private static void CheckContent(CheckInfo c, BcfSource source, string version, List <string> contents, string filter) { var markupFiles = source.GetLocalNames(filter); foreach (var markupFile in markupFiles) { var locP = Path.GetDirectoryName(markupFile); var validatingFile = c.CleanName(new FileInfo(Path.Combine(source.FullName, markupFile))); var docNav = new XPathDocument(source.GetStream(markupFile)); var nav = docNav.CreateNavigator(); foreach (var content in contents) { var iterator1 = nav.Select(content); while (iterator1.MoveNext()) { string loc = ""; if (iterator1.Current is IXmlLineInfo li) { loc = $", Line: {li.LinePosition}, Position: {li.LinePosition}"; } var name = iterator1.Current.Value; var mappedName = Path.Combine(locP, name); if (source.GetLocalNames(mappedName).Count() != 1) { Console.WriteLine($"CONTENT ERROR\t{validatingFile}\tMissing {mappedName}{loc}."); c.Status |= Status.ContentError; } } } } }
private static void CheckSchemaCompliance(CheckInfo c, BcfSource unzippedDir, string version, string fileExtension, string requiredSchema) { List <string> schemas = new List <string> { requiredSchema }; if (version == "v3.0") // version 3 needs the shared type as well { var freq = new FileInfo(requiredSchema); var shared = freq.Directory.GetFiles("shared-types.xsd", new EnumerationOptions() { MatchCasing = MatchCasing.CaseInsensitive }).FirstOrDefault(); schemas.Add(shared.FullName); } var markupFiles = unzippedDir.GetLocalNames($".{fileExtension}"); foreach (var markupFile in markupFiles) { c.validatingFile = c.CleanName(new FileInfo(Path.Combine(unzippedDir.FullName, markupFile))); XmlReaderSettings rSettings = new XmlReaderSettings(); foreach (var schema in schemas) { rSettings.Schemas.Add("", schema); } rSettings.ValidationType = ValidationType.Schema; rSettings.ValidationEventHandler += new ValidationEventHandler(c.validationReporter); XmlReader content = XmlReader.Create(unzippedDir.GetStream(markupFile), rSettings); while (content.Read()) { // read all files to trigger validation events. } } }