Smart rounding was ajusted
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
namespace StructureHelperCommon.Models.Parameters
|
||||
{
|
||||
public interface IProcessValuePairLogic<T>
|
||||
{
|
||||
ValuePair<T> GetValuePairByString(string s);
|
||||
}
|
||||
}
|
||||
12
StructureHelperCommon/Models/Parameters/IValuePair.cs
Normal file
12
StructureHelperCommon/Models/Parameters/IValuePair.cs
Normal 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; }
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
15
StructureHelperCommon/Models/Parameters/ValuePair.cs
Normal file
15
StructureHelperCommon/Models/Parameters/ValuePair.cs
Normal 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; }
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user