0
0

Compare commits

...

9 Commits

52 changed files with 559 additions and 410 deletions

View File

@ -1,3 +1,4 @@
using System.Web;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Primitives;
using RhSolutions.Api.Services;
@ -16,11 +17,11 @@ public abstract class ProductQueryModifierTests
{
["query"] = new StringValues(query)
};
QueryCollection collection = new(queryPair);
QueryString expected = new($"?query={Uri.EscapeDataString(modified)}");
QueryCollection collection = new(queryPair);
var modifier = _factory.GetModifier(productType);
bool result = modifier.TryQueryModify(collection, out var actual);
Assert.True(result);
Assert.That(actual, Is.EqualTo(expected));
Assert.True(modifier.TryQueryModify(collection, out var actual));
string? result = HttpUtility.ParseQueryString(actual.ToString())["query"];
Assert.That(result, Is.EqualTo(modified));
}
}

View File

@ -1,4 +1,5 @@
namespace RhSolutions.Api.Tests;
public class RautitanFittingsTests : ProductQueryModifierTests
{
[TestCase("Гильза 16", "Монтажная гильза 16")]
@ -14,8 +15,13 @@ public class RautitanFittingsTests : ProductQueryModifierTests
[TestCase("муфта 20", "Муфта соединительная равнопроходная 20")]
[TestCase("переходник 20-16", "Муфта соединительная переходная 20-16")]
[TestCase("Соединение труба-труба 20/20, бронза", "Муфта соединительная равнопроходная 20")]
[TestCase("Муфта соединительная переходная 20x16 для труб из сшитого полиэтилена аксиальный", "Муфта соединительная переходная 20-16")]
public void CouplingTest(string query, string modified)
=> Execute(productType: "Муфта соединительная", query, modified);
[TestCase("Переходник с внутренней резьбой 16xG 3/4\" для труб из сшитого полиэтилена аксиальный", "Переходник с внутренней резьбой -угольник-переходник 16 3/4")]
public void AdapterInternalTest(string query, string modified)
=> Execute(productType: "Переходник на внутреннюю резьбу", query, modified);
[TestCase("Угольник 90°, 40 PX", "Угольник RAUTITAN -PLATINUM 90 40")]
public void ElbowTest(string query, string modified)
@ -33,4 +39,19 @@ public class RautitanFittingsTests : ProductQueryModifierTests
[TestCase("Соединение угловое с накидной гайкой 16 х 1/2\", латунь", "Угольник-переходник с накидной гайкой 16 1/2")]
public void ScrewcapElbowTest(string query, string modified)
=> Execute(productType: "Угольник с накидной гайкой", query, modified);
}
[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);
[TestCase("Тройник RAUTITAN RX+ с наружной резьбой 20-20-R 3/4", "Тройник RAUTITAN с наружной резьбой 20-20-R 3/4")]
public void ThreadTPieceExternalTest(string query, string modified)
=> Execute(productType: "Тройник RAUTITAN резьбовой наружный", query, modified);
[TestCase("Фиксатор поворота трубы 16/17/90°, без колец (оцинк. сталь)", "Фиксатор поворота без колец 16/17/90°")]
[TestCase("Дуга 90° 25", "Фиксатор поворота без колец 25/90°")]
[TestCase("Дуга 90° r/d >= 2.5. Ø25 (767025)", "Фиксатор поворота без колец 25/90°")]
public void BendFormerHeatingTest(string query, string modified)
=> Execute(productType: "Фиксатор поворота без колец", query, modified);
}

View File

@ -0,0 +1,30 @@
namespace RhSolutions.Api.Tests;
public class RautitanPipesTests : ProductQueryModifierTests
{
[TestCase("Унив.труба RAUTITAN flex 16x2,2, бухта 100м", "Труба Flex 16x2,2 бухта")]
[TestCase("Труба flex 16", "Труба Flex 16x2,2 бухта")]
[TestCase("Унив.труба RAUTITAN flex 32x4,4, прям.отрезки 6м", "Труба Flex 32x4,4 прям.отрезки")]
[TestCase("Труба flex 32", "Труба Flex 32x4,4 прям.отрезки")]
public void FlexPipeTest(string query, string modified)
=> Execute(productType: "Flex", query, modified);
[TestCase("Унив. труба RAUTITAN pink+ 16х2,2 мм, бухта 120 м", "Труба Pink+ 16х2,2 бухта")]
[TestCase("труба pink 16", "Труба Pink+ 16х2,2 бухта")]
[TestCase("Унив. труба RAUTITAN pink+ 32х4,4 мм, бухта 50 м", "Труба Pink+ 32х4,4 бухта")]
[TestCase("труба pink 32", "Труба Pink+ 32х4,4 прямые отрезки")]
public void PinkPipeTest(string query, string modified)
=> Execute(productType: "Pink", query, modified);
[TestCase("Универсальн.труба RAUTITAN stabil 16,2х2,6 мм, бухта 100 м", "Труба Stabil -PLATINUM 16,2х2,6 бухта")]
[TestCase("труба stabil 16", "Труба Stabil -PLATINUM 16,2х2,6 бухта")]
[TestCase("Универсальн.труба RAUTITAN stabil 32х4,7 мм, прям.отрезки 5м", "Труба Stabil -PLATINUM 32х4,7 прям.отрезки")]
[TestCase("труба stabil 32", "Труба Stabil -PLATINUM 32х4,7 прям.отрезки")]
public void StabilPipeTest(string query, string modified)
=> Execute(productType: "Stabil", query, modified);
[TestCase("Отоп.труба РЕХАУ BLACK 16х2,2 мм, бухта 200 м", "Труба Black 16х2,2 бухта")]
[TestCase("труба BLACK 16", "Труба Black 16х2,2 бухта")]
public void BlackPipeTest(string query, string modified)
=> Execute(productType: "Black", query, modified);
}

View File

@ -4,7 +4,6 @@
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

View File

@ -1 +1,2 @@
global using NUnit.Framework;
global using NUnit.Framework;
global using RhSolutions.QueryModifiers;

View File

@ -1,5 +1,5 @@
using Microsoft.AspNetCore.Http.Extensions;
using RhSolutions.Api.Services;
using RhSolutions.Api.Services;
using RhSolutions.QueryModifiers;
namespace RhSolutions.Api.Middleware;

View File

@ -2,6 +2,7 @@ using Microsoft.EntityFrameworkCore;
using RhSolutions.Models;
using RhSolutions.Api.Services;
using RhSolutions.Api.Middleware;
using RhSolutions.QueryModifiers;
var builder = WebApplication.CreateBuilder(args);

View File

@ -19,6 +19,10 @@
<PackageReference Include="Rhsolutions.ProductSku" Version="1.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\RhSolutions.QueryModifiers\RhSolutions.QueryModifiers.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="MLModels\model.zip">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

View File

@ -1,7 +0,0 @@
namespace RhSolutions.Api.Services
{
public class AdapterExternalModifier : AdapterModifier
{
protected override string name => "Переходник с наружной резьбой";
}
}

View File

@ -1,7 +0,0 @@
namespace RhSolutions.Api.Services
{
public class AdapterInternalModifier : AdapterModifier
{
protected override string name => "Переходник с внутренней резьбой";
}
}

View File

@ -1,39 +0,0 @@
using System.Text.RegularExpressions;
using Microsoft.AspNetCore.Http.Extensions;
namespace RhSolutions.Api.Services
{
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;
}
}
}
}

View File

@ -1,7 +0,0 @@
namespace RhSolutions.Api.Services
{
public class AdapterScrewcapModifier : AdapterModifier
{
protected override string name => "Переходник с накидной гайкой";
}
}

View File

@ -1,14 +0,0 @@
namespace RhSolutions.Api.Services
{
public class BlackPipeQueryModifier : FlexPipeQueryModifier
{
protected override string diameterPattern => @"\b(16|20|25)\b";
protected override string pipeName => "Black";
protected override Dictionary<string, string> diameterNames => new()
{
["16"] = "16х2,2",
["20"] = "20х2,8",
["25"] = "25х3,5"
};
}
}

View File

@ -1,11 +0,0 @@
namespace RhSolutions.Api.Services
{
public class BypassQueryModifier : IProductQueryModifier
{
public bool TryQueryModify(IQueryCollection collection, out QueryString queryString)
{
queryString = QueryString.Empty;
return false;
}
}
}

View File

@ -1,39 +0,0 @@
using System.Text.RegularExpressions;
using Microsoft.AspNetCore.Http.Extensions;
namespace RhSolutions.Api.Services
{
public class CouplingModifier : IProductQueryModifier
{
private string pattern { get; } = @"\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);
if (matches.Count < 1)
{
return false;
}
else
{
QueryBuilder qb = new();
if (matches.Count < 2 || matches.Count > 1 && matches[0].Value == matches[1].Value)
{
qb.Add("query", $"Муфта соединительная равнопроходная {matches[0]}");
}
else
{
qb.Add("query", $"Муфта соединительная переходная {matches[0]}-{matches[1]}");
}
queryString = qb.ToQueryString();
return true;
}
}
}
}

View File

@ -1,36 +0,0 @@
using System.Text.RegularExpressions;
using Microsoft.AspNetCore.Http.Extensions;
namespace RhSolutions.Api.Services
{
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;
}
}
}
}

View File

@ -1,76 +0,0 @@
using System.Text;
using System.Text.RegularExpressions;
using Microsoft.AspNetCore.Http.Extensions;
namespace RhSolutions.Api.Services
{
public class FlexPipeQueryModifier : IProductQueryModifier
{
protected virtual string diameterPattern { get; } = @"\b(16|20|25|32|40|50|63)\b";
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"
};
public bool TryQueryModify(IQueryCollection collection, out QueryString queryString)
{
queryString = QueryString.Empty;
StringBuilder sb = new();
string query = collection["query"].ToString();
if (string.IsNullOrEmpty(query))
{
return false;
}
sb.Append($"Труба {pipeName} ");
var diameterMatches = Regex.Matches(query, diameterPattern);
string diameter;
if (diameterMatches.Count > 0)
{
diameter = diameterMatches.First().Value;
sb.Append($"{diameterNames[diameter]} " );
}
else
{
return false;
}
var typeMatches = Regex.Matches(query, typePattern);
if (typeMatches.Count > 0)
{
var type = typeMatches.First().Value;
if (type.StartsWith("отр") || type.StartsWith("штанг"))
{
sb.Append("прям.отрезки");
}
else
{
sb.Append("бухта");
}
}
else if (int.Parse(diameter) < 32)
{
sb.Append("бухта");
}
else
{
sb.Append("прям.отрезки");
}
QueryBuilder qb = new()
{
{ "query", sb.ToString() }
};
queryString = qb.ToQueryString();
return true;
}
}
}

View File

@ -1,7 +0,0 @@
namespace RhSolutions.Api.Services
{
public interface IProductQueryModifier
{
public bool TryQueryModify(IQueryCollection collection, out QueryString queryString);
}
}

View File

@ -1,39 +0,0 @@
namespace RhSolutions.Api.Services;
public class ProductQueryModifierFactory
{
public IProductQueryModifier GetModifier(string productTypeName)
{
switch (productTypeName)
{
case "Монтажная гильза":
return new SleeveQueryModifier();
case "Тройник RAUTITAN":
return new TPieceQueryModifier();
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 "Stabil":
return new StabilPipeQueryModifier();
case "Black":
return new BlackPipeQueryModifier();
default:
return new BypassQueryModifier();
}
}
}

View File

@ -1,7 +0,0 @@
namespace RhSolutions.Api.Services
{
public class ScrewcapElbowModifier : AdapterModifier
{
protected override string name => "Угольник-переходник с накидной гайкой";
}
}

View File

@ -1,38 +0,0 @@
using System.Text.RegularExpressions;
using System.Text;
using Microsoft.AspNetCore.Http.Extensions;
namespace RhSolutions.Api.Services
{
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;
}
}
}

View File

@ -1,16 +0,0 @@
namespace RhSolutions.Api.Services
{
public class StabilPipeQueryModifier : FlexPipeQueryModifier
{
protected override string diameterPattern => @"\b(16|20|25|32|40)\b";
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"
};
}
}

View File

@ -1,42 +0,0 @@
using Microsoft.AspNetCore.Http.Extensions;
using System.Text;
using System.Text.RegularExpressions;
namespace RhSolutions.Api.Services
{
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;
}
}
}

View File

@ -1,7 +0,0 @@
namespace RhSolutions.Api.Services
{
public class ThreadElbowExternalModifier : AdapterModifier
{
protected override string name => "Угольник-переходник с наружной резьбой";
}
}

View File

@ -1,7 +0,0 @@
namespace RhSolutions.Api.Services
{
public class ThreadElbowInternalModifier : AdapterModifier
{
protected override string name => "Угольник-переходник с внутренней резьбой";
}
}

View File

@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Http;
namespace RhSolutions.QueryModifiers;
public sealed class BypassQueryModifier : IProductQueryModifier
{
public bool TryQueryModify(IQueryCollection collection, out QueryString queryString)
{
queryString = QueryString.Empty;
return false;
}
}

View File

@ -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"]}";
}
}

View File

@ -0,0 +1,6 @@
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
public class AdapterExternal : Adapter
{
protected override string _title => "Переходник с наружной резьбой";
}

View File

@ -0,0 +1,6 @@
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
public class AdapterInternal : Adapter
{
protected override string _title => "Переходник с внутренней резьбой -угольник-переходник";
}

View File

@ -0,0 +1,6 @@
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
public class AdapterScrewcap : Adapter
{
protected override string _title => "Переходник с накидной гайкой";
}

View File

@ -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}°";
}
}

View File

@ -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"]}";
}
}
}

View File

@ -0,0 +1,48 @@
using System.Text.RegularExpressions;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Extensions;
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
public abstract class DrinkingWaterHeatingFitting : IProductQueryModifier
{
protected static readonly Regex _diameter =
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]|$)");
protected static readonly Regex _thread =
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;
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;
}
}

View File

@ -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}";
}
}

View File

@ -0,0 +1,6 @@
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
public class ScrewcapElbow : Adapter
{
protected override string _title => "Угольник-переходник с накидной гайкой";
}

View File

@ -0,0 +1,6 @@
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
public class Sleeve : DrinkingWaterHeatingFitting
{
protected override string _title => "Монтажная гильза";
}

View File

@ -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;
}
}
}

View File

@ -0,0 +1,6 @@
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
public class ThreadElbowExternal : Adapter
{
protected override string _title => "Угольник-переходник с наружной резьбой";
}

View File

@ -0,0 +1,6 @@
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
public class ThreadElbowInternal : Adapter
{
protected override string _title => "Угольник-переходник с внутренней резьбой";
}

View File

@ -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}";
}
}
}

View File

@ -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]}";
}
}
}
}

View File

@ -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"
};
}

View File

@ -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["отр"]}";
}
}
}

View File

@ -0,0 +1,6 @@
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingPipes;
public class FlexPipe : DrinkingWaterHeatingPipe
{
protected override string _title => "Flex";
}

View File

@ -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"
};
}

View File

@ -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"
};
}

View File

@ -0,0 +1,8 @@
using Microsoft.AspNetCore.Http;
namespace RhSolutions.QueryModifiers;
public interface IProductQueryModifier
{
public bool TryQueryModify(IQueryCollection collection, out QueryString queryString);
}

View File

@ -0,0 +1,50 @@
using RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
using RhSolutions.QueryModifiers.DrinkingWaterHeatingPipes;
namespace RhSolutions.QueryModifiers;
public class ProductQueryModifierFactory
{
public IProductQueryModifier GetModifier(string productTypeName)
{
switch (productTypeName)
{
case "Монтажная гильза":
return new Sleeve();
case "Тройник RAUTITAN":
return new TPiece();
case "Тройник RAUTITAN резьбовой наружный":
return new ThreadTPieceExternal();
case "Тройник RAUTITAN резьбовой внутренний":
return new ThreadTPieceInternal();
case "Переходник на наружную резьбу":
return new AdapterExternal();
case "Переходник на внутреннюю резьбу":
return new AdapterInternal();
case "Переходник с накидной гайкой":
return new AdapterScrewcap();
case "Угольник с наружной резьбой":
return new ThreadElbowExternal();
case "Угольник с внутренней резьбой":
return new ThreadElbowInternal();
case "Угольник с накидной гайкой":
return new ScrewcapElbow();
case "Муфта соединительная":
return new Coupling();
case "Угольник RAUTITAN":
return new ElbowModifier();
case "Фиксатор поворота без колец":
return new BendFormerHeating();
case "Flex":
return new FlexPipe();
case "Pink":
return new PinkPipe();
case "Stabil":
return new StabilPipe();
case "Black":
return new BlackPipe();
default:
return new BypassQueryModifier();
}
}
}

View File

@ -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>

View File

@ -5,7 +5,9 @@ VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RhSolutions.Api", "RhSolutions.Api\RhSolutions.Api.csproj", "{FD778359-7E92-4B5C-A4F9-7942A28E58F5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RhSolutions.Api.Tests", "RhSolutions.Api.Tests\RhSolutions.Api.Tests.csproj", "{9A4E9EFA-B854-4C29-AA94-A6CE074EDABA}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RhSolutions.QueryModifiers.Tests", "RhSolutions.Api.Tests\RhSolutions.QueryModifiers.Tests.csproj", "{9A4E9EFA-B854-4C29-AA94-A6CE074EDABA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RhSolutions.QueryModifiers", "RhSolutions.QueryModifiers\RhSolutions.QueryModifiers.csproj", "{0C96960B-859B-4376-882E-AA0EB203B1EA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -24,5 +26,9 @@ Global
{9A4E9EFA-B854-4C29-AA94-A6CE074EDABA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9A4E9EFA-B854-4C29-AA94-A6CE074EDABA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9A4E9EFA-B854-4C29-AA94-A6CE074EDABA}.Release|Any CPU.Build.0 = Release|Any CPU
{0C96960B-859B-4376-882E-AA0EB203B1EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0C96960B-859B-4376-882E-AA0EB203B1EA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0C96960B-859B-4376-882E-AA0EB203B1EA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0C96960B-859B-4376-882E-AA0EB203B1EA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal