mirror of https://github.com/abpframework/abp.git
14 changed files with 282 additions and 104 deletions
@ -1,10 +1,12 @@ |
|||
namespace Volo.CmsKit |
|||
using Volo.Abp.GlobalFeatures; |
|||
|
|||
namespace Volo.CmsKit |
|||
{ |
|||
public static class FeatureConfigurer |
|||
{ |
|||
public static void Configure() |
|||
{ |
|||
CmsKitFeatures.EnableAll(); |
|||
GlobalFeatureManager.Instance.Modules().CmsKit().EnableAll(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,36 @@ |
|||
using JetBrains.Annotations; |
|||
|
|||
namespace Volo.Abp.GlobalFeatures |
|||
{ |
|||
public class GlobalFeature |
|||
{ |
|||
public GlobalFeatureManagerModuleConfigurator ModuleConfigurator { get; } |
|||
|
|||
public string Name { get; } |
|||
|
|||
public bool IsEnabled => ModuleConfigurator.ModulesConfigurator.FeatureManager.IsEnabled(Name); |
|||
|
|||
public GlobalFeature( |
|||
[NotNull] GlobalFeatureManagerModuleConfigurator moduleConfigurator, |
|||
[NotNull] string name) |
|||
{ |
|||
ModuleConfigurator = Check.NotNull(moduleConfigurator, nameof(moduleConfigurator)); |
|||
Name = Check.NotNullOrWhiteSpace(name, nameof(name)); |
|||
} |
|||
|
|||
public virtual void Enable() |
|||
{ |
|||
ModuleConfigurator.ModulesConfigurator.FeatureManager.Enable(Name); |
|||
} |
|||
|
|||
public virtual void Disable() |
|||
{ |
|||
ModuleConfigurator.ModulesConfigurator.FeatureManager.Disable(Name); |
|||
} |
|||
|
|||
public virtual void SetEnabled(bool isEnabled) |
|||
{ |
|||
ModuleConfigurator.ModulesConfigurator.FeatureManager.SetEnabled(Name, isEnabled); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,54 @@ |
|||
using System.Collections.Concurrent; |
|||
using System.Collections.Generic; |
|||
using JetBrains.Annotations; |
|||
|
|||
namespace Volo.Abp.GlobalFeatures |
|||
{ |
|||
public class GlobalFeatureManager //TODO: Move to the ABP Framework..? //rename?
|
|||
{ |
|||
public static GlobalFeatureManager Instance { get; protected set; } = new GlobalFeatureManager(); |
|||
|
|||
[NotNull] |
|||
public ConcurrentDictionary<object, object> Configuration { get; } |
|||
|
|||
protected HashSet<string> EnabledFeatures { get; } |
|||
|
|||
private GlobalFeatureManager() |
|||
{ |
|||
EnabledFeatures = new HashSet<string>(); |
|||
Configuration = new ConcurrentDictionary<object, object>(); |
|||
} |
|||
|
|||
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) |
|||
{ |
|||
EnabledFeatures.AddIfNotContains(featureName); |
|||
} |
|||
|
|||
public virtual void Disable(string featureName) |
|||
{ |
|||
EnabledFeatures.Remove(featureName); |
|||
} |
|||
|
|||
public virtual IEnumerable<string> GetEnabledFeatures() |
|||
{ |
|||
return EnabledFeatures; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
namespace Volo.Abp.GlobalFeatures |
|||
{ |
|||
public class GlobalFeatureManagerCmsKitConfigurator : GlobalFeatureManagerModuleConfigurator |
|||
{ |
|||
public GlobalFeatureManagerCmsKitConfigurator(GlobalFeatureManagerModulesConfigurator modulesConfigurator) |
|||
: base(modulesConfigurator) |
|||
{ |
|||
this.Reactions(); |
|||
this.Comments(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,52 @@ |
|||
using System; |
|||
using JetBrains.Annotations; |
|||
|
|||
namespace Volo.Abp.GlobalFeatures |
|||
{ |
|||
public static class GlobalFeatureManagerCmsKitConfiguratorExtensions |
|||
{ |
|||
public static GlobalFeature Reactions( |
|||
[NotNull] this GlobalFeatureManagerCmsKitConfigurator cmsKitConfigurator) |
|||
{ |
|||
Check.NotNull(cmsKitConfigurator, nameof(cmsKitConfigurator)); |
|||
|
|||
return cmsKitConfigurator |
|||
.Features |
|||
.GetOrAdd("Reactions", _ => new GlobalFeature(cmsKitConfigurator, "CmsKit:Reactions")) |
|||
as GlobalFeature; |
|||
} |
|||
|
|||
public static GlobalFeatureManagerCmsKitConfigurator Reactions( |
|||
[NotNull] this GlobalFeatureManagerCmsKitConfigurator cmsKitConfigurator, |
|||
[NotNull] Action<GlobalFeature> configureAction) |
|||
{ |
|||
Check.NotNull(cmsKitConfigurator, nameof(cmsKitConfigurator)); |
|||
|
|||
configureAction(cmsKitConfigurator.Reactions()); |
|||
|
|||
return cmsKitConfigurator; |
|||
} |
|||
|
|||
public static GlobalFeature Comments( |
|||
[NotNull] this GlobalFeatureManagerCmsKitConfigurator cmsKitConfigurator) |
|||
{ |
|||
Check.NotNull(cmsKitConfigurator, nameof(cmsKitConfigurator)); |
|||
|
|||
return cmsKitConfigurator |
|||
.Features |
|||
.GetOrAdd("Comments", _ => new GlobalFeature(cmsKitConfigurator, "CmsKit:Comments")) |
|||
as GlobalFeature; |
|||
} |
|||
|
|||
public static GlobalFeatureManagerCmsKitConfigurator Comments( |
|||
[NotNull] this GlobalFeatureManagerCmsKitConfigurator cmsKitConfigurator, |
|||
[NotNull] Action<GlobalFeature> configureAction) |
|||
{ |
|||
Check.NotNull(cmsKitConfigurator, nameof(cmsKitConfigurator)); |
|||
|
|||
configureAction(cmsKitConfigurator.Comments()); |
|||
|
|||
return cmsKitConfigurator; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
using JetBrains.Annotations; |
|||
|
|||
namespace Volo.Abp.GlobalFeatures |
|||
{ |
|||
public static class GlobalFeatureManagerExtensions |
|||
{ |
|||
public static GlobalFeatureManagerModulesConfigurator Modules( |
|||
[NotNull] this GlobalFeatureManager featureManager) |
|||
{ |
|||
Check.NotNull(featureManager, nameof(featureManager)); |
|||
|
|||
return featureManager |
|||
.Configuration |
|||
.GetOrAdd("_Modules", _ => new GlobalFeatureManagerModulesConfigurator(featureManager)) |
|||
as GlobalFeatureManagerModulesConfigurator; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,36 @@ |
|||
using System.Collections.Concurrent; |
|||
using JetBrains.Annotations; |
|||
|
|||
namespace Volo.Abp.GlobalFeatures |
|||
{ |
|||
public abstract class GlobalFeatureManagerModuleConfigurator |
|||
{ |
|||
[NotNull] |
|||
public GlobalFeatureManagerModulesConfigurator ModulesConfigurator { get; } |
|||
|
|||
[NotNull] |
|||
public ConcurrentDictionary<string, GlobalFeature> Features { get; } |
|||
|
|||
protected GlobalFeatureManagerModuleConfigurator(GlobalFeatureManagerModulesConfigurator modulesConfigurator) |
|||
{ |
|||
ModulesConfigurator = Check.NotNull(modulesConfigurator, nameof(modulesConfigurator)); |
|||
Features = new ConcurrentDictionary<string, GlobalFeature>(); |
|||
} |
|||
|
|||
public virtual void EnableAll() |
|||
{ |
|||
foreach (var feature in Features.Values) |
|||
{ |
|||
feature.Enable(); |
|||
} |
|||
} |
|||
|
|||
public virtual void DisableAll() |
|||
{ |
|||
foreach (var feature in Features.Values) |
|||
{ |
|||
feature.Disable(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,30 @@ |
|||
using System; |
|||
using JetBrains.Annotations; |
|||
|
|||
namespace Volo.Abp.GlobalFeatures |
|||
{ |
|||
public static class GlobalFeatureManagerModuleConfiguratorCmsKitExtensions |
|||
{ |
|||
public static GlobalFeatureManagerCmsKitConfigurator CmsKit( |
|||
[NotNull] this GlobalFeatureManagerModulesConfigurator modulesConfigurator) |
|||
{ |
|||
Check.NotNull(modulesConfigurator, nameof(modulesConfigurator)); |
|||
|
|||
return modulesConfigurator |
|||
.Modules |
|||
.GetOrAdd("CmsKit", _ => new GlobalFeatureManagerCmsKitConfigurator(modulesConfigurator)) |
|||
as GlobalFeatureManagerCmsKitConfigurator; |
|||
} |
|||
|
|||
public static GlobalFeatureManagerModulesConfigurator CmsKit( |
|||
[NotNull] this GlobalFeatureManagerModulesConfigurator modulesConfigurator, |
|||
[NotNull] Action<GlobalFeatureManagerCmsKitConfigurator> configureAction) |
|||
{ |
|||
Check.NotNull(configureAction, nameof(configureAction)); |
|||
|
|||
configureAction(modulesConfigurator.CmsKit()); |
|||
|
|||
return modulesConfigurator; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
using System.Collections.Concurrent; |
|||
using JetBrains.Annotations; |
|||
|
|||
namespace Volo.Abp.GlobalFeatures |
|||
{ |
|||
public class GlobalFeatureManagerModulesConfigurator //TODO: Change to GlobalFeatureManagerModuleDictionary and inherit from ConcurrentDictionary
|
|||
{ |
|||
public GlobalFeatureManager FeatureManager { get; } |
|||
|
|||
[NotNull] |
|||
public ConcurrentDictionary<string, GlobalFeatureManagerModuleConfigurator> Modules { get; } |
|||
|
|||
public GlobalFeatureManagerModulesConfigurator([NotNull] GlobalFeatureManager featureManager) |
|||
{ |
|||
FeatureManager = Check.NotNull(featureManager, nameof(featureManager)); |
|||
Modules = new ConcurrentDictionary<string, GlobalFeatureManagerModuleConfigurator>(); |
|||
} |
|||
} |
|||
} |
|||
@ -1,56 +0,0 @@ |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Volo.CmsKit |
|||
{ |
|||
public static class CmsKitFeatures |
|||
{ |
|||
public const string NamePrefix = "CmsKit"; |
|||
|
|||
public static class Reactions |
|||
{ |
|||
public const string Name = NamePrefix + ".Reactions"; |
|||
|
|||
public static bool IsEnabled |
|||
{ |
|||
get => GlobalFeatures.IsEnabled(Name); |
|||
set => GlobalFeatures.SetEnabled(Name, value); |
|||
} |
|||
} |
|||
|
|||
public static class Comments |
|||
{ |
|||
public const string Name = NamePrefix + ".Comments"; |
|||
|
|||
public static bool IsEnabled |
|||
{ |
|||
get => GlobalFeatures.IsEnabled(Name); |
|||
set => GlobalFeatures.SetEnabled(Name, value); |
|||
} |
|||
} |
|||
|
|||
public static void EnableAll() |
|||
{ |
|||
foreach (var featureName in GetAllNames()) |
|||
{ |
|||
GlobalFeatures.Enable(featureName); |
|||
} |
|||
} |
|||
|
|||
public static void DisableAll() |
|||
{ |
|||
foreach (var featureName in GetAllNames()) |
|||
{ |
|||
GlobalFeatures.Disable(featureName); |
|||
} |
|||
} |
|||
|
|||
public static IEnumerable<string> GetAllNames() |
|||
{ |
|||
return new[] |
|||
{ |
|||
Reactions.Name, |
|||
Comments.Name |
|||
}; |
|||
} |
|||
} |
|||
} |
|||
@ -1,42 +0,0 @@ |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
|
|||
namespace Volo.CmsKit |
|||
{ |
|||
internal static class GlobalFeatures //TODO: Move to the ABP Framework..?
|
|||
{ |
|||
private static readonly HashSet<string> EnabledFeatures = new HashSet<string>(); |
|||
|
|||
public static bool IsEnabled(string featureName) |
|||
{ |
|||
return EnabledFeatures.Contains(featureName); |
|||
} |
|||
|
|||
public static void SetEnabled(string featureName, bool isEnabled) |
|||
{ |
|||
if (isEnabled) |
|||
{ |
|||
Enable(featureName); |
|||
} |
|||
else |
|||
{ |
|||
Disable(featureName); |
|||
} |
|||
} |
|||
|
|||
public static void Enable(string featureName) |
|||
{ |
|||
EnabledFeatures.AddIfNotContains(featureName); |
|||
} |
|||
|
|||
public static void Disable(string featureName) |
|||
{ |
|||
EnabledFeatures.Remove(featureName); |
|||
} |
|||
|
|||
public static IEnumerable<string> GetEnabledFeatures() |
|||
{ |
|||
return EnabledFeatures; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue