mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Plugins - Added constructors to PluginException to provide a help document
This commit is contained in:
parent
69c623bc8f
commit
2fcc6d7862
@ -10,7 +10,7 @@ public class ArtemisPluginException : Exception
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new instance of the <see cref="ArtemisPluginException" /> class
|
/// Creates a new instance of the <see cref="ArtemisPluginException" /> class
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ArtemisPluginException(Plugin plugin)
|
internal ArtemisPluginException(Plugin plugin)
|
||||||
{
|
{
|
||||||
Plugin = plugin;
|
Plugin = plugin;
|
||||||
}
|
}
|
||||||
@ -18,7 +18,7 @@ public class ArtemisPluginException : Exception
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new instance of the <see cref="ArtemisPluginException" /> class
|
/// Creates a new instance of the <see cref="ArtemisPluginException" /> class
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ArtemisPluginException(Plugin plugin, string message) : base(message)
|
internal ArtemisPluginException(Plugin plugin, string message) : base(message)
|
||||||
{
|
{
|
||||||
Plugin = plugin;
|
Plugin = plugin;
|
||||||
}
|
}
|
||||||
@ -26,7 +26,7 @@ public class ArtemisPluginException : Exception
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new instance of the <see cref="ArtemisPluginException" /> class
|
/// Creates a new instance of the <see cref="ArtemisPluginException" /> class
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ArtemisPluginException(Plugin plugin, string message, Exception inner) : base(message, inner)
|
internal ArtemisPluginException(Plugin plugin, string message, Exception inner) : base(message, inner)
|
||||||
{
|
{
|
||||||
Plugin = plugin;
|
Plugin = plugin;
|
||||||
}
|
}
|
||||||
@ -44,9 +44,31 @@ public class ArtemisPluginException : Exception
|
|||||||
public ArtemisPluginException(string message, Exception inner) : base(message, inner)
|
public ArtemisPluginException(string message, Exception inner) : base(message, inner)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new instance of the <see cref="ArtemisPluginException" /> class
|
||||||
|
/// </summary>
|
||||||
|
public ArtemisPluginException(string message, string helpDocument) : base(message)
|
||||||
|
{
|
||||||
|
HelpDocument = helpDocument;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new instance of the <see cref="ArtemisPluginException" /> class
|
||||||
|
/// </summary>
|
||||||
|
public ArtemisPluginException(string message, Exception inner, string helpDocument) : base(message, inner)
|
||||||
|
{
|
||||||
|
HelpDocument = helpDocument;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the plugin the error is related to
|
/// Gets the plugin the error is related to
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Plugin? Plugin { get; }
|
public Plugin? Plugin { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the help document related to this exception.
|
||||||
|
/// </summary>
|
||||||
|
public string? HelpDocument { get; }
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -127,6 +127,13 @@ public interface IPluginManagementService : IArtemisService, IDisposable
|
|||||||
/// <returns>If the current call stack contains a plugin, the plugin. Otherwise null</returns>
|
/// <returns>If the current call stack contains a plugin, the plugin. Otherwise null</returns>
|
||||||
Plugin? GetCallingPlugin();
|
Plugin? GetCallingPlugin();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the plugin that threw the provided exception.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="exception"></param>
|
||||||
|
/// <returns>If the exception was thrown by a plugin, the plugin. Otherwise null</returns>
|
||||||
|
Plugin? GetPluginFromException(Exception exception);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the plugin that defined the specified device
|
/// Gets the plugin that defined the specified device
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -192,7 +192,19 @@ internal class PluginManagementService : IPluginManagementService
|
|||||||
|
|
||||||
public Plugin? GetCallingPlugin()
|
public Plugin? GetCallingPlugin()
|
||||||
{
|
{
|
||||||
StackTrace stackTrace = new(); // get call stack
|
return GetPluginFromStackTrace(new StackTrace());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Plugin? GetPluginFromException(Exception exception)
|
||||||
|
{
|
||||||
|
if (exception is ArtemisPluginException pluginException && pluginException.Plugin != null)
|
||||||
|
return pluginException.Plugin;
|
||||||
|
|
||||||
|
return GetPluginFromStackTrace(new StackTrace(exception));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Plugin? GetPluginFromStackTrace(StackTrace stackTrace)
|
||||||
|
{
|
||||||
StackFrame[] stackFrames = stackTrace.GetFrames(); // get method calls (frames)
|
StackFrame[] stackFrames = stackTrace.GetFrames(); // get method calls (frames)
|
||||||
|
|
||||||
foreach (StackFrame stackFrame in stackFrames)
|
foreach (StackFrame stackFrame in stackFrames)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user