private string GetExtensionHash(ExtensionLoadingContext context, FileSystems.Dependencies.DependencyDescriptor dependencyDescriptor) { var hash = new Hash(); hash.AddStringInvariant(dependencyDescriptor.Name); foreach (var virtualpathDependency in context.ProcessedExtensions[dependencyDescriptor.Name].VirtualPathDependencies) { hash.AddDateTime(GetVirtualPathModificationTimeUtc(context.VirtualPathModficationDates, virtualpathDependency)); } foreach (var reference in dependencyDescriptor.References) { hash.AddStringInvariant(reference.Name); hash.AddString(reference.LoaderName); hash.AddDateTime(GetVirtualPathModificationTimeUtc(context.VirtualPathModficationDates, reference.VirtualPath)); } return(hash.Value); }
/// <summary> /// 扩展删除。 /// </summary> /// <param name="context">扩展装载上下文。</param> /// <param name="dependency">依赖项描述符。</param> public override void ExtensionRemoved(ExtensionLoadingContext context, FileSystems.Dependencies.DependencyDescriptor dependency) { if (!_assemblyProbingFolder.AssemblyExists(new AssemblyDescriptor(dependency.Name))) { return; } context.DeleteActions.Add( () => { Logger.Information("ExtensionRemoved: 删除在探测目录中的程序集 \"{0}\"", dependency.Name); _assemblyProbingFolder.DeleteAssembly(dependency.Name); }); //如果程序集已经被加载,需要重新启动AppDomain if (!_hostEnvironment.IsAssemblyLoaded(dependency.Name)) { return; } Logger.Information("ExtensionRemoved: 模块\"{0}\"被删除,它的程序集加载,迫使AppDomain重启", dependency.Name); context.RestartAppDomain = true; }
/// <summary> /// 扩展删除。 /// </summary> /// <param name="context">扩展装载上下文。</param> /// <param name="dependency">依赖项描述符。</param> public override void ExtensionRemoved(ExtensionLoadingContext context, FileSystems.Dependencies.DependencyDescriptor dependency) { DeleteAssembly(context, dependency.Name); }
/// <summary> /// 获取依赖文件的虚拟路径。 /// </summary> /// <param name="dependency">依赖项描述符。</param> /// <returns>虚拟路径集合。</returns> public virtual IEnumerable <string> GetVirtualPathDependencies(FileSystems.Dependencies.DependencyDescriptor dependency) { return(Enumerable.Empty <string>()); }
/// <summary> /// 获取编译引用信息。 /// </summary> /// <param name="dependency"></param> /// <returns>扩展编译引用集合。</returns> public virtual IEnumerable <ExtensionCompilationReference> GetCompilationReferences(FileSystems.Dependencies.DependencyDescriptor dependency) { return(Enumerable.Empty <ExtensionCompilationReference>()); }
/// <summary> /// 扩展删除。 /// </summary> /// <param name="context">扩展装载上下文。</param> /// <param name="dependency">依赖项描述符。</param> public virtual void ExtensionRemoved(ExtensionLoadingContext context, FileSystems.Dependencies.DependencyDescriptor dependency) { }
/// <summary> /// 获取依赖文件的虚拟路径。 /// </summary> /// <param name="dependency">依赖项描述符。</param> /// <returns>虚拟路径集合。</returns> public override IEnumerable <string> GetVirtualPathDependencies(FileSystems.Dependencies.DependencyDescriptor dependency) { yield return(_assemblyProbingFolder.GetAssemblyVirtualPath(new AssemblyDescriptor(dependency.Name))); }
/// <summary> /// 获取编译引用信息。 /// </summary> /// <param name="dependency"></param> /// <returns>扩展编译引用集合。</returns> public override IEnumerable <ExtensionCompilationReference> GetCompilationReferences(FileSystems.Dependencies.DependencyDescriptor dependency) { yield return(new ExtensionCompilationReference { AssemblyName = dependency.Name }); }