Compare commits
No commits in common. "36cd74a9599aafee4066d7405932c5ebc6201e33" and "931b08e00d8822e98db036c169dcbe83c2361635" have entirely different histories.
36cd74a959
...
931b08e00d
@ -7,8 +7,7 @@ RUN dotnet publish -c Release -o out
|
|||||||
|
|
||||||
FROM mcr.microsoft.com/dotnet/aspnet:6.0
|
FROM mcr.microsoft.com/dotnet/aspnet:6.0
|
||||||
EXPOSE 5000
|
EXPOSE 5000
|
||||||
EXPOSE 43000
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=build /app/out .
|
COPY --from=build /app/out .
|
||||||
ENV ASPNETCORE_ENVIRONMENT Production
|
ENV ASPNETCORE_ENVIRONMENT Production
|
||||||
ENTRYPOINT [ "dotnet", "RhSolutions.Api.dll" ]
|
ENTRYPOINT [ "dotnet", "RhSolutions.Api.dll", "--urls=http://0.0.0.0:5000" ]
|
@ -1,3 +1,6 @@
|
|||||||
|
using System.Web;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.Extensions.Primitives;
|
||||||
public abstract class ProductQueryModifierTests
|
public abstract class ProductQueryModifierTests
|
||||||
{
|
{
|
||||||
protected ProductQueryModifierFactory _factory;
|
protected ProductQueryModifierFactory _factory;
|
||||||
@ -7,10 +10,17 @@ public abstract class ProductQueryModifierTests
|
|||||||
{
|
{
|
||||||
_factory = new ProductQueryModifierFactory();
|
_factory = new ProductQueryModifierFactory();
|
||||||
}
|
}
|
||||||
public void Execute(string productType, string query, string expected)
|
public void Execute(string productType, string query, string modified)
|
||||||
{
|
{
|
||||||
var modifier = _factory.GetModifier(productType);
|
Dictionary<string, StringValues> queryPair = new()
|
||||||
Assert.True(modifier.TryQueryModify(query, out var actual));
|
{
|
||||||
Assert.That(actual, Is.EqualTo(expected));
|
["query"] = new StringValues(query)
|
||||||
|
};
|
||||||
|
QueryCollection collection = new(queryPair);
|
||||||
|
var modifier = _factory.GetModifier(productType);
|
||||||
|
|
||||||
|
Assert.True(modifier.TryQueryModify(collection, out var actual));
|
||||||
|
string? result = HttpUtility.ParseQueryString(actual.ToString())["query"];
|
||||||
|
Assert.That(result, Is.EqualTo(modified));
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,78 +5,78 @@ using System.Linq;
|
|||||||
|
|
||||||
namespace RhSolutions.Api.Controllers
|
namespace RhSolutions.Api.Controllers
|
||||||
{
|
{
|
||||||
[Route("api/[controller]")]
|
[Route("api/[controller]")]
|
||||||
public class ProductsController : ControllerBase
|
public class ProductsController : ControllerBase
|
||||||
{
|
{
|
||||||
private RhSolutionsContext dbContext;
|
private RhSolutionsContext dbContext;
|
||||||
private IPricelistParser parser;
|
private IPricelistParser parser;
|
||||||
|
|
||||||
public ProductsController(RhSolutionsContext dbContext, IPricelistParser parser)
|
public ProductsController(RhSolutionsContext dbContext, IPricelistParser parser)
|
||||||
{
|
{
|
||||||
this.dbContext = dbContext;
|
this.dbContext = dbContext;
|
||||||
this.parser = parser;
|
this.parser = parser;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public IAsyncEnumerable<Product> GetProducts()
|
public IAsyncEnumerable<Product> GetProducts()
|
||||||
{
|
{
|
||||||
return dbContext.Products
|
return dbContext.Products
|
||||||
.AsAsyncEnumerable();
|
.AsAsyncEnumerable();
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
public IEnumerable<Product> GetProduct(string id)
|
public IEnumerable<Product> GetProduct(string id)
|
||||||
{
|
{
|
||||||
return dbContext.Products
|
return dbContext.Products
|
||||||
.Where(p => p.Id.Equals(id));
|
.Where(p => p.Id.Equals(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public IActionResult PostProductsFromXls()
|
public IActionResult PostProductsFromXls()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var products = parser.GetProducts(HttpContext).GroupBy(p => p.ProductSku)
|
var products = parser.GetProducts(HttpContext).GroupBy(p => p.ProductSku)
|
||||||
.Select(g => new Product(g.Key)
|
.Select(g => new Product(g.Key)
|
||||||
{
|
{
|
||||||
Name = g.First().Name,
|
Name = g.First().Name,
|
||||||
DeprecatedSkus = g.SelectMany(p => p.DeprecatedSkus).Distinct().ToList(),
|
DeprecatedSkus = g.SelectMany(p => p.DeprecatedSkus).Distinct().ToList(),
|
||||||
ProductLines = g.SelectMany(p => p.ProductLines).Distinct().ToList(),
|
ProductLines = g.SelectMany(p => p.ProductLines).Distinct().ToList(),
|
||||||
IsOnWarehouse = g.Any(p => p.IsOnWarehouse == true),
|
IsOnWarehouse = g.Any(p => p.IsOnWarehouse == true),
|
||||||
ProductMeasure = g.First().ProductMeasure,
|
ProductMeasure = g.First().ProductMeasure,
|
||||||
DeliveryMakeUp = g.First().DeliveryMakeUp,
|
DeliveryMakeUp = g.First().DeliveryMakeUp,
|
||||||
Price = g.First().Price
|
Price = g.First().Price
|
||||||
});
|
});
|
||||||
|
|
||||||
foreach (var p in products)
|
foreach (var p in products)
|
||||||
{
|
{
|
||||||
dbContext.Add<Product>(p);
|
dbContext.Add<Product>(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
dbContext.SaveChanges();
|
dbContext.SaveChanges();
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
return BadRequest(ex.Message);
|
return BadRequest(ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpDelete]
|
[HttpDelete]
|
||||||
public IActionResult DeleteAllProducts()
|
public IActionResult DeleteAllProducts()
|
||||||
{
|
{
|
||||||
List<Product> deleted = new();
|
List<Product> deleted = new();
|
||||||
if (dbContext.Products.Count() > 0)
|
if (dbContext.Products.Count() > 0)
|
||||||
{
|
{
|
||||||
foreach (Product p in dbContext.Products)
|
foreach (Product p in dbContext.Products)
|
||||||
{
|
{
|
||||||
deleted.Add(p);
|
deleted.Add(p);
|
||||||
dbContext.Remove(p);
|
dbContext.Remove(p);
|
||||||
}
|
}
|
||||||
dbContext.SaveChanges();
|
dbContext.SaveChanges();
|
||||||
return Ok(deleted);
|
return Ok(deleted);
|
||||||
}
|
}
|
||||||
else return Ok("Empty db");
|
else return Ok("Empty db");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,35 +1,30 @@
|
|||||||
using Microsoft.AspNetCore.Http.Extensions;
|
using RhSolutions.Api.Services;
|
||||||
using RhSolutions.Api.Services;
|
|
||||||
using RhSolutions.QueryModifiers;
|
using RhSolutions.QueryModifiers;
|
||||||
|
|
||||||
namespace RhSolutions.Api.Middleware;
|
namespace RhSolutions.Api.Middleware;
|
||||||
|
|
||||||
public class QueryModifier
|
public class QueryModifier
|
||||||
{
|
{
|
||||||
private RequestDelegate _next;
|
private RequestDelegate _next;
|
||||||
|
|
||||||
public QueryModifier(RequestDelegate nextDelegate)
|
public QueryModifier(RequestDelegate nextDelegate)
|
||||||
{
|
{
|
||||||
_next = nextDelegate;
|
_next = nextDelegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Invoke(HttpContext context, IProductTypePredicter typePredicter, ProductQueryModifierFactory productQueryModifierFactory)
|
public async Task Invoke(HttpContext context, IProductTypePredicter typePredicter, ProductQueryModifierFactory productQueryModifierFactory)
|
||||||
{
|
{
|
||||||
if (context.Request.Method == HttpMethods.Get
|
if (context.Request.Method == HttpMethods.Get
|
||||||
&& context.Request.Path == "/api/search")
|
&& context.Request.Path == "/api/search")
|
||||||
{
|
{
|
||||||
string query = context.Request.Query["query"].ToString();
|
string query = context.Request.Query["query"].ToString();
|
||||||
var productType = typePredicter.GetPredictedProductType(query);
|
var productType = typePredicter.GetPredictedProductType(query);
|
||||||
var modifier = productQueryModifierFactory.GetModifier(productType!);
|
var modifier = productQueryModifierFactory.GetModifier(productType!);
|
||||||
if (modifier.TryQueryModify(query, out var modified))
|
if (modifier.TryQueryModify(context.Request.Query, out var newQuery))
|
||||||
{
|
{
|
||||||
QueryBuilder qb = new()
|
context.Request.QueryString = newQuery;
|
||||||
{
|
}
|
||||||
{"query", modified}
|
}
|
||||||
};
|
await _next(context);
|
||||||
context.Request.QueryString = qb.ToQueryString();
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
await _next(context);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ using RhSolutions.Api.Services;
|
|||||||
using RhSolutions.Api.Middleware;
|
using RhSolutions.Api.Middleware;
|
||||||
using RhSolutions.QueryModifiers;
|
using RhSolutions.QueryModifiers;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder();
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
string dbHost = builder.Configuration["DB_HOST"],
|
string dbHost = builder.Configuration["DB_HOST"],
|
||||||
dbPort = builder.Configuration["DB_PORT"],
|
dbPort = builder.Configuration["DB_PORT"],
|
||||||
@ -23,18 +23,17 @@ builder.Services.AddDbContext<RhSolutionsContext>(opts =>
|
|||||||
opts.EnableSensitiveDataLogging(true);
|
opts.EnableSensitiveDataLogging(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
builder.Services.AddScoped<IPricelistParser, ClosedXMLParser>()
|
builder.Services.AddScoped<IPricelistParser, ClosedXMLParser>()
|
||||||
.AddScoped<IProductTypePredicter, ProductTypePredicter>()
|
.AddScoped<IProductTypePredicter, ProductTypePredicter>()
|
||||||
.AddSingleton<ProductQueryModifierFactory>()
|
.AddSingleton<ProductQueryModifierFactory>();
|
||||||
.AddGrpc();
|
|
||||||
|
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
app.MapGrpcService<SearchService>();
|
|
||||||
app.UseMiddleware<QueryModifier>();
|
app.UseMiddleware<QueryModifier>();
|
||||||
|
|
||||||
|
var context = app.Services.CreateScope().ServiceProvider
|
||||||
|
.GetRequiredService<RhSolutionsContext>();
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
"anonymousAuthentication": true,
|
"anonymousAuthentication": true,
|
||||||
"launchBrowser": false,
|
"launchBrowser": false,
|
||||||
"iisExpress": {
|
"iisExpress": {
|
||||||
"applicationUrl": "http://localhost:5000;http://localhost:43000",
|
"applicationUrl": "http://localhost:5000",
|
||||||
"sslPort": 0
|
"sslPort": 0
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -13,7 +13,7 @@
|
|||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"dotnetRunMessages": true,
|
"dotnetRunMessages": true,
|
||||||
"launchBrowser": false,
|
"launchBrowser": false,
|
||||||
"applicationUrl": "http://localhost:5000;http://localhost:43000",
|
"applicationUrl": "http://localhost:5000",
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
}
|
}
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
|
|
||||||
service ProductSearch {
|
|
||||||
rpc GetProduct (ProductRequest) returns (ProductReply);
|
|
||||||
}
|
|
||||||
|
|
||||||
message ProductRequest {
|
|
||||||
string query = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
message ProductReply {
|
|
||||||
string id = 1;
|
|
||||||
string name = 2;
|
|
||||||
double price = 3;
|
|
||||||
}
|
|
@ -9,11 +9,6 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="ClosedXML" Version="0.100.0" />
|
<PackageReference Include="ClosedXML" Version="0.100.0" />
|
||||||
<PackageReference Include="Grpc.AspnetCore" Version="2.58.0" />
|
|
||||||
<PackageReference Include="Grpc.Tools" Version="2.59.0">
|
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
|
||||||
<PrivateAssets>all</PrivateAssets>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.5">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.5">
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
@ -34,9 +29,4 @@
|
|||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Protobuf Include="Protos\product.proto" GrpcServices="Server" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -5,40 +5,40 @@ namespace RhSolutions.Api.Services;
|
|||||||
|
|
||||||
public class ProductTypePredicter : IProductTypePredicter
|
public class ProductTypePredicter : IProductTypePredicter
|
||||||
{
|
{
|
||||||
private readonly string _modelPath = @"./MLModels/model.zip";
|
private readonly string _modelPath = @"./MLModels/model.zip";
|
||||||
private MLContext _mlContext;
|
private MLContext _mlContext;
|
||||||
private ITransformer _loadedModel;
|
private ITransformer _loadedModel;
|
||||||
private PredictionEngine<Product, TypePrediction> _predEngine;
|
private PredictionEngine<Product, TypePrediction> _predEngine;
|
||||||
|
|
||||||
public ProductTypePredicter()
|
public ProductTypePredicter()
|
||||||
{
|
{
|
||||||
_mlContext = new MLContext(seed: 0);
|
_mlContext = new MLContext(seed: 0);
|
||||||
_loadedModel = _mlContext.Model.Load(_modelPath, out var _);
|
_loadedModel = _mlContext.Model.Load(_modelPath, out var _);
|
||||||
_predEngine = _mlContext.Model.CreatePredictionEngine<Product, TypePrediction>(_loadedModel);
|
_predEngine = _mlContext.Model.CreatePredictionEngine<Product, TypePrediction>(_loadedModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string? GetPredictedProductType(string productName)
|
public string? GetPredictedProductType(string productName)
|
||||||
{
|
{
|
||||||
Product p = new()
|
Product p = new()
|
||||||
{
|
{
|
||||||
Name = productName
|
Name = productName
|
||||||
};
|
};
|
||||||
var prediction = _predEngine.Predict(p);
|
var prediction = _predEngine.Predict(p);
|
||||||
return prediction.Type;
|
return prediction.Type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Product
|
public class Product
|
||||||
{
|
{
|
||||||
[LoadColumn(0)]
|
[LoadColumn(0)]
|
||||||
public string? Name { get; set; }
|
public string? Name { get; set; }
|
||||||
[LoadColumn(1)]
|
[LoadColumn(1)]
|
||||||
public string? Type { get; set; }
|
public string? Type { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TypePrediction
|
public class TypePrediction
|
||||||
{
|
{
|
||||||
[ColumnName("PredictedLabel")]
|
[ColumnName("PredictedLabel")]
|
||||||
public string? Type { get; set; }
|
public string? Type { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,48 +0,0 @@
|
|||||||
using Grpc.Core;
|
|
||||||
using RhSolutions.Models;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using RhSolutions.QueryModifiers;
|
|
||||||
|
|
||||||
namespace RhSolutions.Api.Services;
|
|
||||||
|
|
||||||
public class SearchService : ProductSearch.ProductSearchBase
|
|
||||||
{
|
|
||||||
private RhSolutionsContext _dbContext;
|
|
||||||
private IProductTypePredicter _typePredicter;
|
|
||||||
private ProductQueryModifierFactory _productQueryModifierFactory;
|
|
||||||
|
|
||||||
public SearchService(RhSolutionsContext dbContext, IProductTypePredicter typePredicter, ProductQueryModifierFactory productQueryModifierFactory)
|
|
||||||
{
|
|
||||||
_dbContext = dbContext;
|
|
||||||
_typePredicter = typePredicter;
|
|
||||||
_productQueryModifierFactory = productQueryModifierFactory;
|
|
||||||
}
|
|
||||||
public override async Task<ProductReply?> GetProduct(ProductRequest request, ServerCallContext context)
|
|
||||||
{
|
|
||||||
var productType = _typePredicter.GetPredictedProductType(request.Query);
|
|
||||||
var modifier = _productQueryModifierFactory.GetModifier(productType!);
|
|
||||||
string query = request.Query;
|
|
||||||
if (modifier.TryQueryModify(query, out var modified))
|
|
||||||
{
|
|
||||||
query = modified;
|
|
||||||
}
|
|
||||||
var product = await _dbContext.Products
|
|
||||||
.Where(p => EF.Functions.ToTsVector(
|
|
||||||
"russian", string.Join(' ', new[] { p.Name, string.Join(' ', p.ProductLines) }))
|
|
||||||
.Matches(EF.Functions.WebSearchToTsQuery("russian", query)))
|
|
||||||
.OrderByDescending(p => p.IsOnWarehouse)
|
|
||||||
.FirstOrDefaultAsync();
|
|
||||||
|
|
||||||
if (product != null)
|
|
||||||
{
|
|
||||||
return new ProductReply()
|
|
||||||
{
|
|
||||||
Id = product.Id,
|
|
||||||
Name = product.Name,
|
|
||||||
Price = (double)product.Price
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -6,17 +6,5 @@
|
|||||||
"Microsoft.EntityFrameworkCore": "Information"
|
"Microsoft.EntityFrameworkCore": "Information"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*"
|
||||||
"Kestrel": {
|
|
||||||
"Endpoints": {
|
|
||||||
"Http": {
|
|
||||||
"Url": "http://0.0.0.0:5000",
|
|
||||||
"Protocols": "Http1AndHttp2"
|
|
||||||
},
|
|
||||||
"gRPC": {
|
|
||||||
"Url": "http://0.0.0.0:43000",
|
|
||||||
"Protocols": "Http2"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
@ -1,10 +1,12 @@
|
|||||||
namespace RhSolutions.QueryModifiers;
|
using Microsoft.AspNetCore.Http;
|
||||||
|
|
||||||
|
namespace RhSolutions.QueryModifiers;
|
||||||
|
|
||||||
public sealed class BypassQueryModifier : IProductQueryModifier
|
public sealed class BypassQueryModifier : IProductQueryModifier
|
||||||
{
|
{
|
||||||
public bool TryQueryModify(string query, out string queryModified)
|
public bool TryQueryModify(IQueryCollection collection, out QueryString queryString)
|
||||||
{
|
{
|
||||||
queryModified = string.Empty;
|
queryString = QueryString.Empty;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,20 +4,18 @@ namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
|
|||||||
|
|
||||||
public abstract class Adapter : DrinkingWaterHeatingFitting
|
public abstract class Adapter : DrinkingWaterHeatingFitting
|
||||||
{
|
{
|
||||||
public override bool TryQueryModify(string input, out string output)
|
protected override string? BuildRhSolutionsName(string query)
|
||||||
{
|
{
|
||||||
output = string.Empty;
|
Match diameter = _diameter.Match(query);
|
||||||
Match diameter = _diameter.Match(input);
|
|
||||||
if (!diameter.Success)
|
if (!diameter.Success)
|
||||||
{
|
{
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
Match thread = _thread.Match(input);
|
Match thread = _thread.Match(query);
|
||||||
if (!thread.Success)
|
if (!thread.Success)
|
||||||
{
|
{
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
output = $"{_title} {diameter.Groups["Diameter"]} {thread.Groups["Thread"]}";
|
return $"{_title} {diameter.Groups["Diameter"]} {thread.Groups["Thread"]}";
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,23 +2,21 @@
|
|||||||
|
|
||||||
public class BendFormerHeating : DrinkingWaterHeatingFitting
|
public class BendFormerHeating : DrinkingWaterHeatingFitting
|
||||||
{
|
{
|
||||||
protected override string _title => "Фиксатор поворота";
|
protected override string _title => "Фиксатор поворота";
|
||||||
public override bool TryQueryModify(string input, out string output)
|
protected override string? BuildRhSolutionsName(string query)
|
||||||
{
|
{
|
||||||
output = string.Empty;
|
var diameterMatch = _diameter.Match(query);
|
||||||
var diameterMatch = _diameter.Match(input);
|
if (!diameterMatch.Success)
|
||||||
if (!diameterMatch.Success)
|
{
|
||||||
{
|
return null;
|
||||||
return false;
|
}
|
||||||
}
|
string diameter = diameterMatch.Groups["Diameter"].Value;
|
||||||
string diameter = diameterMatch.Groups["Diameter"].Value;
|
if (diameter == "16")
|
||||||
if (diameter == "16")
|
{
|
||||||
{
|
diameter += "/17";
|
||||||
diameter += "/17";
|
}
|
||||||
}
|
var angleMatch = _angle.Match(query);
|
||||||
var angleMatch = _angle.Match(input);
|
string angle = angleMatch.Success ? angleMatch.Groups["Angle"].Value : "90";
|
||||||
string angle = angleMatch.Success ? angleMatch.Groups["Angle"].Value : "90";
|
return $"{_title} {diameter}/{angle}°";
|
||||||
output = $"{_title} {diameter}/{angle}°";
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -2,20 +2,17 @@ namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
|
|||||||
|
|
||||||
public class BendFormerSanitary : DrinkingWaterHeatingFitting
|
public class BendFormerSanitary : DrinkingWaterHeatingFitting
|
||||||
{
|
{
|
||||||
protected override string _title => "Фиксатор поворота с кольцами";
|
protected override string _title => "Фиксатор поворота с кольцами";
|
||||||
|
protected override string? BuildRhSolutionsName(string query)
|
||||||
public override bool TryQueryModify(string input, out string output)
|
{
|
||||||
{
|
var diameterMatch = _diameter.Match(query);
|
||||||
output = string.Empty;
|
if (!diameterMatch.Success)
|
||||||
var diameterMatch = _diameter.Match(input);
|
{
|
||||||
if (!diameterMatch.Success)
|
return null;
|
||||||
{
|
}
|
||||||
return false;
|
string diameter = diameterMatch.Groups["Diameter"].Value;
|
||||||
}
|
var angleMatch = _angle.Match(query);
|
||||||
string diameter = diameterMatch.Groups["Diameter"].Value;
|
string angle = angleMatch.Success ? angleMatch.Groups["Angle"].Value : "90";
|
||||||
var angleMatch = _angle.Match(input);
|
return $"{_title} {angle}° {diameter}";
|
||||||
string angle = angleMatch.Success ? angleMatch.Groups["Angle"].Value : "90";
|
}
|
||||||
output = $"{_title} {angle}° {diameter}";
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -9,18 +9,16 @@ public class ConnectionBend : DrinkingWaterHeatingFitting
|
|||||||
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 => "Трубка Г-образная";
|
||||||
|
|
||||||
public override bool TryQueryModify(string input, out string output)
|
protected override string? BuildRhSolutionsName(string query)
|
||||||
{
|
{
|
||||||
output = string.Empty;
|
var match = _pattern.Match(query);
|
||||||
var match = _pattern.Match(input);
|
|
||||||
if (!match.Success)
|
if (!match.Success)
|
||||||
{
|
{
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
string diameter = match.Groups["Diameter"].Value;
|
string diameter = match.Groups["Diameter"].Value;
|
||||||
int length = int.Parse(match.Groups["Length"].Value);
|
int length = int.Parse(match.Groups["Length"].Value);
|
||||||
int nearest = lengths.OrderBy(x => Math.Abs(x - length)).First();
|
int nearest = lengths.OrderBy(x => Math.Abs(x - length)).First();
|
||||||
output = $"{_title} {diameter}/{nearest}";
|
return $"{_title} {diameter}/{nearest}";
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,27 +3,24 @@ namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
|
|||||||
public class Coupling : DrinkingWaterHeatingFitting
|
public class Coupling : DrinkingWaterHeatingFitting
|
||||||
{
|
{
|
||||||
protected override string _title => "Муфта соединительная";
|
protected override string _title => "Муфта соединительная";
|
||||||
|
protected override string? BuildRhSolutionsName(string query)
|
||||||
public override bool TryQueryModify(string input, out string output)
|
|
||||||
{
|
{
|
||||||
output = string.Empty;
|
var diametersMatches = _diameter.Matches(query);
|
||||||
var diametersMatches = _diameter.Matches(input);
|
|
||||||
if (diametersMatches.Count == 0)
|
if (diametersMatches.Count == 0)
|
||||||
{
|
{
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
var diameters = diametersMatches.Select(x => x.Groups["Diameter"].Value)
|
var diameters = diametersMatches.Select(x => x.Groups["Diameter"].Value)
|
||||||
.Take(2)
|
.Take(2)
|
||||||
.OrderByDescending(x => int.Parse(x))
|
.OrderByDescending(x => int.Parse(x))
|
||||||
.ToArray();
|
.ToArray();
|
||||||
if (diameters.Length == 1 || diameters[0] == diameters[1])
|
if (diameters.Length == 1 || diameters[0] == diameters[1])
|
||||||
{
|
{
|
||||||
output = $"{_title} равнопроходная {diameters[0]}";
|
return $"{_title} равнопроходная {diameters[0]}";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
output = $"{_title} переходная {diameters[0]}-{diameters[1]}";
|
return $"{_title} переходная {diameters[0]}-{diameters[1]}";
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Http.Extensions;
|
||||||
|
|
||||||
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
|
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
|
||||||
|
|
||||||
@ -13,18 +15,34 @@ public abstract class DrinkingWaterHeatingFitting : IProductQueryModifier
|
|||||||
|
|
||||||
protected virtual string _title { get; } = string.Empty;
|
protected virtual string _title { get; } = string.Empty;
|
||||||
|
|
||||||
public virtual bool TryQueryModify(string input, out string output)
|
public bool TryQueryModify(IQueryCollection collection, out QueryString queryString)
|
||||||
{
|
{
|
||||||
var match = _diameter.Match(input);
|
queryString = QueryString.Empty;
|
||||||
if (match.Success)
|
string query = collection["query"].ToString();
|
||||||
|
if (string.IsNullOrEmpty(query))
|
||||||
{
|
{
|
||||||
output = $"{_title} {match.Groups["Diameter"]}";
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
output = string.Empty;
|
|
||||||
return false;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,20 +2,17 @@ namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
|
|||||||
|
|
||||||
public class ElbowModifier : DrinkingWaterHeatingFitting
|
public class ElbowModifier : DrinkingWaterHeatingFitting
|
||||||
{
|
{
|
||||||
protected override string _title { get; } = "Угольник RAUTITAN -PLATINUM";
|
protected override string _title { get; } = "Угольник RAUTITAN -PLATINUM";
|
||||||
|
protected override string? BuildRhSolutionsName(string query)
|
||||||
public override bool TryQueryModify(string input, out string output)
|
{
|
||||||
{
|
var diameterMatch = _diameter.Match(query);
|
||||||
output = string.Empty;
|
if (!diameterMatch.Success)
|
||||||
var diameterMatch = _diameter.Match(input);
|
{
|
||||||
if (!diameterMatch.Success)
|
return null;
|
||||||
{
|
}
|
||||||
return false;
|
string diameter = diameterMatch.Groups["Diameter"].Value;
|
||||||
}
|
var angleMatch = _angle.Match(query);
|
||||||
string diameter = diameterMatch.Groups["Diameter"].Value;
|
string angle = angleMatch.Success ? angleMatch.Groups["Angle"].Value : "90";
|
||||||
var angleMatch = _angle.Match(input);
|
return $"{_title} {angle} {diameter}";
|
||||||
string angle = angleMatch.Success ? angleMatch.Groups["Angle"].Value : "90";
|
}
|
||||||
output = $"{_title} {angle} {diameter}";
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -4,19 +4,18 @@ public abstract class Eurocone : DrinkingWaterHeatingFitting
|
|||||||
{
|
{
|
||||||
protected virtual Dictionary<string, string> _titles { get; } = new();
|
protected virtual Dictionary<string, string> _titles { get; } = new();
|
||||||
|
|
||||||
public override bool TryQueryModify(string input, out string output)
|
protected override string? BuildRhSolutionsName(string query)
|
||||||
{
|
{
|
||||||
output = string.Empty;
|
var diameterMatch = _diameter.Match(query);
|
||||||
var diameterMatch = _diameter.Match(input);
|
|
||||||
if (diameterMatch.Success)
|
if (diameterMatch.Success)
|
||||||
{
|
{
|
||||||
string diameter = diameterMatch.Groups["Diameter"].Value;
|
string diameter = diameterMatch.Groups["Diameter"].Value;
|
||||||
if (_titles.TryGetValue(diameter, out string? title))
|
if (_titles.TryGetValue(diameter, out string? title))
|
||||||
{
|
{
|
||||||
output = title;
|
return title;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
else return null;
|
||||||
}
|
}
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,17 +3,14 @@ namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
|
|||||||
public class EuroconeAdapter : DrinkingWaterHeatingFitting
|
public class EuroconeAdapter : DrinkingWaterHeatingFitting
|
||||||
{
|
{
|
||||||
protected override string _title => "Переходник на евроконус";
|
protected override string _title => "Переходник на евроконус";
|
||||||
|
protected override string? BuildRhSolutionsName(string query)
|
||||||
public override bool TryQueryModify(string input, out string output)
|
|
||||||
{
|
{
|
||||||
output = string.Empty;
|
var diameterMatch = _diameter.Match(query);
|
||||||
var diameterMatch = _diameter.Match(input);
|
|
||||||
if (diameterMatch.Success)
|
if (diameterMatch.Success)
|
||||||
{
|
{
|
||||||
string diameter = diameterMatch.Groups["Diameter"].Value;
|
string diameter = diameterMatch.Groups["Diameter"].Value;
|
||||||
output = $"{_title} {diameter}-G 3/4";
|
return $"{_title} {diameter}-G 3/4";
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,9 +2,8 @@ namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
|
|||||||
|
|
||||||
public class EuroconeConnectionBend : DrinkingWaterHeatingFitting
|
public class EuroconeConnectionBend : DrinkingWaterHeatingFitting
|
||||||
{
|
{
|
||||||
public override bool TryQueryModify(string input, out string output)
|
protected override string? BuildRhSolutionsName(string query)
|
||||||
{
|
{
|
||||||
output = "Резьбозажимное соединение для металлической трубки G 3/4 -15";
|
return "Резьбозажимное соединение для металлической трубки G 3/4 -15";
|
||||||
return true;
|
}
|
||||||
}
|
|
||||||
}
|
}
|
@ -2,9 +2,8 @@ namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
|
|||||||
|
|
||||||
public class Nippel : DrinkingWaterHeatingFitting
|
public class Nippel : DrinkingWaterHeatingFitting
|
||||||
{
|
{
|
||||||
public override bool TryQueryModify(string input, out string output)
|
protected override string? BuildRhSolutionsName(string query)
|
||||||
{
|
{
|
||||||
output = "К-т двух резьбозажим. нипелей с нар.резьбой 1/2х3/4";
|
return "К-т двух резьбозажим. нипелей с нар.резьбой 1/2х3/4";
|
||||||
return true;
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,9 @@ public class SupportingClip : DrinkingWaterHeatingFitting
|
|||||||
{
|
{
|
||||||
protected override string _title => "Фиксирующий желоб для ПЭ-трубы";
|
protected override string _title => "Фиксирующий желоб для ПЭ-трубы";
|
||||||
|
|
||||||
public override bool TryQueryModify(string input, out string output)
|
protected override string? BuildRhSolutionsName(string query)
|
||||||
{
|
{
|
||||||
output = string.Empty;
|
var diameterMatch = _diameter.Match(query);
|
||||||
var diameterMatch = _diameter.Match(input);
|
|
||||||
if (diameterMatch.Success)
|
if (diameterMatch.Success)
|
||||||
{
|
{
|
||||||
string diameter = diameterMatch.Groups["Diameter"].Value;
|
string diameter = diameterMatch.Groups["Diameter"].Value;
|
||||||
@ -15,9 +14,8 @@ public class SupportingClip : DrinkingWaterHeatingFitting
|
|||||||
{
|
{
|
||||||
diameter += "/17";
|
diameter += "/17";
|
||||||
}
|
}
|
||||||
output = $"{_title} {diameter}";
|
return $"{_title} {diameter}";
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,26 +2,24 @@
|
|||||||
|
|
||||||
public class TPiece : DrinkingWaterHeatingFitting
|
public class TPiece : DrinkingWaterHeatingFitting
|
||||||
{
|
{
|
||||||
protected override string _title => "Тройник RAUTITAN -PLATINUM";
|
protected override string _title => "Тройник RAUTITAN -PLATINUM";
|
||||||
|
|
||||||
public override bool TryQueryModify(string input, out string output)
|
protected override string? BuildRhSolutionsName(string query)
|
||||||
{
|
{
|
||||||
output = string.Empty;
|
var diameters = _diameter.Matches(query)
|
||||||
var diameters = _diameter.Matches(input)
|
.Select(match => match.Groups["Diameter"].Value)
|
||||||
.Select(match => match.Groups["Diameter"].Value)
|
.ToArray();
|
||||||
.ToArray();
|
if (diameters.Length == 1)
|
||||||
if (diameters.Length == 1)
|
{
|
||||||
{
|
return $"{_title} {diameters[0]}-{diameters[0]}-{diameters[0]}";
|
||||||
output = $"{_title} {diameters[0]}-{diameters[0]}-{diameters[0]}";
|
}
|
||||||
}
|
else if (diameters.Length >= 3)
|
||||||
else if (diameters.Length >= 3)
|
{
|
||||||
{
|
return $"{_title} {diameters[0]}-{diameters[1]}-{diameters[2]}";
|
||||||
output = $"{_title} {diameters[0]}-{diameters[1]}-{diameters[2]}";
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
return null;
|
||||||
return false;
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -7,25 +7,23 @@ public class ThreadElbowDoubleWallInternal : DrinkingWaterHeatingFitting
|
|||||||
protected override string _title => "Проточный настенный угольник";
|
protected override string _title => "Проточный настенный угольник";
|
||||||
private Regex _type = new(@"([\b\Wу])(?<Type>длин)([\b\w\.\s])");
|
private Regex _type = new(@"([\b\Wу])(?<Type>длин)([\b\w\.\s])");
|
||||||
|
|
||||||
public override bool TryQueryModify(string input, out string output)
|
protected override string? BuildRhSolutionsName(string query)
|
||||||
{
|
{
|
||||||
output = string.Empty;
|
var diameterMatches = _diameter.Matches(query);
|
||||||
var diameterMatches = _diameter.Matches(input);
|
|
||||||
if (diameterMatches.Count == 0)
|
if (diameterMatches.Count == 0)
|
||||||
{
|
{
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
var threadMatch = _thread.Match(input);
|
var threadMatch = _thread.Match(query);
|
||||||
if (!threadMatch.Success)
|
if (!threadMatch.Success)
|
||||||
{
|
{
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
var typeMatch = _type.Match(input);
|
var typeMatch = _type.Match(query);
|
||||||
string[] diameters = diameterMatches.Select(x => x.Groups["Diameter"].Value).ToArray();
|
string[] diameters = diameterMatches.Select(x => x.Groups["Diameter"].Value).ToArray();
|
||||||
string thread = threadMatch.Groups["Thread"].Value;
|
string thread = threadMatch.Groups["Thread"].Value;
|
||||||
string type = typeMatch.Success ? "длинный" : "короткий";
|
string type = typeMatch.Success ? "длинный" : "короткий";
|
||||||
|
|
||||||
output = $"{_title} {diameters[0]}/{(diameters.Length > 1 ? diameters[1] : diameters[0])}-Rp {thread} {type}";
|
return $"{_title} {diameters[0]}/{(diameters.Length > 1 ? diameters[1] : diameters[0])}-Rp {thread} {type}";
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,23 +3,20 @@ namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
|
|||||||
public class ThreadElbowWallExternal : DrinkingWaterHeatingFitting
|
public class ThreadElbowWallExternal : DrinkingWaterHeatingFitting
|
||||||
{
|
{
|
||||||
protected override string _title => "Угольник настенный с наружной резьбой";
|
protected override string _title => "Угольник настенный с наружной резьбой";
|
||||||
|
protected override string? BuildRhSolutionsName(string query)
|
||||||
public override bool TryQueryModify(string input, out string output)
|
|
||||||
{
|
{
|
||||||
output = string.Empty;
|
var diameterMatch = _diameter.Match(query);
|
||||||
var diameterMatch = _diameter.Match(input);
|
|
||||||
if (!diameterMatch.Success)
|
if (!diameterMatch.Success)
|
||||||
{
|
{
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
var threadMatch = _thread.Match(input);
|
var threadMatch = _thread.Match(query);
|
||||||
if (!threadMatch.Success)
|
if (!threadMatch.Success)
|
||||||
{
|
{
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
string diameter = diameterMatch.Groups["Diameter"].Value;
|
string diameter = diameterMatch.Groups["Diameter"].Value;
|
||||||
string thread = threadMatch.Groups["Thread"].Value;
|
string thread = threadMatch.Groups["Thread"].Value;
|
||||||
output = $"{_title} {diameter}-R {thread}";
|
return $"{_title} {diameter}-R {thread}";
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,24 +6,21 @@ public class ThreadElbowWallInternal : DrinkingWaterHeatingFitting
|
|||||||
{
|
{
|
||||||
protected override string _title => "Угольник настенный внутр. резьба";
|
protected override string _title => "Угольник настенный внутр. резьба";
|
||||||
private Regex _type = new(@"([\b\Wу])(?<Type>длин)([\b\w\.\s])");
|
private Regex _type = new(@"([\b\Wу])(?<Type>длин)([\b\w\.\s])");
|
||||||
|
protected override string? BuildRhSolutionsName(string query)
|
||||||
public override bool TryQueryModify(string input, out string output)
|
{
|
||||||
{
|
var diameterMatch = _diameter.Match(query);
|
||||||
output = string.Empty;
|
|
||||||
var diameterMatch = _diameter.Match(input);
|
|
||||||
if (!diameterMatch.Success)
|
if (!diameterMatch.Success)
|
||||||
{
|
{
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
var threadMatch = _thread.Match(input);
|
var threadMatch = _thread.Match(query);
|
||||||
if (!threadMatch.Success)
|
if (!threadMatch.Success)
|
||||||
{
|
{
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
var typeMatch = _type.Match(input);
|
var typeMatch = _type.Match(query);
|
||||||
string diameter = diameterMatch.Groups["Diameter"].Value;
|
string diameter = diameterMatch.Groups["Diameter"].Value;
|
||||||
string thread = threadMatch.Groups["Thread"].Value;
|
string thread = threadMatch.Groups["Thread"].Value;
|
||||||
output = $"{_title} {(typeMatch.Success ? "длинный " : string.Empty)}{diameter}-Rp {thread}";
|
return $"{_title} {(typeMatch.Success ? "длинный " : string.Empty)}{diameter}-Rp {thread}";
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,26 +4,23 @@ namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
|
|||||||
|
|
||||||
public class ThreadTPieceExternal : DrinkingWaterHeatingFitting
|
public class ThreadTPieceExternal : DrinkingWaterHeatingFitting
|
||||||
{
|
{
|
||||||
protected override string _title => "Тройник RAUTITAN с наружной резьбой";
|
protected override string _title => "Тройник RAUTITAN с наружной резьбой";
|
||||||
|
protected override string? BuildRhSolutionsName(string query)
|
||||||
public override bool TryQueryModify(string input, out string output)
|
{
|
||||||
{
|
MatchCollection diametersMatches = _diameter.Matches(query);
|
||||||
output = string.Empty;
|
if (diametersMatches.Count == 0)
|
||||||
MatchCollection diametersMatches = _diameter.Matches(input);
|
{
|
||||||
if (diametersMatches.Count == 0)
|
return null;
|
||||||
{
|
}
|
||||||
return false;
|
string thread = _thread.Match(query).Groups["Thread"].Value;
|
||||||
}
|
int[] diameters = diametersMatches.Select(match => int.Parse(match.Groups["Diameter"].Value)).ToArray();
|
||||||
string thread = _thread.Match(input).Groups["Thread"].Value;
|
if (diameters.Length == 1)
|
||||||
int[] diameters = diametersMatches.Select(match => int.Parse(match.Groups["Diameter"].Value)).ToArray();
|
{
|
||||||
if (diameters.Length == 1)
|
return $"{_title} {diameters[0]}-{diameters[0]}-R {thread}";
|
||||||
{
|
}
|
||||||
output = $"{_title} {diameters[0]}-{diameters[0]}-R {thread}";
|
else
|
||||||
}
|
{
|
||||||
else
|
return $"{_title} {diameters[0]}-{diameters[1]}-R {thread}";
|
||||||
{
|
}
|
||||||
output = $"{_title} {diameters[0]}-{diameters[1]}-R {thread}";
|
}
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -4,38 +4,36 @@ namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingFittings;
|
|||||||
|
|
||||||
public class ThreadTPieceInternal : DrinkingWaterHeatingFitting
|
public class ThreadTPieceInternal : DrinkingWaterHeatingFitting
|
||||||
{
|
{
|
||||||
public override bool TryQueryModify(string input, out string output)
|
protected override string? BuildRhSolutionsName(string query)
|
||||||
{
|
{
|
||||||
output = string.Empty;
|
MatchCollection diametersMatches = _diameter.Matches(query);
|
||||||
MatchCollection diametersMatches = _diameter.Matches(input);
|
if (diametersMatches.Count == 0)
|
||||||
if (diametersMatches.Count == 0)
|
{
|
||||||
{
|
return null;
|
||||||
return false;
|
}
|
||||||
}
|
string thread = _thread.Match(query).Groups["Thread"].Value;
|
||||||
string thread = _thread.Match(input).Groups["Thread"].Value;
|
int[] diameters = diametersMatches.Select(match => int.Parse(match.Groups["Diameter"].Value)).ToArray();
|
||||||
int[] diameters = diametersMatches.Select(match => int.Parse(match.Groups["Diameter"].Value)).ToArray();
|
if (diameters.Length == 1)
|
||||||
if (diameters.Length == 1)
|
{
|
||||||
{
|
if (diameters[0] < 25)
|
||||||
if (diameters[0] < 25)
|
{
|
||||||
{
|
return $"Тройник RAUTITAN настенный с внутренней резьбой {diameters[0]}-Rp{thread}-{diameters[0]}";
|
||||||
output = $"Тройник RAUTITAN настенный с внутренней резьбой {diameters[0]}-Rp{thread}-{diameters[0]}";
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
return $"Тройник RAUTITAN с внутр. резьбой на боков. проходе {diameters[0]}-Rp {thread}-{diameters[0]}";
|
||||||
output = $"Тройник RAUTITAN с внутр. резьбой на боков. проходе {diameters[0]}-Rp {thread}-{diameters[0]}";
|
}
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
if (diameters[0] < 25)
|
||||||
if (diameters[0] < 25)
|
{
|
||||||
{
|
return $"Тройник RAUTITAN настенный с внутренней резьбой {diameters[0]}-Rp{thread}-{diameters[1]}";
|
||||||
output = $"Тройник RAUTITAN настенный с внутренней резьбой {diameters[0]}-Rp{thread}-{diameters[1]}";
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
return $"Тройник RAUTITAN с внутр. резьбой на боков. проходе {diameters[0]}-Rp {thread}-{diameters[1]}";
|
||||||
output = $"Тройник RAUTITAN с внутр. резьбой на боков. проходе {diameters[0]}-Rp {thread}-{diameters[1]}";
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,56 +1,77 @@
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Http.Extensions;
|
||||||
|
|
||||||
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingPipes;
|
namespace RhSolutions.QueryModifiers.DrinkingWaterHeatingPipes;
|
||||||
|
|
||||||
public class DrinkingWaterHeatingPipe : IProductQueryModifier
|
public class DrinkingWaterHeatingPipe : IProductQueryModifier
|
||||||
{
|
{
|
||||||
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]|$)");
|
||||||
protected static readonly Regex _type =
|
protected static readonly Regex _type =
|
||||||
new(@"([\b\W])(?<Type>бухт|отр|штанг)([\b\w\.\s])");
|
new(@"([\b\W])(?<Type>бухт|отр|штанг)([\b\w\.\s])");
|
||||||
protected virtual string _title { get; } = string.Empty;
|
protected virtual string _title { get; } = string.Empty;
|
||||||
|
|
||||||
protected virtual Dictionary<int, string> _diameterNames { get; } = new()
|
protected virtual Dictionary<int, string> _diameterNames { get; } = new()
|
||||||
{
|
{
|
||||||
[16] = "16x2,2",
|
[16] = "16x2,2",
|
||||||
[20] = "20x2,8",
|
[20] = "20x2,8",
|
||||||
[25] = "25x3,5",
|
[25] = "25x3,5",
|
||||||
[32] = "32x4,4",
|
[32] = "32x4,4",
|
||||||
[40] = "40x5,5",
|
[40] = "40x5,5",
|
||||||
[50] = "50x6,9",
|
[50] = "50x6,9",
|
||||||
[63] = "63x8,6"
|
[63] = "63x8,6"
|
||||||
};
|
};
|
||||||
|
|
||||||
protected virtual Dictionary<string, string> _makeUp { get; } = new()
|
protected virtual Dictionary<string, string> _makeUp { get; } = new()
|
||||||
{
|
{
|
||||||
["бухт"] = "бухта",
|
["бухт"] = "бухта",
|
||||||
["штанг"] = "прям.отрезки",
|
["штанг"] = "прям.отрезки",
|
||||||
["отр"] = "прям.отрезки"
|
["отр"] = "прям.отрезки"
|
||||||
};
|
};
|
||||||
|
|
||||||
public bool TryQueryModify(string input, out string output)
|
public bool TryQueryModify(IQueryCollection collection, out QueryString queryString)
|
||||||
{
|
{
|
||||||
output = string.Empty;
|
queryString = QueryString.Empty;
|
||||||
var diameterMatch = _diameter.Match(input);
|
string query = collection["query"].ToString();
|
||||||
if (!diameterMatch.Success)
|
if (string.IsNullOrEmpty(query))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var diameter = int.Parse(diameterMatch.Groups["Diameter"].Value);
|
string? result = BuildRhSolutionsName(query);
|
||||||
var typeMatch = _type.Match(input);
|
if (result != null)
|
||||||
if (typeMatch.Success)
|
{
|
||||||
{
|
QueryBuilder qb = new()
|
||||||
var type = typeMatch.Groups["Type"].Value;
|
{
|
||||||
output = $"Труба {_title} {_diameterNames[diameter]} {_makeUp[type]}";
|
{ "query", result }
|
||||||
}
|
};
|
||||||
else if (diameter < 32)
|
queryString = qb.ToQueryString();
|
||||||
{
|
return true;
|
||||||
output = $"Труба {_title} {_diameterNames[diameter]} {_makeUp["бухт"]}";
|
}
|
||||||
}
|
return false;
|
||||||
else
|
}
|
||||||
{
|
|
||||||
output = $"Труба {_title} {_diameterNames[diameter]} {_makeUp["отр"]}";
|
protected virtual string? BuildRhSolutionsName(string query)
|
||||||
}
|
{
|
||||||
return true;
|
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["отр"]}";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
namespace RhSolutions.QueryModifiers;
|
using Microsoft.AspNetCore.Http;
|
||||||
|
|
||||||
|
namespace RhSolutions.QueryModifiers;
|
||||||
|
|
||||||
public interface IProductQueryModifier
|
public interface IProductQueryModifier
|
||||||
{
|
{
|
||||||
public bool TryQueryModify(string query, out string queryModified);
|
public bool TryQueryModify(IQueryCollection collection, out QueryString queryString);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user