using System.Configuration;
using Kreta.Core.MessageBroker.Configuration.IntegratedMessageClient;
using Validators = Kreta.Core.Configuration.Validators;
namespace Kreta.MessageBroker.Configuration
{
///
/// Message client configuration element
///
class MessageClientConfigurationElement : ConfigurationElement, IIntegratedMessageClientConfiguration
{
///
/// Element name
///
public const string ElementName = "Client";
///
/// Client name
///
[ConfigurationProperty(nameof(Name), IsRequired = true, DefaultValue = Validators.StringValidator.SkipValidationForDefaultValue)]
[Validators.StringValidator(false, MaxLength = 128)]
public string Name
{
get
{
return (string)this[nameof(Name)];
}
}
string IIntegratedMessageClientConfiguration.EndpointClientName => this.Name;
///
/// Message signature key
///
[ConfigurationProperty(nameof(MessageSignatureKey), IsRequired = true, DefaultValue = Validators.StringValidator.SkipValidationForDefaultValue)]
[Validators.StringValidator(false, MinLength = 32, MaxLength = 128)]
public string MessageSignatureKey
{
get
{
return (string)this[nameof(MessageSignatureKey)];
}
}
[ConfigurationProperty(nameof(QueueSize), DefaultValue = 0)]
public int QueueSize
{
get
{
return (int)this[nameof(QueueSize)];
}
}
[ConfigurationProperty(nameof(ClientPoolSize), DefaultValue = 8)]
[Validators.IntegerValidator(MinValue = 1)]
public int ClientPoolSize
{
get
{
return (int)this[nameof(ClientPoolSize)];
}
}
[ConfigurationProperty(nameof(CreateNewClientAfterErrorsCount), DefaultValue = 20)]
[Validators.IntegerValidator(MinValue = 3)]
public int CreateNewClientAfterErrorsCount
{
get
{
return (int)this[nameof(CreateNewClientAfterErrorsCount)];
}
}
int? IIntegratedMessageClientConfiguration.CreateNewClientAfterErrorsCount => this.CreateNewClientAfterErrorsCount == 0 ? (int?)null : this.CreateNewClientAfterErrorsCount;
///
/// Enable logging
///
[ConfigurationProperty(nameof(EnableLogging), IsRequired = true)]
public bool EnableLogging
{
get
{
return (bool)this[nameof(EnableLogging)];
}
}
bool IIntegratedMessageClientConfiguration.IsLoggingEnabled => this.EnableLogging;
[ConfigurationProperty(nameof(LoggerType), DefaultValue = LoggerType.Log4Net)]
public LoggerType LoggerType
{
get
{
return (LoggerType)this[nameof(LoggerType)];
}
}
[ConfigurationProperty(nameof(SerilogLogger))]
public SerilogConfigurationElement SerilogLogger
{
get
{
return (SerilogConfigurationElement)this[nameof(SerilogLogger)];
}
}
[ConfigurationProperty(nameof(CalculateBackOffTimeSpan), DefaultValue = true)]
public bool CalculateBackOffTimeSpan
{
get
{
return (bool)this[nameof(CalculateBackOffTimeSpan)];
}
}
}
}