Move Modifiers to own project
This commit is contained in:
parent
942c60beea
commit
6b9c0dfffc
@ -18,6 +18,10 @@ public class RautitanFittingsTests : ProductQueryModifierTests
|
||||
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)
|
||||
=> Execute(productType: "Угольник RAUTITAN", query, modified);
|
||||
@ -35,11 +39,8 @@ public class RautitanFittingsTests : ProductQueryModifierTests
|
||||
public void ScrewcapElbowTest(string query, string modified)
|
||||
=> Execute(productType: "Угольник с накидной гайкой", query, modified);
|
||||
|
||||
[TestCase("Тройник настенный с внутренней резьбой 16-Rp1/2-16 RX+", "Тройник настенный с внутренней резьбой 16-Rp1/2-16")]
|
||||
public void ThreadTPieceWallTest(string query, string modified)
|
||||
=> Execute(productType: "Тройник RAUTITAN резьбовой настенный", query, modified);
|
||||
|
||||
[TestCase("Тройник с внутр. резьбой на боков. проходе 25-Rp 1/2-25 RX+", "Тройник с внутр. резьбой на боков. проходе 25-Rp 1/2-25")]
|
||||
[TestCase("Тройник настенный с внутренней резьбой 16-Rp1/2-16 RX+", "Тройник настенный с внутренней резьбой 16-Rp1/2-16")]
|
||||
public void ThreadTPieceInternalTest(string query, string modified)
|
||||
=> Execute(productType: "Тройник RAUTITAN резьбовой внутренний", query, modified);
|
||||
|
||||
|
@ -4,7 +4,6 @@
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
@ -1 +1,2 @@
|
||||
global using NUnit.Framework;
|
||||
global using RhSolutions.QueryModifiers;
|
@ -1,5 +1,5 @@
|
||||
using Microsoft.AspNetCore.Http.Extensions;
|
||||
using RhSolutions.Api.Services;
|
||||
using RhSolutions.Api.Services;
|
||||
using RhSolutions.QueryModifiers;
|
||||
|
||||
namespace RhSolutions.Api.Middleware;
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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>
|
||||
|
@ -1,14 +0,0 @@
|
||||
namespace RhSolutions.Api.Services
|
||||
{
|
||||
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"
|
||||
};
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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\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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
namespace RhSolutions.Api.Services
|
||||
{
|
||||
public class FlexPipeQueryModifier : PipeQueryModifier { }
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
namespace RhSolutions.Api.Services
|
||||
{
|
||||
public interface IProductQueryModifier
|
||||
{
|
||||
public bool TryQueryModify(IQueryCollection collection, out QueryString queryString);
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
|
||||
namespace RhSolutions.Api.Services
|
||||
{
|
||||
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.Extensions;
|
||||
|
||||
namespace RhSolutions.Api.Services
|
||||
{
|
||||
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,7 +0,0 @@
|
||||
namespace RhSolutions.Api.Services
|
||||
{
|
||||
public class ScrewcapElbowModifier : AdapterModifier
|
||||
{
|
||||
protected override string name => "Угольник-переходник с накидной гайкой";
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
namespace RhSolutions.Api.Services
|
||||
{
|
||||
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.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;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
namespace RhSolutions.Api.Services
|
||||
{
|
||||
public class ThreadElbowExternalModifier : AdapterModifier
|
||||
{
|
||||
protected override string name => "Угольник-переходник с наружной резьбой";
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
namespace RhSolutions.Api.Services
|
||||
{
|
||||
public class ThreadElbowInternalModifier : AdapterModifier
|
||||
{
|
||||
protected override string name => "Угольник-переходник с внутренней резьбой";
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace RhSolutions.Api.Services;
|
||||
|
||||
public class ThreadTPieceInternal : ThreadTPieceWall
|
||||
{
|
||||
protected override string ConstructName(MatchCollection diameters, Match thread)
|
||||
{
|
||||
Capture t = thread.Groups["Thread"].Captures.First();
|
||||
if (diameters.Count == 1)
|
||||
{
|
||||
return $"Тройник с внутр. резьбой на боков. проходе {diameters[0]}-Rp {t}-{diameters[0]}";
|
||||
}
|
||||
else
|
||||
{
|
||||
return $"Тройник с внутр. резьбой на боков. проходе {diameters[0]}-Rp {t}-{diameters[1]}";
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
namespace RhSolutions.Api.Services
|
||||
namespace RhSolutions.QueryModifiers
|
||||
{
|
||||
public class AdapterExternalModifier : AdapterModifier
|
||||
{
|
@ -1,7 +1,7 @@
|
||||
namespace RhSolutions.Api.Services
|
||||
namespace RhSolutions.QueryModifiers
|
||||
{
|
||||
public class AdapterInternalModifier : AdapterModifier
|
||||
{
|
||||
protected override string name => "Переходник с внутренней резьбой";
|
||||
protected override string name => "Переходник с внутренней резьбой -угольник-переходник";
|
||||
}
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
|
||||
using System.Text.RegularExpressions;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.Extensions;
|
||||
|
||||
namespace RhSolutions.Api.Services
|
||||
namespace RhSolutions.QueryModifiers
|
||||
{
|
||||
public abstract class AdapterModifier : IProductQueryModifier
|
||||
{
|
@ -1,4 +1,4 @@
|
||||
namespace RhSolutions.Api.Services
|
||||
namespace RhSolutions.QueryModifiers
|
||||
{
|
||||
public class AdapterScrewcapModifier : AdapterModifier
|
||||
{
|
13
RhSolutions.QueryModifiers/BlackPipeQueryModifier.cs
Normal file
13
RhSolutions.QueryModifiers/BlackPipeQueryModifier.cs
Normal file
@ -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"
|
||||
};
|
||||
}
|
12
RhSolutions.QueryModifiers/BypassQueryModifier.cs
Normal file
12
RhSolutions.QueryModifiers/BypassQueryModifier.cs
Normal file
@ -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;
|
||||
}
|
||||
}
|
38
RhSolutions.QueryModifiers/CouplingModifier.cs
Normal file
38
RhSolutions.QueryModifiers/CouplingModifier.cs
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
|
||||
using System.Text.RegularExpressions;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.Extensions;
|
||||
|
||||
namespace RhSolutions.Api.Services
|
||||
namespace RhSolutions.QueryModifiers
|
||||
{
|
||||
public class ElbowModifier : IProductQueryModifier
|
||||
{
|
3
RhSolutions.QueryModifiers/FlexPipeQueryModifier.cs
Normal file
3
RhSolutions.QueryModifiers/FlexPipeQueryModifier.cs
Normal file
@ -0,0 +1,3 @@
|
||||
namespace RhSolutions.QueryModifiers;
|
||||
|
||||
public class FlexPipeQueryModifier : PipeQueryModifier { }
|
8
RhSolutions.QueryModifiers/IProductQueryModifier.cs
Normal file
8
RhSolutions.QueryModifiers/IProductQueryModifier.cs
Normal file
@ -0,0 +1,8 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace RhSolutions.QueryModifiers;
|
||||
|
||||
public interface IProductQueryModifier
|
||||
{
|
||||
public bool TryQueryModify(IQueryCollection collection, out QueryString queryString);
|
||||
}
|
22
RhSolutions.QueryModifiers/PinkPipeQueryModifier.cs
Normal file
22
RhSolutions.QueryModifiers/PinkPipeQueryModifier.cs
Normal file
@ -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()
|
||||
{
|
||||
["бухт"] = "бухта",
|
||||
["штанг"] = "прямые отрезки",
|
||||
["отр"] = "прямые отрезки"
|
||||
};
|
||||
}
|
59
RhSolutions.QueryModifiers/PipeQueryModifier.cs
Normal file
59
RhSolutions.QueryModifiers/PipeQueryModifier.cs
Normal file
@ -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;
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
namespace RhSolutions.Api.Services;
|
||||
namespace RhSolutions.QueryModifiers;
|
||||
|
||||
public class ProductQueryModifierFactory
|
||||
{
|
||||
@ -15,7 +15,7 @@ public class ProductQueryModifierFactory
|
||||
case "Тройник RAUTITAN резьбовой внутренний":
|
||||
return new ThreadTPieceInternal();
|
||||
case "Тройник RAUTITAN резьбовой настенный":
|
||||
return new ThreadTPieceWall();
|
||||
return new ThreadTPieceInternal();
|
||||
case "Переходник на наружную резьбу":
|
||||
return new AdapterExternalModifier();
|
||||
case "Переходник на внутреннюю резьбу":
|
13
RhSolutions.QueryModifiers/RhSolutions.QueryModifiers.csproj
Normal file
13
RhSolutions.QueryModifiers/RhSolutions.QueryModifiers.csproj
Normal 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>
|
6
RhSolutions.QueryModifiers/ScrewcapElbowModifier.cs
Normal file
6
RhSolutions.QueryModifiers/ScrewcapElbowModifier.cs
Normal file
@ -0,0 +1,6 @@
|
||||
namespace RhSolutions.QueryModifiers;
|
||||
|
||||
public class ScrewcapElbowModifier : AdapterModifier
|
||||
{
|
||||
protected override string name => "Угольник-переходник с накидной гайкой";
|
||||
}
|
38
RhSolutions.QueryModifiers/SleeveQueryModifier.cs
Normal file
38
RhSolutions.QueryModifiers/SleeveQueryModifier.cs
Normal file
@ -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;
|
||||
}
|
||||
}
|
15
RhSolutions.QueryModifiers/StabilPipeQueryModifier.cs
Normal file
15
RhSolutions.QueryModifiers/StabilPipeQueryModifier.cs
Normal file
@ -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"
|
||||
};
|
||||
}
|
42
RhSolutions.QueryModifiers/TPieceQueryModifier.cs
Normal file
42
RhSolutions.QueryModifiers/TPieceQueryModifier.cs
Normal file
@ -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;
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
namespace RhSolutions.QueryModifiers;
|
||||
|
||||
public class ThreadElbowExternalModifier : AdapterModifier
|
||||
{
|
||||
protected override string name => "Угольник-переходник с наружной резьбой";
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
namespace RhSolutions.QueryModifiers;
|
||||
|
||||
public class ThreadElbowInternalModifier : AdapterModifier
|
||||
{
|
||||
protected override string name => "Угольник-переходник с внутренней резьбой";
|
||||
}
|
@ -1,9 +1,8 @@
|
||||
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace RhSolutions.Api.Services;
|
||||
namespace RhSolutions.QueryModifiers;
|
||||
|
||||
public class ThreadTPieceExternal : ThreadTPieceWall
|
||||
public class ThreadTPieceExternal : ThreadTPieceInternal
|
||||
{
|
||||
protected override string ConstructName(MatchCollection diameters, Match thread)
|
||||
{
|
@ -1,10 +1,10 @@
|
||||
|
||||
using System.Text.RegularExpressions;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.Extensions;
|
||||
|
||||
namespace RhSolutions.Api.Services;
|
||||
namespace RhSolutions.QueryModifiers;
|
||||
|
||||
public class ThreadTPieceWall : IProductQueryModifier
|
||||
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|$)";
|
||||
@ -39,12 +39,26 @@ public class ThreadTPieceWall : IProductQueryModifier
|
||||
{
|
||||
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]}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user