private WsdlFileInfo GetMainWsdl() { var importedWsdl = new List <string>(); var wsdlFiles = this.MetadataFiles.OfType <WsdlFileInfo>(); // record imported wsld files to be able to identify the core wsdl file. foreach (var wsdl in wsdlFiles.Select(f => f.Wsdl)) { foreach (WsdlNS.Import import in wsdl.Imports) { var filePath = Path.Combine(this.DirectoryPath, import.Location); importedWsdl.Add(filePath); } } var mainWsdlFile = wsdlFiles.Where(w => !importedWsdl.Any(i => MetadataFileNameManager.UriEqual(i, w.FilePath))).FirstOrDefault(); if (mainWsdlFile == null) { // this may be the case of docs with circular dependencies, this is ok as they are not imported multiple times, select the first one (if any). mainWsdlFile = wsdlFiles.FirstOrDefault(); } return(mainWsdlFile); }
private MetadataFileInfo AddSchema(XmlSchema schema) { MetadataFileInfo metadataFileInfo = null; if (schema != null && !this.MetadataFiles.Any(mi => mi.Metadata == schema) /*&& schema.Items.Count > 0*/) { var sourceUrl = schema.SourceUri; var filePath = AddFilePath(schema.SourceUri, schema.TargetNamespace, ".xsd"); schema.SourceUri = Path.GetFileName(filePath); metadataFileInfo = new SchemaFileInfo(schema, filePath, sourceUrl, schema.Write); this.MetadataFiles.Add(metadataFileInfo); var unresolvedRefs = UnresolvedReferences.Where(u => (MetadataFileNameManager.UriEqual(u.SchemaExternal?.SchemaLocation, sourceUrl) || (!string.IsNullOrEmpty(u.Namespace) && u.Namespace == schema.TargetNamespace))).ToList(); foreach (var unresolvedRef in unresolvedRefs) { unresolvedRef.SchemaExternal.SchemaLocation = schema.SourceUri; UnresolvedReferences.Remove(unresolvedRef); } } return(metadataFileInfo); }
private MetadataFileInfo AddWsdl(WsdlNS.ServiceDescription wsdl) { MetadataFileInfo metadataFileInfo = null; if (wsdl != null && !this.MetadataFiles.Any(mi => mi.Metadata == wsdl)) { var sourceUrl = wsdl.RetrievalUrl; var filePath = AddFilePath(wsdl.RetrievalUrl, wsdl.TargetNamespace, ".wsdl"); wsdl.RetrievalUrl = Path.GetFileName(filePath); metadataFileInfo = new WsdlFileInfo(wsdl, filePath, sourceUrl, wsdl.Write); this.MetadataFiles.Add(metadataFileInfo); var unresolvedRefs = UnresolvedReferences.Where(u => MetadataFileNameManager.UriEqual(u.WsdlImport?.Location, sourceUrl)).ToList(); foreach (var unresolvedRef in unresolvedRefs) { unresolvedRef.WsdlImport.Location = wsdl.RetrievalUrl; UnresolvedReferences.Remove(unresolvedRef); } } return(metadataFileInfo); }
public override bool Equals(object obj) { UnresolvedUri other = obj as UnresolvedUri; return(other != null && MetadataFileNameManager.UriEqual(this.Uri, other.Uri)); }
private void AddMetadataFiles(IEnumerable <MetadataSection> documents) { if (documents == null) { throw new ArgumentNullException(nameof(documents)); } // prepopulate schema/wsdl includes/imports so references can be resolved/updated when resolving document paths. foreach (var doc in documents) { if (!AddUnresolvedSchemaRefs(doc.Metadata as XmlNS.Schema.XmlSchema)) { AddUnresolvedWsdlRefs(doc.Metadata as WsdlNS.ServiceDescription); } } // compute document paths. foreach (var doc in documents) { if (AddWsdl(doc.Metadata as WsdlNS.ServiceDescription) == null) { if (AddSchema(doc.Metadata as XmlNS.Schema.XmlSchema) == null) { if (AddXmlDocument(doc.Metadata as XmlNS.XmlElement, doc.Dialect) == null) { #if DEBUG string typeName = doc.Metadata.GetType().ToString(); Debug.Fail("Unknown metadata found: " + typeName); #endif } } } } for (int idx = UnresolvedReferences.Count - 1; idx >= 0; idx--) { var unresolvedRef = UnresolvedReferences[idx]; if (unresolvedRef.Namespace != null) { // remove namespace-only schema references as they are still valid UnresolvedReferences.RemoveAt(idx); } else { // remove schema references for which multiple files are resolved (wildcards). var location = unresolvedRef.WsdlImport != null ? unresolvedRef.WsdlImport.Location : unresolvedRef.SchemaExternal?.SchemaLocation; if (MetadataFileNameManager.TryCreateUri(location, out Uri locationUri) && MetadataFileNameManager.TryResolveFiles(locationUri.LocalPath, out var files)) { var missingRefs = files.Where(file => !this.MetadataFiles.Any(metaFile => MetadataFileNameManager.UriEqual(file.FullName, metaFile.SourceUri))); if (missingRefs.Count() == 0) { var updatedLocation = Path.Combine(this.DirectoryPath, Path.GetFileName(location)); if (unresolvedRef.WsdlImport != null) { unresolvedRef.WsdlImport.Location = updatedLocation; } else { unresolvedRef.SchemaExternal.SchemaLocation = updatedLocation; } UnresolvedReferences.Remove(unresolvedRef); } } } } }
public bool Equals(string otherFilePath) { return(otherFilePath != null && MetadataFileNameManager.UriEqual(this.FilePath, otherFilePath)); }
private static void FixupChameleonSchemas(IEnumerable <MetadataSection> metadataSections) { // Chameleon schemas are those w/o a target namespace, types from these schemas become part of the namespace of the enclosing schema. var documents = metadataSections.Select((s) => s.Metadata); var schemas = documents.OfType <XmlNS.Schema.XmlSchema>(); var chameleonSchemas = schemas.Where(s => string.IsNullOrEmpty(s.TargetNamespace)); foreach (var schema in schemas) { foreach (XmlNS.Schema.XmlSchemaExternal include in schema.Includes) { var chameleonSchema = chameleonSchemas.FirstOrDefault(c => c != schema && MetadataFileNameManager.UriEqual(MetadataFileNameManager.GetComposedUri(c.SourceUri, null), MetadataFileNameManager.GetComposedUri(schema.SourceUri, include.SchemaLocation))); if (chameleonSchema != null) { include.Schema = chameleonSchema; } } } }