| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Reflection;
- using Abp.Collections.Extensions;
- using Abp.Modules;
- using Abp.Reflection;
- namespace Abp.PlugIns
- {
- public class FolderPlugInSource : IPlugInSource
- {
- public string Folder { get; }
- public SearchOption SearchOption { get; set; }
- private readonly Lazy<List<Assembly>> _assemblies;
-
- public FolderPlugInSource(string folder, SearchOption searchOption = SearchOption.TopDirectoryOnly)
- {
- Folder = folder;
- SearchOption = searchOption;
- _assemblies = new Lazy<List<Assembly>>(LoadAssemblies, true);
- }
- public List<Assembly> GetAssemblies()
- {
- return _assemblies.Value;
- }
- public List<Type> GetModules()
- {
- var modules = new List<Type>();
- foreach (var assembly in GetAssemblies())
- {
- try
- {
- foreach (var type in assembly.GetTypes())
- {
- if (AbpModule.IsAbpModule(type))
- {
- modules.AddIfNotContains(type);
- }
- }
- }
- catch (Exception ex)
- {
- throw new AbpInitializationException("Could not get module types from assembly: " + assembly.FullName, ex);
- }
- }
- return modules;
- }
- private List<Assembly> LoadAssemblies()
- {
- return AssemblyHelper.GetAllAssembliesInFolder(Folder, SearchOption);
- }
- }
- }
|