2022-01-26 11:32:16 -05:00
|
|
|
|
using System;
|
2020-01-17 18:31:53 -05:00
|
|
|
|
using System.Linq;
|
2022-01-26 11:32:16 -05:00
|
|
|
|
using System.Net;
|
|
|
|
|
using FluentValidation;
|
2020-01-17 18:31:53 -05:00
|
|
|
|
|
|
|
|
|
namespace SharedLibraryCore.Configuration.Validation
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2022-01-26 11:32:16 -05:00
|
|
|
|
/// Validation class for main application configuration
|
2020-01-17 18:31:53 -05:00
|
|
|
|
/// </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)
|
2022-01-26 11:32:16 -05:00
|
|
|
|
.NotEmpty()
|
|
|
|
|
.When(_app => _app.EnableSocialLink);
|
2020-01-17 18:31:53 -05:00
|
|
|
|
|
|
|
|
|
RuleFor(_app => _app.CustomParserEncoding)
|
2022-01-26 11:32:16 -05:00
|
|
|
|
.NotEmpty()
|
|
|
|
|
.When(_app => _app.EnableCustomParserEncoding);
|
2020-01-17 18:31:53 -05:00
|
|
|
|
|
|
|
|
|
RuleFor(_app => _app.WebfrontConnectionWhitelist)
|
|
|
|
|
.NotEmpty()
|
|
|
|
|
.When(_app => _app.EnableWebfrontConnectionWhitelist);
|
|
|
|
|
|
|
|
|
|
RuleForEach(_app => _app.WebfrontConnectionWhitelist)
|
2022-01-26 11:32:16 -05:00
|
|
|
|
.Must(_address => IPAddress.TryParse(_address, out _));
|
2020-01-17 18:31:53 -05:00
|
|
|
|
|
|
|
|
|
RuleFor(_app => _app.CustomLocale)
|
2022-01-26 11:32:16 -05:00
|
|
|
|
.NotEmpty()
|
|
|
|
|
.When(_app => _app.EnableCustomLocale);
|
2020-01-17 18:31:53 -05:00
|
|
|
|
|
|
|
|
|
RuleFor(_app => _app.DatabaseProvider)
|
2022-01-26 11:32:16 -05:00
|
|
|
|
.NotEmpty()
|
|
|
|
|
.Must(_provider => new[] { "sqlite", "mysql", "postgresql" }.Contains(_provider));
|
2020-01-17 18:31:53 -05:00
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
2020-06-30 17:39:32 -04:00
|
|
|
|
RuleFor(_app => _app.MasterUrl)
|
|
|
|
|
.NotNull()
|
2023-09-02 14:38:56 -04:00
|
|
|
|
.Must(_url => _url != null && (_url.Scheme == Uri.UriSchemeHttp || _url.Scheme == Uri.UriSchemeHttps));
|
2020-07-31 21:40:03 -04:00
|
|
|
|
|
|
|
|
|
RuleFor(_app => _app.CommandPrefix)
|
|
|
|
|
.NotEmpty();
|
|
|
|
|
|
|
|
|
|
RuleFor(_app => _app.BroadcastCommandPrefix)
|
|
|
|
|
.NotEmpty();
|
|
|
|
|
|
|
|
|
|
RuleForEach(_app => _app.Servers)
|
|
|
|
|
.NotEmpty()
|
|
|
|
|
.SetValidator(new ServerConfigurationValidator());
|
2020-01-17 18:31:53 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-02 14:38:56 -04:00
|
|
|
|
}
|