From d6ec91c89676760b552546d57b90e735efe080ee Mon Sep 17 00:00:00 2001 From: glax <--local> Date: Thu, 18 May 2023 12:26:15 +0200 Subject: [PATCH] Moved files Added DownloadClient to Connector --- Connector.cs | 9 ------- Tranga.sln | 2 +- Chapter.cs => Tranga/Chapter.cs | 0 Tranga/Connector.cs | 35 +++++++++++++++++++++++++ Publication.cs => Tranga/Publication.cs | 0 TaskManager.cs => Tranga/TaskManager.cs | 0 Tranga.csproj => Tranga/Tranga.csproj | 0 TrangaTask.cs => Tranga/TrangaTask.cs | 0 8 files changed, 36 insertions(+), 10 deletions(-) delete mode 100644 Connector.cs rename Chapter.cs => Tranga/Chapter.cs (100%) create mode 100644 Tranga/Connector.cs rename Publication.cs => Tranga/Publication.cs (100%) rename TaskManager.cs => Tranga/TaskManager.cs (100%) rename Tranga.csproj => Tranga/Tranga.csproj (100%) rename TrangaTask.cs => Tranga/TrangaTask.cs (100%) diff --git a/Connector.cs b/Connector.cs deleted file mode 100644 index a4655bf..0000000 --- a/Connector.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Tranga; - -public abstract class Connector -{ - public abstract string name { get; } - public abstract bool GetPublications(out Publication[] publications); - public abstract bool GetChapters(Publication publication, out Chapter[] chapters); - public abstract bool DownloadChapter(Chapter chapter); //where to? -} \ No newline at end of file diff --git a/Tranga.sln b/Tranga.sln index 7bd9c5d..4a0e686 100644 --- a/Tranga.sln +++ b/Tranga.sln @@ -1,6 +1,6 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tranga", "Tranga.csproj", "{545E81B9-D96B-4C8F-A97F-2C02414DE566}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tranga", ".\Tranga\Tranga.csproj", "{545E81B9-D96B-4C8F-A97F-2C02414DE566}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/Chapter.cs b/Tranga/Chapter.cs similarity index 100% rename from Chapter.cs rename to Tranga/Chapter.cs diff --git a/Tranga/Connector.cs b/Tranga/Connector.cs new file mode 100644 index 0000000..812a146 --- /dev/null +++ b/Tranga/Connector.cs @@ -0,0 +1,35 @@ +using System.Net; + +namespace Tranga; + +public abstract class Connector +{ + public abstract string name { get; } + public abstract bool GetPublications(out Publication[] publications); + public abstract bool GetChapters(Publication publication, out Chapter[] chapters); + public abstract bool DownloadChapter(Chapter chapter); //where to? + + internal class DownloadClient + { + static readonly HttpClient client = new HttpClient(); + public RequestResult GetPage(string url) + { + HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, url); + HttpResponseMessage response = client.Send(requestMessage); + Stream resultString = response.IsSuccessStatusCode ? response.Content.ReadAsStream() : Stream.Null; + return new RequestResult(response.StatusCode, resultString); + } + + public struct RequestResult + { + public HttpStatusCode statusCode { get; } + public Stream result { get; } + + public RequestResult(HttpStatusCode statusCode, Stream result) + { + this.statusCode = statusCode; + this.result = result; + } + } + } +} \ No newline at end of file diff --git a/Publication.cs b/Tranga/Publication.cs similarity index 100% rename from Publication.cs rename to Tranga/Publication.cs diff --git a/TaskManager.cs b/Tranga/TaskManager.cs similarity index 100% rename from TaskManager.cs rename to Tranga/TaskManager.cs diff --git a/Tranga.csproj b/Tranga/Tranga.csproj similarity index 100% rename from Tranga.csproj rename to Tranga/Tranga.csproj diff --git a/TrangaTask.cs b/Tranga/TrangaTask.cs similarity index 100% rename from TrangaTask.cs rename to Tranga/TrangaTask.cs