mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-16 08:25:28 +00:00
Use file-scoped namespaces
This commit is contained in:
@@ -37,273 +37,273 @@ using Markdig.Syntax;
|
||||
using Markdig.Syntax.Inlines;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace ArchiSteamFarm.Web {
|
||||
internal static class GitHub {
|
||||
internal static async Task<ReleaseResponse?> GetLatestRelease(bool stable = true) {
|
||||
Uri request = new(SharedInfo.GithubReleaseURL + (stable ? "/latest" : "?per_page=1"));
|
||||
namespace ArchiSteamFarm.Web;
|
||||
|
||||
if (stable) {
|
||||
return await GetReleaseFromURL(request).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
ImmutableList<ReleaseResponse>? response = await GetReleasesFromURL(request).ConfigureAwait(false);
|
||||
|
||||
return response?.FirstOrDefault();
|
||||
}
|
||||
|
||||
internal static async Task<ReleaseResponse?> GetRelease(string version) {
|
||||
if (string.IsNullOrEmpty(version)) {
|
||||
throw new ArgumentNullException(nameof(version));
|
||||
}
|
||||
|
||||
Uri request = new($"{SharedInfo.GithubReleaseURL}/tags/{version}");
|
||||
internal static class GitHub {
|
||||
internal static async Task<ReleaseResponse?> GetLatestRelease(bool stable = true) {
|
||||
Uri request = new(SharedInfo.GithubReleaseURL + (stable ? "/latest" : "?per_page=1"));
|
||||
|
||||
if (stable) {
|
||||
return await GetReleaseFromURL(request).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
internal static async Task<Dictionary<string, DateTime>?> GetWikiHistory(string page) {
|
||||
if (string.IsNullOrEmpty(page)) {
|
||||
throw new ArgumentNullException(nameof(page));
|
||||
}
|
||||
ImmutableList<ReleaseResponse>? response = await GetReleasesFromURL(request).ConfigureAwait(false);
|
||||
|
||||
if (ASF.WebBrowser == null) {
|
||||
throw new InvalidOperationException(nameof(ASF.WebBrowser));
|
||||
}
|
||||
return response?.FirstOrDefault();
|
||||
}
|
||||
|
||||
Uri request = new($"{SharedInfo.ProjectURL}/wiki/{page}/_history");
|
||||
internal static async Task<ReleaseResponse?> GetRelease(string version) {
|
||||
if (string.IsNullOrEmpty(version)) {
|
||||
throw new ArgumentNullException(nameof(version));
|
||||
}
|
||||
|
||||
using HtmlDocumentResponse? response = await ASF.WebBrowser.UrlGetToHtmlDocument(request, requestOptions: WebBrowser.ERequestOptions.ReturnClientErrors).ConfigureAwait(false);
|
||||
Uri request = new($"{SharedInfo.GithubReleaseURL}/tags/{version}");
|
||||
|
||||
return await GetReleaseFromURL(request).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
internal static async Task<Dictionary<string, DateTime>?> GetWikiHistory(string page) {
|
||||
if (string.IsNullOrEmpty(page)) {
|
||||
throw new ArgumentNullException(nameof(page));
|
||||
}
|
||||
|
||||
if (ASF.WebBrowser == null) {
|
||||
throw new InvalidOperationException(nameof(ASF.WebBrowser));
|
||||
}
|
||||
|
||||
Uri request = new($"{SharedInfo.ProjectURL}/wiki/{page}/_history");
|
||||
|
||||
using HtmlDocumentResponse? response = await ASF.WebBrowser.UrlGetToHtmlDocument(request, requestOptions: WebBrowser.ERequestOptions.ReturnClientErrors).ConfigureAwait(false);
|
||||
|
||||
if (response == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (response.StatusCode.IsClientErrorCode()) {
|
||||
return response.StatusCode switch {
|
||||
HttpStatusCode.NotFound => new Dictionary<string, DateTime>(0),
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
|
||||
IEnumerable<IElement> revisionNodes = response.Content.SelectNodes("//li[contains(@class, 'wiki-history-revision')]");
|
||||
|
||||
Dictionary<string, DateTime> result = new();
|
||||
|
||||
foreach (IElement revisionNode in revisionNodes) {
|
||||
IElement? versionNode = revisionNode.SelectSingleElementNode(".//input/@value");
|
||||
|
||||
if (versionNode == null) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(versionNode));
|
||||
|
||||
if (response == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (response.StatusCode.IsClientErrorCode()) {
|
||||
return response.StatusCode switch {
|
||||
HttpStatusCode.NotFound => new Dictionary<string, DateTime>(0),
|
||||
_ => null
|
||||
string versionText = versionNode.GetAttribute("value");
|
||||
|
||||
if (string.IsNullOrEmpty(versionText)) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(versionText));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
IElement? dateTimeNode = revisionNode.SelectSingleElementNode(".//relative-time/@datetime");
|
||||
|
||||
if (dateTimeNode == null) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(dateTimeNode));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
string dateTimeText = dateTimeNode.GetAttribute("datetime");
|
||||
|
||||
if (string.IsNullOrEmpty(dateTimeText)) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(dateTimeText));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!DateTime.TryParse(dateTimeText, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal, out DateTime dateTime)) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(dateTime));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
result[versionText] = dateTime.ToUniversalTime();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static async Task<string?> GetWikiPage(string page, string? revision = null) {
|
||||
if (string.IsNullOrEmpty(page)) {
|
||||
throw new ArgumentNullException(nameof(page));
|
||||
}
|
||||
|
||||
if (ASF.WebBrowser == null) {
|
||||
throw new InvalidOperationException(nameof(ASF.WebBrowser));
|
||||
}
|
||||
|
||||
Uri request = new($"{SharedInfo.ProjectURL}/wiki/{page}{(!string.IsNullOrEmpty(revision) ? $"/{revision}" : "")}");
|
||||
|
||||
using HtmlDocumentResponse? response = await ASF.WebBrowser.UrlGetToHtmlDocument(request).ConfigureAwait(false);
|
||||
|
||||
if (response == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
IElement? markdownBodyNode = response.Content.SelectSingleNode("//div[@class='markdown-body']");
|
||||
|
||||
return markdownBodyNode?.InnerHtml.Trim() ?? "";
|
||||
}
|
||||
|
||||
private static MarkdownDocument ExtractChangelogFromBody(string markdownText) {
|
||||
if (string.IsNullOrEmpty(markdownText)) {
|
||||
throw new ArgumentNullException(nameof(markdownText));
|
||||
}
|
||||
|
||||
MarkdownDocument markdownDocument = Markdown.Parse(markdownText);
|
||||
MarkdownDocument result = new();
|
||||
|
||||
foreach (Block block in markdownDocument.SkipWhile(static block => block is not HeadingBlock { Inline: { FirstChild: LiteralInline literalInline } } || !literalInline.Content.ToString().Equals("Changelog", StringComparison.OrdinalIgnoreCase)).Skip(1).TakeWhile(static block => block is not ThematicBreakBlock).ToList()) {
|
||||
// All blocks that we're interested in must be removed from original markdownDocument firstly
|
||||
markdownDocument.Remove(block);
|
||||
result.Add(block);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static async Task<ReleaseResponse?> GetReleaseFromURL(Uri request) {
|
||||
if (request == null) {
|
||||
throw new ArgumentNullException(nameof(request));
|
||||
}
|
||||
|
||||
if (ASF.WebBrowser == null) {
|
||||
throw new InvalidOperationException(nameof(ASF.WebBrowser));
|
||||
}
|
||||
|
||||
ObjectResponse<ReleaseResponse>? response = await ASF.WebBrowser.UrlGetToJsonObject<ReleaseResponse>(request).ConfigureAwait(false);
|
||||
|
||||
return response?.Content;
|
||||
}
|
||||
|
||||
private static async Task<ImmutableList<ReleaseResponse>?> GetReleasesFromURL(Uri request) {
|
||||
if (request == null) {
|
||||
throw new ArgumentNullException(nameof(request));
|
||||
}
|
||||
|
||||
if (ASF.WebBrowser == null) {
|
||||
throw new InvalidOperationException(nameof(ASF.WebBrowser));
|
||||
}
|
||||
|
||||
ObjectResponse<ImmutableList<ReleaseResponse>>? response = await ASF.WebBrowser.UrlGetToJsonObject<ImmutableList<ReleaseResponse>>(request).ConfigureAwait(false);
|
||||
|
||||
return response?.Content;
|
||||
}
|
||||
|
||||
[SuppressMessage("ReSharper", "ClassCannotBeInstantiated")]
|
||||
internal sealed class ReleaseResponse {
|
||||
[JsonProperty(PropertyName = "assets", Required = Required.Always)]
|
||||
internal readonly ImmutableHashSet<Asset> Assets = ImmutableHashSet<Asset>.Empty;
|
||||
|
||||
[JsonProperty(PropertyName = "prerelease", Required = Required.Always)]
|
||||
internal readonly bool IsPreRelease;
|
||||
|
||||
[JsonProperty(PropertyName = "published_at", Required = Required.Always)]
|
||||
internal readonly DateTime PublishedAt;
|
||||
|
||||
[JsonProperty(PropertyName = "tag_name", Required = Required.Always)]
|
||||
internal readonly string Tag = "";
|
||||
|
||||
internal string? ChangelogHTML {
|
||||
get {
|
||||
if (BackingChangelogHTML != null) {
|
||||
return BackingChangelogHTML;
|
||||
}
|
||||
|
||||
if (Changelog == null) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(Changelog));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
using StringWriter writer = new();
|
||||
|
||||
HtmlRenderer renderer = new(writer);
|
||||
|
||||
renderer.Render(Changelog);
|
||||
writer.Flush();
|
||||
|
||||
return BackingChangelogHTML = writer.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
internal string? ChangelogPlainText {
|
||||
get {
|
||||
if (BackingChangelogPlainText != null) {
|
||||
return BackingChangelogPlainText;
|
||||
}
|
||||
|
||||
if (Changelog == null) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(Changelog));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
using StringWriter writer = new();
|
||||
|
||||
HtmlRenderer renderer = new(writer) {
|
||||
EnableHtmlForBlock = false,
|
||||
EnableHtmlForInline = false,
|
||||
EnableHtmlEscape = false
|
||||
};
|
||||
|
||||
renderer.Render(Changelog);
|
||||
writer.Flush();
|
||||
|
||||
return BackingChangelogPlainText = writer.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerable<IElement> revisionNodes = response.Content.SelectNodes("//li[contains(@class, 'wiki-history-revision')]");
|
||||
[JsonProperty(PropertyName = "body", Required = Required.Always)]
|
||||
private readonly string? MarkdownBody = "";
|
||||
|
||||
Dictionary<string, DateTime> result = new();
|
||||
private MarkdownDocument? Changelog {
|
||||
get {
|
||||
if (BackingChangelog != null) {
|
||||
return BackingChangelog;
|
||||
}
|
||||
|
||||
foreach (IElement revisionNode in revisionNodes) {
|
||||
IElement? versionNode = revisionNode.SelectSingleElementNode(".//input/@value");
|
||||
|
||||
if (versionNode == null) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(versionNode));
|
||||
if (string.IsNullOrEmpty(MarkdownBody)) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(MarkdownBody));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
string versionText = versionNode.GetAttribute("value");
|
||||
|
||||
if (string.IsNullOrEmpty(versionText)) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(versionText));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
IElement? dateTimeNode = revisionNode.SelectSingleElementNode(".//relative-time/@datetime");
|
||||
|
||||
if (dateTimeNode == null) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(dateTimeNode));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
string dateTimeText = dateTimeNode.GetAttribute("datetime");
|
||||
|
||||
if (string.IsNullOrEmpty(dateTimeText)) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(dateTimeText));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!DateTime.TryParse(dateTimeText, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal, out DateTime dateTime)) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(dateTime));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
result[versionText] = dateTime.ToUniversalTime();
|
||||
return BackingChangelog = ExtractChangelogFromBody(MarkdownBody!);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static async Task<string?> GetWikiPage(string page, string? revision = null) {
|
||||
if (string.IsNullOrEmpty(page)) {
|
||||
throw new ArgumentNullException(nameof(page));
|
||||
}
|
||||
private MarkdownDocument? BackingChangelog;
|
||||
private string? BackingChangelogHTML;
|
||||
private string? BackingChangelogPlainText;
|
||||
|
||||
if (ASF.WebBrowser == null) {
|
||||
throw new InvalidOperationException(nameof(ASF.WebBrowser));
|
||||
}
|
||||
[JsonConstructor]
|
||||
private ReleaseResponse() { }
|
||||
|
||||
Uri request = new($"{SharedInfo.ProjectURL}/wiki/{page}{(!string.IsNullOrEmpty(revision) ? $"/{revision}" : "")}");
|
||||
internal sealed class Asset {
|
||||
[JsonProperty(PropertyName = "browser_download_url", Required = Required.Always)]
|
||||
internal readonly Uri? DownloadURL;
|
||||
|
||||
using HtmlDocumentResponse? response = await ASF.WebBrowser.UrlGetToHtmlDocument(request).ConfigureAwait(false);
|
||||
[JsonProperty(PropertyName = "name", Required = Required.Always)]
|
||||
internal readonly string? Name;
|
||||
|
||||
if (response == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
IElement? markdownBodyNode = response.Content.SelectSingleNode("//div[@class='markdown-body']");
|
||||
|
||||
return markdownBodyNode?.InnerHtml.Trim() ?? "";
|
||||
}
|
||||
|
||||
private static MarkdownDocument ExtractChangelogFromBody(string markdownText) {
|
||||
if (string.IsNullOrEmpty(markdownText)) {
|
||||
throw new ArgumentNullException(nameof(markdownText));
|
||||
}
|
||||
|
||||
MarkdownDocument markdownDocument = Markdown.Parse(markdownText);
|
||||
MarkdownDocument result = new();
|
||||
|
||||
foreach (Block block in markdownDocument.SkipWhile(static block => block is not HeadingBlock { Inline: { FirstChild: LiteralInline literalInline } } || !literalInline.Content.ToString().Equals("Changelog", StringComparison.OrdinalIgnoreCase)).Skip(1).TakeWhile(static block => block is not ThematicBreakBlock).ToList()) {
|
||||
// All blocks that we're interested in must be removed from original markdownDocument firstly
|
||||
markdownDocument.Remove(block);
|
||||
result.Add(block);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static async Task<ReleaseResponse?> GetReleaseFromURL(Uri request) {
|
||||
if (request == null) {
|
||||
throw new ArgumentNullException(nameof(request));
|
||||
}
|
||||
|
||||
if (ASF.WebBrowser == null) {
|
||||
throw new InvalidOperationException(nameof(ASF.WebBrowser));
|
||||
}
|
||||
|
||||
ObjectResponse<ReleaseResponse>? response = await ASF.WebBrowser.UrlGetToJsonObject<ReleaseResponse>(request).ConfigureAwait(false);
|
||||
|
||||
return response?.Content;
|
||||
}
|
||||
|
||||
private static async Task<ImmutableList<ReleaseResponse>?> GetReleasesFromURL(Uri request) {
|
||||
if (request == null) {
|
||||
throw new ArgumentNullException(nameof(request));
|
||||
}
|
||||
|
||||
if (ASF.WebBrowser == null) {
|
||||
throw new InvalidOperationException(nameof(ASF.WebBrowser));
|
||||
}
|
||||
|
||||
ObjectResponse<ImmutableList<ReleaseResponse>>? response = await ASF.WebBrowser.UrlGetToJsonObject<ImmutableList<ReleaseResponse>>(request).ConfigureAwait(false);
|
||||
|
||||
return response?.Content;
|
||||
}
|
||||
|
||||
[SuppressMessage("ReSharper", "ClassCannotBeInstantiated")]
|
||||
internal sealed class ReleaseResponse {
|
||||
[JsonProperty(PropertyName = "assets", Required = Required.Always)]
|
||||
internal readonly ImmutableHashSet<Asset> Assets = ImmutableHashSet<Asset>.Empty;
|
||||
|
||||
[JsonProperty(PropertyName = "prerelease", Required = Required.Always)]
|
||||
internal readonly bool IsPreRelease;
|
||||
|
||||
[JsonProperty(PropertyName = "published_at", Required = Required.Always)]
|
||||
internal readonly DateTime PublishedAt;
|
||||
|
||||
[JsonProperty(PropertyName = "tag_name", Required = Required.Always)]
|
||||
internal readonly string Tag = "";
|
||||
|
||||
internal string? ChangelogHTML {
|
||||
get {
|
||||
if (BackingChangelogHTML != null) {
|
||||
return BackingChangelogHTML;
|
||||
}
|
||||
|
||||
if (Changelog == null) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(Changelog));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
using StringWriter writer = new();
|
||||
|
||||
HtmlRenderer renderer = new(writer);
|
||||
|
||||
renderer.Render(Changelog);
|
||||
writer.Flush();
|
||||
|
||||
return BackingChangelogHTML = writer.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
internal string? ChangelogPlainText {
|
||||
get {
|
||||
if (BackingChangelogPlainText != null) {
|
||||
return BackingChangelogPlainText;
|
||||
}
|
||||
|
||||
if (Changelog == null) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(Changelog));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
using StringWriter writer = new();
|
||||
|
||||
HtmlRenderer renderer = new(writer) {
|
||||
EnableHtmlForBlock = false,
|
||||
EnableHtmlForInline = false,
|
||||
EnableHtmlEscape = false
|
||||
};
|
||||
|
||||
renderer.Render(Changelog);
|
||||
writer.Flush();
|
||||
|
||||
return BackingChangelogPlainText = writer.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
[JsonProperty(PropertyName = "body", Required = Required.Always)]
|
||||
private readonly string? MarkdownBody = "";
|
||||
|
||||
private MarkdownDocument? Changelog {
|
||||
get {
|
||||
if (BackingChangelog != null) {
|
||||
return BackingChangelog;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(MarkdownBody)) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(MarkdownBody));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return BackingChangelog = ExtractChangelogFromBody(MarkdownBody!);
|
||||
}
|
||||
}
|
||||
|
||||
private MarkdownDocument? BackingChangelog;
|
||||
private string? BackingChangelogHTML;
|
||||
private string? BackingChangelogPlainText;
|
||||
[JsonProperty(PropertyName = "size", Required = Required.Always)]
|
||||
internal readonly uint Size;
|
||||
|
||||
[JsonConstructor]
|
||||
private ReleaseResponse() { }
|
||||
|
||||
internal sealed class Asset {
|
||||
[JsonProperty(PropertyName = "browser_download_url", Required = Required.Always)]
|
||||
internal readonly Uri? DownloadURL;
|
||||
|
||||
[JsonProperty(PropertyName = "name", Required = Required.Always)]
|
||||
internal readonly string? Name;
|
||||
|
||||
[JsonProperty(PropertyName = "size", Required = Required.Always)]
|
||||
internal readonly uint Size;
|
||||
|
||||
[JsonConstructor]
|
||||
private Asset() { }
|
||||
}
|
||||
private Asset() { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,29 +24,29 @@ using System.Net;
|
||||
using System.Net.Http;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace ArchiSteamFarm.Web.Responses {
|
||||
public class BasicResponse {
|
||||
[PublicAPI]
|
||||
public HttpStatusCode StatusCode { get; }
|
||||
namespace ArchiSteamFarm.Web.Responses;
|
||||
|
||||
internal readonly Uri FinalUri;
|
||||
public class BasicResponse {
|
||||
[PublicAPI]
|
||||
public HttpStatusCode StatusCode { get; }
|
||||
|
||||
internal BasicResponse(HttpResponseMessage httpResponseMessage) {
|
||||
if (httpResponseMessage == null) {
|
||||
throw new ArgumentNullException(nameof(httpResponseMessage));
|
||||
}
|
||||
internal readonly Uri FinalUri;
|
||||
|
||||
FinalUri = httpResponseMessage.Headers.Location ?? httpResponseMessage.RequestMessage?.RequestUri ?? throw new InvalidOperationException();
|
||||
StatusCode = httpResponseMessage.StatusCode;
|
||||
internal BasicResponse(HttpResponseMessage httpResponseMessage) {
|
||||
if (httpResponseMessage == null) {
|
||||
throw new ArgumentNullException(nameof(httpResponseMessage));
|
||||
}
|
||||
|
||||
internal BasicResponse(BasicResponse basicResponse) {
|
||||
if (basicResponse == null) {
|
||||
throw new ArgumentNullException(nameof(basicResponse));
|
||||
}
|
||||
FinalUri = httpResponseMessage.Headers.Location ?? httpResponseMessage.RequestMessage?.RequestUri ?? throw new InvalidOperationException();
|
||||
StatusCode = httpResponseMessage.StatusCode;
|
||||
}
|
||||
|
||||
FinalUri = basicResponse.FinalUri;
|
||||
StatusCode = basicResponse.StatusCode;
|
||||
internal BasicResponse(BasicResponse basicResponse) {
|
||||
if (basicResponse == null) {
|
||||
throw new ArgumentNullException(nameof(basicResponse));
|
||||
}
|
||||
|
||||
FinalUri = basicResponse.FinalUri;
|
||||
StatusCode = basicResponse.StatusCode;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,19 +23,19 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace ArchiSteamFarm.Web.Responses {
|
||||
public sealed class BinaryResponse : BasicResponse {
|
||||
[PublicAPI]
|
||||
public IReadOnlyCollection<byte> Content => Bytes;
|
||||
namespace ArchiSteamFarm.Web.Responses;
|
||||
|
||||
private readonly byte[] Bytes;
|
||||
public sealed class BinaryResponse : BasicResponse {
|
||||
[PublicAPI]
|
||||
public IReadOnlyCollection<byte> Content => Bytes;
|
||||
|
||||
public BinaryResponse(BasicResponse basicResponse, byte[] bytes) : base(basicResponse) {
|
||||
if (basicResponse == null) {
|
||||
throw new ArgumentNullException(nameof(basicResponse));
|
||||
}
|
||||
private readonly byte[] Bytes;
|
||||
|
||||
Bytes = bytes ?? throw new ArgumentNullException(nameof(bytes));
|
||||
public BinaryResponse(BasicResponse basicResponse, byte[] bytes) : base(basicResponse) {
|
||||
if (basicResponse == null) {
|
||||
throw new ArgumentNullException(nameof(basicResponse));
|
||||
}
|
||||
|
||||
Bytes = bytes ?? throw new ArgumentNullException(nameof(bytes));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,38 +26,38 @@ using AngleSharp.Dom;
|
||||
using ArchiSteamFarm.Core;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace ArchiSteamFarm.Web.Responses {
|
||||
public sealed class HtmlDocumentResponse : BasicResponse, IDisposable {
|
||||
[PublicAPI]
|
||||
public IDocument Content { get; }
|
||||
namespace ArchiSteamFarm.Web.Responses;
|
||||
|
||||
private HtmlDocumentResponse(BasicResponse basicResponse, IDocument content) : base(basicResponse) {
|
||||
if (basicResponse == null) {
|
||||
throw new ArgumentNullException(nameof(basicResponse));
|
||||
}
|
||||
public sealed class HtmlDocumentResponse : BasicResponse, IDisposable {
|
||||
[PublicAPI]
|
||||
public IDocument Content { get; }
|
||||
|
||||
Content = content ?? throw new ArgumentNullException(nameof(content));
|
||||
private HtmlDocumentResponse(BasicResponse basicResponse, IDocument content) : base(basicResponse) {
|
||||
if (basicResponse == null) {
|
||||
throw new ArgumentNullException(nameof(basicResponse));
|
||||
}
|
||||
|
||||
public void Dispose() => Content.Dispose();
|
||||
Content = content ?? throw new ArgumentNullException(nameof(content));
|
||||
}
|
||||
|
||||
[PublicAPI]
|
||||
public static async Task<HtmlDocumentResponse?> Create(StreamResponse streamResponse) {
|
||||
if (streamResponse == null) {
|
||||
throw new ArgumentNullException(nameof(streamResponse));
|
||||
}
|
||||
public void Dispose() => Content.Dispose();
|
||||
|
||||
IBrowsingContext context = BrowsingContext.New();
|
||||
[PublicAPI]
|
||||
public static async Task<HtmlDocumentResponse?> Create(StreamResponse streamResponse) {
|
||||
if (streamResponse == null) {
|
||||
throw new ArgumentNullException(nameof(streamResponse));
|
||||
}
|
||||
|
||||
try {
|
||||
IDocument document = await context.OpenAsync(req => req.Content(streamResponse.Content, true)).ConfigureAwait(false);
|
||||
IBrowsingContext context = BrowsingContext.New();
|
||||
|
||||
return new HtmlDocumentResponse(streamResponse, document);
|
||||
} catch (Exception e) {
|
||||
ASF.ArchiLogger.LogGenericWarningException(e);
|
||||
try {
|
||||
IDocument document = await context.OpenAsync(req => req.Content(streamResponse.Content, true)).ConfigureAwait(false);
|
||||
|
||||
return null;
|
||||
}
|
||||
return new HtmlDocumentResponse(streamResponse, document);
|
||||
} catch (Exception e) {
|
||||
ASF.ArchiLogger.LogGenericWarningException(e);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,17 +22,17 @@
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace ArchiSteamFarm.Web.Responses {
|
||||
public sealed class ObjectResponse<T> : BasicResponse {
|
||||
[PublicAPI]
|
||||
public T Content { get; }
|
||||
namespace ArchiSteamFarm.Web.Responses;
|
||||
|
||||
public ObjectResponse(BasicResponse basicResponse, T content) : base(basicResponse) {
|
||||
if (basicResponse == null) {
|
||||
throw new ArgumentNullException(nameof(basicResponse));
|
||||
}
|
||||
public sealed class ObjectResponse<T> : BasicResponse {
|
||||
[PublicAPI]
|
||||
public T Content { get; }
|
||||
|
||||
Content = content ?? throw new ArgumentNullException(nameof(content));
|
||||
public ObjectResponse(BasicResponse basicResponse, T content) : base(basicResponse) {
|
||||
if (basicResponse == null) {
|
||||
throw new ArgumentNullException(nameof(basicResponse));
|
||||
}
|
||||
|
||||
Content = content ?? throw new ArgumentNullException(nameof(content));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,27 +25,27 @@ using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace ArchiSteamFarm.Web.Responses {
|
||||
public sealed class StreamResponse : BasicResponse, IAsyncDisposable {
|
||||
[PublicAPI]
|
||||
public Stream Content { get; }
|
||||
namespace ArchiSteamFarm.Web.Responses;
|
||||
|
||||
[PublicAPI]
|
||||
public long Length { get; }
|
||||
public sealed class StreamResponse : BasicResponse, IAsyncDisposable {
|
||||
[PublicAPI]
|
||||
public Stream Content { get; }
|
||||
|
||||
private readonly HttpResponseMessage ResponseMessage;
|
||||
[PublicAPI]
|
||||
public long Length { get; }
|
||||
|
||||
internal StreamResponse(HttpResponseMessage httpResponseMessage, Stream content) : base(httpResponseMessage) {
|
||||
ResponseMessage = httpResponseMessage ?? throw new ArgumentNullException(nameof(httpResponseMessage));
|
||||
Content = content ?? throw new ArgumentNullException(nameof(content));
|
||||
private readonly HttpResponseMessage ResponseMessage;
|
||||
|
||||
Length = httpResponseMessage.Content.Headers.ContentLength.GetValueOrDefault();
|
||||
}
|
||||
internal StreamResponse(HttpResponseMessage httpResponseMessage, Stream content) : base(httpResponseMessage) {
|
||||
ResponseMessage = httpResponseMessage ?? throw new ArgumentNullException(nameof(httpResponseMessage));
|
||||
Content = content ?? throw new ArgumentNullException(nameof(content));
|
||||
|
||||
public async ValueTask DisposeAsync() {
|
||||
await Content.DisposeAsync().ConfigureAwait(false);
|
||||
Length = httpResponseMessage.Content.Headers.ContentLength.GetValueOrDefault();
|
||||
}
|
||||
|
||||
ResponseMessage.Dispose();
|
||||
}
|
||||
public async ValueTask DisposeAsync() {
|
||||
await Content.DisposeAsync().ConfigureAwait(false);
|
||||
|
||||
ResponseMessage.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,18 +23,18 @@ using System;
|
||||
using System.Net.Http;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace ArchiSteamFarm.Web.Responses {
|
||||
[Obsolete("ASF no longer uses this class, re-implement it yourself using " + nameof(BasicResponse) + " if needed.")]
|
||||
public sealed class StringResponse : BasicResponse {
|
||||
[PublicAPI]
|
||||
public string Content { get; }
|
||||
namespace ArchiSteamFarm.Web.Responses;
|
||||
|
||||
internal StringResponse(HttpResponseMessage httpResponseMessage, string content) : base(httpResponseMessage) {
|
||||
if (httpResponseMessage == null) {
|
||||
throw new ArgumentNullException(nameof(httpResponseMessage));
|
||||
}
|
||||
[Obsolete("ASF no longer uses this class, re-implement it yourself using " + nameof(BasicResponse) + " if needed.")]
|
||||
public sealed class StringResponse : BasicResponse {
|
||||
[PublicAPI]
|
||||
public string Content { get; }
|
||||
|
||||
Content = content ?? throw new ArgumentNullException(nameof(content));
|
||||
internal StringResponse(HttpResponseMessage httpResponseMessage, string content) : base(httpResponseMessage) {
|
||||
if (httpResponseMessage == null) {
|
||||
throw new ArgumentNullException(nameof(httpResponseMessage));
|
||||
}
|
||||
|
||||
Content = content ?? throw new ArgumentNullException(nameof(content));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,18 +23,18 @@ using System;
|
||||
using System.Xml;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace ArchiSteamFarm.Web.Responses {
|
||||
[Obsolete("ASF no longer uses any XML-related functions, re-implement it yourself using " + nameof(BasicResponse) + " if needed.")]
|
||||
public sealed class XmlDocumentResponse : BasicResponse {
|
||||
[PublicAPI]
|
||||
public XmlDocument Content { get; }
|
||||
namespace ArchiSteamFarm.Web.Responses;
|
||||
|
||||
public XmlDocumentResponse(BasicResponse basicResponse, XmlDocument content) : base(basicResponse) {
|
||||
if (basicResponse == null) {
|
||||
throw new ArgumentNullException(nameof(basicResponse));
|
||||
}
|
||||
[Obsolete("ASF no longer uses any XML-related functions, re-implement it yourself using " + nameof(BasicResponse) + " if needed.")]
|
||||
public sealed class XmlDocumentResponse : BasicResponse {
|
||||
[PublicAPI]
|
||||
public XmlDocument Content { get; }
|
||||
|
||||
Content = content ?? throw new ArgumentNullException(nameof(content));
|
||||
public XmlDocumentResponse(BasicResponse basicResponse, XmlDocument content) : base(basicResponse) {
|
||||
if (basicResponse == null) {
|
||||
throw new ArgumentNullException(nameof(basicResponse));
|
||||
}
|
||||
|
||||
Content = content ?? throw new ArgumentNullException(nameof(content));
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user