2023-10-08 15:19:13 +03:00
|
|
|
|
using System.Text.RegularExpressions;
|
2023-10-10 22:26:16 +03:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
2023-10-08 15:19:13 +03:00
|
|
|
|
using Microsoft.AspNetCore.Http.Extensions;
|
|
|
|
|
|
2023-10-10 22:26:16 +03:00
|
|
|
|
namespace RhSolutions.QueryModifiers;
|
2023-10-08 15:19:13 +03:00
|
|
|
|
|
2023-10-10 22:26:16 +03:00
|
|
|
|
public class ThreadTPieceInternal : IProductQueryModifier
|
2023-10-08 15:19:13 +03:00
|
|
|
|
{
|
|
|
|
|
private string diameterPattern = "16|20|25|32|40|50|63";
|
|
|
|
|
private string threadPattern = @"(\D|^)(?<Thread>1\s+1/4|1\s+1/2|1/2|3/4|2|1)(\D|$)";
|
|
|
|
|
|
|
|
|
|
public bool TryQueryModify(IQueryCollection collection, out QueryString queryString)
|
|
|
|
|
{
|
|
|
|
|
queryString = QueryString.Empty;
|
|
|
|
|
var query = collection["query"].ToString();
|
|
|
|
|
if (string.IsNullOrEmpty(query))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
var diameters = Regex.Matches(query, diameterPattern);
|
|
|
|
|
if (diameters.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
var thread = Regex.Match(query, threadPattern);
|
|
|
|
|
if (!thread.Success)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
QueryBuilder qb = new()
|
|
|
|
|
{
|
|
|
|
|
{"query", ConstructName(diameters, thread)}
|
|
|
|
|
};
|
|
|
|
|
queryString = qb.ToQueryString();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual string ConstructName(MatchCollection diameters, Match thread)
|
|
|
|
|
{
|
|
|
|
|
Capture t = thread.Groups["Thread"].Captures.First();
|
|
|
|
|
if (diameters.Count == 1)
|
|
|
|
|
{
|
2023-10-10 22:26:16 +03:00
|
|
|
|
if (int.Parse(diameters[0].Value) < 25)
|
|
|
|
|
{
|
|
|
|
|
return $"Тройник настенный с внутренней резьбой {diameters[0]}-Rp{t}-{diameters[0]}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return $"Тройник с внутр. резьбой на боков. проходе {diameters[0]}-Rp {t}-{diameters[0]}";
|
|
|
|
|
}
|
2023-10-08 15:19:13 +03:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-10-10 22:26:16 +03:00
|
|
|
|
if (int.Parse(diameters[0].Value) < 25)
|
|
|
|
|
{
|
|
|
|
|
return $"Тройник настенный с внутренней резьбой {diameters[0]}-Rp{t}-{diameters[1]}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return $"Тройник с внутр. резьбой на боков. проходе {diameters[0]}-Rp {t}-{diameters[1]}";
|
|
|
|
|
}
|
2023-10-08 15:19:13 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|