Use streams for http responses instead of strings where possible, replace HtmlAgilityPack with AngleSharp (#1703)

* Replace HAP with AngleSharp, add stream support to WebBrowser

* Fix skipped nullable operator

* Add extension method

* Rename function to be closer to HAP API

* Add JSON deserialization from stream, fix variable names, remove obsolete code

* Add more extension methods

* Fixes after review:

Remove excessive dependency
Move string value to const
Different handling for null and empty cases for confirmations
Use more human-friendly names

* Add http completion options, make GetToStream private

* Cleanup

* Add null checks, make StreamResponse disposable

* Refactor UrlGetToBinaryWithProgress into using UrlGetToStream
This commit is contained in:
Vitaliy
2020-04-02 18:01:55 +03:00
committed by GitHub
parent 862d4b006d
commit fbe5bd12ae
8 changed files with 232 additions and 127 deletions

View File

@@ -23,8 +23,8 @@ using System;
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
using AngleSharp.Dom;
using ArchiSteamFarm.Localization;
using HtmlAgilityPack;
using JetBrains.Annotations;
namespace ArchiSteamFarm {
@@ -83,20 +83,20 @@ namespace ArchiSteamFarm {
}
private async Task<bool?> IsDiscoveryQueueAvailable() {
HtmlDocument htmlDocument = await Bot.ArchiWebHandler.GetDiscoveryQueuePage().ConfigureAwait(false);
IDocument htmlDocument = await Bot.ArchiWebHandler.GetDiscoveryQueuePage().ConfigureAwait(false);
if (htmlDocument == null) {
return null;
}
HtmlNode htmlNode = htmlDocument.DocumentNode.SelectSingleNode("//div[@class='subtext']");
IElement htmlNode = htmlDocument.SelectSingleNode("//div[@class='subtext']");
if (htmlNode == null) {
// Valid, no cards for exploring the queue available
return false;
}
string text = htmlNode.InnerText;
string text = htmlNode.TextContent;
if (string.IsNullOrEmpty(text)) {
Bot.ArchiLogger.LogNullError(nameof(text));