コード例 #1
0
        private Uri ResolveBaseUri(ResolveSchemaContext context, out string fragment)
        {
            Uri baseUri = context.ResolverBaseUri;

            Uri uri = context.ResolvedSchemaId;

            if (!uri.IsAbsoluteUri && uri.OriginalString.StartsWith("#", StringComparison.OrdinalIgnoreCase))
            {
                fragment = uri.OriginalString;
                return(baseUri);
            }

            if (baseUri == null || (!baseUri.IsAbsoluteUri && baseUri.OriginalString.Length == 0))
            {
                return(RemoveFragment(uri, out fragment));
            }

            if (!baseUri.IsAbsoluteUri)
            {
                throw new NotSupportedException("Relative URIs are not supported.");
            }

            uri = RemoveFragment(uri, out fragment);

            uri = new Uri(baseUri, uri);
            return(uri);
        }
コード例 #2
0
        private Uri ResolveBaseUri(ResolveSchemaContext context, out string fragment)
        {
            Uri baseUri = context.ResolverBaseUri;

            Uri uri = context.ResolvedSchemaId;
            if (!uri.IsAbsoluteUri && uri.OriginalString.StartsWith("#", StringComparison.OrdinalIgnoreCase))
            {
                fragment = uri.OriginalString;
                return baseUri;
            }

            if (baseUri == null || (!baseUri.IsAbsoluteUri && baseUri.OriginalString.Length == 0))
            {
                return RemoveFragment(uri, out fragment);
            }

            if (!baseUri.IsAbsoluteUri)
            {
                throw new NotSupportedException("Relative URIs are not supported.");
            }

            uri = RemoveFragment(uri, out fragment);

            uri = new Uri(baseUri, uri);
            return uri;
        }
コード例 #3
0
        /// <summary>
        /// Gets the schema resource for a given schema reference.
        /// </summary>
        /// <param name="context">The schema ID context.</param>
        /// <param name="reference">The schema reference.</param>
        /// <returns>The schema resource for a given schema reference.</returns>
        public override Stream?GetSchemaResource(ResolveSchemaContext context, SchemaReference reference)
        {
            if (reference.BaseUri == null)
            {
                throw new InvalidOperationException("Can't get schema resource because SchemaReference.BaseUri doesn't have a value.");
            }

            if (_preloadedData.TryGetValue(reference.BaseUri, out byte[] data))
コード例 #4
0
        /// <summary>
        /// Gets the schema resource for a given schema reference.
        /// </summary>
        /// <param name="context">The schema ID context.</param>
        /// <param name="reference">The schema reference.</param>
        /// <returns>The schema resource for a given schema reference.</returns>
        public override Stream GetSchemaResource(ResolveSchemaContext context, SchemaReference reference)
        {
            byte[] data;
            if (_preloadedData.TryGetValue(reference.BaseUri, out data))
            {
                return(new MemoryStream(data));
            }

            return(_resolver?.GetSchemaResource(context, reference));
        }
コード例 #5
0
        /// <summary>
        /// Gets the schema resource for a given schema reference.
        /// </summary>
        /// <param name="context">The schema ID context.</param>
        /// <param name="reference">The schema reference.</param>
        /// <returns>The schema resource for a given schema reference.</returns>
        public override Stream GetSchemaResource(ResolveSchemaContext context, SchemaReference reference)
        {
            byte[] data;
            if (_preloadedData.TryGetValue(reference.BaseUri, out data))
                return new MemoryStream(data);

            if (_resolver != null)
                return _resolver.GetSchemaResource(context, reference);

            return null;
        }
コード例 #6
0
        /// <summary>
        /// Resolves the schema reference from the specified schema ID context.
        /// </summary>
        /// <param name="context">The schema ID context to resolve.</param>
        /// <returns>The resolved schema reference.</returns>
        public virtual SchemaReference ResolveSchemaReference(ResolveSchemaContext context)
        {
            string fragment;
            Uri baseUri = ResolveBaseUri(context, out fragment);

            SchemaReference schemaReference = new SchemaReference();
            schemaReference.BaseUri = baseUri;
            if (fragment != null)
                schemaReference.SubschemaId = new Uri(fragment, UriKind.RelativeOrAbsolute);

            return schemaReference;
        }
コード例 #7
0
        /// <summary>
        /// Resolves the schema reference from the specified schema ID context.
        /// </summary>
        /// <param name="context">The schema ID context to resolve.</param>
        /// <returns>The resolved schema reference.</returns>
        public virtual SchemaReference ResolveSchemaReference(ResolveSchemaContext context)
        {
            Uri baseUri = ResolveBaseUri(context, out string fragment);

            SchemaReference schemaReference = new SchemaReference();

            schemaReference.BaseUri = baseUri;
            if (fragment != null)
            {
                schemaReference.SubschemaId = new Uri(fragment, UriKind.RelativeOrAbsolute);
            }

            return(schemaReference);
        }
コード例 #8
0
        /// <summary>
        /// Gets the schema resource for a given schema reference.
        /// </summary>
        /// <param name="context">The schema ID context.</param>
        /// <param name="reference">The schema reference.</param>
        /// <returns>The schema resource for a given schema reference.</returns>
        public override Stream GetSchemaResource(ResolveSchemaContext context, SchemaReference reference)
        {
            if (!reference.BaseUri.IsAbsoluteUri)
            {
                return(null);
            }

#if !PORTABLE
            int?timeout = Timeout;
#else
            int?timeout = null;
#endif

            return(_downloader.GetStream(reference.BaseUri, _credentials, timeout, ByteLimit));
        }
コード例 #9
0
        private Uri ResolveBaseUri(ResolveSchemaContext context, out string fragment)
        {
            Uri baseUri = context.ResolverBaseUri;

            Uri uri = context.ResolvedSchemaId;

            if (!uri.IsAbsoluteUri && uri.OriginalString.StartsWith("#", StringComparison.OrdinalIgnoreCase))
            {
                fragment = uri.OriginalString;
                return(baseUri);
            }

            if (baseUri == null || (!baseUri.IsAbsoluteUri && baseUri.OriginalString.Length == 0))
            {
                return(RemoveFragment(uri, out fragment));
            }

            uri = RemoveFragment(uri, out fragment);

            uri = SchemaDiscovery.ResolveSchemaId(baseUri, uri);
            return(uri);
        }
コード例 #10
0
 /// <summary>
 /// Gets the schema resource for a given schema reference.
 /// </summary>
 /// <param name="context">The schema ID context.</param>
 /// <param name="reference">The schema reference.</param>
 /// <returns>The schema resource for a given schema reference.</returns>
 public abstract Stream GetSchemaResource(ResolveSchemaContext context, SchemaReference reference);
コード例 #11
0
 /// <summary>
 /// Gets the schema resource for a given schema reference.
 /// </summary>
 /// <param name="context">The schema ID context.</param>
 /// <param name="reference">The schema reference.</param>
 /// <returns>The schema resource for a given schema reference.</returns>
 public abstract Stream GetSchemaResource(ResolveSchemaContext context, SchemaReference reference);
コード例 #12
0
 /// <summary>
 /// Gets the schema resource for a given schema reference.
 /// </summary>
 /// <param name="context">The schema ID context.</param>
 /// <param name="reference">The schema reference.</param>
 /// <returns>The schema resource for a given schema reference.</returns>
 public override Stream GetSchemaResource(ResolveSchemaContext context, SchemaReference reference)
 {
     if (_preloadedData.TryGetValue(reference.BaseUri, out byte[] data))