public override void ExtensionRemoved(ExtensionLoadingContext ctx, DependencyDescriptor dependency)
        {
            if (_assemblyProbingFolder.AssemblyExists(dependency.Name))
            {
                ctx.DeleteActions.Add(
                    () => {
                    Logger.Information("ExtensionRemoved: Deleting assembly \"{0}\" from probing directory", dependency.Name);
                    _assemblyProbingFolder.DeleteAssembly(dependency.Name);
                });

                // We need to restart the appDomain if the assembly is loaded
                if (_hostEnvironment.IsAssemblyLoaded(dependency.Name))
                {
                    Logger.Information("ExtensionRemoved: Module \"{0}\" is removed and its assembly is loaded, forcing AppDomain restart", dependency.Name);
                    ctx.RestartAppDomain = true;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 扩展停用。
        /// </summary>
        /// <param name="context">扩展装载上下文。</param>
        /// <param name="descriptor">扩展描述符条目。</param>
        public override void ExtensionDeactivated(ExtensionLoadingContext context, ExtensionDescriptorEntry descriptor)
        {
            if (!_assemblyProbingFolder.AssemblyExists(new AssemblyDescriptor(descriptor.Id)))
            {
                return;
            }

            context.DeleteActions.Add(
                () =>
            {
                Logger.Information("ExtensionDeactivated: 删除在探测目录中的程序集 \"{0}\"", descriptor.Id);
                _assemblyProbingFolder.DeleteAssembly(descriptor.Id);
            });

            //如果程序集已经被加载,需要重新启动AppDomain
            if (!_hostEnvironment.IsAssemblyLoaded(descriptor.Id))
            {
                return;
            }
            Logger.Information("ExtensionDeactivated: 模块 \"{0}\" 已停用,它的程序集已经被加载,迫使AppDomain重启", descriptor.Id);
            context.RestartAppDomain = true;
        }