Revise the global features.

pull/5062/head
Halil İbrahim Kalkan 5 years ago
parent 8467024d54
commit da0d4718ff

@ -16,7 +16,7 @@ namespace Volo.Abp.GlobalFeatures
public bool IsEnabled
{
get => FeatureManager.IsEnabled(FeatureName);
set => FeatureManager.SetEnabled(FeatureName, value);
set => SetEnabled(value);
}
protected GlobalFeature([NotNull] GlobalModuleFeatures module)
@ -36,9 +36,16 @@ namespace Volo.Abp.GlobalFeatures
FeatureManager.Disable(FeatureName);
}
public virtual void SetEnabled(bool isEnabled)
public void SetEnabled(bool isEnabled)
{
FeatureManager.SetEnabled(FeatureName, isEnabled);
if (isEnabled)
{
Enable();
}
else
{
Disable();
}
}
}
}

@ -2,7 +2,7 @@
namespace Volo.Abp.GlobalFeatures
{
public class GlobalFeatureConfiguratorDictionary : Dictionary<string, GlobalFeature>
public class GlobalFeatureDictionary : Dictionary<string, GlobalFeature>
{
}

@ -1,5 +1,4 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Generic;
using JetBrains.Annotations;
namespace Volo.Abp.GlobalFeatures
@ -14,7 +13,7 @@ namespace Volo.Abp.GlobalFeatures
[NotNull]
public Dictionary<object, object> Configuration { get; }
public GlobalFeatureManagerModuleDictionary Modules { get; }
public GlobalModuleFeaturesDictionary Modules { get; }
protected HashSet<string> EnabledFeatures { get; }
@ -22,7 +21,7 @@ namespace Volo.Abp.GlobalFeatures
{
EnabledFeatures = new HashSet<string>();
Configuration = new Dictionary<object, object>();
Modules = new GlobalFeatureManagerModuleDictionary(this);
Modules = new GlobalModuleFeaturesDictionary(this);
}
public virtual bool IsEnabled<TFeature>()
@ -31,47 +30,17 @@ namespace Volo.Abp.GlobalFeatures
return IsEnabled(GlobalFeatureNameAttribute.GetName<TFeature>());
}
public virtual void SetEnabled<TFeature>(bool isEnabled)
where TFeature : GlobalFeature
{
SetEnabled(GlobalFeatureNameAttribute.GetName<TFeature>(), isEnabled);
}
public virtual void Enable<TFeature>()
where TFeature : GlobalFeature
{
Enable(GlobalFeatureNameAttribute.GetName<TFeature>());
}
public virtual void Disable<TFeature>()
where TFeature : GlobalFeature
{
Disable(GlobalFeatureNameAttribute.GetName<TFeature>());
}
public virtual bool IsEnabled(string featureName)
{
return EnabledFeatures.Contains(featureName);
}
public virtual void SetEnabled(string featureName, bool isEnabled)
{
if (isEnabled)
{
Enable(featureName);
}
else
{
Disable(featureName);
}
}
public virtual void Enable(string featureName)
protected internal void Enable(string featureName)
{
EnabledFeatures.AddIfNotContains(featureName);
}
public virtual void Disable(string featureName)
protected internal void Disable(string featureName)
{
EnabledFeatures.Remove(featureName);
}

@ -8,24 +8,24 @@ namespace Volo.Abp.GlobalFeatures
public static class GlobalFeatureManagerModuleConfiguratorCmsKitExtensions
{
public static GlobalCmsKitFeatures CmsKit(
[NotNull] this GlobalFeatureManagerModuleDictionary modules)
[NotNull] this GlobalModuleFeaturesDictionary modulesFeatures)
{
Check.NotNull(modules, nameof(modules));
Check.NotNull(modulesFeatures, nameof(modulesFeatures));
return modules
.GetOrAdd(GlobalCmsKitFeatures.ModuleName, _ => new GlobalCmsKitFeatures(modules.FeatureManager))
return modulesFeatures
.GetOrAdd(GlobalCmsKitFeatures.ModuleName, _ => new GlobalCmsKitFeatures(modulesFeatures.FeatureManager))
as GlobalCmsKitFeatures;
}
public static GlobalFeatureManagerModuleDictionary CmsKit(
[NotNull] this GlobalFeatureManagerModuleDictionary modules,
public static GlobalModuleFeaturesDictionary CmsKit(
[NotNull] this GlobalModuleFeaturesDictionary modulesFeatures,
[NotNull] Action<GlobalCmsKitFeatures> configureAction)
{
Check.NotNull(configureAction, nameof(configureAction));
configureAction(modules.CmsKit());
configureAction(modulesFeatures.CmsKit());
return modules;
return modulesFeatures;
}
}
}

@ -8,13 +8,13 @@ namespace Volo.Abp.GlobalFeatures
public GlobalFeatureManager FeatureManager { get; }
[NotNull]
protected GlobalFeatureConfiguratorDictionary AllFeatures { get; }
protected GlobalFeatureDictionary AllFeatures { get; }
protected GlobalModuleFeatures(
[NotNull] GlobalFeatureManager featureManager)
{
FeatureManager = Check.NotNull(featureManager, nameof(featureManager));
AllFeatures = new GlobalFeatureConfiguratorDictionary();
AllFeatures = new GlobalFeatureDictionary();
}
public virtual void EnableAll()

@ -3,11 +3,11 @@ using JetBrains.Annotations;
namespace Volo.Abp.GlobalFeatures
{
public class GlobalFeatureManagerModuleDictionary : Dictionary<string, GlobalModuleFeatures>
public class GlobalModuleFeaturesDictionary : Dictionary<string, GlobalModuleFeatures>
{
public GlobalFeatureManager FeatureManager { get; }
public GlobalFeatureManagerModuleDictionary(
public GlobalModuleFeaturesDictionary(
[NotNull] GlobalFeatureManager featureManager)
{
FeatureManager = Check.NotNull(featureManager, nameof(featureManager));

@ -12,6 +12,7 @@ namespace Volo.CmsKit.GlobalFeatures
[NotNull] GlobalCmsKitFeatures cmsKit
) : base(cmsKit)
{
}
}
}

Loading…
Cancel
Save