44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
using PARR.BLL.Services.Interfaces;
|
|
using PARR.Constants.Shortcodes;
|
|
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;
|
|
}
|
|
|
|
private List<string> GetShortcodesNames()
|
|
{
|
|
var result = new List<string>();
|
|
var shortcodes = Enum.GetValues(typeof(ShortcodeEnum)).Cast<ShortcodeEnum>();
|
|
foreach (var item in shortcodes)
|
|
{
|
|
result.Add(Shortcodes.GetShortcodeName(item).ToUpper());
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|
|
}
|