mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 06:01:10 +00:00
Adds the host contracts for external plugins projects.
This commit is contained in:
1 parent
a34f5a731e
commit
da5ec53de8
8 files changed
+249
No files matched your search
@@ -0,0 +1,27 @@
|
||||
namespace Lumina.Domain.SharedKernel.Common.Enums.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Enumeration for the types of a plugin setting.
|
||||
/// </summary>
|
||||
public enum PluginSettingType
|
||||
{
|
||||
/// <summary>
|
||||
/// A free-form single line text value.
|
||||
/// </summary>
|
||||
Text,
|
||||
|
||||
/// <summary>
|
||||
/// A numeric value.
|
||||
/// </summary>
|
||||
Number,
|
||||
|
||||
/// <summary>
|
||||
/// A boolean (true/false) value.
|
||||
/// </summary>
|
||||
Boolean,
|
||||
|
||||
/// <summary>
|
||||
/// A value selected from a list of allowed values.
|
||||
/// </summary>
|
||||
Select
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Plugins;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.Contracts.Common.Models.DTO.Settings;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object describing a single setting of a plugin, used by the host to render the plugin settings page.
|
||||
/// </summary>
|
||||
/// <param name="Key">The unique key of the setting, used to persist and retrieve its value.</param>
|
||||
/// <param name="Label">The display label of the setting.</param>
|
||||
/// <param name="Type">The type of the setting.</param>
|
||||
/// <param name="DefaultValue">The optional default value of the setting, serialized as a string.</param>
|
||||
/// <param name="AllowedValues">The list of allowed values, when the setting is a selection.</param>
|
||||
[DebuggerDisplay("Key: {Key}")]
|
||||
public sealed record PluginSettingDescriptorDto(
|
||||
string Key,
|
||||
string Label,
|
||||
PluginSettingType Type,
|
||||
string? DefaultValue = null,
|
||||
IReadOnlyList<string>? AllowedValues = null
|
||||
);
|
||||
@@ -0,0 +1,46 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.Contracts.Core.Metadata;
|
||||
|
||||
/// <summary>
|
||||
/// Contract for a plugin that provides metadata for media items from a remote source.
|
||||
/// </summary>
|
||||
public interface IRemoteMetadataProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the display name of the metadata provider.
|
||||
/// </summary>
|
||||
string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the media library type this metadata provider supports.
|
||||
/// </summary>
|
||||
LibraryType SupportedLibraryType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this metadata provider requires access to the web to retrieve metadata.
|
||||
/// </summary>
|
||||
bool RequiresWebAccess { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Searches for the metadata of the media item described by <paramref name="lookup"/>.
|
||||
/// </summary>
|
||||
/// <param name="lookup">The lookup describing the media item to search for.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The collection of metadata candidates found for the media item.</returns>
|
||||
Task<IReadOnlyList<MetadataDto>> GetSearchResultsAsync(MetadataLookupDto lookup, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the metadata of the media item described by <paramref name="lookup"/>.
|
||||
/// </summary>
|
||||
/// <param name="lookup">The lookup describing the media item to get the metadata for.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The metadata of the media item, or <see langword="null"/> when no metadata was found.</returns>
|
||||
Task<MetadataDto?> GetMetadataAsync(MetadataLookupDto lookup, CancellationToken cancellationToken);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.Contracts.Core.Metadata;
|
||||
|
||||
/// <summary>
|
||||
/// Contract for a plugin that provides metadata for media items from a remote source, typed to the media item lookup and metadata types.
|
||||
/// </summary>
|
||||
/// <typeparam name="TLookup">The type of the lookup describing the media item.</typeparam>
|
||||
/// <typeparam name="TMetadata">The type of the metadata of the media item.</typeparam>
|
||||
public interface IRemoteMetadataProvider<TLookup, TMetadata> : IRemoteMetadataProvider
|
||||
where TLookup : MetadataLookupDto
|
||||
where TMetadata : MetadataDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Searches for the metadata of the media item described by <paramref name="lookup"/>.
|
||||
/// </summary>
|
||||
/// <param name="lookup">The lookup describing the media item to search for.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The collection of metadata candidates found for the media item.</returns>
|
||||
Task<IReadOnlyList<TMetadata>> GetSearchResultsAsync(TLookup lookup, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the metadata of the media item described by <paramref name="lookup"/>.
|
||||
/// </summary>
|
||||
/// <param name="lookup">The lookup describing the media item to get the metadata for.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>The metadata of the media item, or <see langword="null"/> when no metadata was found.</returns>
|
||||
Task<TMetadata?> GetMetadataAsync(TLookup lookup, CancellationToken cancellationToken);
|
||||
|
||||
/// <inheritdoc/>
|
||||
async Task<IReadOnlyList<MetadataDto>> IRemoteMetadataProvider.GetSearchResultsAsync(MetadataLookupDto lookup, CancellationToken cancellationToken)
|
||||
{
|
||||
return await GetSearchResultsAsync((TLookup)lookup, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
async Task<MetadataDto?> IRemoteMetadataProvider.GetMetadataAsync(MetadataLookupDto lookup, CancellationToken cancellationToken)
|
||||
{
|
||||
return await GetMetadataAsync((TLookup)lookup, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Plugins.Contracts.Common.Models.DTO.Settings;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.Contracts.Core.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Contract for a Lumina plugin.
|
||||
/// </summary>
|
||||
public interface IPlugin
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the stable unique identifier of the plugin, used to persist its state.
|
||||
/// </summary>
|
||||
Guid Id { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the display name of the plugin.
|
||||
/// </summary>
|
||||
string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the author of the plugin.
|
||||
/// </summary>
|
||||
string Author { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the version of the plugin.
|
||||
/// </summary>
|
||||
Version Version { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the description of the plugin.
|
||||
/// </summary>
|
||||
string Description { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the settings schema of the plugin, used by the host to render the plugin settings page.
|
||||
/// </summary>
|
||||
/// <returns>The collection of setting descriptors declared by the plugin.</returns>
|
||||
IReadOnlyList<PluginSettingDescriptorDto> GetSettingsSchema();
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.Contracts.Core.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Contract for registering the services of a plugin into the host dependency injection container.
|
||||
/// </summary>
|
||||
public interface IPluginServiceRegistrator
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers the services of the plugin into the host dependency injection container.
|
||||
/// </summary>
|
||||
/// <param name="services">The service collection to which the plugin services are added.</param>
|
||||
void RegisterServices(IServiceCollection services);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Plugins.Contracts.Core.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Contract for reading the settings persisted by the host for a plugin.
|
||||
/// </summary>
|
||||
public interface IPluginSettingsStore
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the settings persisted by the host for the plugin identified by <paramref name="pluginId"/>.
|
||||
/// </summary>
|
||||
/// <param name="pluginId">The unique identifier of the plugin whose settings are read.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to cancel the operation.</param>
|
||||
/// <returns>The persisted settings keyed by setting key, or <see langword="null"/> when no settings were persisted for the plugin.</returns>
|
||||
Task<IReadOnlyDictionary<string, string>?> GetSettingsAsync(Guid pluginId, CancellationToken cancellationToken);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<BaseOutputPath>$(SolutionDir)..\bin\api\</BaseOutputPath>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<WarningsNotAsErrors>$(WarningsNotAsErrors);NU1901;NU1902;NU1903;NU1904</WarningsNotAsErrors>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\AssemblyInfo_Shared.cs" Link="Properties\AssemblyInfo_Shared.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Lumina.Contracts\Lumina.Contracts.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in new issue
Block a user