private bool AddUnresolvedSchemaRefs(XmlNS.Schema.XmlSchema schema)
 {
     if (schema != null)
     {
         foreach (XmlNS.Schema.XmlSchemaExternal schemaExternal in schema.Includes)
         {
             if (!this.UnresolvedReferences.Any(r => r.SchemaExternal == schemaExternal))
             {
                 if (!string.IsNullOrEmpty(schemaExternal.SchemaLocation))
                 {
                     schemaExternal.SchemaLocation = MetadataFileNameManager.GetComposedUri(schema.SourceUri, schemaExternal.SchemaLocation);
                     UnresolvedReferences.Add(new UnresolvedUri {
                         Schema = schema, SchemaExternal = schemaExternal
                     });
                 }
                 else if (schemaExternal.Schema == null)
                 {
                     // the MetadataExchangeClient when using MEX protocol downloads wsdl-embedded schemas separately,
                     // need to gather namespace-only imports (which are valid w/o any schema) to be able to connect
                     // the docs if it is the case.
                     var schemaImport = schemaExternal as XmlNS.Schema.XmlSchemaImport;
                     if (schemaImport != null && !string.IsNullOrEmpty(schemaImport.Namespace))
                     {
                         UnresolvedReferences.Add(new UnresolvedUri {
                             Schema = schema, SchemaExternal = schemaExternal, Namespace = schemaImport.Namespace
                         });
                     }
                 }
             }
         }
         return(true);
     }
     return(false);
 }
        private bool AddUnresolvedWsdlRefs(WsdlNS.ServiceDescription wsdl)
        {
            if (wsdl != null)
            {
                foreach (WsdlNS.Import import in wsdl.Imports)
                {
                    if (!string.IsNullOrEmpty(import.Location) && !this.UnresolvedReferences.Any(r => r.WsdlImport == import))
                    {
                        import.Location = MetadataFileNameManager.GetComposedUri(wsdl.RetrievalUrl, import.Location);
                        UnresolvedReferences.Add(new UnresolvedUri {
                            WsdlImport = import, Wsdl = wsdl
                        });
                    }
                }

                foreach (XmlNS.Schema.XmlSchema schema in wsdl.Types.Schemas)
                {
                    AddUnresolvedSchemaRefs(schema);
                }
                return(true);
            }
            return(false);
        }
        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;
                    }
                }
            }
        }