2025-04-17 16:38:35 +10:00
|
|
|
|
using PARR.BLL.Services.Interfaces;
|
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
|
|
|
|
|
|
namespace PARR.BLL.Services.Implementations
|
|
|
|
|
|
{
|
|
|
|
|
|
internal class TemplateMaskValidator : ITemplateMaskValidator
|
|
|
|
|
|
{
|
|
|
|
|
|
public bool IsValid(string mask)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!mask.Contains("ПАРР"))
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
var shortcodePattern = "%[^%\\s]+%";
|
|
|
|
|
|
var shortcodesInMask = Regex.Matches(mask, shortcodePattern).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
if (shortcodesInMask.Count() == 0)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
var validShortcodes = GetShortcodesNames();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var shortcode in shortcodesInMask)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!validShortcodes.Contains(shortcode.ToString().ToUpper()))
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-01 14:45:36 +10:00
|
|
|
|
private List<string> GetShortcodesNames()//TODO Ну ты опять этот метод дублируешь?!
|
2025-04-17 16:38:35 +10:00
|
|
|
|
{
|
2025-08-01 14:45:36 +10:00
|
|
|
|
var result = new List<string> {
|
|
|
|
|
|
"%ЭК%",
|
|
|
|
|
|
"%ЗО%",
|
|
|
|
|
|
"%РАБОТА%"
|
|
|
|
|
|
};
|
2025-04-17 16:38:35 +10:00
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|