From 61a39540fc9372553497a05a961ecca0c2e2cf1d Mon Sep 17 00:00:00 2001 From: botsharp2018 Date: Sun, 14 Oct 2018 09:15:27 -0500 Subject: [PATCH] fix multiple module loading. --- BotSharp.Core/Modules/IModule.cs | 3 +- BotSharp.Core/Modules/ModulesStartup.cs | 5 ++- .../Modules/PlatformModuleAssembyLoader.cs | 38 ++++++++++--------- BotSharp.WebHost/BotSharp.WebHost.csproj | 2 + BotSharp.WebHost/Settings/app.json | 7 +++- BotSharp.WebHost/Startup.cs | 2 + BotSharp.sln | 28 ++++++++++++++ 7 files changed, 63 insertions(+), 22 deletions(-) diff --git a/BotSharp.Core/Modules/IModule.cs b/BotSharp.Core/Modules/IModule.cs index 550b129b..2f8ed9f9 100644 --- a/BotSharp.Core/Modules/IModule.cs +++ b/BotSharp.Core/Modules/IModule.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using System; @@ -27,6 +28,6 @@ namespace BotSharp.Core.Modules /// /// Instance of . /// - void Configure(IApplicationBuilder app); + void Configure(IApplicationBuilder app, IHostingEnvironment env); } } diff --git a/BotSharp.Core/Modules/ModulesStartup.cs b/BotSharp.Core/Modules/ModulesStartup.cs index 133f8538..3dbae39c 100644 --- a/BotSharp.Core/Modules/ModulesStartup.cs +++ b/BotSharp.Core/Modules/ModulesStartup.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using System; @@ -77,11 +78,11 @@ namespace BotSharp.Core.Modules /// /// Instance of . /// - public void Configure(IApplicationBuilder app) + public void Configure(IApplicationBuilder app, IHostingEnvironment env) { foreach (IModule module in this._modules) { - module.Configure(app); + module.Configure(app, env); } } } diff --git a/BotSharp.Core/Modules/PlatformModuleAssembyLoader.cs b/BotSharp.Core/Modules/PlatformModuleAssembyLoader.cs index 3a8cb6c8..3ab13098 100644 --- a/BotSharp.Core/Modules/PlatformModuleAssembyLoader.cs +++ b/BotSharp.Core/Modules/PlatformModuleAssembyLoader.cs @@ -18,29 +18,31 @@ namespace Microsoft.Extensions.DependencyInjection { ModulesOptions options = configuration.Get(); - var platform = configuration.GetValue("platformModuleName"); - var module = options.Modules.Find(x => x.Name == platform); - // load platform emulator dynamically Console.WriteLine(); - var platformDllPath = Path.Combine(options.ModuleBasePath, module.Path, $"{module.Type}.dll"); - if (File.Exists(platformDllPath)) - { - Assembly library = AssemblyLoadContext.Default.LoadFromAssemblyPath(platformDllPath); - action(library); + options.Modules.ForEach(module => { - Formatter[] settings = new Formatter[] + var dllPath = Path.Combine(options.ModuleBasePath, module.Path, $"{module.Type}.dll"); + if (File.Exists(dllPath)) { - new Formatter(platform, Color.Yellow), - new Formatter(platformDllPath, Color.Yellow) - }; - Console.WriteLineFormatted("Loaded {0} platform emulator from {1} assembly.", Color.White, settings); - } - else - { - Console.WriteLine($"Can't load {module.Type} assembly from {platformDllPath}."); - } + Assembly library = AssemblyLoadContext.Default.LoadFromAssemblyPath(dllPath); + action(library); + + Formatter[] settings = new Formatter[] + { + new Formatter(module.Name, Color.Yellow), + new Formatter(module.Type, Color.Yellow), + new Formatter(dllPath, Color.Yellow) + }; + Console.WriteLineFormatted("Loaded {0} module, type: {1}, path: {2}", Color.White, settings); + } + else + { + Console.WriteLine($"Can't load {module.Type} assembly from {dllPath}."); + } + + }); Console.WriteLine(); } diff --git a/BotSharp.WebHost/BotSharp.WebHost.csproj b/BotSharp.WebHost/BotSharp.WebHost.csproj index cb934411..a498794c 100644 --- a/BotSharp.WebHost/BotSharp.WebHost.csproj +++ b/BotSharp.WebHost/BotSharp.WebHost.csproj @@ -5,6 +5,7 @@ Portable;win10-x64;centos.7-x64 AnyCPU;x64 Debug;Release; + 4ee89154-9131-4e6b-8fd5-d4f04a8d77c4 @@ -79,6 +80,7 @@ + diff --git a/BotSharp.WebHost/Settings/app.json b/BotSharp.WebHost/Settings/app.json index 583f0eec..562b65d4 100644 --- a/BotSharp.WebHost/Settings/app.json +++ b/BotSharp.WebHost/Settings/app.json @@ -15,6 +15,11 @@ "Type": "BotSharp.Platform.Dialogflow", "Path": "botsharp-dialogflow\\BotSharp.Platform.Dialogflow\\bin\\Debug\\netstandard2.0" }, + { + "Name": "WeixinChannel", + "Type": "BotSharp.Channel.Weixin", + "Path": "botsharp-channel-weixin\\BotSharp.Channel.Weixin\\bin\\Debug\\netstandard2.0" + } /*, { "Name": "RasaAi", "Type": "BotSharp.Platform.Rasa", @@ -24,6 +29,6 @@ "Name": "ArticulateAi", "Type": "BotSharp.Platform.Articulate", "Path": "botsharp-articulate\\BotSharp.Platform.Articulate\\bin\\Debug\\netstandard2.0" - } + }*/ ] } diff --git a/BotSharp.WebHost/Startup.cs b/BotSharp.WebHost/Startup.cs index 7952625f..9ef2eecf 100644 --- a/BotSharp.WebHost/Startup.cs +++ b/BotSharp.WebHost/Startup.cs @@ -122,6 +122,8 @@ namespace BotSharp.WebHost app.UseMvc(); + this.modulesStartup.Configure(app, env); + AppDomain.CurrentDomain.SetData("DataPath", Path.Combine(env.ContentRootPath, "App_Data")); AppDomain.CurrentDomain.SetData("Configuration", Configuration); AppDomain.CurrentDomain.SetData("ContentRootPath", env.ContentRootPath); diff --git a/BotSharp.sln b/BotSharp.sln index 417f92e4..81ba14f1 100644 --- a/BotSharp.sln +++ b/BotSharp.sln @@ -22,6 +22,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Platform.Abstracti EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Platform.Models", "BotSharp.Platform.Models\BotSharp.Platform.Models.csproj", "{C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Platform.Dialogflow", "..\botsharp-dialogflow\BotSharp.Platform.Dialogflow\BotSharp.Platform.Dialogflow.csproj", "{4F74387F-7101-428C-B918-38BC5ACCB0A6}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Channel.Weixin", "..\botsharp-channel-weixin\BotSharp.Channel.Weixin\BotSharp.Channel.Weixin.csproj", "{0F34140A-3714-4586-8A8C-3ABA56221D06}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -116,6 +120,30 @@ Global {C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}.Release|Any CPU.Build.0 = Release|Any CPU {C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}.Release|x64.ActiveCfg = Release|Any CPU {C4F2EAE5-F2C7-4F52-9DB2-7E76D7080C72}.Release|x64.Build.0 = Release|Any CPU + {4F74387F-7101-428C-B918-38BC5ACCB0A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4F74387F-7101-428C-B918-38BC5ACCB0A6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4F74387F-7101-428C-B918-38BC5ACCB0A6}.Debug|x64.ActiveCfg = Debug|Any CPU + {4F74387F-7101-428C-B918-38BC5ACCB0A6}.Debug|x64.Build.0 = Debug|Any CPU + {4F74387F-7101-428C-B918-38BC5ACCB0A6}.DIALOGFLOW|Any CPU.ActiveCfg = DIALOGFLOW|Any CPU + {4F74387F-7101-428C-B918-38BC5ACCB0A6}.DIALOGFLOW|Any CPU.Build.0 = DIALOGFLOW|Any CPU + {4F74387F-7101-428C-B918-38BC5ACCB0A6}.DIALOGFLOW|x64.ActiveCfg = DIALOGFLOW|Any CPU + {4F74387F-7101-428C-B918-38BC5ACCB0A6}.DIALOGFLOW|x64.Build.0 = DIALOGFLOW|Any CPU + {4F74387F-7101-428C-B918-38BC5ACCB0A6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4F74387F-7101-428C-B918-38BC5ACCB0A6}.Release|Any CPU.Build.0 = Release|Any CPU + {4F74387F-7101-428C-B918-38BC5ACCB0A6}.Release|x64.ActiveCfg = Release|Any CPU + {4F74387F-7101-428C-B918-38BC5ACCB0A6}.Release|x64.Build.0 = Release|Any CPU + {0F34140A-3714-4586-8A8C-3ABA56221D06}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0F34140A-3714-4586-8A8C-3ABA56221D06}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0F34140A-3714-4586-8A8C-3ABA56221D06}.Debug|x64.ActiveCfg = Debug|Any CPU + {0F34140A-3714-4586-8A8C-3ABA56221D06}.Debug|x64.Build.0 = Debug|Any CPU + {0F34140A-3714-4586-8A8C-3ABA56221D06}.DIALOGFLOW|Any CPU.ActiveCfg = Debug|Any CPU + {0F34140A-3714-4586-8A8C-3ABA56221D06}.DIALOGFLOW|Any CPU.Build.0 = Debug|Any CPU + {0F34140A-3714-4586-8A8C-3ABA56221D06}.DIALOGFLOW|x64.ActiveCfg = Debug|Any CPU + {0F34140A-3714-4586-8A8C-3ABA56221D06}.DIALOGFLOW|x64.Build.0 = Debug|Any CPU + {0F34140A-3714-4586-8A8C-3ABA56221D06}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0F34140A-3714-4586-8A8C-3ABA56221D06}.Release|Any CPU.Build.0 = Release|Any CPU + {0F34140A-3714-4586-8A8C-3ABA56221D06}.Release|x64.ActiveCfg = Release|Any CPU + {0F34140A-3714-4586-8A8C-3ABA56221D06}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE