private void ProcessExtensionReference(ExtensionLoadingContext context, ExtensionProbeEntry activatedExtension, string referenceName, IList <DependencyReferenceDescriptor> activatedReferences) { // If the reference is an extension has been processed already, use the same loader as // that extension, since a given extension should be loaded with a unique loader for the // whole application var bestExtensionReference = context.ProcessedExtensions.ContainsKey(referenceName) ? context.ProcessedExtensions[referenceName] : null; // Activated the extension reference if (bestExtensionReference != null) { activatedReferences.Add(new DependencyReferenceDescriptor { LoaderName = bestExtensionReference.Loader.Name, Name = referenceName, VirtualPath = bestExtensionReference.VirtualPath }); return; } // Skip references from "~/bin" if (_buildManager.HasReferencedAssembly(referenceName)) { return; } // Binary references var references = context.ReferencesByName.ContainsKey(referenceName) ? context.ReferencesByName[referenceName] : Enumerable.Empty <ExtensionReferenceProbeEntry>(); var bestBinaryReference = references .Where(entry => !string.IsNullOrEmpty(entry.VirtualPath)) .Select(entry => new { Entry = entry, LastWriteTimeUtc = _virtualPathProvider.GetFileLastWriteTimeUtc(entry.VirtualPath) }) .OrderBy(e => e.LastWriteTimeUtc) .ThenBy(e => e.Entry.Name) .FirstOrDefault(); // Activate the binary ref if (bestBinaryReference != null) { if (!context.ProcessedReferences.ContainsKey(bestBinaryReference.Entry.Name)) { context.ProcessedReferences.Add(bestBinaryReference.Entry.Name, bestBinaryReference.Entry); bestBinaryReference.Entry.Loader.ReferenceActivated(context, bestBinaryReference.Entry); } activatedReferences.Add(new DependencyReferenceDescriptor { LoaderName = bestBinaryReference.Entry.Loader.Name, Name = bestBinaryReference.Entry.Name, VirtualPath = bestBinaryReference.Entry.VirtualPath }); return; } }
private DateTime GetVirtualPathModificationTimeUtc(ConcurrentDictionary <string, DateTime> virtualPathDependencies, string path) { return(virtualPathDependencies.GetOrAdd(path, p => { var value = _virtualPathProvider.GetFileLastWriteTimeUtc(p); return !value.HasValue ? DateTime.MinValue : value.Value; })); }
/// <summary> /// 获取文件或目录最后的写入UTC时间。 /// </summary> /// <param name="virtualPathProvider">虚拟路径提供者。</param> /// <param name="virtualPath">虚拟路径。</param> /// <returns>UTC时间。</returns> public static DateTime?GetLastWriteTimeUtc(this IVirtualPathProvider virtualPathProvider, string virtualPath) { virtualPathProvider.NotNull("virtualPathProvider"); virtualPath.NotEmptyOrWhiteSpace("virtualPath"); var dateTime = virtualPathProvider.GetFileLastWriteTimeUtc(virtualPath); return(dateTime.HasValue ? dateTime : virtualPathProvider.GetDirectoryLastWriteTimeUtc(virtualPath)); }
/// <summary> /// Determines if a module was recently installed by using the project's last written time. /// </summary> /// <param name="extensionDescriptor">The extension descriptor.</param> public bool IsRecentlyInstalled(ExtensionDescriptor extensionDescriptor) { DateTime lastWrittenUtc = _cacheManager.Get(extensionDescriptor, descriptor => { string projectFile = GetManifestPath(extensionDescriptor); if (!string.IsNullOrEmpty(projectFile)) { // If project file was modified less than 24 hours ago, the module was recently deployed return(_virtualPathProvider.GetFileLastWriteTimeUtc(projectFile)); } return(DateTime.UtcNow); }); return(DateTime.UtcNow.Subtract(lastWrittenUtc) < new TimeSpan(1, 0, 0, 0)); }
private DateTime GetVirtualPathModificationTimeUtc(ConcurrentDictionary <string, DateTime> virtualPathDependencies, string path) { return(virtualPathDependencies.GetOrAdd(path, p => _virtualPathProvider.GetFileLastWriteTimeUtc(p))); }