From 2a5eb8902c6772e1a1ab8aab52e9fac175fd6bf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Fri, 14 Aug 2020 15:27:06 +0300 Subject: [PATCH] Add new methods to GlobalModuleFeatures --- .../GlobalFeatures/GlobalModuleFeatures.cs | 62 ++++++++++++++++--- 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/Abp/GlobalFeatures/GlobalModuleFeatures.cs b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/Abp/GlobalFeatures/GlobalModuleFeatures.cs index 2b3721d331..9a8afd236d 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/Abp/GlobalFeatures/GlobalModuleFeatures.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/Abp/GlobalFeatures/GlobalModuleFeatures.cs @@ -1,4 +1,6 @@ -using JetBrains.Annotations; +using System.Collections.Generic; +using System.Collections.Immutable; +using JetBrains.Annotations; namespace Volo.Abp.GlobalFeatures { @@ -17,6 +19,39 @@ namespace Volo.Abp.GlobalFeatures AllFeatures = new GlobalFeatureDictionary(); } + public virtual void Enable() + where TFeature : GlobalFeature + { + GetFeature().Enable(); + } + + public virtual void Disable() + where TFeature : GlobalFeature + { + GetFeature().Disable(); + } + + public virtual void SetEnabled(bool isEnabled) + where TFeature : GlobalFeature + { + GetFeature().SetEnabled(isEnabled); + } + + public virtual void Enable(string featureName) + { + GetFeature(featureName).Enable(); + } + + public virtual void Disable(string featureName) + { + GetFeature(featureName).Disable(); + } + + public virtual void SetEnabled(string featureName, bool isEnabled) + { + GetFeature(featureName).SetEnabled(isEnabled); + } + public virtual void EnableAll() { foreach (var feature in AllFeatures.Values) @@ -33,20 +68,31 @@ namespace Volo.Abp.GlobalFeatures } } - protected void AddFeature(GlobalFeature feature) + public virtual GlobalFeature GetFeature(string featureName) { - AllFeatures[feature.FeatureName] = feature; - } + var feature = AllFeatures.GetOrDefault(featureName); + if (feature == null) + { + throw new AbpException($"There is no feature defined by name '{featureName}'."); + } - protected GlobalFeature GetFeature(string featureName) - { - return AllFeatures[featureName]; + return feature; } - protected TFeature GetFeature() + public virtual TFeature GetFeature() where TFeature : GlobalFeature { return (TFeature) GetFeature(GlobalFeatureNameAttribute.GetName()); } + + public virtual IReadOnlyList GetFeatures() + { + return AllFeatures.Values.ToImmutableList(); + } + + protected void AddFeature(GlobalFeature feature) + { + AllFeatures[feature.FeatureName] = feature; + } } }