示例#1
0
        /// <summary>
        /// 从程序集中获取可用的服务类型。
        /// </summary>
        /// <param name="serviceTypeHarvester">服务类型收集者。</param>
        /// <param name="assembly">程序集。</param>
        /// <returns>可用的服务类型。</returns>
        public static Type[] GetTypes(this IServiceTypeHarvester serviceTypeHarvester, Assembly assembly)
        {
            serviceTypeHarvester.NotNull("serviceTypeHarvester");
            assembly.NotNull("assembly");

            return(serviceTypeHarvester.GeTypes(assembly.GetTypes()));
        }
示例#2
0
        private Feature LoadFeature(FeatureDescriptor featureDescriptor)
        {
            var extensionDescriptor = featureDescriptor.Extension;
            var featureId           = featureDescriptor.Id;
            var extensionId         = extensionDescriptor.Id;

            ExtensionEntry extensionEntry;

            try
            {
                extensionEntry = _cacheManager.Get(extensionId, ctx =>
                {
                    var entry = BuildEntry(extensionDescriptor);
                    if (entry != null)
                    {
                        ctx.Monitor(_asyncTokenProvider.GetToken(monitor =>
                        {
                            foreach (var loader in _loaders.Value)
                            {
                                loader.Monitor(entry.Descriptor, monitor);
                            }
                        }));
                    }
                    return(entry);
                });
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "加载扩展 '{0}' 失败", extensionId);
                throw new RabbitException(T("加载扩展 '{0}' 失败。", extensionId), ex);
            }

            if (extensionEntry == null)
            {
                //如果该功能因为某种原因不能被编译,返回一个"null"的特性,即没有输出的类型的功能。
                return(new Feature
                {
                    Descriptor = featureDescriptor,
                    ExportedTypes = Enumerable.Empty <Type>()
                });
            }

            var extensionTypes = _serviceTypeHarvester.GeTypes(extensionEntry.ExportedTypes);

            var featureTypes = extensionTypes.Where(
                i =>
                string.Equals(GetSourceFeatureNameForType(i, extensionId), featureId,
                              StringComparison.OrdinalIgnoreCase)).ToArray();

            return(new Feature
            {
                Descriptor = featureDescriptor,
                ExportedTypes = featureTypes
            });
        }