init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
|
@ -0,0 +1,34 @@
|
|||
using System.Configuration;
|
||||
|
||||
namespace Kreta.Core.FeatureToggle.Configuration
|
||||
{
|
||||
public class FeatureConfigurationSection : ConfigurationSection
|
||||
{
|
||||
[ConfigurationProperty(nameof(SimpleFeatures))]
|
||||
public SimpleFeatureConfigurationCollection SimpleFeatures => (SimpleFeatureConfigurationCollection)base[nameof(SimpleFeatures)];
|
||||
|
||||
[ConfigurationProperty(nameof(SendErtekelesNotification))]
|
||||
public ExtendedSendMobileNotification SendErtekelesNotification => (ExtendedSendMobileNotification)base[nameof(SendErtekelesNotification)];
|
||||
|
||||
[ConfigurationProperty(nameof(SendHazifeladatNotification))]
|
||||
public ExtendedSendMobileNotification SendHazifeladatNotification => (ExtendedSendMobileNotification)base[nameof(SendHazifeladatNotification)];
|
||||
|
||||
[ConfigurationProperty(nameof(SendRendszerUzenetNotification))]
|
||||
public ExtendedSendMobileNotification SendRendszerUzenetNotification => (ExtendedSendMobileNotification)base[nameof(SendRendszerUzenetNotification)];
|
||||
|
||||
[ConfigurationProperty(nameof(SendBejelentettSzamonkeresNotification))]
|
||||
public ExtendedSendMobileNotification SendBejelentettSzamonkeresNotification => (ExtendedSendMobileNotification)base[nameof(SendBejelentettSzamonkeresNotification)];
|
||||
|
||||
[ConfigurationProperty(nameof(SendFeljegyzesNotification))]
|
||||
public ExtendedSendMobileNotification SendFeljegyzesNotification => (ExtendedSendMobileNotification)base[nameof(SendFeljegyzesNotification)];
|
||||
|
||||
[ConfigurationProperty(nameof(SendMulasztasNotification))]
|
||||
public ExtendedSendMobileNotification SendMulasztasNotification => (ExtendedSendMobileNotification)base[nameof(SendMulasztasNotification)];
|
||||
|
||||
[ConfigurationProperty(nameof(SendOrarendValtozasNotification))]
|
||||
public ExtendedSendMobileNotification SendOrarendValtozasNotification => (ExtendedSendMobileNotification)base[nameof(SendOrarendValtozasNotification)];
|
||||
|
||||
[ConfigurationProperty(nameof(SendNemNaplozottTanorakMail))]
|
||||
public ExtendedSendMobileNotification SendNemNaplozottTanorakMail => (ExtendedSendMobileNotification)base[nameof(SendNemNaplozottTanorakMail)];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
|
||||
namespace Kreta.Core.FeatureToggle.Configuration
|
||||
{
|
||||
public class SimpleFeatureConfiguration : ConfigurationElement
|
||||
{
|
||||
[ConfigurationProperty(nameof(Name), IsKey = true, IsRequired = true)]
|
||||
public string Name => base[nameof(Name)].ToString();
|
||||
|
||||
[ConfigurationProperty(nameof(IsEnabled), IsKey = false, IsRequired = true)]
|
||||
public bool IsEnabled => bool.Parse(base[nameof(IsEnabled)].ToString());
|
||||
|
||||
[ConfigurationProperty(nameof(InstituteIds), IsKey = false, IsRequired = false)]
|
||||
[TypeConverter(typeof(CommaDelimitedStringCollectionConverter))]
|
||||
public IEnumerable<string> InstituteIds
|
||||
{
|
||||
get
|
||||
{
|
||||
var instituteIds = ((CommaDelimitedStringCollection)base[nameof(InstituteIds)]);
|
||||
|
||||
return (instituteIds != null) ? instituteIds.OfType<string>() : new List<string>();
|
||||
}
|
||||
}
|
||||
|
||||
[ConfigurationProperty(nameof(Environments), IsKey = false, IsRequired = false)]
|
||||
[TypeConverter(typeof(CommaDelimitedStringCollectionConverter))]
|
||||
public IEnumerable<string> Environments
|
||||
{
|
||||
get
|
||||
{
|
||||
var environments = ((CommaDelimitedStringCollection)base[nameof(Environments)]);
|
||||
|
||||
return (environments != null) ? environments.OfType<string>() : new List<string>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
using System.Configuration;
|
||||
|
||||
namespace Kreta.Core.FeatureToggle.Configuration
|
||||
{
|
||||
[ConfigurationCollection(typeof(SimpleFeatureConfiguration))]
|
||||
public class SimpleFeatureConfigurationCollection : ConfigurationElementCollection
|
||||
{
|
||||
protected override string ElementName => nameof(SimpleFeature);
|
||||
|
||||
protected override ConfigurationElement CreateNewElement() => new SimpleFeatureConfiguration();
|
||||
|
||||
protected override object GetElementKey(ConfigurationElement element) => ((SimpleFeatureConfiguration)element).Name;
|
||||
|
||||
public override ConfigurationElementCollectionType CollectionType => ConfigurationElementCollectionType.BasicMapAlternate;
|
||||
}
|
||||
|
||||
public class ExtendedSendMobileNotification : ConfigurationElement
|
||||
{
|
||||
[ConfigurationProperty(nameof(CustomCronExpression))]
|
||||
public string CustomCronExpression => base[nameof(CustomCronExpression)].ToString();
|
||||
|
||||
[ConfigurationProperty(nameof(SendItervalInMinute))]
|
||||
public string SendItervalInMinute => base[nameof(SendItervalInMinute)].ToString();
|
||||
|
||||
[ConfigurationProperty(nameof(RunningIntervalStartHour))]
|
||||
public string RunningIntervalStartHour => base[nameof(RunningIntervalStartHour)].ToString();
|
||||
|
||||
[ConfigurationProperty(nameof(RunningIntervalEndHour))]
|
||||
public string RunningIntervalEndHour => base[nameof(RunningIntervalEndHour)].ToString();
|
||||
}
|
||||
}
|
95
Kreta.Core/FeatureToggle/FeatureContext.cs
Normal file
95
Kreta.Core/FeatureToggle/FeatureContext.cs
Normal file
|
@ -0,0 +1,95 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using Kreta.Core.FeatureToggle.Configuration;
|
||||
|
||||
namespace Kreta.Core.FeatureToggle
|
||||
{
|
||||
public class FeatureContext : IFeatureContext
|
||||
{
|
||||
private Dictionary<string, IFeature> Features { get; }
|
||||
|
||||
private static readonly Lazy<FeatureContext> instance;
|
||||
public static FeatureContext Instance => instance.Value;
|
||||
|
||||
static FeatureContext()
|
||||
{
|
||||
instance = new Lazy<FeatureContext>(() => new FeatureContext((FeatureConfigurationSection)ConfigurationManager.GetSection(Constants.ConfigurationSectionNames.FeatureConfig)));
|
||||
}
|
||||
|
||||
public FeatureContext(FeatureConfigurationSection config)
|
||||
{
|
||||
Features = GetFeaturesFromConfig(config);
|
||||
}
|
||||
|
||||
private static Dictionary<string, IFeature> GetFeaturesFromConfig(FeatureConfigurationSection config)
|
||||
{
|
||||
var features = new Dictionary<string, IFeature>();
|
||||
|
||||
foreach (SimpleFeatureConfiguration featureConfiguration in config.SimpleFeatures)
|
||||
{
|
||||
var feature = new SimpleFeature
|
||||
{
|
||||
Name = featureConfiguration.Name,
|
||||
IsEnabled = featureConfiguration.IsEnabled,
|
||||
InstituteIds = featureConfiguration.InstituteIds,
|
||||
Environments = featureConfiguration.Environments
|
||||
};
|
||||
|
||||
features[feature.Name] = feature;
|
||||
}
|
||||
|
||||
return features;
|
||||
}
|
||||
|
||||
public bool IsEnabled(string featureName, string environment = null, string instituteId = null, List<string> instituteIds = null)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(featureName))
|
||||
{
|
||||
throw new ArgumentException($"{nameof(featureName)} null vagy üres");
|
||||
}
|
||||
|
||||
if (!Features.ContainsKey(featureName))
|
||||
{
|
||||
throw new ArgumentException($"{featureName} nem létező feature");
|
||||
}
|
||||
|
||||
bool isFeatureEnabled = Features[featureName].IsEnabled;
|
||||
|
||||
if (isFeatureEnabled && (!string.IsNullOrWhiteSpace(environment) || !string.IsNullOrWhiteSpace(instituteId)))
|
||||
{
|
||||
IFeature feature = Features[featureName];
|
||||
|
||||
return CheckEnvironment(feature, environment) && CheckInstituteId(feature, instituteId, instituteIds);
|
||||
}
|
||||
|
||||
return isFeatureEnabled;
|
||||
}
|
||||
|
||||
private bool CheckEnvironment(IFeature feature, string environment)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(environment))
|
||||
{
|
||||
return !feature.Environments.Any() || feature.Environments.Contains(environment);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool CheckInstituteId(IFeature feature, string instituteId, List<string> instituteIds = null)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(instituteId))
|
||||
{
|
||||
if (instituteIds != null && instituteIds.Any())
|
||||
{
|
||||
return instituteIds.Contains(instituteId, StringComparer.InvariantCultureIgnoreCase);
|
||||
}
|
||||
|
||||
return !feature.InstituteIds.Any() || feature.InstituteIds.Contains(instituteId, StringComparer.InvariantCultureIgnoreCase);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
15
Kreta.Core/FeatureToggle/IFeature.cs
Normal file
15
Kreta.Core/FeatureToggle/IFeature.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace Kreta.Core.FeatureToggle
|
||||
{
|
||||
public interface IFeature
|
||||
{
|
||||
string Name { get; }
|
||||
|
||||
bool IsEnabled { get; }
|
||||
|
||||
IEnumerable<string> InstituteIds { get; }
|
||||
|
||||
IEnumerable<string> Environments { get; }
|
||||
}
|
||||
}
|
9
Kreta.Core/FeatureToggle/IFeatureContext.cs
Normal file
9
Kreta.Core/FeatureToggle/IFeatureContext.cs
Normal file
|
@ -0,0 +1,9 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace Kreta.Core.FeatureToggle
|
||||
{
|
||||
public interface IFeatureContext
|
||||
{
|
||||
bool IsEnabled(string featureName, string environment = null, string instituteId = null, List<string> instituteIds = null);
|
||||
}
|
||||
}
|
150
Kreta.Core/FeatureToggle/SimpleFeature.cs
Normal file
150
Kreta.Core/FeatureToggle/SimpleFeature.cs
Normal file
|
@ -0,0 +1,150 @@
|
|||
using System.Collections.Generic;
|
||||
using Kreta.Core.FeatureToggle.Configuration;
|
||||
|
||||
namespace Kreta.Core.FeatureToggle
|
||||
{
|
||||
public class SimpleFeature : IFeature
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public bool IsEnabled { get; set; }
|
||||
|
||||
public IEnumerable<string> InstituteIds { get; set; }
|
||||
|
||||
public IEnumerable<string> Environments { get; set; }
|
||||
}
|
||||
|
||||
public class FeatureBase : SimpleFeature
|
||||
{
|
||||
protected FeatureBase(FeatureConfigurationSection config, string name)
|
||||
{
|
||||
foreach (SimpleFeatureConfiguration featureConfiguration in config.SimpleFeatures)
|
||||
{
|
||||
if (featureConfiguration.Name == name)
|
||||
{
|
||||
Name = featureConfiguration.Name;
|
||||
IsEnabled = featureConfiguration.IsEnabled;
|
||||
InstituteIds = featureConfiguration.InstituteIds;
|
||||
Environments = featureConfiguration.Environments;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class DeleteInvalidLinksFeature : FeatureBase
|
||||
{
|
||||
public DeleteInvalidLinksFeature(FeatureConfigurationSection config) : base(config, Constants.FeatureName.DeleteInvalidLinks) { }
|
||||
}
|
||||
|
||||
public class UpdateCOVIDFlagFeature : FeatureBase
|
||||
{
|
||||
public UpdateCOVIDFlagFeature(FeatureConfigurationSection config) : base(config, Constants.FeatureName.UpdateCOVIDFlag) { }
|
||||
}
|
||||
public class UpdateTanuloDualisSzerzodesei : FeatureBase
|
||||
{
|
||||
public UpdateTanuloDualisSzerzodesei(FeatureConfigurationSection config) : base(config, Constants.FeatureName.UpdateTanuloDualisSzerzodesei) { }
|
||||
}
|
||||
|
||||
public class UseGlobalApiConnectionStringFeature : FeatureBase
|
||||
{
|
||||
public UseGlobalApiConnectionStringFeature(FeatureConfigurationSection config) : base(config, Constants.FeatureName.UseGlobalApiConnectionString) { }
|
||||
}
|
||||
|
||||
public class IntervalFeatureBase : FeatureBase
|
||||
{
|
||||
public string CustomCronExpression { get; }
|
||||
public int SendItervalInMinute { get; } = 59;
|
||||
public int? RunningIntervalStartHour { get; }
|
||||
public int? RunningIntervalEndHour { get; }
|
||||
|
||||
public IntervalFeatureBase(FeatureConfigurationSection config, string name, ExtendedSendMobileNotification extendedSendMobileNotification) : base(config, name)
|
||||
{
|
||||
CustomCronExpression = extendedSendMobileNotification.CustomCronExpression;
|
||||
|
||||
if (int.TryParse(extendedSendMobileNotification.SendItervalInMinute, out int sendItervalInMinute))
|
||||
{
|
||||
if (sendItervalInMinute > 0)
|
||||
{
|
||||
SendItervalInMinute = sendItervalInMinute;
|
||||
}
|
||||
}
|
||||
|
||||
if (int.TryParse(extendedSendMobileNotification.RunningIntervalStartHour, out int runningIntervalStartHour))
|
||||
{
|
||||
if (runningIntervalStartHour > -1 && runningIntervalStartHour < 24)
|
||||
{
|
||||
RunningIntervalStartHour = runningIntervalStartHour;
|
||||
|
||||
if (int.TryParse(extendedSendMobileNotification.RunningIntervalEndHour, out int runningIntervalEndHour))
|
||||
{
|
||||
if (runningIntervalEndHour >= runningIntervalStartHour && runningIntervalEndHour < 24)
|
||||
{
|
||||
RunningIntervalEndHour = runningIntervalEndHour;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class SendErtekelesNotificationFeature : IntervalFeatureBase
|
||||
{
|
||||
public SendErtekelesNotificationFeature(FeatureConfigurationSection config) : base(config, Constants.FeatureName.SendErtekelesNotification, config.SendErtekelesNotification) { }
|
||||
}
|
||||
|
||||
public class SendHazifeladatNotificationFeature : IntervalFeatureBase
|
||||
{
|
||||
public SendHazifeladatNotificationFeature(FeatureConfigurationSection config) : base(config, Constants.FeatureName.SendHazifeladatNotification, config.SendHazifeladatNotification) { }
|
||||
}
|
||||
|
||||
public class SendRendszerUzenetNotificationFeature : IntervalFeatureBase
|
||||
{
|
||||
public SendRendszerUzenetNotificationFeature(FeatureConfigurationSection config) : base(config, Constants.FeatureName.SendRendszerUzenetNotification, config.SendRendszerUzenetNotification) { }
|
||||
}
|
||||
|
||||
public class SendMulasztasNotificationFeature : IntervalFeatureBase
|
||||
{
|
||||
public SendMulasztasNotificationFeature(FeatureConfigurationSection config) : base(config, Constants.FeatureName.SendMulasztasNotification, config.SendMulasztasNotification) { }
|
||||
}
|
||||
|
||||
public class SendBejelentettSzamonkeresNotificationFeature : IntervalFeatureBase
|
||||
{
|
||||
public SendBejelentettSzamonkeresNotificationFeature(FeatureConfigurationSection config) : base(config, Constants.FeatureName.SendBejelentettSzamonkeresNotification, config.SendBejelentettSzamonkeresNotification) { }
|
||||
}
|
||||
|
||||
public class SendFeljegyzesNotificationFeature : IntervalFeatureBase
|
||||
{
|
||||
public SendFeljegyzesNotificationFeature(FeatureConfigurationSection config) : base(config, Constants.FeatureName.SendFeljegyzesNotification, config.SendFeljegyzesNotification) { }
|
||||
}
|
||||
|
||||
public class SendNemNaplozottTanorakMailFeature : IntervalFeatureBase
|
||||
{
|
||||
public SendNemNaplozottTanorakMailFeature(FeatureConfigurationSection config) : base(config, Constants.FeatureName.SendNemNaplozottTanorakMail, config.SendNemNaplozottTanorakMail) { }
|
||||
}
|
||||
|
||||
public class SendKozelgoFogadooraMailFeature : FeatureBase
|
||||
{
|
||||
public SendKozelgoFogadooraMailFeature(FeatureConfigurationSection config) : base(config, Constants.FeatureName.SendKozelgoFogadooraMail) { }
|
||||
}
|
||||
|
||||
public class SendOrarendValtozasNotificationFeature : IntervalFeatureBase
|
||||
{
|
||||
public SendOrarendValtozasNotificationFeature(FeatureConfigurationSection config) : base(config, Constants.FeatureName.SendOrarendValtozasNotification, config.SendOrarendValtozasNotification) { }
|
||||
}
|
||||
|
||||
public class MkbBankszamlaIgenylesFeature : FeatureBase
|
||||
{
|
||||
public MkbBankszamlaIgenylesFeature(FeatureConfigurationSection config) : base(config, Constants.FeatureName.MkbBankszamlaIgenyles) { }
|
||||
}
|
||||
|
||||
public class OtpBankszamlaIgenylesFeature : FeatureBase
|
||||
{
|
||||
public OtpBankszamlaIgenylesFeature(FeatureConfigurationSection config) : base(config, Constants.FeatureName.OtpBankszamlaIgenyles) { }
|
||||
}
|
||||
|
||||
public class sapSyncFeature : FeatureBase
|
||||
{
|
||||
public sapSyncFeature(FeatureConfigurationSection config) : base(config, Constants.FeatureName.SAPSync) { }
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue