From ce3a9f90dbbc0bd12388b5e0f4987c6ca1f2e5a8 Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Fri, 28 Jun 2024 02:42:38 +0200 Subject: [PATCH] =?UTF-8?q?Initialer=20Commit:=20Projekteinrichtung=20und?= =?UTF-8?q?=20erste=20Implementierung=20-=20Erstellte=20L=C3=B6sungsstrukt?= =?UTF-8?q?ur=20und=20Projektdateien=20-=20Hinzugef=C3=BCgte=20grundlegend?= =?UTF-8?q?e=20Abstraktionen=20und=20Client-Services=20-=20Implementierte?= =?UTF-8?q?=20anf=C3=A4ngliche=20Antwortverarbeitungsklassen=20-=20Einrich?= =?UTF-8?q?tung=20von=20Dependency=20Injection=20und=20Konfigurationsoptio?= =?UTF-8?q?nen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WindreamHub.sln | 7 ++++ .../Client/Endpoint.cs | 14 ++++++++ .../Client/IWindreamClientService.cs | 12 +++++++ .../Client/Response.cs | 6 ++++ .../WindreamHub.Abstractions.csproj | 4 +++ src/WindreamHub.Client/DIExtensions.cs | 24 ++++++++++++++ src/WindreamHub.Client/ResponseExtensions.cs | 24 ++++++++++++++ .../WindreamClientOptions.cs | 8 +++++ .../WindreamClientService.cs | 33 +++++++++++++++++++ .../WindreamHub.Client.csproj | 9 +++++ 10 files changed, 141 insertions(+) create mode 100644 src/WindreamHub.Abstractions/Client/Endpoint.cs create mode 100644 src/WindreamHub.Abstractions/Client/IWindreamClientService.cs create mode 100644 src/WindreamHub.Abstractions/Client/Response.cs create mode 100644 src/WindreamHub.Client/DIExtensions.cs create mode 100644 src/WindreamHub.Client/ResponseExtensions.cs create mode 100644 src/WindreamHub.Client/WindreamClientOptions.cs create mode 100644 src/WindreamHub.Client/WindreamClientService.cs diff --git a/WindreamHub.sln b/WindreamHub.sln index 0ef9456..a7637df 100644 --- a/WindreamHub.sln +++ b/WindreamHub.sln @@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WindreamHub.Abstractions", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WindreamHub.Client", "src\WindreamHub.Client\WindreamHub.Client.csproj", "{D499FEC3-FDDD-45F0-BEA2-025B533BCD21}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WindreamHub.ConsoleApp", "src\WindreamHub.ConsoleApp\WindreamHub.ConsoleApp.csproj", "{6EABACDA-161C-4F1F-97DD-349EDC6B0ECE}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -23,6 +25,10 @@ Global {D499FEC3-FDDD-45F0-BEA2-025B533BCD21}.Debug|Any CPU.Build.0 = Debug|Any CPU {D499FEC3-FDDD-45F0-BEA2-025B533BCD21}.Release|Any CPU.ActiveCfg = Release|Any CPU {D499FEC3-FDDD-45F0-BEA2-025B533BCD21}.Release|Any CPU.Build.0 = Release|Any CPU + {6EABACDA-161C-4F1F-97DD-349EDC6B0ECE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6EABACDA-161C-4F1F-97DD-349EDC6B0ECE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6EABACDA-161C-4F1F-97DD-349EDC6B0ECE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6EABACDA-161C-4F1F-97DD-349EDC6B0ECE}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -30,6 +36,7 @@ Global GlobalSection(NestedProjects) = preSolution {4C12B988-FEB8-4141-8CD2-1EA4AC3E9270} = {7BFFBEF2-6639-41F6-B6C2-D231FF719F57} {D499FEC3-FDDD-45F0-BEA2-025B533BCD21} = {7BFFBEF2-6639-41F6-B6C2-D231FF719F57} + {6EABACDA-161C-4F1F-97DD-349EDC6B0ECE} = {7BFFBEF2-6639-41F6-B6C2-D231FF719F57} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {C2C9327F-0E3C-40B5-B878-DA59F03CF150} diff --git a/src/WindreamHub.Abstractions/Client/Endpoint.cs b/src/WindreamHub.Abstractions/Client/Endpoint.cs new file mode 100644 index 0000000..3b72a73 --- /dev/null +++ b/src/WindreamHub.Abstractions/Client/Endpoint.cs @@ -0,0 +1,14 @@ +namespace WindreamHub.Abstractions.Client +{ + public record BaseEndpoint(string Route); + + public record SystemDetails(string Route) : BaseEndpoint(Route) + { + public required Func>> GetAsync { get; init; } + } + + public record Subscriptions(string Route) : BaseEndpoint(Route) + { + public required Func>> GetEventsAsync { get; init; } + } +} \ No newline at end of file diff --git a/src/WindreamHub.Abstractions/Client/IWindreamClientService.cs b/src/WindreamHub.Abstractions/Client/IWindreamClientService.cs new file mode 100644 index 0000000..36e097d --- /dev/null +++ b/src/WindreamHub.Abstractions/Client/IWindreamClientService.cs @@ -0,0 +1,12 @@ +using DigitalData.Core.Abstractions.Client; +using System.ComponentModel.Design; + +namespace WindreamHub.Abstractions.Client +{ + public interface IWindreamClientService : IBaseHttpClientService + { + public Subscriptions Subscriptions { get; } + + public SystemDetails SystemDetails { get; } + } +} \ No newline at end of file diff --git a/src/WindreamHub.Abstractions/Client/Response.cs b/src/WindreamHub.Abstractions/Client/Response.cs new file mode 100644 index 0000000..6975df0 --- /dev/null +++ b/src/WindreamHub.Abstractions/Client/Response.cs @@ -0,0 +1,6 @@ +using System.Net; + +namespace WindreamHub.Abstractions.Client +{ + public record SimplifiedResponse(bool Ok, HttpStatusCode Status, TData Data, TError Error); +} \ No newline at end of file diff --git a/src/WindreamHub.Abstractions/WindreamHub.Abstractions.csproj b/src/WindreamHub.Abstractions/WindreamHub.Abstractions.csproj index cfadb03..e60c928 100644 --- a/src/WindreamHub.Abstractions/WindreamHub.Abstractions.csproj +++ b/src/WindreamHub.Abstractions/WindreamHub.Abstractions.csproj @@ -6,4 +6,8 @@ enable + + + + diff --git a/src/WindreamHub.Client/DIExtensions.cs b/src/WindreamHub.Client/DIExtensions.cs new file mode 100644 index 0000000..d0de556 --- /dev/null +++ b/src/WindreamHub.Client/DIExtensions.cs @@ -0,0 +1,24 @@ +using DigitalData.Core.Client; +using Microsoft.Extensions.DependencyInjection; +using WindreamHub.Abstractions.Client; + +namespace WindreamHub.Client +{ + public static class DIExtensions + { + public static IServiceCollection AddWindreamClientService(this IServiceCollection services, string uri, bool useAbstract = true) + { + services.AddHttpClientService(opt => + { + opt.Uri = uri; + }); + + if (useAbstract) + services.AddSingleton(); + else + services.AddSingleton(); + + return services; + } + } +} \ No newline at end of file diff --git a/src/WindreamHub.Client/ResponseExtensions.cs b/src/WindreamHub.Client/ResponseExtensions.cs new file mode 100644 index 0000000..9bf3994 --- /dev/null +++ b/src/WindreamHub.Client/ResponseExtensions.cs @@ -0,0 +1,24 @@ +using DigitalData.Core.Client; +using WindreamHub.Abstractions.Client; + +namespace WindreamHub.Client +{ + public static class ResponseExtensions + { + public static async Task> SimplifyDynamic(this HttpResponseMessage message) + { + dynamic data = message.IsSuccessStatusCode ? await message.Json() : new { }; + dynamic err = message.IsSuccessStatusCode ? await message.Json() : new { }; + + return new (Ok: message.IsSuccessStatusCode,Status: message.StatusCode, Data: data, Error: err); + } + + public static async Task, dynamic>> SimplifyDynamicList(this HttpResponseMessage message) + { + dynamic data = message.IsSuccessStatusCode ? await message.JsonList() : new { }; + dynamic err = message.IsSuccessStatusCode ? await message.Json() : new { }; + + return new(Ok: message.IsSuccessStatusCode, Status: message.StatusCode, Data: data, Error: err); + } + } +} \ No newline at end of file diff --git a/src/WindreamHub.Client/WindreamClientOptions.cs b/src/WindreamHub.Client/WindreamClientOptions.cs new file mode 100644 index 0000000..510e433 --- /dev/null +++ b/src/WindreamHub.Client/WindreamClientOptions.cs @@ -0,0 +1,8 @@ +using DigitalData.Core.Client; + +namespace WindreamHub.Client +{ + public class WindreamClientOptions : HttpClientOptions + { + } +} \ No newline at end of file diff --git a/src/WindreamHub.Client/WindreamClientService.cs b/src/WindreamHub.Client/WindreamClientService.cs new file mode 100644 index 0000000..2760cba --- /dev/null +++ b/src/WindreamHub.Client/WindreamClientService.cs @@ -0,0 +1,33 @@ +using DigitalData.Core.Abstractions.Client; +using DigitalData.Core.Client; +using Microsoft.Extensions.Options; +using System.Net; +using WindreamHub.Abstractions.Client; + +namespace WindreamHub.Client +{ + public class WindreamClientService : + HttpClientService, + IWindreamClientService, + IHttpClientService + { + public WindreamClientService(HttpClient client, CookieContainer cookieContainer, IOptions clientOptions) : base(client, cookieContainer, clientOptions) + { + Subscriptions = new(Route: "subscriptions") + { + GetEventsAsync = async () => await FetchAsync($"/{Subscriptions!.Route}/GetSubscriptionEvents") + .ThenAsync(res => res.SimplifyDynamic()) + }; + + SystemDetails = new(Route: "systemDetails") + { + GetAsync = async () => await FetchAsync($"/{SystemDetails!.Route}/GetSystemDetails") + .ThenAsync(res => res.SimplifyDynamic()) + }; + } + + public Subscriptions Subscriptions { get; } + + public SystemDetails SystemDetails { get; } + } +} \ No newline at end of file diff --git a/src/WindreamHub.Client/WindreamHub.Client.csproj b/src/WindreamHub.Client/WindreamHub.Client.csproj index cfadb03..99b7eed 100644 --- a/src/WindreamHub.Client/WindreamHub.Client.csproj +++ b/src/WindreamHub.Client/WindreamHub.Client.csproj @@ -6,4 +6,13 @@ enable + + + + + + + + +