Repository navigation
Expand file tree
/
Copy pathPlatformModuleAssembyLoader.cs
More file actions
49 lines (44 loc) · 1.73 KB
/
Copy pathPlatformModuleAssembyLoader.cs
File metadata and controls
49 lines (44 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using BotSharp.Core.Modules;
using Colorful;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Runtime.Loader;
using System.Text;
using Console = Colorful.Console;
namespace Microsoft.Extensions.DependencyInjection
{
public static class PlatformModuleAssembyLoader
{
public static void LoadAssemblies(IConfiguration configuration, Action<Assembly> action)
{
ModulesOptions options = configuration.Get<ModulesOptions>();
var platform = configuration.GetValue<string>("platformModuleName");
var module = options.Modules.Find(x => x.Name == platform);
var engine = configuration.GetValue<string>($"{platform}:BotEngine");
Formatter[] settings = new Formatter[]
{
new Formatter(platform, Color.Yellow),
new Formatter(module.Name, Color.Yellow),
new Formatter(engine, Color.Yellow),
};
// 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);
Console.WriteLineFormatted("Loaded {0} platform emulator from {1} assembly which is using {2} engine.", Color.White, settings);
}
else
{
Console.WriteLine($"Can't load {module.Type} assembly.");
}
Console.WriteLine();
}
}
}