Skip to content

Commit

Permalink
Changed up the json stuff. Will start building out the files into the…
Browse files Browse the repository at this point in the history
… SRTPlugins repo next so work can begin on the version checking and 'marketplace/download center'.
  • Loading branch information
Squirrelies committed Mar 17, 2024
1 parent 62f261a commit aab3f41
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 20 deletions.
10 changes: 10 additions & 0 deletions src/SRTPluginBase/Helpers.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Net.Http;
using System.Threading.Tasks;
using System.Net.Http.Json;

namespace SRTPluginBase
{
Expand All @@ -23,5 +25,13 @@ public static Task MudSettingChanged<T>(Action<string, T> 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<T?> GetSRTJsonAsync<T>(this HttpClient client, string uri) => await GetSRTJsonAsync<T>(client, new Uri(uri, UriKind.RelativeOrAbsolute));
public static async Task<T?> GetSRTJsonAsync<T>(this HttpClient client, Uri uri)
{
HttpResponseMessage manifestsResult = await client.GetAsync(uri);
manifestsResult.EnsureSuccessStatusCode();
return await manifestsResult.Content.ReadFromJsonAsync<T>();
}
}
}
9 changes: 9 additions & 0 deletions src/SRTPluginBase/MainHostEntry.cs
Original file line number Diff line number Diff line change
@@ -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<ManifestEntryJson>(client, ManifestURL);
}
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
}
2 changes: 1 addition & 1 deletion src/SRTPluginBase/MainJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<MainHostEntry> Hosts { get; set; }
public IEnumerable<MainPluginEntry> Plugins { get; set; }
}
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
Expand Down
10 changes: 10 additions & 0 deletions src/SRTPluginBase/MainPluginEntry.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
using System;
using System.Collections.Generic;
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 MainPluginEntry
{
public string Name { get; set; }
public string Description { get; set; }
public MainPluginPlatformEnum Platform { get; set; }
public MainPluginTypeEnum Type { get; set; }
public IEnumerable<string> 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<ManifestEntryJson>(client, ManifestURL);
}
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> Contributors { get; set; }
public IEnumerable<ManifestReleaseJson> Releases { get; set; }
}
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
Expand Down
17 changes: 0 additions & 17 deletions src/SRTPluginBase/ManifestPluginJson.cs

This file was deleted.

3 changes: 2 additions & 1 deletion src/SRTPluginBase/SRTPluginBase.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand All @@ -46,6 +46,7 @@
<Private>false</Private>
<ExcludeAssets>runtime</ExcludeAssets>
</PackageReference>
<PackageReference Include="System.Net.Http.Json" Version="8.0.0" />
<PackageReference Include="System.Text.Json" Version="*" />
</ItemGroup>

Expand Down

0 comments on commit aab3f41

Please sign in to comment.