summaryrefslogtreecommitdiff
path: root/RhSolutions.QueryModifiers
diff options
context:
space:
mode:
Diffstat (limited to 'RhSolutions.QueryModifiers')
-rw-r--r--RhSolutions.QueryModifiers/AdapterExternalModifier.cs7
-rw-r--r--RhSolutions.QueryModifiers/AdapterInternalModifier.cs7
-rw-r--r--RhSolutions.QueryModifiers/AdapterModifier.cs39
-rw-r--r--RhSolutions.QueryModifiers/AdapterScrewcapModifier.cs7
-rw-r--r--RhSolutions.QueryModifiers/BlackPipeQueryModifier.cs13
-rw-r--r--RhSolutions.QueryModifiers/BypassQueryModifier.cs12
-rw-r--r--RhSolutions.QueryModifiers/CouplingModifier.cs38
-rw-r--r--RhSolutions.QueryModifiers/ElbowModifier.cs36
-rw-r--r--RhSolutions.QueryModifiers/FlexPipeQueryModifier.cs3
-rw-r--r--RhSolutions.QueryModifiers/IProductQueryModifier.cs8
-rw-r--r--RhSolutions.QueryModifiers/PinkPipeQueryModifier.cs22
-rw-r--r--RhSolutions.QueryModifiers/PipeQueryModifier.cs59
-rw-r--r--RhSolutions.QueryModifiers/ProductQueryModifierFactory.cs47
-rw-r--r--RhSolutions.QueryModifiers/RhSolutions.QueryModifiers.csproj13
-rw-r--r--RhSolutions.QueryModifiers/ScrewcapElbowModifier.cs6
-rw-r--r--RhSolutions.QueryModifiers/SleeveQueryModifier.cs38
-rw-r--r--RhSolutions.QueryModifiers/StabilPipeQueryModifier.cs15
-rw-r--r--RhSolutions.QueryModifiers/TPieceQueryModifier.cs42
-rw-r--r--RhSolutions.QueryModifiers/ThreadElbowExternalModifier.cs6
-rw-r--r--RhSolutions.QueryModifiers/ThreadElbowInternalModifier.cs6
-rw-r--r--RhSolutions.QueryModifiers/ThreadTPieceExternal.cs19
-rw-r--r--RhSolutions.QueryModifiers/ThreadTPieceWall.cs64
22 files changed, 507 insertions, 0 deletions
diff --git a/RhSolutions.QueryModifiers/AdapterExternalModifier.cs b/RhSolutions.QueryModifiers/AdapterExternalModifier.cs
new file mode 100644
index 0000000..1e7bc5d
--- /dev/null
+++ b/RhSolutions.QueryModifiers/AdapterExternalModifier.cs
@@ -0,0 +1,7 @@
+namespace RhSolutions.QueryModifiers
+{
+ public class AdapterExternalModifier : AdapterModifier
+ {
+ protected override string name => "Переходник с наружной резьбой";
+ }
+}
diff --git a/RhSolutions.QueryModifiers/AdapterInternalModifier.cs b/RhSolutions.QueryModifiers/AdapterInternalModifier.cs
new file mode 100644
index 0000000..7761dd1
--- /dev/null
+++ b/RhSolutions.QueryModifiers/AdapterInternalModifier.cs
@@ -0,0 +1,7 @@
+namespace RhSolutions.QueryModifiers
+{
+ public class AdapterInternalModifier : AdapterModifier
+ {
+ protected override string name => "Переходник с внутренней резьбой -угольник-переходник";
+ }
+}
diff --git a/RhSolutions.QueryModifiers/AdapterModifier.cs b/RhSolutions.QueryModifiers/AdapterModifier.cs
new file mode 100644
index 0000000..0ebe40d
--- /dev/null
+++ b/RhSolutions.QueryModifiers/AdapterModifier.cs
@@ -0,0 +1,39 @@
+using System.Text.RegularExpressions;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Http.Extensions;
+
+namespace RhSolutions.QueryModifiers
+{
+ public abstract class AdapterModifier : IProductQueryModifier
+ {
+ protected string pattern { get; } =
+ @"(?<Diameter>\b16|20|25|32|40|50|63\b)\D+(?<Thread>\b1\s+1/4|1\s+1/2|1/2|3/4|2|1\b)";
+ protected virtual string name { get; } = string.Empty;
+ public bool TryQueryModify(IQueryCollection collection, out QueryString queryString)
+ {
+ queryString = QueryString.Empty;
+ var query = collection["query"].ToString();
+ if (string.IsNullOrEmpty(query))
+ {
+ return false;
+ }
+ var matches = Regex.Matches(query, pattern);
+ if (matches.Count == 0)
+ {
+ return false;
+ }
+ else
+ {
+ var match = matches.First();
+ var diameter = match.Groups["Diameter"].Captures.First();
+ var thread = match.Groups["Thread"].Captures.First();
+ QueryBuilder qb = new()
+ {
+ {"query", $"{name} {diameter} {thread}"}
+ };
+ queryString = qb.ToQueryString();
+ return true;
+ }
+ }
+ }
+}
diff --git a/RhSolutions.QueryModifiers/AdapterScrewcapModifier.cs b/RhSolutions.QueryModifiers/AdapterScrewcapModifier.cs
new file mode 100644
index 0000000..9841891
--- /dev/null
+++ b/RhSolutions.QueryModifiers/AdapterScrewcapModifier.cs
@@ -0,0 +1,7 @@
+namespace RhSolutions.QueryModifiers
+{
+ public class AdapterScrewcapModifier : AdapterModifier
+ {
+ protected override string name => "Переходник с накидной гайкой";
+ }
+}
diff --git a/RhSolutions.QueryModifiers/BlackPipeQueryModifier.cs b/RhSolutions.QueryModifiers/BlackPipeQueryModifier.cs
new file mode 100644
index 0000000..d59db67
--- /dev/null
+++ b/RhSolutions.QueryModifiers/BlackPipeQueryModifier.cs
@@ -0,0 +1,13 @@
+namespace RhSolutions.QueryModifiers;
+
+public class BlackPipeQueryModifier : PipeQueryModifier
+{
+ protected override string diameterPattern => @"([\b\D]|^)(?<Diameter>16|20|25)([\b\D]|$)";
+ protected override string pipeName => "Black";
+ protected override Dictionary<string, string> diameterNames => new()
+ {
+ ["16"] = "16х2,2",
+ ["20"] = "20х2,8",
+ ["25"] = "25х3,5"
+ };
+}
diff --git a/RhSolutions.QueryModifiers/BypassQueryModifier.cs b/RhSolutions.QueryModifiers/BypassQueryModifier.cs
new file mode 100644
index 0000000..68d3cb2
--- /dev/null
+++ b/RhSolutions.QueryModifiers/BypassQueryModifier.cs
@@ -0,0 +1,12 @@
+using Microsoft.AspNetCore.Http;
+
+namespace RhSolutions.QueryModifiers;
+
+public class BypassQueryModifier : IProductQueryModifier
+{
+ public bool TryQueryModify(IQueryCollection collection, out QueryString queryString)
+ {
+ queryString = QueryString.Empty;
+ return false;
+ }
+}
diff --git a/RhSolutions.QueryModifiers/CouplingModifier.cs b/RhSolutions.QueryModifiers/CouplingModifier.cs
new file mode 100644
index 0000000..e8a1739
--- /dev/null
+++ b/RhSolutions.QueryModifiers/CouplingModifier.cs
@@ -0,0 +1,38 @@
+using System.Text.RegularExpressions;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Http.Extensions;
+
+namespace RhSolutions.QueryModifiers;
+
+public class CouplingModifier : IProductQueryModifier
+{
+ private string pattern { get; } = @"([\b\D]|^)?(?<Diameter>16|20|25|32|40|50|63)([\b\D]|$)?";
+ public bool TryQueryModify(IQueryCollection collection, out QueryString queryString)
+ {
+ queryString = QueryString.Empty;
+ var query = collection["query"].ToString();
+ if (string.IsNullOrEmpty(query))
+ {
+ return false;
+ }
+ var matches = Regex.Matches(query, pattern);
+ if (matches.Count < 1)
+ {
+ return false;
+ }
+ else
+ {
+ QueryBuilder qb = new();
+ if (matches.Count < 2 || matches.Count > 1 && matches[0].Groups["Diameter"].Value == matches[1].Groups["Diameter"].Value)
+ {
+ qb.Add("query", $"Муфта соединительная равнопроходная {matches[0].Groups["Diameter"].Value}");
+ }
+ else
+ {
+ qb.Add("query", $"Муфта соединительная переходная {matches[0].Groups["Diameter"].Value}-{matches[1].Groups["Diameter"].Value}");
+ }
+ queryString = qb.ToQueryString();
+ return true;
+ }
+ }
+}
diff --git a/RhSolutions.QueryModifiers/ElbowModifier.cs b/RhSolutions.QueryModifiers/ElbowModifier.cs
new file mode 100644
index 0000000..05ca9b4
--- /dev/null
+++ b/RhSolutions.QueryModifiers/ElbowModifier.cs
@@ -0,0 +1,36 @@
+using System.Text.RegularExpressions;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Http.Extensions;
+
+namespace RhSolutions.QueryModifiers
+{
+ public class ElbowModifier : IProductQueryModifier
+ {
+ private string diameterPattern { get; } = @"\b(16|20|25|32|40|50|63)\b";
+ private string anglePattern { get; } = @"\b(45|90)";
+ public bool TryQueryModify(IQueryCollection collection, out QueryString queryString)
+ {
+ queryString = QueryString.Empty;
+ var query = collection["query"].ToString();
+ if (string.IsNullOrEmpty(query))
+ {
+ return false;
+ }
+ var diameter = Regex.Match(query, diameterPattern);
+ if (diameter.Success)
+ {
+ var angle = Regex.Match(query, anglePattern);
+ QueryBuilder qb = new()
+ {
+ {"query", $"Угольник RAUTITAN -PLATINUM {(angle.Success ? angle.Captures.First() : 90)} {diameter.Captures.First()}"}
+ };
+ queryString = qb.ToQueryString();
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ }
+}
diff --git a/RhSolutions.QueryModifiers/FlexPipeQueryModifier.cs b/RhSolutions.QueryModifiers/FlexPipeQueryModifier.cs
new file mode 100644
index 0000000..9bee225
--- /dev/null
+++ b/RhSolutions.QueryModifiers/FlexPipeQueryModifier.cs
@@ -0,0 +1,3 @@
+namespace RhSolutions.QueryModifiers;
+
+public class FlexPipeQueryModifier : PipeQueryModifier { } \ No newline at end of file
diff --git a/RhSolutions.QueryModifiers/IProductQueryModifier.cs b/RhSolutions.QueryModifiers/IProductQueryModifier.cs
new file mode 100644
index 0000000..508aba5
--- /dev/null
+++ b/RhSolutions.QueryModifiers/IProductQueryModifier.cs
@@ -0,0 +1,8 @@
+using Microsoft.AspNetCore.Http;
+
+namespace RhSolutions.QueryModifiers;
+
+public interface IProductQueryModifier
+{
+ public bool TryQueryModify(IQueryCollection collection, out QueryString queryString);
+}
diff --git a/RhSolutions.QueryModifiers/PinkPipeQueryModifier.cs b/RhSolutions.QueryModifiers/PinkPipeQueryModifier.cs
new file mode 100644
index 0000000..c76077f
--- /dev/null
+++ b/RhSolutions.QueryModifiers/PinkPipeQueryModifier.cs
@@ -0,0 +1,22 @@
+namespace RhSolutions.QueryModifiers;
+
+public class PinkPipeQueryModifier : PipeQueryModifier
+{
+ protected override string pipeName => "Pink+";
+ protected override Dictionary<string, string> diameterNames => new()
+ {
+ ["16"] = "16х2,2",
+ ["20"] = "20х2,8",
+ ["25"] = "25х3,5",
+ ["32"] = "32х4,4",
+ ["40"] = "40х5,5",
+ ["50"] = "50х6,9",
+ ["63"] = "63х8,7"
+ };
+ protected override Dictionary<string, string> makeUpNames => new()
+ {
+ ["бухт"] = "бухта",
+ ["штанг"] = "прямые отрезки",
+ ["отр"] = "прямые отрезки"
+ };
+}
diff --git a/RhSolutions.QueryModifiers/PipeQueryModifier.cs b/RhSolutions.QueryModifiers/PipeQueryModifier.cs
new file mode 100644
index 0000000..2126c55
--- /dev/null
+++ b/RhSolutions.QueryModifiers/PipeQueryModifier.cs
@@ -0,0 +1,59 @@
+using System.Text.RegularExpressions;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Http.Extensions;
+
+namespace RhSolutions.QueryModifiers;
+
+public class PipeQueryModifier : IProductQueryModifier
+{
+ protected virtual string diameterPattern { get; } = @"([\b\D]|^)(?<Diameter>16|20|25|32|40|50|63)([\b\D]|$)";
+ protected virtual string typePattern { get; } = @"бухт|отр|штанг";
+ protected virtual string pipeName { get; } = "Flex";
+ protected virtual Dictionary<string, string> diameterNames { get; } = new()
+ {
+ ["16"] = "16x2,2",
+ ["20"] = "20x2,8",
+ ["25"] = "25x3,5",
+ ["32"] = "32x4,4",
+ ["40"] = "40x5,5",
+ ["50"] = "50x6,9",
+ ["63"] = "63x8,6"
+ };
+
+ protected virtual Dictionary<string, string> makeUpNames { get; } = new()
+ {
+ ["бухт"] = "бухта",
+ ["штанг"] = "прям.отрезки",
+ ["отр"] = "прям.отрезки"
+ };
+
+ public bool TryQueryModify(IQueryCollection collection, out QueryString queryString)
+ {
+ queryString = QueryString.Empty;
+ string query = collection["query"].ToString();
+ if (string.IsNullOrEmpty(query))
+ {
+ return false;
+ }
+
+ var diameterMatches = Regex.Matches(query, diameterPattern);
+ if (diameterMatches.Count == 0)
+ {
+ return false;
+ }
+
+ var typeMatches = Regex.Matches(query, typePattern);
+ var diameter = diameterMatches.First().Groups["Diameter"].Value;
+ string? type = typeMatches.FirstOrDefault()?.Value;
+
+ string result =
+ $"Труба {pipeName} {diameterNames[diameter]} {(type != null ? makeUpNames[type] : int.Parse(diameter) < 32 ? makeUpNames["бухт"] : makeUpNames["отр"])}";
+
+ QueryBuilder qb = new()
+ {
+ { "query", result }
+ };
+ queryString = qb.ToQueryString();
+ return true;
+ }
+}
diff --git a/RhSolutions.QueryModifiers/ProductQueryModifierFactory.cs b/RhSolutions.QueryModifiers/ProductQueryModifierFactory.cs
new file mode 100644
index 0000000..32d5e5e
--- /dev/null
+++ b/RhSolutions.QueryModifiers/ProductQueryModifierFactory.cs
@@ -0,0 +1,47 @@
+namespace RhSolutions.QueryModifiers;
+
+public class ProductQueryModifierFactory
+{
+ public IProductQueryModifier GetModifier(string productTypeName)
+ {
+ switch (productTypeName)
+ {
+ case "Монтажная гильза":
+ return new SleeveQueryModifier();
+ case "Тройник RAUTITAN":
+ return new TPieceQueryModifier();
+ case "Тройник RAUTITAN резьбовой наружный":
+ return new ThreadTPieceExternal();
+ case "Тройник RAUTITAN резьбовой внутренний":
+ return new ThreadTPieceInternal();
+ case "Тройник RAUTITAN резьбовой настенный":
+ return new ThreadTPieceInternal();
+ case "Переходник на наружную резьбу":
+ return new AdapterExternalModifier();
+ case "Переходник на внутреннюю резьбу":
+ return new AdapterInternalModifier();
+ case "Переходник с накидной гайкой":
+ return new AdapterScrewcapModifier();
+ case "Угольник с наружной резьбой":
+ return new ThreadElbowExternalModifier();
+ case "Угольник с внутренней резьбой":
+ return new ThreadElbowInternalModifier();
+ case "Угольник с накидной гайкой":
+ return new ScrewcapElbowModifier();
+ case "Муфта соединительная":
+ return new CouplingModifier();
+ case "Угольник RAUTITAN":
+ return new ElbowModifier();
+ case "Flex":
+ return new FlexPipeQueryModifier();
+ case "Pink":
+ return new PinkPipeQueryModifier();
+ case "Stabil":
+ return new StabilPipeQueryModifier();
+ case "Black":
+ return new BlackPipeQueryModifier();
+ default:
+ return new BypassQueryModifier();
+ }
+ }
+}
diff --git a/RhSolutions.QueryModifiers/RhSolutions.QueryModifiers.csproj b/RhSolutions.QueryModifiers/RhSolutions.QueryModifiers.csproj
new file mode 100644
index 0000000..0132e39
--- /dev/null
+++ b/RhSolutions.QueryModifiers/RhSolutions.QueryModifiers.csproj
@@ -0,0 +1,13 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <TargetFramework>net6.0</TargetFramework>
+ <ImplicitUsings>enable</ImplicitUsings>
+ <Nullable>enable</Nullable>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <FrameworkReference Include="Microsoft.AspNetCore.App" />
+ </ItemGroup>
+
+</Project>
diff --git a/RhSolutions.QueryModifiers/ScrewcapElbowModifier.cs b/RhSolutions.QueryModifiers/ScrewcapElbowModifier.cs
new file mode 100644
index 0000000..b83236d
--- /dev/null
+++ b/RhSolutions.QueryModifiers/ScrewcapElbowModifier.cs
@@ -0,0 +1,6 @@
+namespace RhSolutions.QueryModifiers;
+
+public class ScrewcapElbowModifier : AdapterModifier
+{
+ protected override string name => "Угольник-переходник с накидной гайкой";
+}
diff --git a/RhSolutions.QueryModifiers/SleeveQueryModifier.cs b/RhSolutions.QueryModifiers/SleeveQueryModifier.cs
new file mode 100644
index 0000000..788a3a2
--- /dev/null
+++ b/RhSolutions.QueryModifiers/SleeveQueryModifier.cs
@@ -0,0 +1,38 @@
+using System.Text.RegularExpressions;
+using System.Text;
+using Microsoft.AspNetCore.Http.Extensions;
+using Microsoft.AspNetCore.Http;
+
+namespace RhSolutions.QueryModifiers;
+
+public class SleeveQueryModifier : IProductQueryModifier
+{
+ private readonly string pattern = @"\b(16|20|25|32|40|50|63)\b";
+
+ public bool TryQueryModify(IQueryCollection collection, out QueryString queryString)
+ {
+ queryString = QueryString.Empty;
+ var query = collection["query"].ToString();
+ if (string.IsNullOrEmpty(query))
+ {
+ return false;
+ }
+ var matches = Regex.Matches(query, pattern);
+ StringBuilder sb = new();
+ sb.Append("Монтажная гильза ");
+ if (matches.Count > 0)
+ {
+ sb.Append(matches.First());
+ }
+ else
+ {
+ return false;
+ }
+ QueryBuilder qb = new()
+ {
+ {"query", sb.ToString() }
+ };
+ queryString = qb.ToQueryString();
+ return true;
+ }
+}
diff --git a/RhSolutions.QueryModifiers/StabilPipeQueryModifier.cs b/RhSolutions.QueryModifiers/StabilPipeQueryModifier.cs
new file mode 100644
index 0000000..2ace1f3
--- /dev/null
+++ b/RhSolutions.QueryModifiers/StabilPipeQueryModifier.cs
@@ -0,0 +1,15 @@
+namespace RhSolutions.QueryModifiers;
+
+public class StabilPipeQueryModifier : PipeQueryModifier
+{
+ protected override string diameterPattern => @"([\b\D]|^)(?<Diameter>16|20|25|32|40)([\b\D]|$)";
+ protected override string pipeName => "Stabil -PLATINUM";
+ protected override Dictionary<string, string> diameterNames => new()
+ {
+ ["16"] = "16,2х2,6",
+ ["20"] = "20х2,9",
+ ["25"] = "25х3,7",
+ ["32"] = "32х4,7",
+ ["40"] = "40х6,0"
+ };
+}
diff --git a/RhSolutions.QueryModifiers/TPieceQueryModifier.cs b/RhSolutions.QueryModifiers/TPieceQueryModifier.cs
new file mode 100644
index 0000000..87c5b61
--- /dev/null
+++ b/RhSolutions.QueryModifiers/TPieceQueryModifier.cs
@@ -0,0 +1,42 @@
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Http.Extensions;
+using System.Text;
+using System.Text.RegularExpressions;
+
+namespace RhSolutions.QueryModifiers;
+
+public class TPieceQueryModifier : IProductQueryModifier
+{
+ private readonly string pattern = @"16|20|25|32|40|50|63";
+
+ public bool TryQueryModify(IQueryCollection collection, out QueryString queryString)
+ {
+ queryString = QueryString.Empty;
+ var query = collection["query"].ToString();
+ if (string.IsNullOrEmpty(query))
+ {
+ return false;
+ }
+ var matches = Regex.Matches(query, pattern);
+ StringBuilder sb = new();
+ sb.Append("Тройник RAUTITAN -PLATINUM");
+ if (matches.Count == 1)
+ {
+ sb.Append($" {matches.First().Value}-{matches.First().Value}-{matches.First().Value}");
+ }
+ else if (matches.Count >= 3)
+ {
+ sb.Append($" {matches[0].Value}-{matches[1].Value}-{matches[2].Value}");
+ }
+ else
+ {
+ return false;
+ }
+ QueryBuilder qb = new()
+ {
+ { "query", sb.ToString() }
+ };
+ queryString = qb.ToQueryString();
+ return true;
+ }
+}
diff --git a/RhSolutions.QueryModifiers/ThreadElbowExternalModifier.cs b/RhSolutions.QueryModifiers/ThreadElbowExternalModifier.cs
new file mode 100644
index 0000000..3297f44
--- /dev/null
+++ b/RhSolutions.QueryModifiers/ThreadElbowExternalModifier.cs
@@ -0,0 +1,6 @@
+namespace RhSolutions.QueryModifiers;
+
+public class ThreadElbowExternalModifier : AdapterModifier
+{
+ protected override string name => "Угольник-переходник с наружной резьбой";
+}
diff --git a/RhSolutions.QueryModifiers/ThreadElbowInternalModifier.cs b/RhSolutions.QueryModifiers/ThreadElbowInternalModifier.cs
new file mode 100644
index 0000000..88801e7
--- /dev/null
+++ b/RhSolutions.QueryModifiers/ThreadElbowInternalModifier.cs
@@ -0,0 +1,6 @@
+namespace RhSolutions.QueryModifiers;
+
+public class ThreadElbowInternalModifier : AdapterModifier
+{
+ protected override string name => "Угольник-переходник с внутренней резьбой";
+}
diff --git a/RhSolutions.QueryModifiers/ThreadTPieceExternal.cs b/RhSolutions.QueryModifiers/ThreadTPieceExternal.cs
new file mode 100644
index 0000000..b5c910b
--- /dev/null
+++ b/RhSolutions.QueryModifiers/ThreadTPieceExternal.cs
@@ -0,0 +1,19 @@
+using System.Text.RegularExpressions;
+
+namespace RhSolutions.QueryModifiers;
+
+public class ThreadTPieceExternal : ThreadTPieceInternal
+{
+ protected override string ConstructName(MatchCollection diameters, Match thread)
+ {
+ Capture t = thread.Groups["Thread"].Captures.First();
+ if (diameters.Count == 1)
+ {
+ return $"Тройник RAUTITAN с наружной резьбой {diameters[0]}-{diameters[0]}-R {t}";
+ }
+ else
+ {
+ return $"Тройник RAUTITAN с наружной резьбой {diameters[0]}-{diameters[1]}-R {t}";
+ }
+ }
+} \ No newline at end of file
diff --git a/RhSolutions.QueryModifiers/ThreadTPieceWall.cs b/RhSolutions.QueryModifiers/ThreadTPieceWall.cs
new file mode 100644
index 0000000..8e11a91
--- /dev/null
+++ b/RhSolutions.QueryModifiers/ThreadTPieceWall.cs
@@ -0,0 +1,64 @@
+using System.Text.RegularExpressions;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Http.Extensions;
+
+namespace RhSolutions.QueryModifiers;
+
+public class ThreadTPieceInternal : IProductQueryModifier
+{
+ 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)
+ {
+ if (int.Parse(diameters[0].Value) < 25)
+ {
+ return $"Тройник настенный с внутренней резьбой {diameters[0]}-Rp{t}-{diameters[0]}";
+ }
+ else
+ {
+ return $"Тройник с внутр. резьбой на боков. проходе {diameters[0]}-Rp {t}-{diameters[0]}";
+ }
+ }
+ else
+ {
+ if (int.Parse(diameters[0].Value) < 25)
+ {
+ return $"Тройник настенный с внутренней резьбой {diameters[0]}-Rp{t}-{diameters[1]}";
+ }
+ else
+ {
+ return $"Тройник с внутр. резьбой на боков. проходе {diameters[0]}-Rp {t}-{diameters[1]}";
+ }
+ }
+ }
+}