예제 #1
0
        public List <IModule> LoadModules(IDirectoryContents moduleRootFolder)
        {
            foreach (var moduleFolder in moduleRootFolder.Where(x => x.IsDirectory))
            {
                try
                {
                    var binFolder = new DirectoryInfo(Path.Combine(moduleFolder.PhysicalPath, "bin"));
                    if (!binFolder.Exists)
                    {
                        continue;
                    }

                    foreach (var file in binFolder.GetFileSystemInfos("*.dll", SearchOption.AllDirectories))
                    {
                        Assembly assembly;
                        try
                        {
                            assembly = NccAssemblyLoader.LoadFromFileName(file.FullName);
                        }
                        catch (FileLoadException ex)
                        {
                            continue;
                        }
                        catch (BadImageFormatException ex)
                        {
                            continue;
                        }

                        if (assembly.FullName.Contains(moduleFolder.Name))
                        {
                            if (modules.Count(x => x.Folder == moduleFolder.Name && x.Path == moduleFolder.PhysicalPath) == 0)
                            {
                                modules.Add(new Module {
                                    Folder = moduleFolder.Name, Assembly = assembly, Path = moduleFolder.PhysicalPath
                                });
                            }
                        }
                        else
                        {
                            DependencyContextLoader.Default.Load(assembly);
                        }
                    }

                    LoadModuleDependencies(moduleFolder);
                }
                catch (Exception ex)
                {
                    throw new Exception("Could not load module from " + moduleFolder);
                }
            }

            GlobalContext.SetModuleDependencies(_moduleDependencies);

            return(modules);
        }
예제 #2
0
        public void LoadModules(IDirectoryContents moduleRootFolder, ILogger logger)
        {
            _logger = logger;
            foreach (var moduleFolder in moduleRootFolder.Where(x => x.IsDirectory).ToList())
            {
                try
                {
                    var binFolder = new DirectoryInfo(Path.Combine(moduleFolder.PhysicalPath, "bin"));
                    if (!binFolder.Exists)
                    {
                        continue;
                    }

                    foreach (var file in binFolder.GetFileSystemInfos("*.dll", SearchOption.AllDirectories))
                    {
                        Assembly assembly;
                        try
                        {
                            assembly = NccAssemblyLoader.LoadFromFileName(file.FullName);
                        }
                        catch (FileLoadException ex)
                        {
                            _logger.LogWarning(ex.Message, ex);
                            continue;
                        }
                        catch (BadImageFormatException ex)
                        {
                            _logger.LogWarning(ex.Message, ex);
                            continue;
                        }

                        if (assembly.FullName.Contains(moduleFolder.Name))
                        {
                            if (modules.Count(x => x.Folder == moduleFolder.Name && x.Path == moduleFolder.PhysicalPath) == 0)
                            {
                                modules.Add(new Module {
                                    ExecutionOrder = 100, ModuleName = moduleFolder.Name, Folder = moduleFolder.Name, Assembly = assembly, Path = moduleFolder.PhysicalPath
                                });
                            }
                        }
                        else
                        {
                            DependencyContextLoader.Default.Load(assembly);
                        }
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogWarning("Could not load module from " + moduleFolder);
                    _logger.LogError(ex.Message, ex);
                    //throw new Exception("Could not load module from " + moduleFolder);
                }
            }
        }
예제 #3
0
        public void RegisterThemes(IMvcBuilder mvcBuilder, IServiceCollection services, IServiceProvider serviceProvider, IDirectoryContents themes)
        {
            _themeDlls = new List <Assembly>();
            foreach (var themeFolder in themes.Where(x => x.IsDirectory))
            {
                try
                {
                    var binFolder = new DirectoryInfo(Path.Combine(themeFolder.PhysicalPath, "bin"));
                    if (!binFolder.Exists)
                    {
                        continue;
                    }

                    foreach (var file in binFolder.GetFileSystemInfos("*.dll", SearchOption.AllDirectories))
                    {
                        Assembly assembly;
                        try
                        {
                            assembly = NccAssemblyLoader.LoadFromFileName(file.FullName);
                        }
                        catch (FileLoadException ex)
                        {
                            continue;
                        }
                        catch (BadImageFormatException ex)
                        {
                            continue;
                        }

                        if (assembly.FullName.Contains(themeFolder.Name))
                        {
                            _themeDlls.Add(assembly);
                            if (ThemeHelper.ActiveTheme.ThemeId == themeFolder.Name)
                            {
                                mvcBuilder.AddApplicationPart(assembly);
                                var widgetTypeList = assembly.GetTypes().Where(x => typeof(Widget).IsAssignableFrom(x)).ToList();
                                foreach (var widgetType in widgetTypeList)
                                {
                                    services.AddTransient(widgetType);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    RegisterErrorMessage("Could not load theme from " + themeFolder);
                }
            }

            mvcBuilder.AddRazorOptions(o =>
            {
                foreach (var theme in _themeDlls)
                {
                    var themeFolder = theme.GetName().Name;

                    if (themeFolder == ThemeHelper.ActiveTheme.ThemeId)
                    {
                        o.AdditionalCompilationReferences.Add(MetadataReference.CreateFromFile(theme.Location));
                    }
                }
            });
        }
예제 #4
0
        private void LoadModuleDependencies(string modulePath, string moduleName)
        {
            var moduleDependencyFolder = new DirectoryInfo(Path.Combine(modulePath, Constants.ModuleDepencencyFolder, "Module"));

            if (moduleDependencyFolder.Exists)
            {
                foreach (var file in moduleDependencyFolder.GetFileSystemInfos("*.dll", SearchOption.AllDirectories))
                {
                    Assembly assembly;
                    try
                    {
                        assembly = NccAssemblyLoader.LoadFromFileName(file.FullName);
                        DependencyContextLoader.Default.Load(assembly);
                    }
                    catch (FileLoadException ex)
                    {
                        continue;
                    }
                    catch (BadImageFormatException ex)
                    {
                        continue;
                    }
                }
            }


            var viewFolder = new DirectoryInfo(Path.Combine(modulePath, Constants.ModuleDepencencyFolder, "View"));

            if (viewFolder.Exists)
            {
                foreach (var file in viewFolder.GetFileSystemInfos("*.dll", SearchOption.AllDirectories))
                {
                    Assembly assembly;
                    try
                    {
                        var moduleDependency = new ModuleDependedLibrary();
                        if (_moduleDependencies.ContainsKey(moduleName))
                        {
                            moduleDependency = (ModuleDependedLibrary)_moduleDependencies[moduleName];
                        }
                        else
                        {
                            _moduleDependencies.Add(moduleName, moduleDependency);
                        }

                        if (moduleDependency.AssemblyPaths.Contains(Path.Combine(file.FullName)) == false)
                        {
                            assembly = NccAssemblyLoader.LoadFromFileName(file.FullName);
                            DependencyContextLoader.Default.Load(assembly);
                            moduleDependency.AssemblyPaths.Add(file.FullName);
                            _moduleDependencies[moduleName] = moduleDependency;
                        }
                    }
                    catch (FileLoadException ex)
                    {
                        continue;
                    }
                    catch (BadImageFormatException ex)
                    {
                        continue;
                    }
                }
            }
        }