Merge branch 'SciSharp:master' into master
This commit is contained in:
commit
7585e35749
|
|
@ -4,7 +4,6 @@ using Rougamo.Context;
|
|||
using Microsoft.Extensions.DependencyInjection;
|
||||
using BotSharp.Abstraction.Shared;
|
||||
|
||||
|
||||
namespace BotSharp.Abstraction.SideCar.Attributes;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method, Inherited = true)]
|
||||
|
|
@ -34,7 +33,7 @@ public class SideCarAttribute : AsyncMoAttribute
|
|||
if (typeof(Task).IsAssignableFrom(retType))
|
||||
{
|
||||
var syncResultType = retType.IsConstructedGenericType ? retType.GenericTypeArguments[0] : typeof(void);
|
||||
(isHandled, value) = CallAsyncMethod(sidecar, sidecarMethod, syncResultType, methodArgs);
|
||||
(isHandled, value) = await CallAsyncMethod(sidecar, sidecarMethod, syncResultType, methodArgs);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -67,9 +66,10 @@ public class SideCarAttribute : AsyncMoAttribute
|
|||
return (sidecar, sidecarMethod);
|
||||
}
|
||||
|
||||
private (bool, object?) CallAsyncMethod(IConversationSideCar instance, MethodInfo method, Type retType, object[] args)
|
||||
private async Task<(bool, object?)> CallAsyncMethod(IConversationSideCar instance, MethodInfo method, Type retType, object[] args)
|
||||
{
|
||||
object? value = null;
|
||||
object? res = null;
|
||||
var isHandled = false;
|
||||
|
||||
var enabled = instance != null && instance.IsEnabled() && method != null;
|
||||
|
|
@ -81,12 +81,20 @@ public class SideCarAttribute : AsyncMoAttribute
|
|||
isHandled = true;
|
||||
if (retType == typeof(void))
|
||||
{
|
||||
value = GetMethod(nameof(CallAsync)).Invoke(this, [instance, method, args]);
|
||||
res = GetMethod(nameof(CallAsync)).Invoke(this, [instance, method, args]);
|
||||
}
|
||||
else
|
||||
{
|
||||
var task = GetMethod(nameof(CallGenericAsync)).MakeGenericMethod(retType).Invoke(this, [instance, method, args]);
|
||||
value = task?.GetType().GetProperty("Result")?.GetValue(task);
|
||||
res = GetMethod(nameof(CallGenericAsync)).MakeGenericMethod(retType).Invoke(this, [instance, method, args]);
|
||||
}
|
||||
|
||||
if (res != null && res is Task task)
|
||||
{
|
||||
await task;
|
||||
if (method.ReturnType.IsGenericType && method.ReturnType.GetGenericTypeDefinition() == typeof(Task<>))
|
||||
{
|
||||
value = task?.GetType()?.GetProperty("Result")?.GetValue(task);
|
||||
}
|
||||
}
|
||||
|
||||
return (isHandled, value);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using BotSharp.Abstraction.MLTasks;
|
||||
using BotSharp.Abstraction.Plugins.Models;
|
||||
using BotSharp.Abstraction.Settings;
|
||||
using BotSharp.Abstraction.Statistics.Settings;
|
||||
using BotSharp.Abstraction.Templating;
|
||||
using BotSharp.Abstraction.Users.Enums;
|
||||
using BotSharp.Core.Agents.Hooks;
|
||||
|
|
@ -34,6 +35,12 @@ public class AgentPlugin : IBotSharpPlugin
|
|||
services.AddScoped<IAgentHook, BasicAgentHook>();
|
||||
services.AddScoped<IBotSharpStatService, BotSharpStatService>();
|
||||
|
||||
services.AddScoped(provider =>
|
||||
{
|
||||
var settingService = provider.GetRequiredService<ISettingService>();
|
||||
return settingService.Bind<StatisticsSettings>("Statistics");
|
||||
});
|
||||
|
||||
services.AddScoped(provider =>
|
||||
{
|
||||
var settingService = provider.GetRequiredService<ISettingService>();
|
||||
|
|
|
|||
|
|
@ -16,11 +16,6 @@ public class DashboardPlugin : IBotSharpPlugin
|
|||
public void RegisterDI(IServiceCollection services, IConfiguration config)
|
||||
{
|
||||
services.AddScoped<IConversationHook, StatsConversationHook>();
|
||||
services.AddScoped(provider =>
|
||||
{
|
||||
var settingService = provider.GetRequiredService<ISettingService>();
|
||||
return settingService.Bind<StatisticsSettings>("Statistics");
|
||||
});
|
||||
}
|
||||
|
||||
public bool AttachMenu(List<PluginMenuDef> menu)
|
||||
|
|
|
|||
Loading…
Reference in a new issue