Initialer Commit: Projekteinrichtung und erste Implementierung

- Erstellte Lösungsstruktur und Projektdateien
- Hinzugefügte grundlegende Abstraktionen und Client-Services
- Implementierte anfängliche Antwortverarbeitungsklassen
- Einrichtung von Dependency Injection und Konfigurationsoptionen
This commit is contained in:
Developer 02
2024-06-28 02:42:38 +02:00
parent 5cd343216a
commit ce3a9f90db
10 changed files with 141 additions and 0 deletions

View File

@@ -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}

View File

@@ -0,0 +1,14 @@
namespace WindreamHub.Abstractions.Client
{
public record BaseEndpoint(string Route);
public record SystemDetails(string Route) : BaseEndpoint(Route)
{
public required Func<Task<SimplifiedResponse<dynamic, dynamic>>> GetAsync { get; init; }
}
public record Subscriptions(string Route) : BaseEndpoint(Route)
{
public required Func<Task<SimplifiedResponse<dynamic, dynamic>>> GetEventsAsync { get; init; }
}
}

View File

@@ -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; }
}
}

View File

@@ -0,0 +1,6 @@
using System.Net;
namespace WindreamHub.Abstractions.Client
{
public record SimplifiedResponse<TData, TError>(bool Ok, HttpStatusCode Status, TData Data, TError Error);
}

View File

@@ -6,4 +6,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DigitalData.Core.Abstractions" Version="1.0.1.1" />
</ItemGroup>
</Project>

View File

@@ -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<WindreamClientOptions>(opt =>
{
opt.Uri = uri;
});
if (useAbstract)
services.AddSingleton<IWindreamClientService, WindreamClientService>();
else
services.AddSingleton<WindreamClientService>();
return services;
}
}
}

View File

@@ -0,0 +1,24 @@
using DigitalData.Core.Client;
using WindreamHub.Abstractions.Client;
namespace WindreamHub.Client
{
public static class ResponseExtensions
{
public static async Task<SimplifiedResponse<dynamic, dynamic>> 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<SimplifiedResponse<IEnumerable<dynamic>, 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);
}
}
}

View File

@@ -0,0 +1,8 @@
using DigitalData.Core.Client;
namespace WindreamHub.Client
{
public class WindreamClientOptions : HttpClientOptions
{
}
}

View File

@@ -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<WindreamClientOptions>,
IWindreamClientService,
IHttpClientService<WindreamClientOptions>
{
public WindreamClientService(HttpClient client, CookieContainer cookieContainer, IOptions<WindreamClientOptions> 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; }
}
}

View File

@@ -6,4 +6,13 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DigitalData.Core.Abstractions" Version="1.0.1.1" />
<PackageReference Include="DigitalData.Core.Client" Version="1.0.1.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\WindreamHub.Abstractions\WindreamHub.Abstractions.csproj" />
</ItemGroup>
</Project>