RhSolutions-AddIn/Source/Assistant/RequestModifier.cs

63 lines
1.9 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace Rehau.Sku.Assist
{
public static class RequestModifier
{
public static string CleanRequest(this string input)
{
string replace = new StringBuilder(input)
.Replace("+", " plus ")
.Replace("РХ", "")
.Replace("º", " ")
.Replace(".", " ")
.Replace("Ø", " ")
.ToString();
return replace._tPiece();
}
private static string _tPiece(this string line)
{
2021-12-08 10:38:58 +03:00
Regex regex = new Regex(@"\d{2}.\d{2}.\d{2}");
if (!regex.IsMatch(line))
return line;
2021-12-08 10:38:58 +03:00
string match = regex.Match(line).Value;
2021-12-08 10:38:58 +03:00
int endFaceA = int.Parse($"{match[0]}{match[1]}"),
side = int.Parse($"{match[3]}{match[4]}"),
endFaceB = int.Parse($"{match[6]}{match[7]}");
int[] endFaces = new[] { endFaceA, endFaceB };
List<string> additions = new List<string>();
if (endFaces.All(x => x < side))
additions.Add("увеличенный боковой");
else
{
if (new[] { endFaceA, endFaceB, side }.Distinct().Count() == 1)
additions.Add("равнопроходной");
else
additions.Add("уменьшенный");
if (endFaces.Any(x => x > side))
additions.Add("боковой");
2021-12-08 10:38:58 +03:00
if (endFaceA != endFaceB)
additions.Add("торцевой");
}
string piece = $" {endFaces.Max()}-{side}-{endFaces.Min()} ";
2021-12-08 10:38:58 +03:00
string modifiedMatch = string.Join(" ", additions) + piece;
2021-12-08 10:38:58 +03:00
return line.Replace(match, modifiedMatch);
}
}
}