当前位置: 首页>>代码示例>>C#>>正文


C# ExtensionLoadingContext类代码示例

本文整理汇总了C#中ExtensionLoadingContext的典型用法代码示例。如果您正苦于以下问题:C# ExtensionLoadingContext类的具体用法?C# ExtensionLoadingContext怎么用?C# ExtensionLoadingContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ExtensionLoadingContext类属于命名空间,在下文中一共展示了ExtensionLoadingContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExtensionActivated

 public override void ExtensionActivated(ExtensionLoadingContext ctx, ExtensionDescriptor extension)
 {
     if (_reloadWorkaround.AppDomainRestartNeeded) {
         Logger.Information("ExtensionActivated: Module \"{0}\" has changed, forcing AppDomain restart", extension.Id);
         ctx.RestartAppDomain = _reloadWorkaround.AppDomainRestartNeeded;
     }
 }
开发者ID:gokhandisikara,项目名称:Coevery-Framework,代码行数:7,代码来源:DynamicExtensionLoader.cs

示例2: DeleteAssembly

 private void DeleteAssembly(ExtensionLoadingContext ctx, string moduleName) {
     var assemblyPath = _virtualPathProvider.Combine("~/bin", moduleName + ".dll");
     if (_virtualPathProvider.FileExists(assemblyPath)) {
         ctx.DeleteActions.Add(
             () => {
                 Logger.Information("ExtensionRemoved: Deleting assembly \"{0}\" from bin directory (AppDomain will restart)", moduleName);
                 File.Delete(_virtualPathProvider.MapPath(assemblyPath));
             });
         ctx.RestartAppDomain = true;
     }
 }
开发者ID:SunRobin2015,项目名称:RobinWithOrchard,代码行数:11,代码来源:ReferencedExtensionLoader.cs

示例3: ExtensionRemoved

        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;
                }
            }
        }
开发者ID:RasterImage,项目名称:Orchard,代码行数:15,代码来源:PrecompiledExtensionLoader.cs

示例4: ExtensionActivated

        public override void ExtensionActivated(ExtensionLoadingContext ctx, ExtensionDescriptor extension) {
            string sourceFileName = _virtualPathProvider.MapPath(GetAssemblyPath(extension));

            // Copy the assembly if it doesn't exist or if it is older than the source file.
            bool copyAssembly =
                !_assemblyProbingFolder.AssemblyExists(extension.Id) ||
                File.GetLastWriteTimeUtc(sourceFileName) > _assemblyProbingFolder.GetAssemblyDateTimeUtc(extension.Id);

            if (copyAssembly) {
                ctx.CopyActions.Add(() => _assemblyProbingFolder.StoreAssembly(extension.Id, sourceFileName));

                // We need to restart the appDomain if the assembly is loaded
                if (_hostEnvironment.IsAssemblyLoaded(extension.Id)) {
                    Logger.Information("ExtensionRemoved: Module \"{0}\" is activated with newer file and its assembly is loaded, forcing AppDomain restart", extension.Id);
                    ctx.RestartAppDomain = true;
                }
            }
        }
开发者ID:RasterImage,项目名称:Orchard,代码行数:18,代码来源:PrecompiledExtensionLoader.cs

示例5: ExtensionDeactivated

 public override void ExtensionDeactivated(ExtensionLoadingContext ctx, ExtensionDescriptor extension)
 {
     DeleteAssembly(ctx, extension.Id);
 }
开发者ID:gokhandisikara,项目名称:Coevery-Framework,代码行数:4,代码来源:ReferencedExtensionLoader.cs

示例6: ProcessExtension

        private void ProcessExtension(ExtensionLoadingContext context, ExtensionDescriptorEntry extension)
        {
            var extensionProbes = context.AvailableExtensionsProbes.ContainsKey(extension.Id) ?
                context.AvailableExtensionsProbes[extension.Id] :
                Enumerable.Empty<ExtensionProbeEntry>();

            var extensionProbeEntries = extensionProbes as ExtensionProbeEntry[] ?? extensionProbes.ToArray();
            if (Logger.IsEnabled(LogLevel.Debug))
            {
                Logger.Debug("加载扩展 \"{0}\": ", extension.Id);
                foreach (var probe in extensionProbeEntries)
                {
                    Logger.Debug("  Loader: {0}", probe.Loader.Name);
                    Logger.Debug("    VirtualPath: {0}", probe.VirtualPath);
                    Logger.Debug("    VirtualPathDependencies: {0}", string.Join(", ", probe.VirtualPathDependencies));
                }
            }

            var moduleReferences =
                context.AvailableExtensions
                    .Where(e =>
                           context.ReferencesByModule.ContainsKey(extension.Id) &&
                           context.ReferencesByModule[extension.Id].Any(r => StringComparer.OrdinalIgnoreCase.Equals(e.Id, r.Name)))
                    .ToList();

            var processedModuleReferences =
                moduleReferences
                .Where(e => context.ProcessedExtensions.ContainsKey(e.Id))
                .Select(e => context.ProcessedExtensions[e.Id])
                .ToList();

            var activatedExtension = extensionProbeEntries.FirstOrDefault(
                e => e.Loader.IsCompatibleWithModuleReferences(extension, processedModuleReferences)
                );

            var previousDependency = context.PreviousDependencies.FirstOrDefault(
                d => StringComparer.OrdinalIgnoreCase.Equals(d.Name, extension.Id)
                );

            if (activatedExtension == null)
            {
                Logger.Warning("没有找到装载机来装载扩展 \"{0}\"!", extension.Id);
            }

            var references = ProcessExtensionReferences(context, activatedExtension);

            foreach (var loader in _loaders)
            {
                if (activatedExtension != null && activatedExtension.Loader.Name == loader.Name)
                {
                    Logger.Information("使用装载机 \"{1}\" 来激活扩展 \"{0}\"", activatedExtension.Descriptor.Id, loader.Name);
                    loader.ExtensionActivated(context, extension);
                }
                else if (previousDependency != null && previousDependency.LoaderName == loader.Name)
                {
                    Logger.Information("使用装载机 \"{1}\" 来停用扩展 \"{0}\"", previousDependency.Name, loader.Name);
                    loader.ExtensionDeactivated(context, extension);
                }
            }

            if (activatedExtension != null)
            {
                context.NewDependencies.Add(new DependencyDescriptor
                {
                    Name = extension.Id,
                    LoaderName = activatedExtension.Loader.Name,
                    VirtualPath = activatedExtension.VirtualPath,
                    References = references
                });
            }

            //跟踪哪些装载机,我们使用的每一个扩展
            //这将需要从其他相关的扩展处理参考
            context.ProcessedExtensions.Add(extension.Id, activatedExtension);
        }
开发者ID:l1183479157,项目名称:RabbitHub,代码行数:75,代码来源:DefaultExtensionLoaderCoordinator.cs

示例7: ExtensionDeactivated

 public void ExtensionDeactivated(ExtensionLoadingContext ctx, ExtensionDescriptor extension)
 {
 }
开发者ID:jchenga,项目名称:Orchard2,代码行数:3,代码来源:DynamicExtensionLoader.cs

示例8: ExtensionDeactivated

 /// <summary>
 /// 扩展停用。
 /// </summary>
 /// <param name="context">扩展装载上下文。</param>
 /// <param name="descriptor">扩展描述符条目。</param>
 public override void ExtensionDeactivated(ExtensionLoadingContext context, ExtensionDescriptorEntry descriptor)
 {
     DeleteAssembly(context, descriptor.Id);
 }
开发者ID:l1183479157,项目名称:RabbitHub,代码行数:9,代码来源:ReferencedExtensionLoader.cs

示例9: ExtensionRemoved

 public virtual void ExtensionRemoved(ExtensionLoadingContext ctx, DependencyDescriptor dependency) { }
开发者ID:RasterImage,项目名称:Orchard,代码行数:1,代码来源:ExtensionLoaderBase.cs

示例10: ExtensionActivated

        /// <summary>
        /// 扩展激活。
        /// </summary>
        /// <param name="context">扩展装载上下文。</param>
        /// <param name="descriptor">扩展描述符条目。</param>
        public override void ExtensionActivated(ExtensionLoadingContext context, ExtensionDescriptorEntry descriptor)
        {
            var sourceFileName = _applicationFolder.MapPath(GetAssemblyPath(descriptor));

            //如果程序集文件不存在或者比新的旧则复制新的程序集文件到依赖目录。
            var copyAssembly =
                !_assemblyProbingFolder.AssemblyExists(new AssemblyDescriptor(descriptor.Id)) ||
                File.GetLastWriteTimeUtc(sourceFileName) > _assemblyProbingFolder.GetAssemblyDateTimeUtc(new AssemblyDescriptor(descriptor.Id));

            if (!copyAssembly)
                return;
            context.CopyActions.Add(() => _assemblyProbingFolder.StoreAssembly(new AssemblyDescriptor(descriptor.Id), sourceFileName));

            //如果程序集已经被加载,需要重新启动AppDomain
            if (!_hostEnvironment.IsAssemblyLoaded(descriptor.Id))
                return;
            Logger.Information("ExtensionRemoved: 模块 \"{0}\" 激活新的程序集文件加载,迫使AppDomain重启", descriptor.Id);
            context.RestartAppDomain = true;
        }
开发者ID:l1183479157,项目名称:RabbitHub,代码行数:24,代码来源:PrecompiledExtensionLoader.cs

示例11: ReferenceActivated

        /// <summary>
        /// 激活引用。
        /// </summary>
        /// <param name="context">扩展装载上下文。</param>
        /// <param name="referenceEntry">引用条目。</param>
        public override void ReferenceActivated(ExtensionLoadingContext context, ExtensionReferenceProbeEntry referenceEntry)
        {
            if (string.IsNullOrEmpty(referenceEntry.VirtualPath))
                return;

            var sourceFileName = _applicationFolder.MapPath(referenceEntry.VirtualPath);

            //如果程序集文件不存在或者比新的旧则复制新的程序集文件到依赖目录。
            var copyAssembly =
                !_assemblyProbingFolder.AssemblyExists(new AssemblyDescriptor(referenceEntry.Name)) ||
                File.GetLastWriteTimeUtc(sourceFileName) > _assemblyProbingFolder.GetAssemblyDateTimeUtc(new AssemblyDescriptor(referenceEntry.Name));

            if (!copyAssembly)
                return;
            context.CopyActions.Add(() => _assemblyProbingFolder.StoreAssembly(new AssemblyDescriptor(referenceEntry.Name), sourceFileName));

            //如果程序集已经被加载,需要重新启动AppDomain
            if (!_hostEnvironment.IsAssemblyLoaded(referenceEntry.Name))
                return;
            Logger.Information("ReferenceActivated: 引用 \"{0}\" 激活新的程序集文件加载,迫使AppDomain重启", referenceEntry.Name);
            context.RestartAppDomain = true;
        }
开发者ID:l1183479157,项目名称:RabbitHub,代码行数:27,代码来源:PrecompiledExtensionLoader.cs

示例12: ProcessContextCommands

        private void ProcessContextCommands(ExtensionLoadingContext ctx)
        {
            Logger.Information("执行的加载扩展所需的操作列表...");
            foreach (var action in ctx.DeleteActions)
            {
                action();
            }

            foreach (var action in ctx.CopyActions)
            {
                action();
            }
        }
开发者ID:l1183479157,项目名称:RabbitHub,代码行数:13,代码来源:DefaultExtensionLoaderCoordinator.cs

示例13: ProcessExtensionReference

        private void ProcessExtensionReference(ExtensionLoadingContext context, string referenceName, ICollection<DependencyReferenceDescriptor> activatedReferences)
        {
            //如果参考是一个扩展已经被处理,使用相同的装载机扩展,因为给定的扩展名应具有独特的装载机在整个应用程序加载
            var bestExtensionReference = context.ProcessedExtensions.ContainsKey(referenceName) ?
                context.ProcessedExtensions[referenceName] :
                null;

            //激活扩展引用
            if (bestExtensionReference != null)
            {
                activatedReferences.Add(new DependencyReferenceDescriptor
                {
                    LoaderName = bestExtensionReference.Loader.Name,
                    Name = referenceName,
                    VirtualPath = bestExtensionReference.VirtualPath
                });

                return;
            }

            //跳过来自 "~/bin" 的引用。
            if (_buildManager.HasReferencedAssembly(referenceName))
                return;

            //二进制引用
            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();

            //激活二进制引用
            if (bestBinaryReference == null)
                return;

            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
            });
        }
开发者ID:l1183479157,项目名称:RabbitHub,代码行数:52,代码来源:DefaultExtensionLoaderCoordinator.cs

示例14: ProcessExtensionReferences

        private IEnumerable<DependencyReferenceDescriptor> ProcessExtensionReferences(ExtensionLoadingContext context, ExtensionProbeEntry activatedExtension)
        {
            if (activatedExtension == null)
                return Enumerable.Empty<DependencyReferenceDescriptor>();

            var referenceNames = (context.ReferencesByModule.ContainsKey(activatedExtension.Descriptor.Id) ?
                context.ReferencesByModule[activatedExtension.Descriptor.Id] :
                Enumerable.Empty<ExtensionReferenceProbeEntry>())
                .Select(r => r.Name)
                .Distinct(StringComparer.OrdinalIgnoreCase);

            var referencesDecriptors = new List<DependencyReferenceDescriptor>();
            foreach (var referenceName in referenceNames)
            {
                ProcessExtensionReference(context, referenceName, referencesDecriptors);
            }

            return referencesDecriptors;
        }
开发者ID:l1183479157,项目名称:RabbitHub,代码行数:19,代码来源:DefaultExtensionLoaderCoordinator.cs

示例15: ReferenceActivated

        public override void ReferenceActivated(ExtensionLoadingContext context, ExtensionReferenceProbeEntry referenceEntry) {
            //Note: This is the same implementation as "PrecompiledExtensionLoader"
            if (string.IsNullOrEmpty(referenceEntry.VirtualPath))
                return;

            string sourceFileName = _virtualPathProvider.MapPath(referenceEntry.VirtualPath);

            // Copy the assembly if it doesn't exist or if it is older than the source file.
            bool copyAssembly =
                !_assemblyProbingFolder.AssemblyExists(referenceEntry.Name) ||
                File.GetLastWriteTimeUtc(sourceFileName) > _assemblyProbingFolder.GetAssemblyDateTimeUtc(referenceEntry.Name);

            if (copyAssembly) {
                context.CopyActions.Add(() => _assemblyProbingFolder.StoreAssembly(referenceEntry.Name, sourceFileName));

                // We need to restart the appDomain if the assembly is loaded
                if (_hostEnvironment.IsAssemblyLoaded(referenceEntry.Name)) {
                    Logger.Information("ReferenceActivated: Reference \"{0}\" is activated with newer file and its assembly is loaded, forcing AppDomain restart", referenceEntry.Name);
                    context.RestartAppDomain = true;
                }
            }
        }
开发者ID:kyletowb,项目名称:InfusionDocs,代码行数:22,代码来源:DynamicExtensionLoader.cs


注:本文中的ExtensionLoadingContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。