91 lines
2.4 KiB
C#
91 lines
2.4 KiB
C#
namespace Pilz.Features;
|
|
|
|
public abstract class PluginFunction : PluginFeature
|
|
{
|
|
protected PluginFunction(string type, string identifier) : base(type, identifier)
|
|
{
|
|
}
|
|
|
|
protected PluginFunction(string type, string identifier, string? name) : base(type, identifier, name)
|
|
{
|
|
}
|
|
|
|
public virtual object? Execute()
|
|
{
|
|
return Execute((PluginFunctionParameter?)null);
|
|
}
|
|
|
|
public virtual T? Execute<T>(params object?[]? @params)
|
|
{
|
|
return Execute<T>(new PluginFunctionSimpleParamter(@params));
|
|
}
|
|
|
|
public virtual object? Execute(params object?[]? @params)
|
|
{
|
|
return Execute(new PluginFunctionSimpleParamter(@params));
|
|
}
|
|
|
|
public virtual T? Execute<T>(PluginFunctionSimpleParamter? @params)
|
|
{
|
|
if (Execute(@params) is T result)
|
|
return result;
|
|
return default;
|
|
}
|
|
|
|
public virtual object? Execute(PluginFunctionParameter? @params)
|
|
{
|
|
object? result = null;
|
|
|
|
if (OnPreExecute(@params, ref result))
|
|
result = ExecuteFunction(@params);
|
|
|
|
OnPostExecute(@params, ref result);
|
|
|
|
return result;
|
|
}
|
|
|
|
public virtual Task<object?> ExecuteAsync()
|
|
{
|
|
return ExecuteAsync((PluginFunctionParameter?)null);
|
|
}
|
|
|
|
public virtual Task<T?> ExecuteAsync<T>(params object?[]? @params)
|
|
{
|
|
return ExecuteAsync<T>(new PluginFunctionSimpleParamter(@params));
|
|
}
|
|
|
|
public virtual Task<object?> ExecuteAsync(params object?[]? @params)
|
|
{
|
|
return ExecuteAsync(new PluginFunctionSimpleParamter(@params));
|
|
}
|
|
|
|
public virtual async Task<T?> ExecuteAsync<T>(PluginFunctionSimpleParamter? @params)
|
|
{
|
|
if (await ExecuteAsync(@params) is T result)
|
|
return result;
|
|
return default;
|
|
}
|
|
|
|
public virtual async Task<object?> ExecuteAsync(PluginFunctionParameter? @params)
|
|
{
|
|
object? result = null;
|
|
|
|
if (OnPreExecute(@params, ref result))
|
|
result = await ExecuteFunctionAsync(@params);
|
|
|
|
OnPostExecute(@params, ref result);
|
|
|
|
return result;
|
|
}
|
|
|
|
protected virtual object? ExecuteFunction(PluginFunctionParameter? @params)
|
|
{
|
|
return ExecuteFunctionAsync(@params).GetAwaiter().GetResult();
|
|
}
|
|
|
|
protected virtual Task<object?> ExecuteFunctionAsync(PluginFunctionParameter? @params)
|
|
{
|
|
return Task.FromResult(ExecuteFunction(@params));
|
|
}
|
|
}
|