Refactoring
This commit is contained in:
parent
52543cf7a2
commit
60fbfb5e8c
@ -1,4 +1,5 @@
|
||||
namespace RhSolutions.Api.Tests;
|
||||
|
||||
public class RautitanFittingsTests : ProductQueryModifierTests
|
||||
{
|
||||
[TestCase("Гильза 16", "Монтажная гильза 16")]
|
||||
@ -39,8 +40,8 @@ public class RautitanFittingsTests : ProductQueryModifierTests
|
||||
public void ScrewcapElbowTest(string query, string modified)
|
||||
=> Execute(productType: "Угольник с накидной гайкой", query, modified);
|
||||
|
||||
[TestCase("Тройник с внутр. резьбой на боков. проходе 25-Rp 1/2-25 RX+", "Тройник с внутр. резьбой на боков. проходе 25-Rp 1/2-25")]
|
||||
[TestCase("Тройник настенный с внутренней резьбой 16-Rp1/2-16 RX+", "Тройник настенный с внутренней резьбой 16-Rp1/2-16")]
|
||||
[TestCase("Тройник с внутр. резьбой на боков. проходе 25-Rp 1/2-25 RX+", "Тройник RAUTITAN с внутр. резьбой на боков. проходе 25-Rp 1/2-25")]
|
||||
[TestCase("Тройник настенный с внутренней резьбой 16-Rp1/2-16 RX+", "Тройник RAUTITAN настенный с внутренней резьбой 16-Rp1/2-16")]
|
||||
public void ThreadTPieceInternalTest(string query, string modified)
|
||||
=> Execute(productType: "Тройник RAUTITAN резьбовой внутренний", query, modified);
|
||||
|
||||
|
@ -1,7 +0,0 @@
|
||||
namespace RhSolutions.QueryModifiers
|
||||
{
|
||||
public class AdapterExternalModifier : AdapterModifier
|
||||
{
|
||||
protected override string name => "Переходник с наружной резьбой";
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
namespace RhSolutions.QueryModifiers
|
||||
{
|
||||
public class AdapterInternalModifier : AdapterModifier
|
||||
{
|
||||
protected override string name => "Переходник с внутренней резьбой -угольник-переходник";
|
||||
}
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
namespace RhSolutions.QueryModifiers
|
||||
{
|
||||
public class AdapterScrewcapModifier : AdapterModifier
|
||||
{
|
||||
protected override string name => "Переходник с накидной гайкой";
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
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"
|
||||
};
|
||||
}
|
@ -2,11 +2,11 @@
|
||||
|
||||
namespace RhSolutions.QueryModifiers;
|
||||
|
||||
public class BypassQueryModifier : IProductQueryModifier
|
||||
public sealed class BypassQueryModifier : IProductQueryModifier
|
||||
{
|
||||
public bool TryQueryModify(IQueryCollection collection, out QueryString queryString)
|
||||
{
|
||||
queryString = QueryString.Empty;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
|
||||
|
||||
public abstract class Adapter : DrinkingWaterHeatingFitting
|
||||
{
|
||||
protected override string? BuildRhSolutionsName(string query)
|
||||
{
|
||||
Match diameter = _diameter.Match(query);
|
||||
if (!diameter.Success)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Match thread = _thread.Match(query);
|
||||
if (!thread.Success)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return $"{_title} {diameter.Groups["Diameter"]} {thread.Groups["Thread"]}";
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
|
||||
|
||||
public class AdapterExternal : Adapter
|
||||
{
|
||||
protected override string _title => "Переходник с наружной резьбой";
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
|
||||
|
||||
public class AdapterInternal : Adapter
|
||||
{
|
||||
protected override string _title => "Переходник с внутренней резьбой -угольник-переходник";
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
|
||||
|
||||
public class AdapterScrewcap : Adapter
|
||||
{
|
||||
protected override string _title => "Переходник с накидной гайкой";
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
|
||||
|
||||
public class BendFormerHeating : DrinkingWaterHeatingFitting
|
||||
{
|
||||
protected override string _title => "Фиксатор поворота без колец";
|
||||
protected override string? BuildRhSolutionsName(string query)
|
||||
{
|
||||
var diameterMatch = _diameter.Match(query);
|
||||
if (!diameterMatch.Success)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
string diameter = diameterMatch.Groups["Diameter"].Value;
|
||||
if (diameter == "16")
|
||||
{
|
||||
diameter += "/17";
|
||||
}
|
||||
var angleMatch = _angle.Match(query);
|
||||
string angle = angleMatch.Success ? angleMatch.Groups["Angle"].Value : "90";
|
||||
return $"{_title} {diameter}/{angle}°";
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
|
||||
|
||||
public class Coupling : DrinkingWaterHeatingFitting
|
||||
{
|
||||
protected override string _title => "Муфта соединительная";
|
||||
protected override string? BuildRhSolutionsName(string query)
|
||||
{
|
||||
var diameters = _diameter.Matches(query);
|
||||
if (diameters.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (diameters.Count < 2 ||
|
||||
diameters.Count > 1 && diameters[0].Groups["Diameter"].Value == diameters[1].Groups["Diameter"].Value)
|
||||
{
|
||||
return $"{_title} равнопроходная {diameters[0].Groups["Diameter"]}";
|
||||
}
|
||||
else
|
||||
{
|
||||
return $"{_title} переходная {diameters[0].Groups["Diameter"]}-{diameters[1].Groups["Diameter"]}";
|
||||
}
|
||||
}
|
||||
}
|
@ -2,16 +2,16 @@ using System.Text.RegularExpressions;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.Extensions;
|
||||
|
||||
namespace RhSolutions.QueryModifiers.Heating;
|
||||
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
|
||||
|
||||
public abstract class HeatingFittingBase : IProductQueryModifier
|
||||
public abstract class DrinkingWaterHeatingFitting : IProductQueryModifier
|
||||
{
|
||||
protected static readonly Regex _diameter =
|
||||
new(@"([\b\D]|^)(?<Diameter>16|20|25|32|40|50|63)([\b\D]|$)");
|
||||
new(@"([\b\D]|^)?(?<Diameter>16|20|25|32|40|50|63)([\b\D]|$)");
|
||||
protected static readonly Regex _angle =
|
||||
new(@"([\b\D]|^)(?<Angle>45|90)([\b\D]|$)");
|
||||
new(@"([\b\D])(?<Angle>45|90)([\b\D]|$)");
|
||||
protected static readonly Regex _thread =
|
||||
new(@"(\D|^)(?<Thread>1\s+1/4|1\s+1/2|1/2|3/4|2|1)(\D|$)");
|
||||
new(@"([\b\D])(?<Thread>1\s+1/4|1\s+1/2|1/2|3/4|2|1)([\b\D]|$)");
|
||||
|
||||
protected virtual string _title { get; } = string.Empty;
|
||||
|
@ -0,0 +1,18 @@
|
||||
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
|
||||
|
||||
public class ElbowModifier : DrinkingWaterHeatingFitting
|
||||
{
|
||||
protected override string _title { get; } = "Угольник RAUTITAN -PLATINUM";
|
||||
protected override string? BuildRhSolutionsName(string query)
|
||||
{
|
||||
var diameterMatch = _diameter.Match(query);
|
||||
if (!diameterMatch.Success)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
string diameter = diameterMatch.Groups["Diameter"].Value;
|
||||
var angleMatch = _angle.Match(query);
|
||||
string angle = angleMatch.Success ? angleMatch.Groups["Angle"].Value : "90";
|
||||
return $"{_title} {angle} {diameter}";
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
|
||||
|
||||
public class ScrewcapElbow : Adapter
|
||||
{
|
||||
protected override string _title => "Угольник-переходник с накидной гайкой";
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
|
||||
|
||||
public class Sleeve : DrinkingWaterHeatingFitting
|
||||
{
|
||||
protected override string _title => "Монтажная гильза";
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
|
||||
|
||||
public class TPiece : DrinkingWaterHeatingFitting
|
||||
{
|
||||
protected override string _title => "Тройник RAUTITAN -PLATINUM";
|
||||
|
||||
protected override string? BuildRhSolutionsName(string query)
|
||||
{
|
||||
var diameters = _diameter.Matches(query)
|
||||
.Select(match => match.Groups["Diameter"].Value)
|
||||
.ToArray();
|
||||
if (diameters.Length == 1)
|
||||
{
|
||||
return $"{_title} {diameters[0]}-{diameters[0]}-{diameters[0]}";
|
||||
}
|
||||
else if (diameters.Length >= 3)
|
||||
{
|
||||
return $"{_title} {diameters[0]}-{diameters[1]}-{diameters[2]}";
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
|
||||
|
||||
public class ThreadElbowExternal : Adapter
|
||||
{
|
||||
protected override string _title => "Угольник-переходник с наружной резьбой";
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
|
||||
|
||||
public class ThreadElbowInternal : Adapter
|
||||
{
|
||||
protected override string _title => "Угольник-переходник с внутренней резьбой";
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
|
||||
|
||||
public class ThreadTPieceExternal : DrinkingWaterHeatingFitting
|
||||
{
|
||||
protected override string _title => "Тройник RAUTITAN с наружной резьбой";
|
||||
protected override string? BuildRhSolutionsName(string query)
|
||||
{
|
||||
MatchCollection diametersMatches = _diameter.Matches(query);
|
||||
if (diametersMatches.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
string thread = _thread.Match(query).Groups["Thread"].Value;
|
||||
int[] diameters = diametersMatches.Select(match => int.Parse(match.Groups["Diameter"].Value)).ToArray();
|
||||
if (diameters.Length == 1)
|
||||
{
|
||||
return $"{_title} {diameters[0]}-{diameters[0]}-R {thread}";
|
||||
}
|
||||
else
|
||||
{
|
||||
return $"{_title} {diameters[0]}-{diameters[1]}-R {thread}";
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
|
||||
|
||||
public class ThreadTPieceInternal : DrinkingWaterHeatingFitting
|
||||
{
|
||||
protected override string? BuildRhSolutionsName(string query)
|
||||
{
|
||||
MatchCollection diametersMatches = _diameter.Matches(query);
|
||||
if (diametersMatches.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
string thread = _thread.Match(query).Groups["Thread"].Value;
|
||||
int[] diameters = diametersMatches.Select(match => int.Parse(match.Groups["Diameter"].Value)).ToArray();
|
||||
if (diameters.Length == 1)
|
||||
{
|
||||
if (diameters[0] < 25)
|
||||
{
|
||||
return $"Тройник RAUTITAN настенный с внутренней резьбой {diameters[0]}-Rp{thread}-{diameters[0]}";
|
||||
}
|
||||
else
|
||||
{
|
||||
return $"Тройник RAUTITAN с внутр. резьбой на боков. проходе {diameters[0]}-Rp {thread}-{diameters[0]}";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (diameters[0] < 25)
|
||||
{
|
||||
return $"Тройник RAUTITAN настенный с внутренней резьбой {diameters[0]}-Rp{thread}-{diameters[1]}";
|
||||
}
|
||||
else
|
||||
{
|
||||
return $"Тройник RAUTITAN с внутр. резьбой на боков. проходе {diameters[0]}-Rp {thread}-{diameters[1]}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingPipes;
|
||||
|
||||
public class BlackPipe : DrinkingWaterHeatingPipe
|
||||
{
|
||||
protected override string _title => "Black";
|
||||
protected override Dictionary<int, 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,6"
|
||||
};
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.Extensions;
|
||||
|
||||
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingPipes;
|
||||
|
||||
public class DrinkingWaterHeatingPipe : IProductQueryModifier
|
||||
{
|
||||
protected static readonly Regex _diameter =
|
||||
new(@"([\b\D]|^)?(?<Diameter>16|20|25|32|40|50|63)([\b\D]|$)");
|
||||
protected static readonly Regex _type =
|
||||
new(@"([\b\W])(?<Type>бухт|отр|штанг)([\b\w.])");
|
||||
protected virtual string _title { get; } = string.Empty;
|
||||
|
||||
protected virtual Dictionary<int, 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> _makeUp { get; } = new()
|
||||
{
|
||||
["бухт"] = "бухта",
|
||||
["штанг"] = "прям.отрезки",
|
||||
["отр"] = "прям.отрезки"
|
||||
};
|
||||
|
||||
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 diameterMatch = _diameter.Match(query);
|
||||
if (!diameterMatch.Success)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var diameter = int.Parse(diameterMatch.Groups["Diameter"].Value);
|
||||
var typeMatch = _type.Match(query);
|
||||
if (typeMatch.Success)
|
||||
{
|
||||
var type = typeMatch.Groups["Type"].Value;
|
||||
return $"Труба {_title} {_diameterNames[diameter]} {_makeUp[type]}";
|
||||
}
|
||||
else if (diameter < 32)
|
||||
{
|
||||
return $"Труба {_title} {_diameterNames[diameter]} {_makeUp["бухт"]}";
|
||||
}
|
||||
else
|
||||
{
|
||||
return $"Труба {_title} {_diameterNames[diameter]} {_makeUp["отр"]}";
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingPipes;
|
||||
|
||||
public class FlexPipe : DrinkingWaterHeatingPipe
|
||||
{
|
||||
protected override string _title => "Flex";
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingPipes;
|
||||
|
||||
public class PinkPipe : DrinkingWaterHeatingPipe
|
||||
{
|
||||
protected override string _title => "Pink+";
|
||||
|
||||
protected override Dictionary<string, string> _makeUp => new()
|
||||
{
|
||||
["бухт"] = "бухта",
|
||||
["штанг"] = "прямые отрезки",
|
||||
["отр"] = "прямые отрезки"
|
||||
};
|
||||
protected override Dictionary<int, 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,6"
|
||||
};
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingPipes;
|
||||
|
||||
public class StabilPipe : DrinkingWaterHeatingPipe
|
||||
{
|
||||
protected override string _title => "Stabil -PLATINUM";
|
||||
protected override Dictionary<int, string> _diameterNames => new()
|
||||
{
|
||||
[16] = "16,2х2,6",
|
||||
[20] = "20х2,9",
|
||||
[25] = "25х3,7",
|
||||
[32] = "32х4,7",
|
||||
[40] = "40х6,0",
|
||||
[50] = "50x6,9",
|
||||
[63] = "63x8,6"
|
||||
};
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
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\D]|^)(?<Diameter>16|20|25|32|40|50|63)([\b\D]|$)";
|
||||
private string anglePattern { get; } = @"([\b\D]|^)(?<Angle>45|90)([\b\D]|$)";
|
||||
|
||||
protected virtual string name {get;} = "Угольник RAUTITAN -PLATINUM";
|
||||
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", CreateName(angle, diameter)}
|
||||
};
|
||||
queryString = qb.ToQueryString();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual string CreateName(Match angle, Match diameter)
|
||||
{
|
||||
return $"{name} {(angle.Success ? angle.Groups["Angle"].Captures.First() : 90)} {diameter.Groups["Diameter"].Captures.First()}";
|
||||
}
|
||||
}
|
||||
|
||||
public class BendFormerHeating : ElbowModifier
|
||||
{
|
||||
protected override string name => "Фиксатор поворота без колец";
|
||||
protected override string CreateName(Match angle, Match diameter)
|
||||
{
|
||||
return $"{name} {(diameter.Groups["Diameter"].Captures.First().ToString() == "16" ? "16/17" : diameter.Groups["Diameter"].Captures.First())}/{(angle.Success ? angle.Groups["Angle"].Captures.First() : 90)}°";
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
namespace RhSolutions.QueryModifiers;
|
||||
|
||||
public class FlexPipeQueryModifier : PipeQueryModifier { }
|
@ -1,5 +0,0 @@
|
||||
namespace RhSolutions.QueryModifiers.Heating;
|
||||
public class SleeveQueryModifier : HeatingFittingBase
|
||||
{
|
||||
protected override string _title => "Монтажная гильза";
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
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()
|
||||
{
|
||||
["бухт"] = "бухта",
|
||||
["штанг"] = "прямые отрезки",
|
||||
["отр"] = "прямые отрезки"
|
||||
};
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using RhSolutions.QueryModifiers.Heating;
|
||||
using RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
|
||||
using RhSolutions.QueryModifiers.DrinkingWaterHeatingPipes;
|
||||
|
||||
namespace RhSolutions.QueryModifiers;
|
||||
|
||||
@ -9,41 +10,39 @@ public class ProductQueryModifierFactory
|
||||
switch (productTypeName)
|
||||
{
|
||||
case "Монтажная гильза":
|
||||
return new SleeveQueryModifier();
|
||||
return new Sleeve();
|
||||
case "Тройник RAUTITAN":
|
||||
return new TPieceQueryModifier();
|
||||
return new TPiece();
|
||||
case "Тройник RAUTITAN резьбовой наружный":
|
||||
return new ThreadTPieceExternal();
|
||||
case "Тройник RAUTITAN резьбовой внутренний":
|
||||
return new ThreadTPieceInternal();
|
||||
case "Тройник RAUTITAN резьбовой настенный":
|
||||
return new ThreadTPieceInternal();
|
||||
case "Переходник на наружную резьбу":
|
||||
return new AdapterExternalModifier();
|
||||
return new AdapterExternal();
|
||||
case "Переходник на внутреннюю резьбу":
|
||||
return new AdapterInternalModifier();
|
||||
return new AdapterInternal();
|
||||
case "Переходник с накидной гайкой":
|
||||
return new AdapterScrewcapModifier();
|
||||
return new AdapterScrewcap();
|
||||
case "Угольник с наружной резьбой":
|
||||
return new ThreadElbowExternalModifier();
|
||||
return new ThreadElbowExternal();
|
||||
case "Угольник с внутренней резьбой":
|
||||
return new ThreadElbowInternalModifier();
|
||||
return new ThreadElbowInternal();
|
||||
case "Угольник с накидной гайкой":
|
||||
return new ScrewcapElbowModifier();
|
||||
return new ScrewcapElbow();
|
||||
case "Муфта соединительная":
|
||||
return new CouplingModifier();
|
||||
return new Coupling();
|
||||
case "Угольник RAUTITAN":
|
||||
return new ElbowModifier();
|
||||
case "Фиксатор поворота без колец":
|
||||
return new BendFormerHeating();
|
||||
case "Flex":
|
||||
return new FlexPipeQueryModifier();
|
||||
return new FlexPipe();
|
||||
case "Pink":
|
||||
return new PinkPipeQueryModifier();
|
||||
return new PinkPipe();
|
||||
case "Stabil":
|
||||
return new StabilPipeQueryModifier();
|
||||
return new StabilPipe();
|
||||
case "Black":
|
||||
return new BlackPipeQueryModifier();
|
||||
return new BlackPipe();
|
||||
default:
|
||||
return new BypassQueryModifier();
|
||||
}
|
||||
|
@ -1,6 +0,0 @@
|
||||
namespace RhSolutions.QueryModifiers;
|
||||
|
||||
public class ScrewcapElbowModifier : AdapterModifier
|
||||
{
|
||||
protected override string name => "Угольник-переходник с накидной гайкой";
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
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"
|
||||
};
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
namespace RhSolutions.QueryModifiers;
|
||||
|
||||
public class ThreadElbowExternalModifier : AdapterModifier
|
||||
{
|
||||
protected override string name => "Угольник-переходник с наружной резьбой";
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
namespace RhSolutions.QueryModifiers;
|
||||
|
||||
public class ThreadElbowInternalModifier : AdapterModifier
|
||||
{
|
||||
protected override string name => "Угольник-переходник с внутренней резьбой";
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
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}";
|
||||
}
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
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]}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user