IW4M-Admin/SharedLibraryCore/Configuration/Validation/ApplicationConfigurationValidator.cs
RaidMax 697a752be0 make the version name match the actual name for FTP deployment
fix rare issue with summing session scores
copy font to expected wwwroot dir in debug mode so we get pretty icons when developing
upgrade some packages

pretty much reworked the entire server web config to support better validation and stuff.. not really a small fix

finish web configuration changes (I think)

finish up configuration changes and update shared library nuget
2020-01-20 10:23:23 -06:00

73 lines
2.3 KiB
C#

using FluentValidation;
using System;
using System.Linq;
namespace SharedLibraryCore.Configuration.Validation
{
/// <summary>
/// Validation class for main application configuration
/// </summary>
public class ApplicationConfigurationValidator : AbstractValidator<ApplicationConfiguration>
{
public ApplicationConfigurationValidator()
{
RuleFor(_app => _app.WebfrontBindUrl)
.NotEmpty();
RuleFor(_app => _app.CustomSayName)
.NotEmpty()
.When(_app => _app.EnableCustomSayName);
RuleFor(_app => _app.SocialLinkAddress)
.NotEmpty()
.When(_app => _app.EnableSocialLink);
RuleFor(_app => _app.SocialLinkTitle)
.NotEmpty()
.When(_app => _app.EnableSocialLink);
RuleFor(_app => _app.CustomParserEncoding)
.NotEmpty()
.When(_app => _app.EnableCustomParserEncoding);
RuleFor(_app => _app.WebfrontConnectionWhitelist)
.NotEmpty()
.When(_app => _app.EnableWebfrontConnectionWhitelist);
RuleForEach(_app => _app.WebfrontConnectionWhitelist)
.Must(_address => System.Net.IPAddress.TryParse(_address, out _));
RuleFor(_app => _app.CustomLocale)
.NotEmpty()
.When(_app => _app.EnableCustomLocale);
RuleFor(_app => _app.DatabaseProvider)
.NotEmpty()
.Must(_provider => new[] { "sqlite", "mysql", "postgresql" }.Contains(_provider));
RuleFor(_app => _app.ConnectionString)
.NotEmpty()
.When(_app => _app.DatabaseProvider != "sqlite");
RuleFor(_app => _app.RConPollRate)
.GreaterThanOrEqualTo(1000);
RuleFor(_app => _app.AutoMessagePeriod)
.GreaterThanOrEqualTo(60);
RuleFor(_app => _app.Servers)
.NotEmpty();
RuleFor(_app => _app.AutoMessages)
.NotNull();
RuleFor(_app => _app.GlobalRules)
.NotNull();
RuleForEach(_app => _app.Servers)
.NotEmpty()
.SetValidator(new ServerConfigurationValidator());
}
}
}