Smart rounding was ajusted

This commit is contained in:
Evgeny Redikultsev
2024-06-02 16:56:44 +05:00
parent 99d5aa3608
commit 31d668b996
58 changed files with 716 additions and 274 deletions

View File

@@ -0,0 +1,7 @@
namespace StructureHelperCommon.Models.Parameters
{
public interface IProcessValuePairLogic<T>
{
ValuePair<T> GetValuePairByString(string s);
}
}

View File

@@ -0,0 +1,12 @@
namespace StructureHelperCommon.Models.Parameters
{
/// <summary>
/// Represent pair of value with text
/// </summary>
/// <typeparam name="T"></typeparam>
public interface IValuePair<T>
{
string Text { get; set; }
T Value { get; set; }
}
}

View File

@@ -7,14 +7,12 @@ using System.Windows.Media;
namespace StructureHelperCommon.Models.Parameters
{
public interface IValueParameter<T>
public interface IValueParameter<T> : IValuePair<T>
{
bool IsValid { get; set; }
string Name { get; set; }
string ShortName { get; set; }
Color Color { get; set; }
string MeasurementUnit { get; set; }
T Value { get; set; }
string Description { get; set; }
}
}

View File

@@ -0,0 +1,65 @@
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Services.Units;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Media.Media3D;
namespace StructureHelperCommon.Models.Parameters
{
public enum DigitPlace
{
Start,
Any
}
public class ProcessDoublePairLogic : IProcessValuePairLogic<double>
{
const string digitalPattern = @"^[-]?[+]?\d*\.?\,?\d*";
const string allowedPattern = @"[0-9]|\.|\,";
const string characterPattern = "[a-z]+$";
const string target = "";
public DigitPlace DigitPlace { get; set; } = DigitPlace.Start;
public ValuePair<double> GetValuePairByString(string s)
{
s = s.Replace(" ", string.Empty);
Regex regexText = new (allowedPattern);
string textString = regexText.Replace(s, target);
var textMatch = Regex.Match(textString, characterPattern, RegexOptions.IgnoreCase);
if (textMatch.Success == true)
{
textString = textMatch.Value.ToLower();
}
var digitalOnlyString = DigitPlace == DigitPlace.Start ? s : s.ToLower().Replace(textString, string.Empty);
var match = Regex.Match(digitalOnlyString, digitalPattern);
if (match.Success == true)
{
return GetDoubleValue(textString, match);
}
throw new StructureHelperException(ErrorStrings.DataIsInCorrect);
}
private static ValuePair<double> GetDoubleValue(string textString, Match match)
{
string digitalString = match.Value;
if (digitalString != string.Empty || digitalString != "")
{
double digit = ProcessString.ConvertCommaToCultureSettings(digitalString);
return new ValuePair<double>()
{
Value = digit,
Text = textString
};
}
else
{
throw new StructureHelperException(ErrorStrings.DataIsInCorrect + ": value does not contain digital simbols");
}
}
}
}

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelperCommon.Models.Parameters
{
/// <inheritdoc/>
public class ValuePair<T> : IValuePair<T>
{
public string Text { get; set; }
public T Value { get; set; }
}
}

View File

@@ -13,7 +13,7 @@ namespace StructureHelperCommon.Models.Parameters
public string Name { get; set; }
public string ShortName { get; set; }
public Color Color { get; set; }
public string MeasurementUnit { get; set; }
public string Text { get; set; }
public T Value { get; set; }
public string Description { get; set; }
}