Skip to content

Commit

Permalink
Restructured a bit. Added interfaces to a few of the classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Squirrelies committed Mar 17, 2024
1 parent aab3f41 commit 3538ae5
Show file tree
Hide file tree
Showing 22 changed files with 202 additions and 39 deletions.
15 changes: 0 additions & 15 deletions src/SRTPluginBase/IPluginHost.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<ManifestEntryJson>(client, ManifestURL);
public async Task SetManifestAsync(HttpClient client) => Manifest = await client.GetSRTJsonAsync<ManifestEntryJson>(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
@@ -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<MainHostEntry> Hosts { get; set; }
public IEnumerable<MainPluginEntry> Plugins { get; set; }
public IEnumerable<IMainHostEntry> Hosts { get; set; }
public IEnumerable<IMainPluginEntry> Plugins { get; set; }
}
#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
@@ -1,24 +1,27 @@
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; }
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 async Task SetManifestAsync(HttpClient client) => Manifest = await client.GetSRTJsonAsync<ManifestEntryJson>(ManifestURL);
[JsonIgnore(Condition = 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
@@ -1,4 +1,4 @@
namespace SRTPluginBase
namespace SRTPluginBase.Implementations
{
public enum MainPluginPlatformEnum : int
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SRTPluginBase
namespace SRTPluginBase.Implementations
{
public enum MainPluginTypeEnum : int
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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<string> Contributors { get; set; }
public IEnumerable<ManifestReleaseJson> Releases { get; set; }
public IEnumerable<IManifestReleaseJson> Releases { get; set; }
}
#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
@@ -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; }
Expand Down
58 changes: 58 additions & 0 deletions src/SRTPluginBase/Interfaces/IMainEntry.cs
Original file line number Diff line number Diff line change
@@ -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

/// <summary>
/// The unique name for this entry. Must not contain characters not suitable for file and folder paths.
/// </summary>
public string Name { get; set; }

/// <summary>
/// The user-friendly display name for this entry.
/// </summary>
public string DisplayName { get; set; }

/// <summary>
/// A description of what this entry is for.
/// </summary>
public string Description { get; set; }

/// <summary>
/// The URL to this entry's source control repository.
/// </summary>
public Uri RepoURL { get; set; }

/// <summary>
/// The URL to this entry's manifest json file.
/// </summary>
public Uri ManifestURL { get; set; }

#endregion

#region Non-serialized Properties

/// <summary>
/// The manifest file's contents deserialized from the ManifestURL.
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.Always)]
public ManifestEntryJson? Manifest { get; }

#endregion

/// <summary>
/// Deserializes the manifest located at the Uri ManifestURL.
/// </summary>
/// <param name="client">An HttpClient instance to use when retrieving the manifest json.</param>
/// <returns>A asynchronous Task instance for this request.</returns>
public abstract Task SetManifestAsync(HttpClient client);

}
}
6 changes: 6 additions & 0 deletions src/SRTPluginBase/Interfaces/IMainHostEntry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace SRTPluginBase.Interfaces
{
public interface IMainHostEntry : IMainEntry
{
}
}
21 changes: 21 additions & 0 deletions src/SRTPluginBase/Interfaces/IMainJson.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Collections.Generic;

namespace SRTPluginBase.Interfaces
{
public interface IMainJson
{
#region Serialized Properties

/// <summary>
/// An array of plugin hosts.
/// </summary>
public IEnumerable<IMainHostEntry> Hosts { get; set; }

/// <summary>
/// An array of plugins.
/// </summary>
public IEnumerable<IMainPluginEntry> Plugins { get; set; }

#endregion
}
}
27 changes: 27 additions & 0 deletions src/SRTPluginBase/Interfaces/IMainPluginEntry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Collections.Generic;
using SRTPluginBase.Implementations;

namespace SRTPluginBase.Interfaces
{
public interface IMainPluginEntry : IMainEntry
{
#region Serialized Properties

/// <summary>
/// A enumeration value indicating what platform architecture this plugin targets.
/// </summary>
public MainPluginPlatformEnum Platform { get; set; }

/// <summary>
/// A enumeration value indicating which type of plugin this is.
/// </summary>
public MainPluginTypeEnum Type { get; set; }

/// <summary>
/// A list of tags to assist in filtering and sorting. Examples for a DirectX Consumer plugin might include { "Consumer", "UI", "Overlay", "DirectX" }.
/// </summary>
public IEnumerable<string> Tags { get; set; }

#endregion
}
}
21 changes: 21 additions & 0 deletions src/SRTPluginBase/Interfaces/IManifestEntryJson.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Collections.Generic;

namespace SRTPluginBase.Interfaces
{
public interface IManifestEntryJson
{
#region Serialized Properties

/// <summary>
/// The contributors to this entry.
/// </summary>
public IEnumerable<string> Contributors { get; set; }

/// <summary>
/// An array of releases for this entry.
/// </summary>
public IEnumerable<IManifestReleaseJson> Releases { get; set; }

#endregion
}
}
21 changes: 21 additions & 0 deletions src/SRTPluginBase/Interfaces/IManifestReleaseJson.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;

namespace SRTPluginBase.Interfaces
{
public interface IManifestReleaseJson
{
#region Serialized Properties

/// <summary>
/// The version of this entry.
/// </summary>
public string Version { get; set; }

/// <summary>
/// The download Uri for this version of the entry.
/// </summary>
public Uri DownloadURL { get; set; }

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Threading;
using System.Threading.Tasks;

namespace SRTPluginBase
namespace SRTPluginBase.Interfaces
{
public interface IPlugin : IDisposable, IAsyncDisposable, IEquatable<IPlugin>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SRTPluginBase
namespace SRTPluginBase.Interfaces
{
public interface IPluginConfiguration
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace SRTPluginBase
namespace SRTPluginBase.Interfaces
{
public interface IPluginConsumer : IPlugin, IEquatable<IPluginConsumer>
{
Expand Down
15 changes: 15 additions & 0 deletions src/SRTPluginBase/Interfaces/IPluginHost.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Microsoft.Extensions.Hosting;

namespace SRTPluginBase.Interfaces
{
public interface IPluginHost : IHostedService
{
/// <summary>
/// Retrieves a loaded plugin by name.
/// </summary>
/// <typeparam name="T">The type of plugin to retrieve.</typeparam>
/// <param name="pluginName">The plugin's name.</param>
/// <returns>The requested plugin, or null if not loaded.</returns>
T? GetPluginReference<T>(string pluginName) where T : class, IPlugin;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System;
using System.Diagnostics;
using System.Text.Json.Serialization;

namespace SRTPluginBase
namespace SRTPluginBase.Interfaces
{
public interface IPluginInfo : IEquatable<IPluginInfo>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace SRTPluginBase
namespace SRTPluginBase.Interfaces
{
public interface IPluginProducer : IPlugin, IEquatable<IPluginProducer>
{
Expand Down
1 change: 1 addition & 0 deletions src/SRTPluginBase/PluginBase.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/SRTPluginBase/PluginInfoBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Diagnostics;
using System.IO;
using System.Text.Json.Serialization;
using SRTPluginBase.Interfaces;

namespace SRTPluginBase
{
Expand Down

0 comments on commit 3538ae5

Please sign in to comment.