0
0

Add ML Modifiers with attribute

This commit is contained in:
Serghei Cebotari 2024-01-26 15:50:41 +03:00
parent 2befa6a2a0
commit a0a1c23c4d
57 changed files with 239 additions and 211 deletions

View File

@ -1,6 +1,6 @@
namespace RhSolutions.Api.Tests; namespace RhSolutions.Api.Tests;
public sealed class BypassQueryModifier : IProductQueryModifier public sealed class BypassQueryModifier : IProductMLModifier
{ {
public bool TryQueryModify(string query, out string queryModified) public bool TryQueryModify(string query, out string queryModified)
{ {

View File

@ -1,11 +1,11 @@
using RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings; using RhSolutions.MLModifiers.DrinkingWaterHeatingFittings;
using RhSolutions.QueryModifiers.DrinkingWaterHeatingPipes; using RhSolutions.MLModifiers.DrinkingWaterHeatingPipes;
namespace RhSolutions.Api.Tests; namespace RhSolutions.Api.Tests;
public class ProductQueryModifierFactory public class ProductQueryModifierFactory
{ {
public IProductQueryModifier GetModifier(string productTypeName) public IProductMLModifier GetModifier(string productTypeName)
{ {
switch (productTypeName) switch (productTypeName)
{ {

View File

@ -23,7 +23,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\RhSolutions.QueryModifiers\RhSolutions.QueryModifiers.csproj" /> <ProjectReference Include="..\RhSolutions.MLModifiers\RhSolutions.MLModifiers.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

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

34
RhSolutions.Api.sln Normal file
View File

@ -0,0 +1,34 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RhSolutions.Api", "RhSolutions.Api\RhSolutions.Api.csproj", "{6AACEC90-0811-418D-8505-EB142A2B2AFA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RhSolutions.Api.Tests", "RhSolutions.Api.Tests\RhSolutions.Api.Tests.csproj", "{E49F46C4-5F07-4055-AE8B-700AA6FC35FD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RhSolutions.MLModifiers", "RhSolutions.MLModifiers\RhSolutions.MLModifiers.csproj", "{50A53BB3-1F9D-4F19-90DB-BCB4D49FF9FE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6AACEC90-0811-418D-8505-EB142A2B2AFA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6AACEC90-0811-418D-8505-EB142A2B2AFA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6AACEC90-0811-418D-8505-EB142A2B2AFA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6AACEC90-0811-418D-8505-EB142A2B2AFA}.Release|Any CPU.Build.0 = Release|Any CPU
{E49F46C4-5F07-4055-AE8B-700AA6FC35FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E49F46C4-5F07-4055-AE8B-700AA6FC35FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E49F46C4-5F07-4055-AE8B-700AA6FC35FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E49F46C4-5F07-4055-AE8B-700AA6FC35FD}.Release|Any CPU.Build.0 = Release|Any CPU
{50A53BB3-1F9D-4F19-90DB-BCB4D49FF9FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{50A53BB3-1F9D-4F19-90DB-BCB4D49FF9FE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{50A53BB3-1F9D-4F19-90DB-BCB4D49FF9FE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{50A53BB3-1F9D-4F19-90DB-BCB4D49FF9FE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Http.Extensions; using Microsoft.AspNetCore.Http.Extensions;
using RhSolutions.Api.Services; using RhSolutions.Api.Services;
using RhSolutions.QueryModifiers; using RhSolutions.MLModifiers;
namespace RhSolutions.Api.Middleware; namespace RhSolutions.Api.Middleware;
@ -8,7 +8,7 @@ public class QueryModifier
{ {
private RequestDelegate _next; private RequestDelegate _next;
private IServiceProvider _provider; private IServiceProvider _provider;
private IProductQueryModifier? _modifier; private IProductMLModifier? _modifier;
public QueryModifier(RequestDelegate nextDelegate, IServiceProvider provider) public QueryModifier(RequestDelegate nextDelegate, IServiceProvider provider)
{ {
@ -23,7 +23,7 @@ public class QueryModifier
{ {
string query = context.Request.Query["query"].ToString(); string query = context.Request.Query["query"].ToString();
var productType = typePredicter.GetPredictedProductType(query); var productType = typePredicter.GetPredictedProductType(query);
_modifier = _provider.GetRequiredKeyedService<IProductQueryModifier>(productType); _modifier = _provider.GetRequiredKeyedService<IProductMLModifier>(productType);
if (_modifier == null) return; if (_modifier == null) return;
if (_modifier.TryQueryModify(query, out var modified)) if (_modifier.TryQueryModify(query, out var modified))
{ {

View File

@ -2,9 +2,7 @@ using Microsoft.EntityFrameworkCore;
using RhSolutions.Models; using RhSolutions.Models;
using RhSolutions.Api.Services; using RhSolutions.Api.Services;
using RhSolutions.Api.Middleware; using RhSolutions.Api.Middleware;
using RhSolutions.QueryModifiers; using RhSolutions.MLModifiers;
using RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
using RhSolutions.QueryModifiers.DrinkingWaterHeatingPipes;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
using System.Reflection; using System.Reflection;
@ -29,39 +27,8 @@ builder.Services.AddDbContext<RhSolutionsContext>(opts =>
}); });
builder.Services.AddScoped<IPricelistParser, ClosedXMLParser>() builder.Services.AddScoped<IPricelistParser, ClosedXMLParser>()
.AddScoped<IProductTypePredicter, ProductTypePredicter>(); .AddScoped<IProductTypePredicter, ProductTypePredicter>();
builder.Services.AddModifiers();
builder.Services.AddControllers(); builder.Services.AddControllers();
builder.Services.AddKeyedTransient<IProductQueryModifier, Sleeve>("Монтажная гильза")
.AddKeyedTransient<IProductQueryModifier, SupportingClip>("Желоб")
.AddKeyedTransient<IProductQueryModifier, TPiece>("Тройник RAUTITAN")
.AddKeyedTransient<IProductQueryModifier, ThreadTPieceExternal>("Тройник RAUTITAN резьбовой наружный")
.AddKeyedTransient<IProductQueryModifier, ThreadTPieceInternal>("Тройник RAUTITAN резьбовой внутренний")
.AddKeyedTransient<IProductQueryModifier, AdapterExternal>("Переходник на наружную резьбу")
.AddKeyedTransient<IProductQueryModifier, AdapterInternal>("Переходник на внутреннюю резьбу")
.AddKeyedTransient<IProductQueryModifier, AdapterScrewcap>("Переходник с накидной гайкой")
.AddKeyedTransient<IProductQueryModifier, ThreadElbowExternal>("Угольник с наружной резьбой")
.AddKeyedTransient<IProductQueryModifier, ThreadElbowInternal>("Угольник с внутренней резьбой")
.AddKeyedTransient<IProductQueryModifier, ThreadElbowWallExternal>("Угольник настенный наружный")
.AddKeyedTransient<IProductQueryModifier, ThreadElbowWallInternal>("Угольник настенный внутренний")
.AddKeyedTransient<IProductQueryModifier, ThreadElbowDoubleWallInternal>("Проточный настенный угольник")
.AddKeyedTransient<IProductQueryModifier, ScrewcapElbow>("Угольник с накидной гайкой")
.AddKeyedTransient<IProductQueryModifier, Coupling>("Муфта соединительная")
.AddKeyedTransient<IProductQueryModifier, Elbow>("Угольник RAUTITAN")
.AddKeyedTransient<IProductQueryModifier, BendFormerHeating>("Фиксатор поворота отопление")
.AddKeyedTransient<IProductQueryModifier, BendFormerSanitary>("Фиксатор поворота водоснабжение")
.AddKeyedTransient<IProductQueryModifier, ConnectionBend>("Трубка Г-образная")
.AddKeyedTransient<IProductQueryModifier, ConnectionTee>("Трубка Т-образная")
.AddKeyedTransient<IProductQueryModifier, EuroconeFlex>("Резьбозажимное flex")
.AddKeyedTransient<IProductQueryModifier, EuroconeStabil>("Резьбозажимное stabil")
.AddKeyedTransient<IProductQueryModifier, EuroconeAdapter>("Переходник на евроконус")
.AddKeyedTransient<IProductQueryModifier, EuroconeConnectionBend>("Резьбозажимное для трубки")
.AddKeyedTransient<IProductQueryModifier, Nippel>("Ниппель")
.AddKeyedTransient<IProductQueryModifier, DummyPlug>("Заглушка труб RAUTITAN")
.AddKeyedTransient<IProductQueryModifier, FlexPipe>("Flex")
.AddKeyedTransient<IProductQueryModifier, PinkPipe>("Pink")
.AddKeyedTransient<IProductQueryModifier, StabilPipe>("Stabil")
.AddKeyedTransient<IProductQueryModifier, BlackPipe>("Black");
builder.Services.AddSwaggerGen(options => builder.Services.AddSwaggerGen(options =>
{ {
options.SwaggerDoc("v1", new OpenApiInfo options.SwaggerDoc("v1", new OpenApiInfo
@ -77,7 +44,6 @@ builder.Services.AddSwaggerGen(options =>
} }
}); });
var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename)); options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename));
}); });
@ -92,7 +58,4 @@ app.UseSwagger().UseSwaggerUI(options =>
options.RoutePrefix = string.Empty; options.RoutePrefix = string.Empty;
}); });
var context = app.Services.CreateScope().ServiceProvider
.GetRequiredService<RhSolutionsContext>();
app.Run(); app.Run();

View File

@ -24,14 +24,14 @@
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\RhSolutions.QueryModifiers\RhSolutions.QueryModifiers.csproj" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<None Update="MLModels\model.zip"> <None Update="MLModels\model.zip">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\RhSolutions.MLModifiers\RhSolutions.MLModifiers.csproj" />
</ItemGroup>
</Project> </Project>

View File

@ -1,6 +1,6 @@
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings; namespace RhSolutions.MLModifiers.DrinkingWaterHeatingFittings;
public abstract class Adapter : DrinkingWaterHeatingFitting public abstract class Adapter : DrinkingWaterHeatingFitting
{ {

View File

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

View File

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

View File

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

View File

@ -1,5 +1,6 @@
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings; namespace RhSolutions.MLModifiers.DrinkingWaterHeatingFittings;
[MLModifierKey("Фиксатор поворота отопление")]
public class BendFormerHeating : DrinkingWaterHeatingFitting public class BendFormerHeating : DrinkingWaterHeatingFitting
{ {
protected override string _title => "Фиксатор поворота"; protected override string _title => "Фиксатор поворота";

View File

@ -1,5 +1,6 @@
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings; namespace RhSolutions.MLModifiers.DrinkingWaterHeatingFittings;
[MLModifierKey("Фиксатор поворота водоснабжение")]
public class BendFormerSanitary : DrinkingWaterHeatingFitting public class BendFormerSanitary : DrinkingWaterHeatingFitting
{ {
protected override string _title => "Фиксатор поворота с кольцами"; protected override string _title => "Фиксатор поворота с кольцами";

View File

@ -1,10 +1,11 @@
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings; namespace RhSolutions.MLModifiers.DrinkingWaterHeatingFittings;
[MLModifierKey("Трубка Г-образная")]
public class ConnectionBend : DrinkingWaterHeatingFitting public class ConnectionBend : DrinkingWaterHeatingFitting
{ {
private static readonly int[] lengths = new [] { 250, 500, 1000 }; private static readonly int[] lengths = [250, 500, 1000];
private static readonly Regex _pattern = private static readonly Regex _pattern =
new(@"([\b\D]|^)?(?<Diameter>16|20|25)(\D+|.*15.*)(?<Length>\b\d{3,4})([\b\D]|$)"); new(@"([\b\D]|^)?(?<Diameter>16|20|25)(\D+|.*15.*)(?<Length>\b\d{3,4})([\b\D]|$)");
protected override string _title => "Трубка Г-образная"; protected override string _title => "Трубка Г-образная";

View File

@ -1,5 +1,6 @@
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings; namespace RhSolutions.MLModifiers.DrinkingWaterHeatingFittings;
[MLModifierKey("Трубка Т-образная")]
public class ConnectionTee : ConnectionBend public class ConnectionTee : ConnectionBend
{ {
protected override string _title => "Трубка Т-образная"; protected override string _title => "Трубка Т-образная";

View File

@ -1,5 +1,6 @@
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings; namespace RhSolutions.MLModifiers.DrinkingWaterHeatingFittings;
[MLModifierKey("Муфта соединительная")]
public class Coupling : DrinkingWaterHeatingFitting public class Coupling : DrinkingWaterHeatingFitting
{ {
protected override string _title => "Муфта соединительная"; protected override string _title => "Муфта соединительная";

View File

@ -1,8 +1,8 @@
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings; namespace RhSolutions.MLModifiers.DrinkingWaterHeatingFittings;
public abstract class DrinkingWaterHeatingFitting : IProductQueryModifier public abstract class DrinkingWaterHeatingFitting : IProductMLModifier
{ {
protected static readonly Regex _diameter = 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]|$)");

View File

@ -0,0 +1,7 @@
namespace RhSolutions.MLModifiers.DrinkingWaterHeatingFittings;
[MLModifierKey("Заглушка труб RAUTITAN")]
public class DummyPlug : DrinkingWaterHeatingFitting
{
protected override string _title => "Заглушка для полимерн. трубы";
}

View File

@ -1,5 +1,6 @@
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings; namespace RhSolutions.MLModifiers.DrinkingWaterHeatingFittings;
[MLModifierKey("Угольник RAUTITAN")]
public class Elbow : DrinkingWaterHeatingFitting public class Elbow : DrinkingWaterHeatingFitting
{ {
protected override string _title { get; } = "Угольник -PLATINUM"; protected override string _title { get; } = "Угольник -PLATINUM";

View File

@ -1,4 +1,4 @@
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings; namespace RhSolutions.MLModifiers.DrinkingWaterHeatingFittings;
public abstract class Eurocone : DrinkingWaterHeatingFitting public abstract class Eurocone : DrinkingWaterHeatingFitting
{ {

View File

@ -1,5 +1,6 @@
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings; namespace RhSolutions.MLModifiers.DrinkingWaterHeatingFittings;
[MLModifierKey("Переходник на евроконус")]
public class EuroconeAdapter : DrinkingWaterHeatingFitting public class EuroconeAdapter : DrinkingWaterHeatingFitting
{ {
protected override string _title => "Переходник на евроконус"; protected override string _title => "Переходник на евроконус";

View File

@ -1,5 +1,6 @@
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings; namespace RhSolutions.MLModifiers.DrinkingWaterHeatingFittings;
[MLModifierKey("Резьбозажимное для трубки")]
public class EuroconeConnectionBend : DrinkingWaterHeatingFitting public class EuroconeConnectionBend : DrinkingWaterHeatingFitting
{ {
public override bool TryQueryModify(string input, out string output) public override bool TryQueryModify(string input, out string output)

View File

@ -1,5 +1,6 @@
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings; namespace RhSolutions.MLModifiers.DrinkingWaterHeatingFittings;
[MLModifierKey("Резьбозажимное flex")]
public class EuroconeFlex : Eurocone public class EuroconeFlex : Eurocone
{ {
protected override Dictionary<string, string> _titles => new() protected override Dictionary<string, string> _titles => new()

View File

@ -1,5 +1,6 @@
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings; namespace RhSolutions.MLModifiers.DrinkingWaterHeatingFittings;
[MLModifierKey("Резьбозажимное stabil")]
public class EuroconeStabil : Eurocone public class EuroconeStabil : Eurocone
{ {
protected override Dictionary<string, string> _titles => new() protected override Dictionary<string, string> _titles => new()

View File

@ -1,5 +1,6 @@
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings; namespace RhSolutions.MLModifiers.DrinkingWaterHeatingFittings;
[MLModifierKey("Ниппель")]
public class Nippel : DrinkingWaterHeatingFitting public class Nippel : DrinkingWaterHeatingFitting
{ {
public override bool TryQueryModify(string input, out string output) public override bool TryQueryModify(string input, out string output)

View File

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

View File

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

View File

@ -1,5 +1,6 @@
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings; namespace RhSolutions.MLModifiers.DrinkingWaterHeatingFittings;
[MLModifierKey("Желоб")]
public class SupportingClip : DrinkingWaterHeatingFitting public class SupportingClip : DrinkingWaterHeatingFitting
{ {
protected override string _title => "Фиксирующий желоб для ПЭ-трубы"; protected override string _title => "Фиксирующий желоб для ПЭ-трубы";

View File

@ -1,5 +1,6 @@
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings; namespace RhSolutions.MLModifiers.DrinkingWaterHeatingFittings;
[MLModifierKey("Тройник RAUTITAN")]
public class TPiece : DrinkingWaterHeatingFitting public class TPiece : DrinkingWaterHeatingFitting
{ {
protected override string _title => "Тройник -PLATINUM"; protected override string _title => "Тройник -PLATINUM";

View File

@ -1,7 +1,8 @@
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings; namespace RhSolutions.MLModifiers.DrinkingWaterHeatingFittings;
[MLModifierKey("Проточный настенный угольник")]
public class ThreadElbowDoubleWallInternal : DrinkingWaterHeatingFitting public class ThreadElbowDoubleWallInternal : DrinkingWaterHeatingFitting
{ {
protected override string _title => "Проточный настенный угольник"; protected override string _title => "Проточный настенный угольник";

View File

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

View File

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

View File

@ -1,5 +1,6 @@
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings; namespace RhSolutions.MLModifiers.DrinkingWaterHeatingFittings;
[MLModifierKey("Угольник настенный наружный")]
public class ThreadElbowWallExternal : DrinkingWaterHeatingFitting public class ThreadElbowWallExternal : DrinkingWaterHeatingFitting
{ {
protected override string _title => "Угольник настенный с наружной резьбой"; protected override string _title => "Угольник настенный с наружной резьбой";

View File

@ -1,7 +1,8 @@
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings; namespace RhSolutions.MLModifiers.DrinkingWaterHeatingFittings;
[MLModifierKey("Угольник настенный внутренний")]
public class ThreadElbowWallInternal : DrinkingWaterHeatingFitting public class ThreadElbowWallInternal : DrinkingWaterHeatingFitting
{ {
protected override string _title => "Угольник настенный внутр. резьба"; protected override string _title => "Угольник настенный внутр. резьба";

View File

@ -1,7 +1,8 @@
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings; namespace RhSolutions.MLModifiers.DrinkingWaterHeatingFittings;
[MLModifierKey("Тройник RAUTITAN резьбовой наружный")]
public class ThreadTPieceExternal : DrinkingWaterHeatingFitting public class ThreadTPieceExternal : DrinkingWaterHeatingFitting
{ {
protected override string _title => "Тройник с наружной резьбой"; protected override string _title => "Тройник с наружной резьбой";

View File

@ -1,7 +1,8 @@
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings; namespace RhSolutions.MLModifiers.DrinkingWaterHeatingFittings;
[MLModifierKey("Тройник RAUTITAN резьбовой внутренний")]
public class ThreadTPieceInternal : DrinkingWaterHeatingFitting public class ThreadTPieceInternal : DrinkingWaterHeatingFitting
{ {
public override bool TryQueryModify(string input, out string output) public override bool TryQueryModify(string input, out string output)

View File

@ -0,0 +1,17 @@
namespace RhSolutions.MLModifiers.DrinkingWaterHeatingPipes;
[MLModifierKey("Black")]
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] = string.Empty,
[40] = string.Empty,
[50] = string.Empty,
[63] = string.Empty
};
}

View File

@ -1,8 +1,8 @@
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingPipes; namespace RhSolutions.MLModifiers.DrinkingWaterHeatingPipes;
public class DrinkingWaterHeatingPipe : IProductQueryModifier public abstract class DrinkingWaterHeatingPipe : IProductMLModifier
{ {
protected static readonly Regex _diameter = 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]|$)");

View File

@ -0,0 +1,7 @@
namespace RhSolutions.MLModifiers.DrinkingWaterHeatingPipes;
[MLModifierKey("Flex")]
public class FlexPipe : DrinkingWaterHeatingPipe
{
protected override string _title => "Flex";
}

View File

@ -0,0 +1,24 @@
namespace RhSolutions.MLModifiers.DrinkingWaterHeatingPipes;
[MLModifierKey("Pink")]
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,7"
};
}

View File

@ -0,0 +1,17 @@
namespace RhSolutions.MLModifiers.DrinkingWaterHeatingPipes;
[MLModifierKey("Stabil")]
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,6 @@
namespace RhSolutions.MLModifiers;
public interface IProductMLModifier
{
public bool TryQueryModify(string query, out string queryModified);
}

View File

@ -0,0 +1,10 @@
namespace RhSolutions.MLModifiers;
public class MLModifierKey : Attribute
{
public string Value { get; private set; }
public MLModifierKey(string value)
{
Value = value;
}
}

View File

@ -0,0 +1,25 @@
using Microsoft.Extensions.DependencyInjection;
using System.Reflection;
namespace RhSolutions.MLModifiers;
public static class MLModifiersRegistration
{
public static void AddModifiers(this IServiceCollection services)
{
var types = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(s => s.GetTypes())
.Where(p => p.IsDefined(typeof(MLModifierKey), true));
foreach (Type t in types)
{
string key = GetModifierKey(t);
services.AddKeyedTransient(typeof(IProductMLModifier), key, t);
}
}
private static string GetModifierKey(Type t)
{
return t.GetCustomAttribute<MLModifierKey>()?.Value ?? string.Empty;
}
}

View File

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

View File

@ -1,6 +0,0 @@
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
public class DummyPlug : DrinkingWaterHeatingFitting
{
protected override string _title => "Заглушка для полимерн. трубы";
}

View File

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

View File

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

View File

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

View File

@ -1,16 +0,0 @@
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] = string.Empty,
[40] = string.Empty,
[50] = string.Empty,
[63] = string.Empty
};
}

View File

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

View File

@ -1,23 +0,0 @@
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,7"
};
}

View File

@ -1,16 +0,0 @@
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

@ -1,6 +0,0 @@
namespace RhSolutions.QueryModifiers;
public interface IProductQueryModifier
{
public bool TryQueryModify(string query, out string queryModified);
}

View File

@ -1,34 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
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.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
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FD778359-7E92-4B5C-A4F9-7942A28E58F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FD778359-7E92-4B5C-A4F9-7942A28E58F5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FD778359-7E92-4B5C-A4F9-7942A28E58F5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FD778359-7E92-4B5C-A4F9-7942A28E58F5}.Release|Any CPU.Build.0 = Release|Any CPU
{9A4E9EFA-B854-4C29-AA94-A6CE074EDABA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{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