RhSolutions-AddIn/Source/Assistant/RequestModifier.cs

64 lines
1.9 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
2021-12-08 13:58:37 +03:00
namespace RehauSku.Assist
{
public static class RequestModifier
{
public static string CleanRequest(this string input)
{
string replace = new StringBuilder(input)
.Replace("+", " plus ")
.Replace("РХ", "")
.Replace("º", " ")
.Replace(".", " ")
.Replace("Ø", " ")
.ToString();
2021-12-08 12:03:33 +03:00
return replace._tPieceNormalize();
}
2021-12-08 12:03:33 +03:00
private static string _tPieceNormalize(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 12:03:33 +03:00
int side = int.Parse($"{match[3]}{match[4]}");
int[] endFaces = new int[]
{
int.Parse($"{match[0]}{match[1]}"),
int.Parse($"{match[6]}{match[7]}")
};
List<string> additions = new List<string>();
if (endFaces.All(x => x < side))
additions.Add("увеличенный боковой");
else
{
2021-12-08 12:03:33 +03:00
if (new[] { endFaces[0], endFaces[1], 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
2021-12-08 12:03:33 +03:00
if (endFaces[0] != endFaces[1])
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);
}
}
}