internal static void LoadAssembliesInDirrectory() { var path = Path.Combine(Directory.GetCurrentDirectory(), "Modules"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var files = Directory.EnumerateFiles(path).Where(x => x.Contains("HeroBot.Plugins")); foreach (var file in files) { if (!file.Contains(".dll")) { continue; } var moduleContext = new ModuleLoadContext(); var ass = moduleContext.LoadFromAssemblyPath(file); RuntimeAssemblies.AssemblyEntities.TryAdd(ass.GetName().Name, new AssemblyEntity() { Assembly = ass, Context = moduleContext }); } }
private void LoadFromPath(DirectoryPath path) { var registrationBuilder = BootstrapperConventions.GetRegistrationBuilder(); var moduleFiles = Directory.GetFiles(path.ToString(), moduleNamePattern); var moduleCatalogs = moduleFiles.Select(x => { var loadContext = new ModuleLoadContext(x); var assembly = loadContext.LoadFromAssemblyPath(x); return(new AssemblyCatalog(assembly, registrationBuilder) as ComposablePartCatalog); }).ToArray(); var applicationCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly(), registrationBuilder); var aggregateCatalog = new AggregateCatalog(moduleCatalogs.Append(applicationCatalog)); container = new CompositionContainer(aggregateCatalog); }
private void FetchExternalAssemblies() { var path = Directory.GetCurrentDirectory(); // Path.Combine(Directory.GetCurrentDirectory(), "Modules"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var files = Directory.EnumerateFiles(path).Where(x => x.Contains("Assembly")); foreach (var file in files) { if (!file.Contains(".dll")) { continue; } var moduleContext = new ModuleLoadContext(); var ass = moduleContext.LoadFromAssemblyPath(file); var name = ass.GetName().Name.SanitizAssembly(); var context = new ContextEntity { Name = name, Context = moduleContext, Assembly = ass }; if (_contexts.ContainsKey(name)) { continue; } _contexts.TryAdd(name, context); ConsoleHelper.Log(LogSeverity.Info, "Core", $"Loaded {name} v{ass.GetName().Version} assembly."); } if (!_contexts.IsEmpty) { return; } ConsoleHelper.Log(LogSeverity.Warning, "Core", "No external assemblies were found."); }