-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathStartGameViewModelValidator.cs
28 lines (22 loc) · 1.24 KB
/
StartGameViewModelValidator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using ImeSense.Launchers.Belarus.Core.Manager;
using ImeSense.Launchers.Belarus.Core.Validators;
using ReactiveUI.Validation.Extensions;
using ReactiveUI.Validation.Helpers;
namespace ImeSense.Launchers.Belarus.ViewModels.Validators;
public sealed class StartGameViewModelValidator(IStartGameValidator validator, IApplicationLocaleManager localeManager)
{
private readonly IStartGameValidator _validator = validator;
private readonly IApplicationLocaleManager _localeManager = localeManager;
public ValidationHelper EnsureIpAddressNotEmpty(StartGameViewModel startGameViewModel)
{
return startGameViewModel.ValidationRule(viewModel => viewModel.IpAddress,
serverAddress => serverAddress is not null && _validator.IsIpAddressNotEmpty(serverAddress),
_localeManager.GetStringByKey("LocalizedStrings.IpAddressNotEntered"));
}
public ValidationHelper EnsureValidIpAddressOrUrl(StartGameViewModel startGameViewModel)
{
return startGameViewModel.ValidationRule(viewModel => viewModel.IpAddress,
serverAddress => serverAddress is not null && _validator.IsValidIpAddressOrUrl(serverAddress),
_localeManager.GetStringByKey("LocalizedStrings.InvalidIpAddress"));
}
}