Plugins - Added constructors to PluginException to provide a help document

This commit is contained in:
Robert committed 2023-04-08 13:13:58 +02:00
1 parent 69c623bc8f
commit 2fcc6d7862
3 files changed
+45 -4

No files matched your search

@@ -127,6 +127,13 @@ public interface IPluginManagementService : IArtemisService, IDisposable
/// <returns>If the current call stack contains a plugin, the plugin. Otherwise null</returns>
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>
/// Gets the plugin that defined the specified device
/// </summary>
@@ -192,7 +192,19 @@ internal class PluginManagementService : IPluginManagementService
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)
foreach (StackFrame stackFrame in stackFrames)