mirror of https://github.com/abpframework/abp.git
18 changed files with 239 additions and 164 deletions
@ -1,36 +0,0 @@ |
|||
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,45 @@ |
|||
using JetBrains.Annotations; |
|||
|
|||
namespace Volo.Abp.GlobalFeatures |
|||
{ |
|||
public class GlobalFeature |
|||
{ |
|||
[NotNull] |
|||
public GlobalModuleFeatures Module { get; } |
|||
|
|||
[NotNull] |
|||
public GlobalFeatureManager FeatureManager { get; } |
|||
|
|||
public string FeatureName { get; } |
|||
|
|||
public bool IsEnabled |
|||
{ |
|||
get => FeatureManager.IsEnabled(FeatureName); |
|||
set => FeatureManager.SetEnabled(FeatureName, value); |
|||
} |
|||
|
|||
public GlobalFeature( |
|||
[NotNull] GlobalModuleFeatures module, |
|||
[NotNull] string name) |
|||
{ |
|||
Module = Check.NotNull(module, nameof(module)); |
|||
FeatureName = Check.NotNullOrWhiteSpace(name, nameof(name)); |
|||
FeatureManager = Module.FeatureManager; |
|||
} |
|||
|
|||
public virtual void Enable() |
|||
{ |
|||
FeatureManager.Enable(FeatureName); |
|||
} |
|||
|
|||
public virtual void Disable() |
|||
{ |
|||
FeatureManager.Disable(FeatureName); |
|||
} |
|||
|
|||
public virtual void SetEnabled(bool isEnabled) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Volo.Abp.GlobalFeatures |
|||
{ |
|||
public class GlobalFeatureConfiguratorDictionary : Dictionary<string, GlobalFeature> |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -1,12 +0,0 @@ |
|||
namespace Volo.Abp.GlobalFeatures |
|||
{ |
|||
public class GlobalFeatureManagerCmsKitConfigurator : GlobalFeatureManagerModuleConfigurator |
|||
{ |
|||
public GlobalFeatureManagerCmsKitConfigurator(GlobalFeatureManagerModulesConfigurator modulesConfigurator) |
|||
: base(modulesConfigurator) |
|||
{ |
|||
this.Reactions(); |
|||
this.Comments(); |
|||
} |
|||
} |
|||
} |
|||
@ -1,52 +0,0 @@ |
|||
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; |
|||
} |
|||
} |
|||
} |
|||
@ -1,18 +0,0 @@ |
|||
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; |
|||
} |
|||
} |
|||
} |
|||
@ -1,30 +1,31 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using JetBrains.Annotations; |
|||
using Volo.CmsKit.GlobalFeatures; |
|||
|
|||
namespace Volo.Abp.GlobalFeatures |
|||
{ |
|||
public static class GlobalFeatureManagerModuleConfiguratorCmsKitExtensions |
|||
{ |
|||
public static GlobalFeatureManagerCmsKitConfigurator CmsKit( |
|||
[NotNull] this GlobalFeatureManagerModulesConfigurator modulesConfigurator) |
|||
public static GlobalCmsKitFeatures CmsKit( |
|||
[NotNull] this GlobalFeatureManagerModuleDictionary modules) |
|||
{ |
|||
Check.NotNull(modulesConfigurator, nameof(modulesConfigurator)); |
|||
Check.NotNull(modules, nameof(modules)); |
|||
|
|||
return modulesConfigurator |
|||
.Modules |
|||
.GetOrAdd("CmsKit", _ => new GlobalFeatureManagerCmsKitConfigurator(modulesConfigurator)) |
|||
as GlobalFeatureManagerCmsKitConfigurator; |
|||
return modules |
|||
.GetOrAdd(GlobalCmsKitFeatures.ModuleName, _ => new GlobalCmsKitFeatures(modules.FeatureManager)) |
|||
as GlobalCmsKitFeatures; |
|||
} |
|||
|
|||
public static GlobalFeatureManagerModulesConfigurator CmsKit( |
|||
[NotNull] this GlobalFeatureManagerModulesConfigurator modulesConfigurator, |
|||
[NotNull] Action<GlobalFeatureManagerCmsKitConfigurator> configureAction) |
|||
public static GlobalFeatureManagerModuleDictionary CmsKit( |
|||
[NotNull] this GlobalFeatureManagerModuleDictionary modules, |
|||
[NotNull] Action<GlobalCmsKitFeatures> configureAction) |
|||
{ |
|||
Check.NotNull(configureAction, nameof(configureAction)); |
|||
|
|||
configureAction(modulesConfigurator.CmsKit()); |
|||
configureAction(modules.CmsKit()); |
|||
|
|||
return modulesConfigurator; |
|||
return modules; |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,19 +1,16 @@ |
|||
using System.Collections.Concurrent; |
|||
using System.Collections.Generic; |
|||
using JetBrains.Annotations; |
|||
|
|||
namespace Volo.Abp.GlobalFeatures |
|||
{ |
|||
public class GlobalFeatureManagerModulesConfigurator //TODO: Change to GlobalFeatureManagerModuleDictionary and inherit from ConcurrentDictionary
|
|||
public class GlobalFeatureManagerModuleDictionary : Dictionary<string, GlobalModuleFeatures> |
|||
{ |
|||
public GlobalFeatureManager FeatureManager { get; } |
|||
|
|||
[NotNull] |
|||
public ConcurrentDictionary<string, GlobalFeatureManagerModuleConfigurator> Modules { get; } |
|||
|
|||
public GlobalFeatureManagerModulesConfigurator([NotNull] GlobalFeatureManager featureManager) |
|||
public GlobalFeatureManagerModuleDictionary( |
|||
[NotNull] GlobalFeatureManager featureManager) |
|||
{ |
|||
FeatureManager = Check.NotNull(featureManager, nameof(featureManager)); |
|||
Modules = new ConcurrentDictionary<string, GlobalFeatureManagerModuleConfigurator>(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,40 @@ |
|||
using System; |
|||
using System.Linq; |
|||
using System.Reflection; |
|||
using JetBrains.Annotations; |
|||
|
|||
namespace Volo.Abp.GlobalFeatures |
|||
{ |
|||
[AttributeUsage(AttributeTargets.Class)] |
|||
public class GlobalFeatureNameAttribute : Attribute |
|||
{ |
|||
public string Name { get; } |
|||
|
|||
public GlobalFeatureNameAttribute([NotNull] string name) |
|||
{ |
|||
Name = Check.NotNullOrWhiteSpace(name, nameof(name)); |
|||
} |
|||
|
|||
public static string GetName<TFeature>() |
|||
where TFeature : GlobalFeature |
|||
{ |
|||
return GetName(typeof(TFeature)); |
|||
} |
|||
|
|||
public static string GetName(Type type) |
|||
{ |
|||
var attribute = type |
|||
.GetCustomAttributes<GlobalFeatureNameAttribute>() |
|||
.FirstOrDefault(); |
|||
|
|||
if (attribute == null) |
|||
{ |
|||
throw new AbpException($"{type.AssemblyQualifiedName} should define the {typeof(GlobalFeatureNameAttribute).FullName} atttribute!"); |
|||
} |
|||
|
|||
return attribute |
|||
.As<GlobalFeatureNameAttribute>() |
|||
.Name; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp.GlobalFeatures; |
|||
|
|||
namespace Volo.CmsKit.GlobalFeatures |
|||
{ |
|||
[GlobalFeatureName(Name)] |
|||
public class CommentsFeature : GlobalFeature |
|||
{ |
|||
public const string Name = "CmsKit.Comments"; |
|||
|
|||
public CommentsFeature( |
|||
[NotNull] GlobalCmsKitFeatures cmsKit |
|||
) : base(cmsKit, Name) |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
using Volo.Abp.GlobalFeatures; |
|||
|
|||
namespace Volo.CmsKit.GlobalFeatures |
|||
{ |
|||
public class GlobalCmsKitFeatures : GlobalModuleFeatures |
|||
{ |
|||
public const string ModuleName = "CmsKit"; |
|||
|
|||
public ReactionsFeature Reactions => GetFeature<ReactionsFeature>(ReactionsFeature.Name); |
|||
|
|||
public CommentsFeature Comments => GetFeature<CommentsFeature>(CommentsFeature.Name); |
|||
|
|||
public GlobalCmsKitFeatures(GlobalFeatureManager featureManager) |
|||
: base(featureManager) |
|||
{ |
|||
AddFeature(new ReactionsFeature(this)); |
|||
AddFeature(new CommentsFeature(this)); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp.GlobalFeatures; |
|||
|
|||
namespace Volo.CmsKit.GlobalFeatures |
|||
{ |
|||
[GlobalFeatureName(Name)] |
|||
public class ReactionsFeature : GlobalFeature |
|||
{ |
|||
public const string Name = "CmsKit.Reactions"; |
|||
|
|||
public ReactionsFeature( |
|||
[NotNull] GlobalCmsKitFeatures cmsKit |
|||
) : base(cmsKit, Name) |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue