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); }
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; }
/// <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))
/// <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)); }
/// <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; }
/// <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; }
/// <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); }
/// <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)); }
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); }
/// <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);
/// <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))