Exemplo n.º 1
0
        public IEnumerable <IFeatureInfo> GetFeatures(IPluginInfo pluginInfo, IManifestInfo manifestInfo)
        {
            var featuresInfos = new List <IFeatureInfo>();

            var features = manifestInfo.ModuleInfo.Features.ToList();

            if (features.Count > 0)
            {
                foreach (var feature in features)
                {
                    if (String.IsNullOrWhiteSpace(feature.Id))
                    {
                        throw new ArgumentException($"包含这个功能的Plugin没有定义Id '{pluginInfo.Id}'");
                    }

                    var featureId   = feature.Id;
                    var featureName = feature.Name ?? feature.Id;

                    var featureDependencyIds = feature.Dependencies
                                               .Select(e => e.Trim()).ToArray();

                    if (!int.TryParse(feature.Priority ?? manifestInfo.ModuleInfo.Priority, out int featurePriority))
                    {
                        featurePriority = 0;
                    }

                    var featureCategory          = feature.Category ?? manifestInfo.ModuleInfo.Category;
                    var featureDescription       = feature.Description ?? manifestInfo.ModuleInfo.Description;
                    var featureDefaultTenantOnly = feature.DefaultTenantOnly;
                    var featureManageDisallowed  = feature.ManageDisallowed;

                    var context = new FeatureBuildingContext
                    {
                        FeatureId            = featureId,
                        FeatureName          = featureName,
                        Category             = featureCategory,
                        Description          = featureDescription,
                        PluginInfo           = pluginInfo,
                        ManifestInfo         = manifestInfo,
                        Priority             = featurePriority,
                        FeatureDependencyIds = featureDependencyIds,
                        DefaultTenantOnly    = featureDefaultTenantOnly,
                        ManageDisallowed     = featureManageDisallowed
                    };

                    foreach (var builder in _featureBuilderEvents)
                    {
                        builder.Building(context);
                    }

                    var featureInfo = new FeatureInfo(
                        featureId,
                        featureName,
                        featurePriority,
                        featureCategory,
                        featureDescription,
                        pluginInfo,
                        featureDependencyIds,
                        featureDefaultTenantOnly,
                        featureManageDisallowed);

                    foreach (var builder in _featureBuilderEvents)
                    {
                        builder.Built(featureInfo);
                    }

                    featuresInfos.Add(featureInfo);
                }
            }
            else
            {
                var featureId   = pluginInfo.Id;
                var featureName = manifestInfo.Name;

                var featureDependencyIds = manifestInfo.ModuleInfo.Dependencies
                                           .Select(e => e.Trim()).ToArray();

                if (!int.TryParse(manifestInfo.ModuleInfo.Priority, out int featurePriority))
                {
                    featurePriority = 0;
                }

                var featureCategory          = manifestInfo.ModuleInfo.Category;
                var featureDescription       = manifestInfo.ModuleInfo.Description;
                var featureDefaultTenantOnly = manifestInfo.ModuleInfo.DefaultTenantOnly;
                var featureManageDisallowed  = manifestInfo.ModuleInfo.ManageDisallowed;

                var context = new FeatureBuildingContext
                {
                    FeatureId            = featureId,
                    FeatureName          = featureName,
                    Category             = featureCategory,
                    Description          = featureDescription,
                    PluginInfo           = pluginInfo,
                    ManifestInfo         = manifestInfo,
                    Priority             = featurePriority,
                    FeatureDependencyIds = featureDependencyIds,
                    DefaultTenantOnly    = featureDefaultTenantOnly,
                    ManageDisallowed     = featureManageDisallowed
                };

                foreach (var builder in _featureBuilderEvents)
                {
                    builder.Building(context);
                }

                var featureInfo = new FeatureInfo(
                    context.FeatureId,
                    context.FeatureName,
                    context.Priority,
                    context.Category,
                    context.Description,
                    context.PluginInfo,
                    context.FeatureDependencyIds,
                    context.DefaultTenantOnly,
                    context.ManageDisallowed);

                foreach (var builder in _featureBuilderEvents)
                {
                    builder.Built(featureInfo);
                }

                featuresInfos.Add(featureInfo);
            }

            return(featuresInfos);
        }
Exemplo n.º 2
0
 public virtual void Building(FeatureBuildingContext context)
 {
 }