From aab3f41024acc07ff38a53e71f3c258b8b8fddb4 Mon Sep 17 00:00:00 2001 From: "Travis J. Gutjahr" <33809229+Squirrelies@users.noreply.github.com> Date: Sat, 16 Mar 2024 23:19:37 -0500 Subject: [PATCH] Changed up the json stuff. Will start building out the files into the SRTPlugins repo next so work can begin on the version checking and 'marketplace/download center'. --- src/SRTPluginBase/Helpers.cs | 10 ++++++++++ src/SRTPluginBase/MainHostEntry.cs | 9 +++++++++ src/SRTPluginBase/MainJson.cs | 2 +- src/SRTPluginBase/MainPluginEntry.cs | 10 ++++++++++ ...ManifestHostJson.cs => ManifestEntryJson.cs} | 3 ++- src/SRTPluginBase/ManifestPluginJson.cs | 17 ----------------- src/SRTPluginBase/SRTPluginBase.csproj | 3 ++- 7 files changed, 34 insertions(+), 20 deletions(-) rename src/SRTPluginBase/{ManifestHostJson.cs => ManifestEntryJson.cs} (81%) delete mode 100644 src/SRTPluginBase/ManifestPluginJson.cs diff --git a/src/SRTPluginBase/Helpers.cs b/src/SRTPluginBase/Helpers.cs index 4114f25..7544d78 100644 --- a/src/SRTPluginBase/Helpers.cs +++ b/src/SRTPluginBase/Helpers.cs @@ -1,5 +1,7 @@ using System; +using System.Net.Http; using System.Threading.Tasks; +using System.Net.Http.Json; namespace SRTPluginBase { @@ -23,5 +25,13 @@ public static Task MudSettingChanged(Action action, string name, T cascadingStateChanger?.NotifyStateChanged(); // Allows us to re-render another component (NavMenu) from this component. StateHasChanged alone does not allow us to do that. return Task.CompletedTask; } + + public static async Task GetSRTJsonAsync(this HttpClient client, string uri) => await GetSRTJsonAsync(client, new Uri(uri, UriKind.RelativeOrAbsolute)); + public static async Task GetSRTJsonAsync(this HttpClient client, Uri uri) + { + HttpResponseMessage manifestsResult = await client.GetAsync(uri); + manifestsResult.EnsureSuccessStatusCode(); + return await manifestsResult.Content.ReadFromJsonAsync(); + } } } diff --git a/src/SRTPluginBase/MainHostEntry.cs b/src/SRTPluginBase/MainHostEntry.cs index 2ecec16..a3bc429 100644 --- a/src/SRTPluginBase/MainHostEntry.cs +++ b/src/SRTPluginBase/MainHostEntry.cs @@ -1,11 +1,20 @@ using System; +using System.Net.Http; +using System.Threading.Tasks; namespace SRTPluginBase { #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. public class MainHostEntry { + public string Name { get; set; } + public string Description { get; set; } + public Uri RepoURL { get; set; } public Uri ManifestURL { get; set; } + + [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Always)] + public ManifestEntryJson? Manifest { get; private set; } + public async Task SetManifestAsync(HttpClient client) => Manifest = await Helpers.GetSRTJsonAsync(client, ManifestURL); } #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. } diff --git a/src/SRTPluginBase/MainJson.cs b/src/SRTPluginBase/MainJson.cs index 0103f6d..f9e463c 100644 --- a/src/SRTPluginBase/MainJson.cs +++ b/src/SRTPluginBase/MainJson.cs @@ -5,7 +5,7 @@ namespace SRTPluginBase #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. public class MainJson { - public MainHostEntry Host { get; set; } + public IEnumerable Hosts { get; set; } public IEnumerable Plugins { get; set; } } #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. diff --git a/src/SRTPluginBase/MainPluginEntry.cs b/src/SRTPluginBase/MainPluginEntry.cs index 3c3ad85..73ae53a 100644 --- a/src/SRTPluginBase/MainPluginEntry.cs +++ b/src/SRTPluginBase/MainPluginEntry.cs @@ -1,4 +1,7 @@ using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Threading.Tasks; namespace SRTPluginBase { @@ -6,9 +9,16 @@ namespace SRTPluginBase public class MainPluginEntry { public string Name { get; set; } + public string Description { get; set; } public MainPluginPlatformEnum Platform { get; set; } public MainPluginTypeEnum Type { get; set; } + public IEnumerable Tags { get; set; } + public Uri RepoURL { get; set; } public Uri ManifestURL { get; set; } + + [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Always)] + public ManifestEntryJson? Manifest { get; private set; } + public async Task SetManifestAsync(HttpClient client) => Manifest = await Helpers.GetSRTJsonAsync(client, ManifestURL); } #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. } diff --git a/src/SRTPluginBase/ManifestHostJson.cs b/src/SRTPluginBase/ManifestEntryJson.cs similarity index 81% rename from src/SRTPluginBase/ManifestHostJson.cs rename to src/SRTPluginBase/ManifestEntryJson.cs index ccb7216..fd963f5 100644 --- a/src/SRTPluginBase/ManifestHostJson.cs +++ b/src/SRTPluginBase/ManifestEntryJson.cs @@ -3,8 +3,9 @@ namespace SRTPluginBase { #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. - public class ManifestHostJson + public class ManifestEntryJson { + public IEnumerable Contributors { get; set; } public IEnumerable Releases { get; set; } } #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. diff --git a/src/SRTPluginBase/ManifestPluginJson.cs b/src/SRTPluginBase/ManifestPluginJson.cs deleted file mode 100644 index ea47ad6..0000000 --- a/src/SRTPluginBase/ManifestPluginJson.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace SRTPluginBase -{ -#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. - public class ManifestPluginJson - { - public string Name { get; set; } - public string Description { get; set; } - public Uri RepoURL { get; set; } - public IEnumerable Contributors { get; set; } - public IEnumerable Tags { get; set; } - public IEnumerable Releases { get; set; } - } -#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. -} diff --git a/src/SRTPluginBase/SRTPluginBase.csproj b/src/SRTPluginBase/SRTPluginBase.csproj index 6668679..0112330 100644 --- a/src/SRTPluginBase/SRTPluginBase.csproj +++ b/src/SRTPluginBase/SRTPluginBase.csproj @@ -37,7 +37,7 @@ - + all runtime; build; native; contentfiles; analyzers @@ -46,6 +46,7 @@ false runtime +