fix multiple module loading.

This commit is contained in:
botsharp2018 2018-10-14 09:15:27 -05:00
parent c226aca91c
commit 61a39540fc
7 changed files with 63 additions and 22 deletions

View file

@ -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
/// <param name="app">
/// Instance of <see cref="IApplicationBuilder"/>.
/// </param>
void Configure(IApplicationBuilder app);
void Configure(IApplicationBuilder app, IHostingEnvironment env);
}
}

View file

@ -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
/// <param name="app">
/// Instance of <see cref="IApplicationBuilder"/>.
/// </param>
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);
}
}
}

View file

@ -18,29 +18,31 @@ namespace Microsoft.Extensions.DependencyInjection
{
ModulesOptions options = configuration.Get<ModulesOptions>();
var platform = configuration.GetValue<string>("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();
}

View file

@ -5,6 +5,7 @@
<RuntimeIdentifiers>Portable;win10-x64;centos.7-x64</RuntimeIdentifiers>
<Platforms>AnyCPU;x64</Platforms>
<Configurations>Debug;Release;</Configurations>
<UserSecretsId>4ee89154-9131-4e6b-8fd5-d4f04a8d77c4</UserSecretsId>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
@ -79,6 +80,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\botsharp-channel-weixin\BotSharp.Channel.Weixin\BotSharp.Channel.Weixin.csproj" />
<ProjectReference Include="..\BotSharp.Core\BotSharp.Core.csproj" />
</ItemGroup>

View file

@ -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"
}
}*/
]
}

View file

@ -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);

View file

@ -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