Esempio n. 1
0
        public async Task <object> List([FromQuery] string keyword)
        {
            // 这里需要加特殊权限,只允许Default的管理员可访问
            var enabledFeatures = await _engineFeaturesManager.GetEnabledFeaturesAsync();

            var moduleFeatures = new List <FeatureModel>();

            foreach (var moduleFeatureInfo in _pluginManager.GetFeatures().ToList())
            {
                moduleFeatures.Add(new FeatureModel()
                {
                    Descriptor   = moduleFeatureInfo,
                    Enabled      = enabledFeatures.Contains(moduleFeatureInfo),
                    Dependencies = _pluginManager.GetDependentFeatures(moduleFeatureInfo.Id).Where(d => d.Id != moduleFeatureInfo.Id).ToList()
                });
            }
            var query = moduleFeatures.AsQueryable();

            if (!string.IsNullOrEmpty(keyword))
            {
                query = query.Where(e => e.Descriptor.Name.Contains(keyword) || e.Descriptor.Id.Contains(keyword));
            }
            return(new
            {
                List = query.GroupBy(e => !string.IsNullOrEmpty(e.Descriptor.Category) ? e.Descriptor.Category : "其他")
                       .Select(e => new FeatureGroupModel()
                {
                    Category = e.Key,
                    Features = e
                }).ToList(),
                Total = moduleFeatures.Count
            });
        }
        public Task <EngineDescriptor> GetEngineDescriptorAsync()
        {
            if (_engineDescriptor == null)
            {
                _engineDescriptor = new EngineDescriptor
                {
                    Features = _pluginManager.GetFeatures().Select(x => new EngineFeature {
                        Id = x.Id
                    }).ToList()
                };
            }

            return(Task.FromResult(_engineDescriptor));
        }
Esempio n. 3
0
        public EngineContainerFactory(
            IHostingEnvironment hostingEnvironment,
            IPluginManager pluginManager,
            IServiceProvider serviceProvider,
            ILoggerFactory loggerFactory,
            ILogger <EngineContainerFactory> logger,
            IServiceCollection applicationServices)
        {
            _applicationFeature = pluginManager.GetFeatures().FirstOrDefault(
                f => f.Id == hostingEnvironment.ApplicationName);

            _applicationServices = applicationServices;
            _serviceProvider     = serviceProvider;
            _loggerFactory       = loggerFactory;
            _logger = logger;
        }
        private async Task <IEnumerable <object> > GetFeatureTypeConfigurations(IEnumerable <string> features)
        {
            var providers    = new List <IEntityTypeConfigurationProvider>();
            var providerType = typeof(IEntityTypeConfigurationProvider);

            _pluginManager.GetFeatures(features.ToArray())
            .Select(e => e.Plugin)
            .Distinct()
            .Select(e =>
            {
                return(_pluginManager.LoadPluginAsync(e).Result.ExportedTypes
                       .Where(pro => providerType.IsAssignableFrom(pro))
                       .Select(pro => ActivatorUtilities.GetServiceOrCreateInstance(_serviceProvider, pro) as IEntityTypeConfigurationProvider)
                       .ToList());
            })
            .ToList()
            .ForEach(list =>
            {
                providers = providers.Concat(list).ToList();
            });

            return(await providers.Distinct().InvokeAsync(e => e.GetEntityTypeConfigurationsAsync(), _logger));
        }
Esempio n. 5
0
        public async Task ExecuteAsync(ProjectExecutionContext context)
        {
            if (!String.Equals(context.Name, "Feature", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            var step = context.Step.ToObject <FeatureStepModel>();

            var features = _pluginManager.GetFeatures();

            foreach (var featureId in step.Disable)
            {
                if (features.Any(x => x.Id == featureId))
                {
                    throw new InvalidOperationException(string.Format("无法启用功能 {0}, 不存在.", featureId));
                }
            }

            foreach (var featureId in step.Enable)
            {
                if (!features.Any(x => x.Id == featureId))
                {
                    throw new InvalidOperationException(string.Format("无法启用功能 {0}, 不存在.", featureId));
                }
            }

            if (step.Disable.Any())
            {
                await _engineFeatureManager.DisableFeaturesAsync(features.Where(x => step.Disable.Contains(x.Id)).ToList(), true);
            }

            if (step.Enable.Any())
            {
                await _engineFeatureManager.EnableFeaturesAsync(features.Where(x => step.Enable.Contains(x.Id)).ToList(), true);
            }
        }
Esempio n. 6
0
        public virtual IEnumerable <string> ExpandViewLocations(ViewLocationExpanderContext context,
                                                                IEnumerable <string> viewLocations)
        {
            if (context.ActionContext.ActionDescriptor is PageActionDescriptor page)
            {
                var pageViewLocations = PageViewLocations().ToList();
                pageViewLocations.AddRange(viewLocations);
                return(pageViewLocations);

                IEnumerable <string> PageViewLocations()
                {
                    if (page.RelativePath.Contains("/Pages/") && !page.RelativePath.StartsWith("/Pages/", StringComparison.Ordinal))
                    {
                        yield return(page.RelativePath.Substring(0, page.RelativePath.IndexOf("/Pages/", StringComparison.Ordinal))
                                     + "/Views/Shared/{0}" + RazorViewEngine.ViewExtension);
                    }
                }
            }

            var plugin = _pluginManager.GetPlugin(context.AreaName);

            if (!plugin.Exists)
            {
                return(viewLocations);
            }

            var result = new List <string>();

            var pluginViewsPath = '/' + plugin.SubPath + "/Views";

            result.Add(pluginViewsPath + "/{1}/{0}" + RazorViewEngine.ViewExtension);

            if (!context.ViewName.StartsWith("Components/", StringComparison.Ordinal))
            {
                result.Add(pluginViewsPath + "/Shared/{0}" + RazorViewEngine.ViewExtension);
            }
            else
            {
                if (!_memoryCache.TryGetValue(CacheKey, out IEnumerable <string> moduleComponentViewLocations))
                {
                    var enabledIds = _pluginManager.GetFeatures().Where(f => _engineDescriptor
                                                                        .Features.Any(sf => sf.Id == f.Id)).Select(f => f.Plugin.Id).Distinct().ToArray();

                    var enabledExtensions = _pluginManager.GetPlugins()
                                            .Where(e => enabledIds.Contains(e.Id)).ToArray();

                    var sharedViewsPath = "/Views/Shared/{0}" + RazorViewEngine.ViewExtension;

                    moduleComponentViewLocations = _modulesWithComponentViews
                                                   .Where(m => enabledExtensions.Any(e => e.Id == m.Id))
                                                   .Select(m => '/' + m.SubPath + sharedViewsPath);

                    _memoryCache.Set(CacheKey, moduleComponentViewLocations);
                }

                result.AddRange(moduleComponentViewLocations);
            }

            result.AddRange(viewLocations);

            return(result);
        }
 public Task <IEnumerable <IFeatureInfo> > GetEnabledFeaturesAsync()
 {
     return(Task.FromResult(_pluginManager.GetFeatures().Where(f => _engineDescriptor.Features.Any(sf => sf.Id == f.Id))));
 }