• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# ExtensionLoadingContext类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: ExtensionRemoved

 public override void ExtensionRemoved(ExtensionLoadingContext ctx, DependencyDescriptor dependency) {
 }
开发者ID:kyletowb,项目名称:InfusionDocs,代码行数:2,代码来源:DynamicExtensionLoader.cs


示例17: ExtensionDeactivated

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


示例18: DeleteAssembly

 private void DeleteAssembly(ExtensionLoadingContext ctx, string moduleName)
 {
     var assemblyPath = _virtualPathProvider.Combine("~/bin", moduleName + ".dll");
     if (!_virtualPathProvider.FileExists(assemblyPath))
         return;
     ctx.DeleteActions.Add(
         () =>
         {
             Logger.Information("ExtensionRemoved: 从 bin 目录删除程序集 \"{0}\"(AppDomain将重新启动)", moduleName);
             _virtualPathProvider.DeleteFile(assemblyPath);
         });
     ctx.RestartAppDomain = true;
 }
开发者ID:l1183479157,项目名称:RabbitHub,代码行数:13,代码来源:ReferencedExtensionLoader.cs


示例19: ExtensionRemoved

        /// <summary>
        /// 扩展删除。
        /// </summary>
        /// <param name="context">扩展装载上下文。</param>
        /// <param name="dependency">依赖项描述符。</param>
        public override void ExtensionRemoved(ExtensionLoadingContext context, 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;
        }
开发者ID:l1183479157,项目名称:RabbitHub,代码行数:23,代码来源:PrecompiledExtensionLoader.cs


示例20: ExtensionRemoved

 /// <summary>
 /// 扩展删除。
 /// </summary>
 /// <param name="context">扩展装载上下文。</param>
 /// <param name="dependency">依赖项描述符。</param>
 public override void ExtensionRemoved(ExtensionLoadingContext context, DependencyDescriptor dependency)
 {
     DeleteAssembly(context, dependency.Name);
 }
开发者ID:l1183479157,项目名称:RabbitHub,代码行数:9,代码来源:ReferencedExtensionLoader.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ExtensionType类代码示例发布时间:2022-05-24
下一篇:
C# ExtensibleModelBindingContext类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap