Ejemplo n.º 1
0
        private HtmlDocument CreateDocument(Stream source)
        {
            var encoding   = _context.GetDefaultEncoding();
            var textSource = new TextSource(source, encoding);

            return(CreateDocument(textSource));
        }
        protected override async Task ProcessResponseAsync(IResponse response)
        {
            var context  = new BrowsingContext(_context, Sandboxes.None);
            var encoding = _context.GetDefaultEncoding();
            var options  = new CreateDocumentOptions(response, encoding, _parentDocument);
            var factory  = _context.GetFactory <IDocumentFactory>();

            ChildDocument = await factory.CreateAsync(context, options, CancellationToken.None).ConfigureAwait(false);
        }
        /// <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));
        }