Exemplo n.º 1
0
    public Type[] GetModules()
    {
        var modules = new List <Type>();

        foreach (var filePath in FilePaths)
        {
            var assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(filePath);

            try
            {
                foreach (var type in assembly.GetTypes())
                {
                    if (AbpModule.IsAbpModule(type))
                    {
                        modules.AddIfNotContains(type);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new AbpException("Could not get module types from assembly: " + assembly.FullName, ex);
            }
        }

        return(modules.ToArray());
    }
        public List <Type> GetModules()
        {
            var modules = new List <Type>();

            foreach (var filePath in this.FilePaths)
            {
                var assembly = Assembly.LoadFile(filePath);

                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);
        }
Exemplo n.º 3
0
        public List <Type> GetModules()
        {
            var modules = new List <Type>();

            var assemblies = AssemblyHelper.GetAllAssembliesInFolder(Folder, SearchOption);

            foreach (var assembly in assemblies)
            {
                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);
        }
        public CollectibleAssemblyLoadContext Get(string moduleName, IServiceCollection services, ApplicationPartManager apm, IServiceScope scope, InBizModuleEnum inBizModuleEnum = InBizModuleEnum.Boot)
        {
            string folderName = inBizModuleEnum == InBizModuleEnum.Boot ? "boot" : "hot";
            CollectibleAssemblyLoadContext context = new CollectibleAssemblyLoadContext(moduleName);
            IReferenceLoader  loader              = scope.ServiceProvider.GetService <IReferenceLoader>();
            InBizModuleLoader inBizModuleLoader   = scope.ServiceProvider.GetService <InBizModuleLoader>();
            string            filePath            = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "modules", folderName, moduleName, $"{moduleName}.dll");
            string            viewFilePath        = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "modules", folderName, moduleName, $"{moduleName}.Views.dll");
            string            referenceFolderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "modules", folderName, moduleName);

            if (File.Exists(filePath))
            {
                using (FileStream fs = new FileStream(filePath, FileMode.Open))
                {
                    Assembly assembly = context.LoadFromStream(fs);
                    context.SetEntryPoint(assembly);
                    loader.LoadStreamsIntoContext(context, referenceFolderPath, assembly);
                    AssemblyPart controllerAssemblyPart = new AssemblyPart(assembly);
                    apm.ApplicationParts.Add(controllerAssemblyPart);
                    //services.AddAssembly(assembly);
                    foreach (var type in assembly.GetTypes())
                    {
                        if (AbpModule.IsAbpModule(type))
                        {
                            inBizModuleLoader.LoadModules(services, type, new PlugInSourceList());
                            inBizModuleLoader.ConfigureServices(services);
                            inBizModuleLoader.InitializeModules(new Volo.Abp.ApplicationInitializationContext(scope.ServiceProvider));
                        }
                    }
                    var resources = assembly.GetManifestResourceNames();
                    if (resources.Any())
                    {
                        foreach (var item in resources)
                        {
                            var stream = new MemoryStream();
                            var source = assembly.GetManifestResourceStream(item);
                            source.CopyTo(stream);
                            context.RegisterResource(item, stream.ToArray());
                        }
                    }
                }
            }
            else
            {
                return(null);
            }
            if (File.Exists(viewFilePath))
            {
                using (FileStream fsView = new FileStream(viewFilePath, FileMode.Open))
                {
                    Assembly vwAssembly = context.LoadFromStream(fsView);
                    loader.LoadStreamsIntoContext(context, referenceFolderPath, vwAssembly);

                    InBizRazorAssemblyPart moduleView = new InBizRazorAssemblyPart(vwAssembly, moduleName);
                    apm.ApplicationParts.Add(moduleView);
                }
            }
            context.Enable();
            return(context);
        }
        public Type[] GetModules()
        {
            var modules = new List <Type>();

            foreach (var assemblyName in _assemblyNames)
            {
                var assembly = Assembly.Load(assemblyName);

                try
                {
                    foreach (var type in assembly.GetTypes())
                    {
                        if (AbpModule.IsAbpModule(type))
                        {
                            modules.AddIfNotContains(type);
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new AbpException("Could not get module types from assembly: " + assembly.FullName, ex);
                }
            }

            return(modules.ToArray());
        }
 public override IModuleDescriptor Create(Type moduleType)
 {
     if (AbpModule.IsAbpModule(moduleType))
     {
         var adaptedModuleType = typeof(AbpModuleAdapterModule <>).MakeGenericType(moduleType);
         return(new ModuleDescriptor(adaptedModuleType));
     }
     else
     {
         return(base.Create(moduleType));
     }
 }
 public override IEnumerable <Type> GetDependedModuleTypes(Type moduleType)
 {
     if (AbpModule.IsAbpModule(moduleType))
     {
         return(moduleType.GetCustomAttributes()
                .OfType <Volo.Abp.Modularity.IDependedTypesProvider>()
                .SelectMany(m => m.GetDependedTypes())
                .Distinct()
                .ToArray());
     }
     else
     {
         return(base.GetDependedModuleTypes(moduleType));
     }
 }
Exemplo n.º 8
0
        private static void AddModuleAndDependenciesResursively(List <Type> moduleTypes, Type moduleType)
        {
            if (!AbpModule.IsAbpModule(moduleType))
            {
                throw new ArgumentException("Given type is not an ABP module: " + moduleType.AssemblyQualifiedName);
            }
            if (moduleTypes.Contains(moduleType))
            {
                return;
            }

            moduleTypes.Add(moduleType);

            foreach (var dependedModuleType in FindDependedModuleTypes(moduleType))
            {
                AddModuleAndDependenciesResursively(moduleTypes, dependedModuleType);
            }
        }
Exemplo n.º 9
0
        public static List <Type> FindDependedModuleTypes(Type moduleType)
        {
            if (!AbpModule.IsAbpModule(moduleType))
            {
                throw new ArgumentException("Given type is not an ABP module: " + moduleType.AssemblyQualifiedName);
            }
            var dependencies = new List <Type>();

            var dependencyDescriptors = moduleType
                                        .GetCustomAttributes()
                                        .OfType <IDependedTypesProvider>();

            foreach (var descriptor in dependencyDescriptors)
            {
                foreach (var dependedModuleType in descriptor.GetDependedTypes())
                {
                    dependencies.AddIfNotContains(dependedModuleType);
                }
            }

            return(dependencies);
        }
 public override bool CanCreate(Type type)
 {
     return(base.CanCreate(type) || AbpModule.IsAbpModule(type));
 }