diff --git a/WindreamHub.sln b/WindreamHub.sln index 75b72cd..53e0130 100644 --- a/WindreamHub.sln +++ b/WindreamHub.sln @@ -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} diff --git a/src/WindreamHub.Legacy.Client/Models/ModelExtensions.cs b/src/WindreamHub.Legacy.Client/Models/ModelExtensions.cs new file mode 100644 index 0000000..630c774 --- /dev/null +++ b/src/WindreamHub.Legacy.Client/Models/ModelExtensions.cs @@ -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> Simplify(this HttpResponseMessage message) + { + TData data = message.IsSuccessStatusCode ? await message.Json() : default; + TError err = !message.IsSuccessStatusCode ? await message.Json() : default; + + return new SimplifiedResponse(ok: message.IsSuccessStatusCode, status: message.StatusCode, data: data, error: err); + } + + public static async Task Subscribe(this Task> responseAsync, Action next, Action error) + { + var res = await responseAsync; + if (res.Ok) + next(res.Data); + else + error(res.Error); + } + } +} \ No newline at end of file diff --git a/src/WindreamHub.Legacy.Client/Models/SimplifiedResponse.cs b/src/WindreamHub.Legacy.Client/Models/SimplifiedResponse.cs new file mode 100644 index 0000000..c42739a --- /dev/null +++ b/src/WindreamHub.Legacy.Client/Models/SimplifiedResponse.cs @@ -0,0 +1,20 @@ +using System.Net; + +namespace WindreamHub.Legacy.Client.Models +{ + public class SimplifiedResponse + { + 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; } + } +} \ No newline at end of file diff --git a/src/WindreamHub.Legacy.Client/Models/SystemDetails.cs b/src/WindreamHub.Legacy.Client/Models/SystemDetails.cs new file mode 100644 index 0000000..b1ab43b --- /dev/null +++ b/src/WindreamHub.Legacy.Client/Models/SystemDetails.cs @@ -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; } + } +} \ No newline at end of file diff --git a/src/WindreamHub.Legacy.Client/Models/SystemDetailsResponse.cs b/src/WindreamHub.Legacy.Client/Models/SystemDetailsResponse.cs new file mode 100644 index 0000000..7a52949 --- /dev/null +++ b/src/WindreamHub.Legacy.Client/Models/SystemDetailsResponse.cs @@ -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; } + } +} \ No newline at end of file diff --git a/src/WindreamHub.Legacy.Client/Routes/BaseRouteService.cs b/src/WindreamHub.Legacy.Client/Routes/BaseRouteService.cs index a2a8768..9b65199 100644 --- a/src/WindreamHub.Legacy.Client/Routes/BaseRouteService.cs +++ b/src/WindreamHub.Legacy.Client/Routes/BaseRouteService.cs @@ -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; } } } \ No newline at end of file diff --git a/src/WindreamHub.Legacy.Client/Routes/RouteExtensions.cs b/src/WindreamHub.Legacy.Client/Routes/RouteExtensions.cs index 025c8a2..8d7dcaf 100644 --- a/src/WindreamHub.Legacy.Client/Routes/RouteExtensions.cs +++ b/src/WindreamHub.Legacy.Client/Routes/RouteExtensions.cs @@ -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 diff --git a/src/WindreamHub.Legacy.Client/Routes/SystemDetailsRouteService.cs b/src/WindreamHub.Legacy.Client/Routes/SystemDetailsRouteService.cs index fc93c18..3aafcb1 100644 --- a/src/WindreamHub.Legacy.Client/Routes/SystemDetailsRouteService.cs +++ b/src/WindreamHub.Legacy.Client/Routes/SystemDetailsRouteService.cs @@ -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> GetSystemDetails() + => await FetchAsync(route: "/GetSystemDetails") + .ThenAsync(res => res.Simplify()); } } \ No newline at end of file diff --git a/src/WindreamHub.Legacy.Client/WindreamClientOptions.cs b/src/WindreamHub.Legacy.Client/WindreamClientOptions.cs index 58d7311..007a8da 100644 --- a/src/WindreamHub.Legacy.Client/WindreamClientOptions.cs +++ b/src/WindreamHub.Legacy.Client/WindreamClientOptions.cs @@ -7,8 +7,8 @@ namespace WindreamHub.Legacy.Client { public Dictionary Routes = new Dictionary() { - { "subscriptions", "/subscriptions" }, - { "systemDetails", "/systemDetails" } + { "Subscriptions", "/subscriptions" }, + { "SystemDetails", "/systemDetails" } }; } } \ No newline at end of file diff --git a/src/WindreamHub.Legacy.Client/WindreamHub.Legacy.Client.csproj b/src/WindreamHub.Legacy.Client/WindreamHub.Legacy.Client.csproj index 33d3d31..0ee7316 100644 --- a/src/WindreamHub.Legacy.Client/WindreamHub.Legacy.Client.csproj +++ b/src/WindreamHub.Legacy.Client/WindreamHub.Legacy.Client.csproj @@ -77,6 +77,10 @@ + + + +