private static Task <IDocument> LoadSvgAsync(IBrowsingContext context, CreateDocumentOptions options, CancellationToken cancellationToken) { var parser = context.GetService <IXmlParser>() ?? throw new InvalidOperationException("The IXmlParser service has been removed. Cannot continue."); var document = new SvgDocument(context, options.Source); document.Setup(options.Response, options.ContentType, options.ImportAncestor); context.NavigateTo(document); return(parser.ParseDocumentAsync(document, cancellationToken)); }
/// <summary> /// Opens a new document created from the response asynchronously in /// the given context. /// </summary> /// <param name="context">The browsing context to use.</param> /// <param name="response">The response to examine.</param> /// <param name="cancel">The cancellation token.</param> /// <returns>The task that creates the document.</returns> public static Task <IDocument> OpenAsync(this IBrowsingContext context, IResponse response, CancellationToken cancel = default) { response = response ?? throw new ArgumentNullException(nameof(response)); context = context ?? BrowsingContext.New(); var encoding = context.GetDefaultEncoding(); var factory = context.GetFactory <IDocumentFactory>(); var options = new CreateDocumentOptions(response, encoding); return(factory.CreateAsync(context, options, cancel)); }
/// <summary> /// Opens a new document created from the response asynchronously in /// the given context. /// </summary> /// <param name="context">The browsing context to use.</param> /// <param name="response">The response to examine.</param> /// <param name="cancel">The cancellation token.</param> /// <returns>The task that creates the document.</returns> public static Task<IDocument> OpenAsync(this IBrowsingContext context, IResponse response, CancellationToken cancel) { if (response == null) throw new ArgumentNullException(nameof(response)); if (context == null) { context = BrowsingContext.New(); } var options = new CreateDocumentOptions(response, context.Configuration); var factory = context.Configuration.GetFactory<IDocumentFactory>(); return factory.CreateAsync(context, options, cancel); }
/// <summary> /// Opens a new document created from the response asynchronously in /// the given context. /// </summary> /// <param name="context">The browsing context to use.</param> /// <param name="response">The response to examine.</param> /// <param name="cancel">The cancellation token.</param> /// <returns>The task that creates the document.</returns> public static Task<IDocument> OpenAsync(this IBrowsingContext context, IResponse response, CancellationToken cancel) { if (response == null) { throw new ArgumentNullException("response"); } if (context == null) { context = BrowsingContext.New(); } var options = new CreateDocumentOptions(response, context.Configuration); return context.OpenAsync(options, cancel); }
/// <summary> /// Opens a new document created from the response asynchronously in /// the given context. /// </summary> /// <param name="context">The browsing context to use.</param> /// <param name="response">The response to examine.</param> /// <param name="cancel">The cancellation token.</param> /// <returns>The task that creates the document.</returns> public static Task <IDocument> OpenAsync(this IBrowsingContext context, IResponse response, CancellationToken cancel) { if (response == null) { throw new ArgumentNullException("response"); } if (context == null) { context = BrowsingContext.New(); } var options = new CreateDocumentOptions(response, context.Configuration); return(context.OpenAsync(options, cancel)); }
/// <summary> /// Opens a new document created from the response asynchronously in /// the given context. /// </summary> /// <param name="context">The browsing context to use.</param> /// <param name="response">The response to examine.</param> /// <param name="cancel">The cancellation token.</param> /// <returns>The task that creates the document.</returns> public static Task <IDocument> OpenAsync(this IBrowsingContext context, IResponse response, CancellationToken cancel) { if (response == null) { throw new ArgumentNullException(nameof(response)); } if (context == null) { context = BrowsingContext.New(); } var options = new CreateDocumentOptions(response, context.Configuration); var factory = context.Configuration.GetFactory <IDocumentFactory>(); return(factory.CreateAsync(context, options, cancel)); }
/// <summary> /// Opens a new document loaded from a virtual response that can be /// filled via the provided callback. /// </summary> /// <param name="context">The browsing context to use.</param> /// <param name="request">Callback with the response to setup.</param> /// <param name="cancel">The cancellation token.</param> /// <returns>The task that creates the document.</returns> public static Task <IDocument> OpenAsync(this IBrowsingContext context, Action <VirtualResponse> request, CancellationToken cancel) { if (request == null) { throw new ArgumentNullException("request"); } if (context == null) { context = BrowsingContext.New(); } using (var response = new VirtualResponse()) { request(response); var contentType = response.GetContentType(MimeTypeNames.Html); var source = response.CreateSourceFor(context.Configuration); var options = new CreateDocumentOptions(response, source); return(context.OpenAsync(options, cancel)); } }
/// <summary> /// Opens a new document created with the provided document options /// asynchronously in the given context. /// </summary> /// <param name="context">The browsing context to use.</param> /// <param name="options">The creation options.</param> /// <param name="cancel">The cancellation token.</param> /// <returns>The task that creates the document.</returns> internal static Task <IDocument> OpenAsync(this IBrowsingContext context, CreateDocumentOptions options, CancellationToken cancel) { var creator = options.FindCreator(); return(creator(context, options, cancel)); }
/// <summary> /// Opens a new document created with the provided document options /// asynchronously in the given context. /// </summary> /// <param name="context">The browsing context to use.</param> /// <param name="options">The creation options.</param> /// <param name="cancel">The cancellation token.</param> /// <returns>The task that creates the document.</returns> internal static Task<IDocument> OpenAsync(this IBrowsingContext context, CreateDocumentOptions options, CancellationToken cancel) { var creator = options.FindCreator(); return creator(context, options, cancel); }
/// <summary> /// Opens a new document loaded from a virtual response that can be /// filled via the provided callback. /// </summary> /// <param name="context">The browsing context to use.</param> /// <param name="request">Callback with the response to setup.</param> /// <param name="cancel">The cancellation token.</param> /// <returns>The task that creates the document.</returns> public static Task<IDocument> OpenAsync(this IBrowsingContext context, Action<VirtualResponse> request, CancellationToken cancel) { if (request == null) { throw new ArgumentNullException("request"); } if (context == null) { context = BrowsingContext.New(); } using (var response = new VirtualResponse()) { request(response); var contentType = response.GetContentType(MimeTypeNames.Html); var source = response.CreateSourceFor(context.Configuration); var options = new CreateDocumentOptions(response, source); return context.OpenAsync(options, cancel); } }