/// <summary> /// Package typed document asynchronously /// </summary> /// <typeparam name="T">Type of document body</typeparam> /// <param name="request">Request to be packaged</param> /// <param name="responseTask">Reponse task to be packaged</param> /// <returns>Packaged document</returns> protected async Task <IDocument <T> > PackageAndAddDocumentAsync <T>(IRestRequest request, Task <IRestResponse <T> > responseTask) { Uri requestUri = _restClient.BaseUrl; IRestResponse <T> response = await responseTask; HtmlParser parser = new HtmlParser(); IHtmlDocument htmlDocument = parser.ParseDocument(response.Content); IDocument <T> document = new Document <T>(request, response, htmlDocument); Task <int> result = null; Task <int> styleResult = null; if (JavascriptScrapingEnabled) { result = JavascriptEngine.AddAsync(document); } if (StyleScrapingEnabled) { styleResult = StyleEngine.AddAsync(document); } if (JavascriptScrapingEnabled && result != null) { await result; } if (StyleScrapingEnabled && styleResult != null) { await styleResult; } document.RequestUri = requestUri; Documents.Add(document); return(document); }