Geometry property results have been added
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Infrastructures.Settings
|
||||
{
|
||||
public class CrossSectionAxisNames
|
||||
{
|
||||
public string FirstAxis => "x";
|
||||
public string SecondAxis => "y";
|
||||
public string ThirdAxis => "z";
|
||||
}}
|
||||
@@ -1,9 +1,11 @@
|
||||
using StructureHelperCommon.Infrastructures.Enums;
|
||||
using System.Windows.Navigation;
|
||||
|
||||
namespace StructureHelperCommon.Infrastructures.Settings
|
||||
{
|
||||
public static class ProgramSetting
|
||||
{
|
||||
public static CodeTypes CodeType => CodeTypes.SP63_13330_2018;
|
||||
public static CrossSectionAxisNames CrossSectionAxisNames => new CrossSectionAxisNames();
|
||||
}
|
||||
}
|
||||
|
||||
18
StructureHelperCommon/Models/Parameters/ITextParameter.cs
Normal file
18
StructureHelperCommon/Models/Parameters/ITextParameter.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Parameters
|
||||
{
|
||||
public interface ITextParameter
|
||||
{
|
||||
bool IsValid { get; set; }
|
||||
string Name { get; set; }
|
||||
string ShortName { get; set; }
|
||||
string MeasurementUnit { get; set; }
|
||||
double Value { get; set; }
|
||||
string Description { get; set; }
|
||||
}
|
||||
}
|
||||
18
StructureHelperCommon/Models/Parameters/TextParameter.cs
Normal file
18
StructureHelperCommon/Models/Parameters/TextParameter.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Models.Parameters
|
||||
{
|
||||
public class TextParameter : ITextParameter
|
||||
{
|
||||
public bool IsValid { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string ShortName { get; set; }
|
||||
public string MeasurementUnit { get; set; }
|
||||
public double Value { get; set; }
|
||||
public string Description { get; set; }
|
||||
}
|
||||
}
|
||||
96
StructureHelperCommon/Services/Units/CommonOperation.cs
Normal file
96
StructureHelperCommon/Services/Units/CommonOperation.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using StructureHelperCommon.Infrastructures.Enums;
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Strings;
|
||||
using StructureHelperCommon.Services.Units;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace StructureHelperCommon.Services.Units
|
||||
{
|
||||
public static class CommonOperation
|
||||
{
|
||||
private static IEnumerable<IUnit> units = UnitsFactory.GetUnitCollection();
|
||||
|
||||
public static double ConvertToDoubleChangeComma(string s)
|
||||
{
|
||||
double result;
|
||||
if (!double.TryParse(s, NumberStyles.Any, CultureInfo.CurrentCulture, out result) &&
|
||||
!double.TryParse(s, NumberStyles.Any, CultureInfo.GetCultureInfo("en-US"), out result) &&
|
||||
!double.TryParse(s, NumberStyles.Any, CultureInfo.InvariantCulture, out result))
|
||||
{
|
||||
throw new StructureHelperException($"{ErrorStrings.IncorrectValue}: {s}");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static IStringDoublePair DivideIntoStringDoublePair(string s)
|
||||
{
|
||||
s = s.Replace(" ", "");
|
||||
string digitPattern = @"^[-]?[+]?\d+(\.?|\,?)\d*";
|
||||
string textPattern = @"[0-9]|\.|\,";
|
||||
string caracterPattern = "[a-z]+$";
|
||||
string target = "";
|
||||
Regex regexText = new Regex(textPattern);
|
||||
string textString = regexText.Replace(s, target);
|
||||
var textMatch = Regex.Match(textString, caracterPattern, RegexOptions.IgnoreCase);
|
||||
if (textMatch.Success) {textString = textMatch.Value.ToLower();}
|
||||
var match = Regex.Match(s, digitPattern);
|
||||
if (match.Success)
|
||||
{
|
||||
string digitString = match.Value;
|
||||
double digit = ConvertToDoubleChangeComma(digitString);
|
||||
return new StringDoublePair() { Digit = digit, Text = textString };
|
||||
}
|
||||
throw new StructureHelperException(ErrorStrings.DataIsInCorrect);
|
||||
}
|
||||
|
||||
public static IUnit GetUnit(UnitTypes unitType, string unitName)
|
||||
{
|
||||
return units.Where(u => u.UnitType == unitType & u.Name == unitName).Single();
|
||||
}
|
||||
|
||||
public static string Convert(IUnit unit, string unitName, object value)
|
||||
{
|
||||
double val;
|
||||
if (value != null) { val = (double)value; }
|
||||
else { throw new Exception($"{unitName} value is null"); }
|
||||
val *= unit.Multiplyer;
|
||||
string strValue = $"{val} {unit.Name}";
|
||||
return strValue;
|
||||
}
|
||||
|
||||
public static double ConvertBack(UnitTypes unitType, IUnit unit, object value)
|
||||
{
|
||||
double val;
|
||||
double multy;
|
||||
double coefficient = unit.Multiplyer;
|
||||
var strVal = value as string;
|
||||
IStringDoublePair pair = DivideIntoStringDoublePair(strVal);
|
||||
try
|
||||
{
|
||||
multy = GetMultiplyer(unitType, pair.Text);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
multy = coefficient;
|
||||
}
|
||||
val = pair.Digit / multy;
|
||||
return val;
|
||||
}
|
||||
|
||||
private static double GetMultiplyer(UnitTypes unitType, string unitName)
|
||||
{
|
||||
try
|
||||
{
|
||||
return units.Where(u => u.UnitType == unitType & u.Name == unitName).Single().Multiplyer;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new StructureHelperException(ErrorStrings.DataIsInCorrect + ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
14
StructureHelperCommon/Services/Units/IStringDoublePair.cs
Normal file
14
StructureHelperCommon/Services/Units/IStringDoublePair.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Services.Units
|
||||
{
|
||||
public interface IStringDoublePair
|
||||
{
|
||||
double Digit { get; }
|
||||
string Text { get; }
|
||||
}
|
||||
}
|
||||
14
StructureHelperCommon/Services/Units/StringDoublePair.cs
Normal file
14
StructureHelperCommon/Services/Units/StringDoublePair.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Services.Units
|
||||
{
|
||||
internal class StringDoublePair : IStringDoublePair
|
||||
{
|
||||
public double Digit { get; set; }
|
||||
public string Text { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user