2023-10-11 22:35:19 +03:00
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
using Microsoft.AspNetCore.Http.Extensions;
|
|
|
|
|
2023-10-13 15:04:27 +03:00
|
|
|
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
|
2023-10-11 22:35:19 +03:00
|
|
|
|
2023-10-13 15:04:27 +03:00
|
|
|
public abstract class DrinkingWaterHeatingFitting : IProductQueryModifier
|
2023-10-11 22:35:19 +03:00
|
|
|
{
|
|
|
|
protected static readonly Regex _diameter =
|
2023-10-13 15:04:27 +03:00
|
|
|
new(@"([\b\D]|^)?(?<Diameter>16|20|25|32|40|50|63)([\b\D]|$)");
|
2023-10-11 22:35:19 +03:00
|
|
|
protected static readonly Regex _angle =
|
2023-10-13 15:04:27 +03:00
|
|
|
new(@"([\b\D])(?<Angle>45|90)([\b\D]|$)");
|
2023-10-11 22:35:19 +03:00
|
|
|
protected static readonly Regex _thread =
|
2023-10-13 15:04:27 +03:00
|
|
|
new(@"([\b\D])(?<Thread>1\s+1/4|1\s+1/2|1/2|3/4|2|1)([\b\D]|$)");
|
2023-10-11 22:35:19 +03:00
|
|
|
|
|
|
|
protected virtual string _title { get; } = string.Empty;
|
|
|
|
|
|
|
|
public bool TryQueryModify(IQueryCollection collection, out QueryString queryString)
|
|
|
|
{
|
|
|
|
queryString = QueryString.Empty;
|
|
|
|
string query = collection["query"].ToString();
|
|
|
|
if (string.IsNullOrEmpty(query))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
string? result = BuildRhSolutionsName(query);
|
|
|
|
if (result != null)
|
|
|
|
{
|
|
|
|
QueryBuilder qb = new()
|
|
|
|
{
|
|
|
|
{ "query", result }
|
|
|
|
};
|
|
|
|
queryString = qb.ToQueryString();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual string? BuildRhSolutionsName(string query)
|
|
|
|
{
|
|
|
|
var match = _diameter.Match(query);
|
|
|
|
if (match.Success)
|
|
|
|
{
|
|
|
|
return $"{_title} {match.Groups["Diameter"]}";
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|