From 3538ae5d18da830bd9bf7402b9ec37597f0e3767 Mon Sep 17 00:00:00 2001
From: "Travis J. Gutjahr" <33809229+Squirrelies@users.noreply.github.com>
Date: Sun, 17 Mar 2024 02:23:07 -0500
Subject: [PATCH] Restructured a bit. Added interfaces to a few of the classes.
---
src/SRTPluginBase/IPluginHost.cs | 15 -----
.../{ => Implementations}/MainHostEntry.cs | 8 ++-
.../{ => Implementations}/MainJson.cs | 9 +--
.../{ => Implementations}/MainPluginEntry.cs | 11 ++--
.../MainPluginPlatformEnum.cs | 2 +-
.../MainPluginTypeEnum.cs | 2 +-
.../ManifestEntryJson.cs | 7 ++-
.../ManifestReleaseJson.cs | 5 +-
src/SRTPluginBase/Interfaces/IMainEntry.cs | 58 +++++++++++++++++++
.../Interfaces/IMainHostEntry.cs | 6 ++
src/SRTPluginBase/Interfaces/IMainJson.cs | 21 +++++++
.../Interfaces/IMainPluginEntry.cs | 27 +++++++++
.../Interfaces/IManifestEntryJson.cs | 21 +++++++
.../Interfaces/IManifestReleaseJson.cs | 21 +++++++
src/SRTPluginBase/{ => Interfaces}/IPlugin.cs | 2 +-
.../{ => Interfaces}/IPluginConfiguration.cs | 2 +-
.../{ => Interfaces}/IPluginConsumer.cs | 2 +-
src/SRTPluginBase/Interfaces/IPluginHost.cs | 15 +++++
.../{ => Interfaces}/IPluginInfo.cs | 3 +-
.../{ => Interfaces}/IPluginProducer.cs | 2 +-
src/SRTPluginBase/PluginBase.cs | 1 +
src/SRTPluginBase/PluginInfoBase.cs | 1 +
22 files changed, 202 insertions(+), 39 deletions(-)
delete mode 100644 src/SRTPluginBase/IPluginHost.cs
rename src/SRTPluginBase/{ => Implementations}/MainHostEntry.cs (76%)
rename src/SRTPluginBase/{ => Implementations}/MainJson.cs (58%)
rename src/SRTPluginBase/{ => Implementations}/MainPluginEntry.cs (71%)
rename src/SRTPluginBase/{ => Implementations}/MainPluginPlatformEnum.cs (78%)
rename src/SRTPluginBase/{ => Implementations}/MainPluginTypeEnum.cs (70%)
rename src/SRTPluginBase/{ => Implementations}/ManifestEntryJson.cs (66%)
rename src/SRTPluginBase/{ => Implementations}/ManifestReleaseJson.cs (75%)
create mode 100644 src/SRTPluginBase/Interfaces/IMainEntry.cs
create mode 100644 src/SRTPluginBase/Interfaces/IMainHostEntry.cs
create mode 100644 src/SRTPluginBase/Interfaces/IMainJson.cs
create mode 100644 src/SRTPluginBase/Interfaces/IMainPluginEntry.cs
create mode 100644 src/SRTPluginBase/Interfaces/IManifestEntryJson.cs
create mode 100644 src/SRTPluginBase/Interfaces/IManifestReleaseJson.cs
rename src/SRTPluginBase/{ => Interfaces}/IPlugin.cs (98%)
rename src/SRTPluginBase/{ => Interfaces}/IPluginConfiguration.cs (60%)
rename src/SRTPluginBase/{ => Interfaces}/IPluginConsumer.cs (88%)
create mode 100644 src/SRTPluginBase/Interfaces/IPluginHost.cs
rename src/SRTPluginBase/{ => Interfaces}/IPluginInfo.cs (97%)
rename src/SRTPluginBase/{ => Interfaces}/IPluginProducer.cs (92%)
diff --git a/src/SRTPluginBase/IPluginHost.cs b/src/SRTPluginBase/IPluginHost.cs
deleted file mode 100644
index afe22fd..0000000
--- a/src/SRTPluginBase/IPluginHost.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-using Microsoft.Extensions.Hosting;
-
-namespace SRTPluginBase
-{
- public interface IPluginHost : IHostedService
- {
- ///
- /// Retrieves a loaded plugin by name.
- ///
- /// The type of plugin to retrieve.
- /// The plugin's name.
- /// The requested plugin, or null if not loaded.
- T? GetPluginReference(string pluginName) where T : class, IPlugin;
- }
-}
diff --git a/src/SRTPluginBase/MainHostEntry.cs b/src/SRTPluginBase/Implementations/MainHostEntry.cs
similarity index 76%
rename from src/SRTPluginBase/MainHostEntry.cs
rename to src/SRTPluginBase/Implementations/MainHostEntry.cs
index a3bc429..15b24a2 100644
--- a/src/SRTPluginBase/MainHostEntry.cs
+++ b/src/SRTPluginBase/Implementations/MainHostEntry.cs
@@ -1,20 +1,22 @@
using System;
using System.Net.Http;
using System.Threading.Tasks;
+using SRTPluginBase.Interfaces;
-namespace SRTPluginBase
+namespace SRTPluginBase.Implementations
{
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
- public class MainHostEntry
+ public class MainHostEntry : IMainHostEntry
{
public string Name { get; set; }
+ public string DisplayName { 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);
+ public async Task SetManifestAsync(HttpClient client) => Manifest = await client.GetSRTJsonAsync(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/Implementations/MainJson.cs
similarity index 58%
rename from src/SRTPluginBase/MainJson.cs
rename to src/SRTPluginBase/Implementations/MainJson.cs
index f9e463c..9876d14 100644
--- a/src/SRTPluginBase/MainJson.cs
+++ b/src/SRTPluginBase/Implementations/MainJson.cs
@@ -1,12 +1,13 @@
using System.Collections.Generic;
+using SRTPluginBase.Interfaces;
-namespace SRTPluginBase
+namespace SRTPluginBase.Implementations
{
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
- public class MainJson
+ public class MainJson : IMainJson
{
- public IEnumerable Hosts { get; set; }
- public IEnumerable Plugins { 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/Implementations/MainPluginEntry.cs
similarity index 71%
rename from src/SRTPluginBase/MainPluginEntry.cs
rename to src/SRTPluginBase/Implementations/MainPluginEntry.cs
index 73ae53a..3be3a79 100644
--- a/src/SRTPluginBase/MainPluginEntry.cs
+++ b/src/SRTPluginBase/Implementations/MainPluginEntry.cs
@@ -1,14 +1,17 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
+using System.Text.Json.Serialization;
using System.Threading.Tasks;
+using SRTPluginBase.Interfaces;
-namespace SRTPluginBase
+namespace SRTPluginBase.Implementations
{
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
- public class MainPluginEntry
+ public class MainPluginEntry : IMainPluginEntry
{
public string Name { get; set; }
+ public string DisplayName { get; set; }
public string Description { get; set; }
public MainPluginPlatformEnum Platform { get; set; }
public MainPluginTypeEnum Type { get; set; }
@@ -16,9 +19,9 @@ public class MainPluginEntry
public Uri RepoURL { get; set; }
public Uri ManifestURL { get; set; }
- [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Always)]
+ public async Task SetManifestAsync(HttpClient client) => Manifest = await client.GetSRTJsonAsync(ManifestURL);
+ [JsonIgnore(Condition = 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/MainPluginPlatformEnum.cs b/src/SRTPluginBase/Implementations/MainPluginPlatformEnum.cs
similarity index 78%
rename from src/SRTPluginBase/MainPluginPlatformEnum.cs
rename to src/SRTPluginBase/Implementations/MainPluginPlatformEnum.cs
index fdb0c13..6646cd0 100644
--- a/src/SRTPluginBase/MainPluginPlatformEnum.cs
+++ b/src/SRTPluginBase/Implementations/MainPluginPlatformEnum.cs
@@ -1,4 +1,4 @@
-namespace SRTPluginBase
+namespace SRTPluginBase.Implementations
{
public enum MainPluginPlatformEnum : int
{
diff --git a/src/SRTPluginBase/MainPluginTypeEnum.cs b/src/SRTPluginBase/Implementations/MainPluginTypeEnum.cs
similarity index 70%
rename from src/SRTPluginBase/MainPluginTypeEnum.cs
rename to src/SRTPluginBase/Implementations/MainPluginTypeEnum.cs
index d173b5b..c6eb56b 100644
--- a/src/SRTPluginBase/MainPluginTypeEnum.cs
+++ b/src/SRTPluginBase/Implementations/MainPluginTypeEnum.cs
@@ -1,4 +1,4 @@
-namespace SRTPluginBase
+namespace SRTPluginBase.Implementations
{
public enum MainPluginTypeEnum : int
{
diff --git a/src/SRTPluginBase/ManifestEntryJson.cs b/src/SRTPluginBase/Implementations/ManifestEntryJson.cs
similarity index 66%
rename from src/SRTPluginBase/ManifestEntryJson.cs
rename to src/SRTPluginBase/Implementations/ManifestEntryJson.cs
index fd963f5..4396413 100644
--- a/src/SRTPluginBase/ManifestEntryJson.cs
+++ b/src/SRTPluginBase/Implementations/ManifestEntryJson.cs
@@ -1,12 +1,13 @@
using System.Collections.Generic;
+using SRTPluginBase.Interfaces;
-namespace SRTPluginBase
+namespace SRTPluginBase.Implementations
{
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
- public class ManifestEntryJson
+ public class ManifestEntryJson : IManifestEntryJson
{
public IEnumerable Contributors { get; set; }
- public IEnumerable Releases { 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/ManifestReleaseJson.cs b/src/SRTPluginBase/Implementations/ManifestReleaseJson.cs
similarity index 75%
rename from src/SRTPluginBase/ManifestReleaseJson.cs
rename to src/SRTPluginBase/Implementations/ManifestReleaseJson.cs
index 7576d64..a160326 100644
--- a/src/SRTPluginBase/ManifestReleaseJson.cs
+++ b/src/SRTPluginBase/Implementations/ManifestReleaseJson.cs
@@ -1,9 +1,10 @@
using System;
+using SRTPluginBase.Interfaces;
-namespace SRTPluginBase
+namespace SRTPluginBase.Implementations
{
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
- public class ManifestReleaseJson
+ public class ManifestReleaseJson : IManifestReleaseJson
{
public string Version { get; set; }
public Uri DownloadURL { get; set; }
diff --git a/src/SRTPluginBase/Interfaces/IMainEntry.cs b/src/SRTPluginBase/Interfaces/IMainEntry.cs
new file mode 100644
index 0000000..ed8a847
--- /dev/null
+++ b/src/SRTPluginBase/Interfaces/IMainEntry.cs
@@ -0,0 +1,58 @@
+using System.Net.Http;
+using System.Threading.Tasks;
+using System;
+using System.Text.Json.Serialization;
+using SRTPluginBase.Implementations;
+
+namespace SRTPluginBase.Interfaces
+{
+ public interface IMainEntry
+ {
+ #region Serialized Properties
+
+ ///
+ /// The unique name for this entry. Must not contain characters not suitable for file and folder paths.
+ ///
+ public string Name { get; set; }
+
+ ///
+ /// The user-friendly display name for this entry.
+ ///
+ public string DisplayName { get; set; }
+
+ ///
+ /// A description of what this entry is for.
+ ///
+ public string Description { get; set; }
+
+ ///
+ /// The URL to this entry's source control repository.
+ ///
+ public Uri RepoURL { get; set; }
+
+ ///
+ /// The URL to this entry's manifest json file.
+ ///
+ public Uri ManifestURL { get; set; }
+
+ #endregion
+
+ #region Non-serialized Properties
+
+ ///
+ /// The manifest file's contents deserialized from the ManifestURL.
+ ///
+ [JsonIgnore(Condition = JsonIgnoreCondition.Always)]
+ public ManifestEntryJson? Manifest { get; }
+
+ #endregion
+
+ ///
+ /// Deserializes the manifest located at the Uri ManifestURL.
+ ///
+ /// An HttpClient instance to use when retrieving the manifest json.
+ /// A asynchronous Task instance for this request.
+ public abstract Task SetManifestAsync(HttpClient client);
+
+ }
+}
diff --git a/src/SRTPluginBase/Interfaces/IMainHostEntry.cs b/src/SRTPluginBase/Interfaces/IMainHostEntry.cs
new file mode 100644
index 0000000..1e3e453
--- /dev/null
+++ b/src/SRTPluginBase/Interfaces/IMainHostEntry.cs
@@ -0,0 +1,6 @@
+namespace SRTPluginBase.Interfaces
+{
+ public interface IMainHostEntry : IMainEntry
+ {
+ }
+}
diff --git a/src/SRTPluginBase/Interfaces/IMainJson.cs b/src/SRTPluginBase/Interfaces/IMainJson.cs
new file mode 100644
index 0000000..8ef1b12
--- /dev/null
+++ b/src/SRTPluginBase/Interfaces/IMainJson.cs
@@ -0,0 +1,21 @@
+using System.Collections.Generic;
+
+namespace SRTPluginBase.Interfaces
+{
+ public interface IMainJson
+ {
+ #region Serialized Properties
+
+ ///
+ /// An array of plugin hosts.
+ ///
+ public IEnumerable Hosts { get; set; }
+
+ ///
+ /// An array of plugins.
+ ///
+ public IEnumerable Plugins { get; set; }
+
+ #endregion
+ }
+}
diff --git a/src/SRTPluginBase/Interfaces/IMainPluginEntry.cs b/src/SRTPluginBase/Interfaces/IMainPluginEntry.cs
new file mode 100644
index 0000000..7adbd6c
--- /dev/null
+++ b/src/SRTPluginBase/Interfaces/IMainPluginEntry.cs
@@ -0,0 +1,27 @@
+using System.Collections.Generic;
+using SRTPluginBase.Implementations;
+
+namespace SRTPluginBase.Interfaces
+{
+ public interface IMainPluginEntry : IMainEntry
+ {
+ #region Serialized Properties
+
+ ///
+ /// A enumeration value indicating what platform architecture this plugin targets.
+ ///
+ public MainPluginPlatformEnum Platform { get; set; }
+
+ ///
+ /// A enumeration value indicating which type of plugin this is.
+ ///
+ public MainPluginTypeEnum Type { get; set; }
+
+ ///
+ /// A list of tags to assist in filtering and sorting. Examples for a DirectX Consumer plugin might include { "Consumer", "UI", "Overlay", "DirectX" }.
+ ///
+ public IEnumerable Tags { get; set; }
+
+ #endregion
+ }
+}
diff --git a/src/SRTPluginBase/Interfaces/IManifestEntryJson.cs b/src/SRTPluginBase/Interfaces/IManifestEntryJson.cs
new file mode 100644
index 0000000..5f3a367
--- /dev/null
+++ b/src/SRTPluginBase/Interfaces/IManifestEntryJson.cs
@@ -0,0 +1,21 @@
+using System.Collections.Generic;
+
+namespace SRTPluginBase.Interfaces
+{
+ public interface IManifestEntryJson
+ {
+ #region Serialized Properties
+
+ ///
+ /// The contributors to this entry.
+ ///
+ public IEnumerable Contributors { get; set; }
+
+ ///
+ /// An array of releases for this entry.
+ ///
+ public IEnumerable Releases { get; set; }
+
+ #endregion
+ }
+}
diff --git a/src/SRTPluginBase/Interfaces/IManifestReleaseJson.cs b/src/SRTPluginBase/Interfaces/IManifestReleaseJson.cs
new file mode 100644
index 0000000..7fb8836
--- /dev/null
+++ b/src/SRTPluginBase/Interfaces/IManifestReleaseJson.cs
@@ -0,0 +1,21 @@
+using System;
+
+namespace SRTPluginBase.Interfaces
+{
+ public interface IManifestReleaseJson
+ {
+ #region Serialized Properties
+
+ ///
+ /// The version of this entry.
+ ///
+ public string Version { get; set; }
+
+ ///
+ /// The download Uri for this version of the entry.
+ ///
+ public Uri DownloadURL { get; set; }
+
+ #endregion
+ }
+}
diff --git a/src/SRTPluginBase/IPlugin.cs b/src/SRTPluginBase/Interfaces/IPlugin.cs
similarity index 98%
rename from src/SRTPluginBase/IPlugin.cs
rename to src/SRTPluginBase/Interfaces/IPlugin.cs
index 2b2392b..abae8ef 100644
--- a/src/SRTPluginBase/IPlugin.cs
+++ b/src/SRTPluginBase/Interfaces/IPlugin.cs
@@ -6,7 +6,7 @@
using System.Threading;
using System.Threading.Tasks;
-namespace SRTPluginBase
+namespace SRTPluginBase.Interfaces
{
public interface IPlugin : IDisposable, IAsyncDisposable, IEquatable
{
diff --git a/src/SRTPluginBase/IPluginConfiguration.cs b/src/SRTPluginBase/Interfaces/IPluginConfiguration.cs
similarity index 60%
rename from src/SRTPluginBase/IPluginConfiguration.cs
rename to src/SRTPluginBase/Interfaces/IPluginConfiguration.cs
index 8aa13dd..26c38ac 100644
--- a/src/SRTPluginBase/IPluginConfiguration.cs
+++ b/src/SRTPluginBase/Interfaces/IPluginConfiguration.cs
@@ -1,4 +1,4 @@
-namespace SRTPluginBase
+namespace SRTPluginBase.Interfaces
{
public interface IPluginConfiguration
{
diff --git a/src/SRTPluginBase/IPluginConsumer.cs b/src/SRTPluginBase/Interfaces/IPluginConsumer.cs
similarity index 88%
rename from src/SRTPluginBase/IPluginConsumer.cs
rename to src/SRTPluginBase/Interfaces/IPluginConsumer.cs
index 7c4fc4c..2801ef6 100644
--- a/src/SRTPluginBase/IPluginConsumer.cs
+++ b/src/SRTPluginBase/Interfaces/IPluginConsumer.cs
@@ -1,6 +1,6 @@
using System;
-namespace SRTPluginBase
+namespace SRTPluginBase.Interfaces
{
public interface IPluginConsumer : IPlugin, IEquatable
{
diff --git a/src/SRTPluginBase/Interfaces/IPluginHost.cs b/src/SRTPluginBase/Interfaces/IPluginHost.cs
new file mode 100644
index 0000000..b936c4e
--- /dev/null
+++ b/src/SRTPluginBase/Interfaces/IPluginHost.cs
@@ -0,0 +1,15 @@
+using Microsoft.Extensions.Hosting;
+
+namespace SRTPluginBase.Interfaces
+{
+ public interface IPluginHost : IHostedService
+ {
+ ///
+ /// Retrieves a loaded plugin by name.
+ ///
+ /// The type of plugin to retrieve.
+ /// The plugin's name.
+ /// The requested plugin, or null if not loaded.
+ T? GetPluginReference(string pluginName) where T : class, IPlugin;
+ }
+}
diff --git a/src/SRTPluginBase/IPluginInfo.cs b/src/SRTPluginBase/Interfaces/IPluginInfo.cs
similarity index 97%
rename from src/SRTPluginBase/IPluginInfo.cs
rename to src/SRTPluginBase/Interfaces/IPluginInfo.cs
index 560bdce..ca6b25e 100644
--- a/src/SRTPluginBase/IPluginInfo.cs
+++ b/src/SRTPluginBase/Interfaces/IPluginInfo.cs
@@ -1,8 +1,7 @@
using System;
-using System.Diagnostics;
using System.Text.Json.Serialization;
-namespace SRTPluginBase
+namespace SRTPluginBase.Interfaces
{
public interface IPluginInfo : IEquatable
{
diff --git a/src/SRTPluginBase/IPluginProducer.cs b/src/SRTPluginBase/Interfaces/IPluginProducer.cs
similarity index 92%
rename from src/SRTPluginBase/IPluginProducer.cs
rename to src/SRTPluginBase/Interfaces/IPluginProducer.cs
index 39e8725..a2ff932 100644
--- a/src/SRTPluginBase/IPluginProducer.cs
+++ b/src/SRTPluginBase/Interfaces/IPluginProducer.cs
@@ -1,6 +1,6 @@
using System;
-namespace SRTPluginBase
+namespace SRTPluginBase.Interfaces
{
public interface IPluginProducer : IPlugin, IEquatable
{
diff --git a/src/SRTPluginBase/PluginBase.cs b/src/SRTPluginBase/PluginBase.cs
index b0792c9..a4c8e13 100644
--- a/src/SRTPluginBase/PluginBase.cs
+++ b/src/SRTPluginBase/PluginBase.cs
@@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Data.Sqlite;
using Microsoft.Extensions.Logging;
+using SRTPluginBase.Interfaces;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
diff --git a/src/SRTPluginBase/PluginInfoBase.cs b/src/SRTPluginBase/PluginInfoBase.cs
index ce8cbd3..6f558c3 100644
--- a/src/SRTPluginBase/PluginInfoBase.cs
+++ b/src/SRTPluginBase/PluginInfoBase.cs
@@ -2,6 +2,7 @@
using System.Diagnostics;
using System.IO;
using System.Text.Json.Serialization;
+using SRTPluginBase.Interfaces;
namespace SRTPluginBase
{