60 lines
1.9 KiB
C#
60 lines
1.9 KiB
C#
namespace Pilz.Plugins.Advanced
|
|
{
|
|
public sealed class PluginFunctionController
|
|
{
|
|
public static PluginFunctionController Instance { get; private set; } = new();
|
|
|
|
private readonly List<PluginFunction> functions = new();
|
|
|
|
public IReadOnlyCollection<PluginFunction> Functions => functions.AsReadOnly();
|
|
|
|
public void RegisterFunction(PluginFunction function)
|
|
{
|
|
if (!functions.Contains(function))
|
|
functions.Add(function);
|
|
}
|
|
|
|
public void UnregisterFunction(PluginFunction function)
|
|
{
|
|
functions.Remove(function);
|
|
}
|
|
|
|
public IEnumerable<PluginFunction> GetFunctions(string functionType)
|
|
{
|
|
return functions.Where(n => n.Type == functionType);
|
|
}
|
|
|
|
public void ExecuteAll(string functionType)
|
|
{
|
|
foreach (var function in GetFunctions(functionType))
|
|
function.Execute();
|
|
}
|
|
|
|
public void ExecuteAll(string functionType, params object?[]? @params)
|
|
{
|
|
foreach (var function in GetFunctions(functionType))
|
|
function.Execute(@params);
|
|
}
|
|
|
|
public void ExecuteAll(string functionType, PluginFunctionParameter @params)
|
|
{
|
|
foreach (var function in GetFunctions(functionType))
|
|
function.Execute(@params);
|
|
}
|
|
|
|
public IEnumerable<object?> ExcuteAndGetResults(string functionType)
|
|
{
|
|
return GetFunctions(functionType).Select(n => n.Execute());
|
|
}
|
|
|
|
public IEnumerable<object?> ExcuteAndGetResults(string functionType, params object?[]? @params)
|
|
{
|
|
return GetFunctions(functionType).Select(n => n.Execute(@params));
|
|
}
|
|
|
|
public IEnumerable<object?> ExcuteAndGetResults(string functionType, PluginFunctionParameter @params)
|
|
{
|
|
return GetFunctions(functionType).Select(n => n.Execute(@params));
|
|
}
|
|
}
|
|
} |