Browse Source

Add new methods to GlobalModuleFeatures

pull/5062/head
Halil İbrahim Kalkan 6 years ago
parent
commit
2a5eb8902c
  1. 62
      modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/Abp/GlobalFeatures/GlobalModuleFeatures.cs

62
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<TFeature>()
where TFeature : GlobalFeature
{
GetFeature<TFeature>().Enable();
}
public virtual void Disable<TFeature>()
where TFeature : GlobalFeature
{
GetFeature<TFeature>().Disable();
}
public virtual void SetEnabled<TFeature>(bool isEnabled)
where TFeature : GlobalFeature
{
GetFeature<TFeature>().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<TFeature>()
public virtual TFeature GetFeature<TFeature>()
where TFeature : GlobalFeature
{
return (TFeature) GetFeature(GlobalFeatureNameAttribute.GetName<TFeature>());
}
public virtual IReadOnlyList<GlobalFeature> GetFeatures()
{
return AllFeatures.Values.ToImmutableList();
}
protected void AddFeature(GlobalFeature feature)
{
AllFeatures[feature.FeatureName] = feature;
}
}
}

Loading…
Cancel
Save