mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Plugins - Added utility to get the calling plugin
Plugins - Removed IParameter overloads to avoid Ninject dependency in plugins
This commit is contained in:
1 parent
d59b36c3d1
commit
c7f3a8283a
4 files changed
+62
-51
No files matched your search
@@ -70,10 +70,10 @@ namespace Artemis.Core.Services
|
||||
List<PluginInfo> GetAllPluginInfo();
|
||||
|
||||
/// <summary>
|
||||
/// Finds all enabled <see cref="Plugin" /> instances of <typeparamref name="T"/>
|
||||
/// Finds all enabled <see cref="Plugin" /> instances of <typeparamref name="T" />
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Either <see cref="Plugin" /> or a plugin type implementing <see cref="Plugin" /></typeparam>
|
||||
/// <returns>Returns a list of plugin instances of <typeparamref name="T"/></returns>
|
||||
/// <returns>Returns a list of plugin instances of <typeparamref name="T" /></returns>
|
||||
List<T> GetPluginsOfType<T>() where T : Plugin;
|
||||
|
||||
/// <summary>
|
||||
@@ -90,6 +90,12 @@ namespace Artemis.Core.Services
|
||||
/// <returns></returns>
|
||||
Plugin GetPluginByDevice(IRGBDevice device);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the plugin info of the current call stack
|
||||
/// </summary>
|
||||
/// <returns>If the current call stack contains a plugin, the plugin. Otherwise null</returns>
|
||||
Plugin GetCallingPlugin();
|
||||
|
||||
#region Events
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
@@ -360,6 +361,22 @@ namespace Artemis.Core.Services
|
||||
return GetPluginsOfType<DeviceProvider>().First(d => d.RgbDeviceProvider.Devices != null && d.RgbDeviceProvider.Devices.Contains(rgbDevice));
|
||||
}
|
||||
|
||||
public Plugin GetCallingPlugin()
|
||||
{
|
||||
StackTrace stackTrace = new StackTrace(); // get call stack
|
||||
StackFrame[] stackFrames = stackTrace.GetFrames(); // get method calls (frames)
|
||||
|
||||
foreach (StackFrame stackFrame in stackFrames)
|
||||
{
|
||||
Assembly assembly = stackFrame.GetMethod().DeclaringType.Assembly;
|
||||
Plugin plugin = GetPluginByAssembly(assembly);
|
||||
if (plugin != null)
|
||||
return plugin;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
UnloadPlugins();
|
||||
|
||||
Reference in new issue
Block a user