feat: Integration von SimplifiedResponse und seiner Erweiterung abgeschlossen
- Methode ähnlich zu Angular's Subscribe für verbesserte asynchrone Verarbeitung implementiert. - Modelle erstellt und Methoden für den GetSystemDetails-Endpunkt hinzugefügt.
This commit is contained in:
parent
31ac95ab24
commit
353088a6b2
@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WindreamHub.Client", "src\W
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WindreamHub.Legacy.Client", "src\WindreamHub.Legacy.Client\WindreamHub.Legacy.Client.csproj", "{67E6A3A1-F863-417E-9619-DC9B6A710512}"
|
||||
EndProject
|
||||
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "WindreamHub.Legacy.ConsoleApp", "src\WindreamHub.Legacy.ConsoleApp\WindreamHub.Legacy.ConsoleApp.vbproj", "{DE6A7FB2-87D6-471E-8019-DF6E196FA471}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -29,6 +31,10 @@ Global
|
||||
{67E6A3A1-F863-417E-9619-DC9B6A710512}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{67E6A3A1-F863-417E-9619-DC9B6A710512}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{67E6A3A1-F863-417E-9619-DC9B6A710512}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{DE6A7FB2-87D6-471E-8019-DF6E196FA471}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{DE6A7FB2-87D6-471E-8019-DF6E196FA471}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{DE6A7FB2-87D6-471E-8019-DF6E196FA471}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{DE6A7FB2-87D6-471E-8019-DF6E196FA471}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@ -37,6 +43,7 @@ Global
|
||||
{4C12B988-FEB8-4141-8CD2-1EA4AC3E9270} = {7BFFBEF2-6639-41F6-B6C2-D231FF719F57}
|
||||
{D499FEC3-FDDD-45F0-BEA2-025B533BCD21} = {7BFFBEF2-6639-41F6-B6C2-D231FF719F57}
|
||||
{67E6A3A1-F863-417E-9619-DC9B6A710512} = {7BFFBEF2-6639-41F6-B6C2-D231FF719F57}
|
||||
{DE6A7FB2-87D6-471E-8019-DF6E196FA471} = {7BFFBEF2-6639-41F6-B6C2-D231FF719F57}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {C2C9327F-0E3C-40B5-B878-DA59F03CF150}
|
||||
|
||||
28
src/WindreamHub.Legacy.Client/Models/ModelExtensions.cs
Normal file
28
src/WindreamHub.Legacy.Client/Models/ModelExtensions.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using DigitalData.Core.Legacy.Client;
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using static System.Net.Mime.MediaTypeNames;
|
||||
|
||||
namespace WindreamHub.Legacy.Client.Models
|
||||
{
|
||||
public static class ModelExtensions
|
||||
{
|
||||
public static async Task<SimplifiedResponse<TData, TError>> Simplify<TData, TError>(this HttpResponseMessage message)
|
||||
{
|
||||
TData data = message.IsSuccessStatusCode ? await message.Json<TData>() : default;
|
||||
TError err = !message.IsSuccessStatusCode ? await message.Json<TError>() : default;
|
||||
|
||||
return new SimplifiedResponse<TData, TError>(ok: message.IsSuccessStatusCode, status: message.StatusCode, data: data, error: err);
|
||||
}
|
||||
|
||||
public static async Task Subscribe<TData, TError>(this Task<SimplifiedResponse<TData, TError>> responseAsync, Action<TData> next, Action<TError> error)
|
||||
{
|
||||
var res = await responseAsync;
|
||||
if (res.Ok)
|
||||
next(res.Data);
|
||||
else
|
||||
error(res.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
20
src/WindreamHub.Legacy.Client/Models/SimplifiedResponse.cs
Normal file
20
src/WindreamHub.Legacy.Client/Models/SimplifiedResponse.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System.Net;
|
||||
|
||||
namespace WindreamHub.Legacy.Client.Models
|
||||
{
|
||||
public class SimplifiedResponse<TData, TError>
|
||||
{
|
||||
public SimplifiedResponse(bool ok, HttpStatusCode status, TData data, TError error)
|
||||
{
|
||||
Ok = ok;
|
||||
Status = status;
|
||||
Data = data;
|
||||
Error = error;
|
||||
}
|
||||
|
||||
public bool Ok { get; }
|
||||
public HttpStatusCode Status { get; }
|
||||
public TData Data { get; }
|
||||
public TError Error { get; }
|
||||
}
|
||||
}
|
||||
13
src/WindreamHub.Legacy.Client/Models/SystemDetails.cs
Normal file
13
src/WindreamHub.Legacy.Client/Models/SystemDetails.cs
Normal file
@ -0,0 +1,13 @@
|
||||
namespace WindreamHub.Legacy.Client.Models
|
||||
{
|
||||
public class SystemDetails
|
||||
{
|
||||
public string SystemDateTime { get; set; }
|
||||
|
||||
public string WebserviceVersion { get; set; }
|
||||
|
||||
public string DefaultDomain { get; set; }
|
||||
|
||||
public int AuthenticationModes { get; set; }
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
namespace WindreamHub.Legacy.Client.Models
|
||||
{
|
||||
public class SystemDetailsResponse
|
||||
{
|
||||
public SystemDetails SystemDetails { get; set; }
|
||||
|
||||
public object Error { get; set; }
|
||||
|
||||
public object Errors { get; set; }
|
||||
|
||||
public bool HasErrors { get; set; }
|
||||
}
|
||||
}
|
||||
@ -18,7 +18,7 @@ namespace WindreamHub.Legacy.Client.Routes
|
||||
if(route is null)
|
||||
throw new InvalidOperationException($"Route not found for the route name: {route_name}.");
|
||||
|
||||
Uri = route;
|
||||
Uri += route;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -22,11 +22,7 @@ namespace WindreamHub.Legacy.Client.Routes
|
||||
{
|
||||
// Remove the "RouteService" part
|
||||
string prefix = className.Substring(0, className.Length - suffix.Length);
|
||||
// Convert the first letter to lowercase
|
||||
if (prefix.Length > 0)
|
||||
{
|
||||
prefix = char.ToLower(prefix[0]) + prefix.Substring(1);
|
||||
}
|
||||
|
||||
return prefix;
|
||||
}
|
||||
else
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
using Microsoft.Extensions.Options;
|
||||
using DigitalData.Core.Legacy.Client;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using WindreamHub.Legacy.Client.Models;
|
||||
using WindreamHub.Legacy.Client.Routes;
|
||||
|
||||
namespace WindreamHub.Legacy.Client.Route
|
||||
@ -11,5 +14,9 @@ namespace WindreamHub.Legacy.Client.Route
|
||||
base(client, cookieContainer, clientOptions)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<SimplifiedResponse<SystemDetailsResponse, object>> GetSystemDetails()
|
||||
=> await FetchAsync(route: "/GetSystemDetails")
|
||||
.ThenAsync(res => res.Simplify<SystemDetailsResponse, object>());
|
||||
}
|
||||
}
|
||||
@ -7,8 +7,8 @@ namespace WindreamHub.Legacy.Client
|
||||
{
|
||||
public Dictionary<string, string> Routes = new Dictionary<string, string>()
|
||||
{
|
||||
{ "subscriptions", "/subscriptions" },
|
||||
{ "systemDetails", "/systemDetails" }
|
||||
{ "Subscriptions", "/subscriptions" },
|
||||
{ "SystemDetails", "/systemDetails" }
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -77,6 +77,10 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="DIExtensions.cs" />
|
||||
<Compile Include="Models\ModelExtensions.cs" />
|
||||
<Compile Include="Models\SimplifiedResponse.cs" />
|
||||
<Compile Include="Models\SystemDetails.cs" />
|
||||
<Compile Include="Models\SystemDetailsResponse.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Routes\BaseRouteService.cs" />
|
||||
<Compile Include="Routes\RouteExtensions.cs" />
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user