/// <summary> /// Generates the code from the contents of the address space. /// </summary> public void Validate(Stream stream) { m_schema.Load(stream); foreach (XmlNode import in m_schema.ChildNodes) { if (import.NamespaceURI == Namespaces.OpcUa) { StreamReader strm = new StreamReader(Assembly.Load(new AssemblyName("Opc.Ua.Core")).GetManifestResourceStream("Opc.Ua.Model.Opc.Ua.Types.xsd")); m_schema.Load(strm); continue; } string location = null; if (!KnownFiles.TryGetValue(import.NamespaceURI, out location)) { location = import.NamespaceURI; } FileInfo fileInfo = new FileInfo(location); if (!fileInfo.Exists) { StreamReader strm = new StreamReader(Assembly.Load(new AssemblyName("Opc.Ua.Core")).GetManifestResourceStream(location)); m_schema.Load(strm); } else { Stream strm = File.OpenRead(location); m_schema.Load(strm); } } }
public bool Exists(string Uri) { string toMatch = TrimTilde(Uri); if (Path.DirectorySeparatorChar == '\\') { toMatch = toMatch.Replace("/", "\\"); } if (!this.IsCaseSensitive) { toMatch = toMatch.ToLower(CultureInfo.CurrentCulture); } if (KnownFiles.TryGetValue(Uri, out bool result)) { return(result); } else { result = File.Exists(Path.Combine(this.ApplicationPath, toMatch)); KnownFiles.TryAdd(toMatch, result); return(result); } }
public void KnownFile_ReturnsTrue() { var status = KnownFiles.IsKnownFile(16924); status.IsKnown.Should().Be(KnownState.Exact); status.Description.Should().Contain("Phoenix"); }
public void KnownApproxFile_IsProbablyTrackFile_TopOfRange() { var status = KnownFiles.IsKnownFile(24000); status.IsKnown.Should().Be(KnownState.Probable); status.Description.Should().Be("an F1GP Track File?"); }
public void Run(Options options) { if (options.UnrecognizedInput) { _console.WriteUnrecognizedInputMessage(); return; } if (options.DisplayHelp) { _console.WriteHelpMessage(); return; } if (string.IsNullOrWhiteSpace(options.FileName)) { _console.WriteFileArgumentMissingMessage(); return; } if (!_fileSystem.FileExists(options.FileName)) { _console.WriteFileDoesNotExistMessage(options.FileName); return; } var fileLength = _fileSystem.GetFileLength(options.FileName); var file = KnownFiles.IsKnownFile(fileLength); if (file.IsKnown == KnownState.Exact) { _console.WriteIdentifiedFileMessage(file.Description); } else if (file.IsKnown == KnownState.Probable) { _console.WriteProbableFileMessage(file.Description); } else { _console.WriteUnknownFileMessage(); if (!ShouldProceed(options.Force)) { _console.WriteDidNotProceedWithUnknownFileMessage(); return; } } _checksumCalculator.UpdateChecksum(options.FileName); _console.WriteSuccessMessage(); if (options.Pause) { _console.WritePauseMessage(); } }
/// <summary> /// Generates the code from the contents of the address space. /// </summary> public void Validate(Stream stream) { using (var xmlReader = XmlReader.Create(stream, Utils.DefaultXmlReaderSettings())) { m_schema.Load(xmlReader); } foreach (XmlNode import in m_schema.ChildNodes) { if (import.NamespaceURI == Namespaces.OpcUa) { using (StreamReader strm = new StreamReader(Assembly.Load(new AssemblyName("Opc.Ua.Core")).GetManifestResourceStream("Opc.Ua.Model.Opc.Ua.Types.xsd"))) using (var xmlReader = XmlReader.Create(strm, Utils.DefaultXmlReaderSettings())) { m_schema.Load(xmlReader); } continue; } string location = null; if (!KnownFiles.TryGetValue(import.NamespaceURI, out location)) { location = import.NamespaceURI; } FileInfo fileInfo = new FileInfo(location); if (!fileInfo.Exists) { using (StreamReader strm = new StreamReader(Assembly.Load(new AssemblyName("Opc.Ua.Core")).GetManifestResourceStream(location))) using (var xmlReader = XmlReader.Create(strm, Utils.DefaultXmlReaderSettings())) { m_schema.Load(xmlReader); } } else { using (Stream strm = File.OpenRead(location)) using (var xmlReader = XmlReader.Create(strm, Utils.DefaultXmlReaderSettings())) { m_schema.Load(xmlReader); } } } }
/// <summary> /// Generates the code from the contents of the address space. /// </summary> public void Validate(Stream stream) { m_schema = XmlSchema.Read(stream, new ValidationEventHandler(OnValidate)); foreach (XmlSchemaImport import in m_schema.Includes) { if (import.Namespace == Namespaces.OpcUa) { StreamReader strm = new StreamReader(Assembly.Load("Opc.Ua.Core").GetManifestResourceStream("Opc.Ua.Model.Opc.Ua.Types.xsd")); import.Schema = XmlSchema.Read(strm, new ValidationEventHandler(OnValidate)); continue; } string location = null; if (!KnownFiles.TryGetValue(import.Namespace, out location)) { location = import.SchemaLocation; } FileInfo fileInfo = new FileInfo(location); if (!fileInfo.Exists) { using (StreamReader strm = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(location))) { import.Schema = XmlSchema.Read(strm, new ValidationEventHandler(OnValidate)); } } else { using (Stream strm = File.OpenRead(location)) { import.Schema = XmlSchema.Read(strm, new ValidationEventHandler(OnValidate)); } } } m_schemaSet = new XmlSchemaSet(); m_schemaSet.Add(m_schema); m_schemaSet.Compile(); }
/// <summary> /// Generates the code from the contents of the address space. /// </summary> public void Validate(Stream stream) { using (var xmlReader = XmlReader.Create(stream, Utils.DefaultXmlReaderSettings())) { m_schema = XmlSchema.Read(xmlReader, new ValidationEventHandler(OnValidate)); var assembly = typeof(XmlSchemaValidator).GetTypeInfo().Assembly; foreach (XmlSchemaImport import in m_schema.Includes) { string location = null; if (!KnownFiles.TryGetValue(import.Namespace, out location)) { location = import.SchemaLocation; } FileInfo fileInfo = new FileInfo(location); var settings = Utils.DefaultXmlReaderSettings(); if (!fileInfo.Exists) { using (StreamReader strm = new StreamReader(assembly.GetManifestResourceStream(location))) using (var schemaReader = XmlReader.Create(strm, settings)) { import.Schema = XmlSchema.Read(schemaReader, new ValidationEventHandler(OnValidate)); } } else { using (Stream strm = File.OpenRead(location)) using (var schemaReader = XmlReader.Create(strm, settings)) { import.Schema = XmlSchema.Read(schemaReader, new ValidationEventHandler(OnValidate)); } } } m_schemaSet = new XmlSchemaSet(); m_schemaSet.Add(m_schema); m_schemaSet.Compile(); } }
private static void Watcher_Event(object sender, FileSystemEventArgs e) { KnownFiles.Clear(); }
public void UnknownFile_ReturnsFalse() { var status = KnownFiles.IsKnownFile(123456); status.IsKnown.Should().Be(KnownState.Unknown); }