示例#1
0
        public void DeleteModule(string moduleName)
        {
            var context = _pluginsLoadContexts.Get(moduleName);

            if (context != null)
            {
                _pluginsLoadContexts.Remove(moduleName);
            }
            ModuleChangeEventHandler?.Invoke(ModuleEvent.UnInstalled, context);
            //删除静态文件
            DirectoryInfo staticDirectory = new DirectoryInfo(Path.Combine(_baseDirectory, _pluginOptions.InstallBasePath, moduleName, $"wwwroot"));

            if (staticDirectory.Exists)
            {
                foreach (var item in staticDirectory.GetDirectories())
                {
                    DirectoryInfo tempdir = new DirectoryInfo(Path.Combine(_env.WebRootPath, item.Name));
                    if (tempdir.Exists)
                    {
                        tempdir.Delete(true);
                    }
                }
            }

            DirectoryInfo directory = new DirectoryInfo(Path.Combine(_baseDirectory, _pluginOptions.InstallBasePath, moduleName));

            directory.Delete(true);
        }
示例#2
0
        public void DisableModule(string moduleName)
        {
            var ss      = System.Runtime.Loader.AssemblyLoadContext.All;
            var context = _pluginsLoadContexts.Get(moduleName);

            foreach (var part in context.PluginAssemblyParts)
            {
                _partManager.ApplicationParts.Remove(part);
            }
            context.Disable();
            //_pluginContextContainer.Remove(moduleName);
            ModuleChangeEventHandler?.Invoke(ModuleEvent.Stoped, context);
            _notificationRegister.UnRegisterFrom(context);
            ResetControllActions();
            ss = System.Runtime.Loader.AssemblyLoadContext.All;
        }
示例#3
0
        public void LoadModule(string moduleName, bool isInstall = true)
        {
            if (!_pluginsLoadContexts.Any(moduleName))
            {
                CollectibleAssemblyLoadContext context = new CollectibleAssemblyLoadContext(moduleName);

                string filePath            = Path.Combine(_baseDirectory, _pluginOptions.InstallBasePath, moduleName, $"{moduleName}.dll");
                string referenceFolderPath = Path.Combine(_baseDirectory, _pluginOptions.InstallBasePath, moduleName);
                using (FileStream fs = new FileStream(filePath, FileMode.Open))
                {
                    Assembly assembly = context.LoadFromStream(fs);
                    _referenceLoader.LoadStreamsIntoContext(context, referenceFolderPath, assembly);

                    context.SetEntryPoint(assembly);
                    context.PluginAssemblyParts.Add(new PluginAssemblyPart(assembly));
                    if (!AdditionalReferencePathHolder.AdditionalReferencePaths.Contains(filePath))
                    {
                        AdditionalReferencePathHolder.AdditionalReferencePaths.Add(filePath);
                    }
                }
                var viewsFilePath = Path.Combine(_baseDirectory, _pluginOptions.InstallBasePath, moduleName, $"{moduleName}.Views.dll");
                if (File.Exists(viewsFilePath))
                {
                    using (FileStream fs = new FileStream(viewsFilePath, FileMode.Open))
                    {
                        Assembly assembly = context.LoadFromStream(fs);
                        context.PluginAssemblyParts.Add(new CompiledRazorAssemblyPart(assembly));
                        _referenceLoader.LoadStreamsIntoContext(context, referenceFolderPath, assembly);
                    }
                }
                var pluginWebRoot = Path.Combine(_baseDirectory, _pluginOptions.InstallBasePath, moduleName, $"wwwroot");
                DirectoryCopy(pluginWebRoot, _env.WebRootPath, true);
                _pluginsLoadContexts.Add(moduleName, context);
                if (isInstall)
                {
                    ModuleChangeEventHandler?.Invoke(ModuleEvent.Installed, context);
                }
                else
                {
                    ModuleChangeEventHandler?.Invoke(ModuleEvent.Loaded, context);
                }
            }
        }
示例#4
0
        public void EnableModule(string moduleName)
        {
            if (!_pluginsLoadContexts.Any(moduleName))
            {
                ReLoadModule(moduleName, false);
            }
            CollectibleAssemblyLoadContext context = _pluginsLoadContexts.Get(moduleName);

            foreach (var part in context.PluginAssemblyParts)
            {
                _partManager.ApplicationParts.Add(part);
            }

            context.Enable();
            //_pluginContextContainer.AddFromLoadContext(context);
            _notificationRegister.RegisterFrom(_pluginsLoadContexts.Get(moduleName));
            ResetControllActions();
            ModuleChangeEventHandler?.Invoke(ModuleEvent.Started, context);
        }