Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 53 additions & 12 deletions PlugHub.Shared/Interfaces/Services/Plugins/IPluginRegistrar.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,68 @@
using PlugHub.Shared.Models.Plugins;

namespace PlugHub.Shared.Interfaces.Services.Plugins
{
/// <summary>
/// Defines methods for enabling or disabling plugins and plugin interfaces in the PlugHub system.
/// All state changes are persisted in the plugin registry manifest.
/// Manages the enabled/disabled state of plugins and their interfaces within the PlugHub system.
/// Responsible for persisting state changes to the plugin manifest, and providing metadata about plugin extension points.
/// </summary>
public interface IPluginRegistrar
{
/// <summary>
/// Gets the extension point descriptors for the specified <see cref="IPlugin"/> interface type.
/// Retrieves the list of plugin descriptors associated with a specified plugin interface type.
/// These descriptors define how various plugins implement or extend the given interface.
/// </summary>
/// <param name="pluginInterfaceType">
/// The interface type that defines a plugin extension point. Must be assignable from <see cref="IPlugin"/>.
/// The <see cref="Type"/> representing a plugin extension interface.
/// Must be assignable to <see cref="IPlugin"/>.
/// </param>
/// <returns>
/// A list of <see cref="PluginDescriptor"/> objects describing how plugins interact with the given <see cref="IPlugin"/> interface type.
/// A <see cref="List{PluginDescriptor}"/> containing metadata descriptors for plugins that interact with the specified interface type.
/// </returns>
public List<PluginDescriptor> GetDescriptorsForInterface(Type pluginInterfaceType);
PluginManifest GetManifest();
bool IsEnabled(Guid pluginId, Type interfaceType);
void SaveManifest(PluginManifest manifest);
void SetAllEnabled(Guid pluginId, bool enabled = true);
void SetEnabled(Guid pluginId, Type interfaceType, bool enabled = true);

/// <summary>
/// Retrieves the current plugin manifest representing the global interface enable state.
/// </summary>
/// <returns>
/// The <see cref="PluginManifest"/> instance that records interface enable status.
/// </returns>
public PluginManifest GetManifest();

/// <summary>
/// Persists the given plugin manifest to the underlying storage,
/// </summary>
/// <param name="manifest">The <see cref="PluginManifest"/> instance containing updated interface states.</param>
public void SaveManifest(PluginManifest manifest);

/// <summary>
/// Determines whether a specific plugin interface is currently enabled for a given plugin ID.
/// </summary>
/// <param name="pluginId">The <see cref="Guid"/> uniquely identifying the plugin.</param>
/// <param name="interfaceType">The <see cref="Type"/> of the plugin interface.</param>
/// <returns>
/// <c>true</c> if the specified interface on the plugin is enabled; otherwise, <c>false</c>.
/// </returns>
public bool IsEnabled(Guid pluginId, Type interfaceType);

/// <summary>
/// Sets the enabled or disabled state of a specific interface for a specified plugin.
/// </summary>
/// <param name="pluginId">The unique <see cref="Guid"/> of the plugin.</param>
/// <param name="interfaceType">The <see cref="Type"/> of the interface to modify.</param>
/// <param name="enabled">
/// <c>true</c> to enable the interface; <c>false</c> to disable it.
/// Defaults to <c>true</c>.
/// </param>
public void SetEnabled(Guid pluginId, Type interfaceType, bool enabled = true);

/// <summary>
/// Sets all interfaces of a given plugin to an enabled or disabled state.
/// </summary>
/// <param name="pluginId">The unique <see cref="Guid"/> of the plugin.</param>
/// <param name="enabled">
/// <c>true</c> to enable all interfaces; <c>false</c> to disable them.
/// Defaults to <c>true</c>.
/// </param>
public void SetAllEnabled(Guid pluginId, bool enabled = true);
}
}
}
21 changes: 11 additions & 10 deletions PlugHub/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;

namespace PlugHub
{
Expand All @@ -48,12 +47,13 @@ public override void Initialize()
string temp = Path.GetTempPath();

Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.File(Path.Combine(temp, $"plughub-{Environment.ProcessId}.log"), rollingInterval: RollingInterval.Day)
.MinimumLevel.Information()
//.WriteTo.File(Path.Combine(temp, $"plughub-{Environment.ProcessId}.log"), rollingInterval: RollingInterval.Day)
.WriteTo.File(Path.Combine(temp, $"plughub.log"), rollingInterval: RollingInterval.Infinite)
.CreateLogger();

builder.ClearProviders();
builder.AddSerilog(Log.Logger, dispose: true);
builder.AddSerilog(Log.Logger, dispose: false);
});

CollectServices(services);
Expand Down Expand Up @@ -152,7 +152,7 @@ private static void ConfigureSystemLogs(IConfigService configService, TokenSet t

if (string.IsNullOrWhiteSpace(defaultFileName))
{
Log.Warning("ConfigureSystemLogs: Default log file name is missing or empty. Exiting log configuration.");
Log.Warning("[App] Default log file name is missing or empty. Exiting log configuration.");

return;
}
Expand All @@ -161,7 +161,7 @@ private static void ConfigureSystemLogs(IConfigService configService, TokenSet t

if (string.IsNullOrWhiteSpace(logFileName))
{
Log.Warning("ConfigureSystemLogs: Runtime log file name is missing or empty. Exiting log configuration.");
Log.Warning("[App] Runtime log file name is missing or empty. Exiting log configuration.");

return;
}
Expand All @@ -170,7 +170,7 @@ private static void ConfigureSystemLogs(IConfigService configService, TokenSet t

if (string.IsNullOrWhiteSpace(defaultDir))
{
Log.Warning("ConfigureSystemLogs: Default log directory is missing or empty. Exiting log configuration.");
Log.Warning("[App] Default log directory is missing or empty. Exiting log configuration.");

return;
}
Expand All @@ -179,7 +179,7 @@ private static void ConfigureSystemLogs(IConfigService configService, TokenSet t

if (string.IsNullOrWhiteSpace(runtimeDir))
{
Log.Warning("ConfigureSystemLogs: Runtime log directory is missing or empty. Exiting log configuration.");
Log.Warning("[App] Runtime log directory is missing or empty. Exiting log configuration.");

return;
}
Expand All @@ -192,15 +192,16 @@ private static void ConfigureSystemLogs(IConfigService configService, TokenSet t
Path.GetFullPath(Path.Combine(defaultDir, defaultFileName))
.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);

// Replace manual comparison with PlatformPath.Equals
if (!PlatformPath.Equals(configLogPath, standardLogPath))
{
Log.CloseAndFlush();

Directory.CreateDirectory(runtimeDir);

Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.File(configLogPath, rollingInterval: rolloverInterval)
.CreateLogger();
Log.CloseAndFlush();
}
}
private static void ConfigureStorageLocation(IServiceProvider provider, IConfigService configService, TokenSet tokenSet)
Expand Down
Loading
Loading