示例#1
0
        public ExtensionEntry LoadExtension(ExtensionDescriptor extensionDescriptor)
        {
            // Results are cached so that there is no mismatch when loading an assembly twice.
            // Otherwise the same types would not match.

            try
            {
                return(_extensions.GetOrAdd(extensionDescriptor.Id, id =>
                {
                    foreach (var loader in _loaders)
                    {
                        ExtensionEntry entry = loader.Load(extensionDescriptor);
                        if (entry != null)
                        {
                            return entry;
                        }
                    }

                    if (_logger.IsEnabled(LogLevel.Warning))
                    {
                        _logger.LogWarning("No suitable loader found for extension \"{0}\"", extensionDescriptor.Id);
                    }

                    return null;
                }));
            }
            catch (Exception ex)
            {
                _logger.LogError(string.Format("Error loading extension '{0}'", extensionDescriptor.Id), ex);
                throw new OrchardException(T("Error while loading extension '{0}'.", extensionDescriptor.Id), ex);
            }
        }
示例#2
0
        private ExtensionEntry BuildEntry(ExtensionDescriptor descriptor)
        {
            foreach (var loader in _loaders)
            {
                ExtensionEntry entry = loader.Load(descriptor);
                if (entry != null)
                {
                    return(entry);
                }
            }

            Logger.Warning("No suitable loader found for extension \"{0}\"", descriptor.Id);
            return(null);
        }
        public void ExtensionManagerTestFeatureAttribute() {
            var extensionManager = new Moq.Mock<IExtensionManager>();
            var extensionEntry =  new ExtensionEntry {
                                                            Descriptor = new ExtensionDescriptor { Name = "Module"},
                                                            ExportedTypes = new[] { typeof(Alpha), typeof(Beta), typeof(Phi) }
                                                        };
            extensionEntry.Descriptor.Features = new[] {
                                                           new FeatureDescriptor
                                                           {Name = "Module", Extension = extensionEntry.Descriptor},
                                                           new FeatureDescriptor
                                                           {Name = "TestFeature", Extension = extensionEntry.Descriptor}
                                                       };
            extensionManager.Setup(x => x.ActiveExtensions_Obsolete()).Returns(new[] {extensionEntry});

            foreach (var type in extensionManager.Object.ActiveExtensions_Obsolete().SelectMany(x => x.ExportedTypes)) {
                foreach (OrchardFeatureAttribute featureAttribute in type.GetCustomAttributes(typeof(OrchardFeatureAttribute), false)) {
                    Assert.That(featureAttribute.FeatureName, Is.EqualTo("TestFeature"));
                }
            }
        }