init
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
using System;
|
||||
|
||||
namespace DatabaseImport
|
||||
{
|
||||
/// <summary>
|
||||
/// InitialOffset is the replacement for InitialEU
|
||||
/// it encompasses the old InitialOffset specified in EU with a method of specifying it in mV @EU
|
||||
/// Initial EU is a post data collection adjustment to engineering units recorded
|
||||
/// </summary>
|
||||
public class InitialOffset
|
||||
{
|
||||
/// <summary>
|
||||
/// copy constructor
|
||||
/// </summary>
|
||||
/// <param name="copy"></param>
|
||||
public InitialOffset(InitialOffset copy)
|
||||
{
|
||||
if (null == copy) { return; }
|
||||
EU = copy.EU;
|
||||
MV = copy.MV;
|
||||
Form = copy.Form;
|
||||
}
|
||||
/// <summary>
|
||||
/// default constructor
|
||||
/// </summary>
|
||||
public InitialOffset()
|
||||
{
|
||||
Form = Forms.None;
|
||||
EU = 0D;
|
||||
MV = 0D;
|
||||
}
|
||||
/// <summary>
|
||||
/// constructor for the old format Initial EU (a single double represting offset in EU)
|
||||
/// </summary>
|
||||
/// <param name="d"></param>
|
||||
public InitialOffset(double d)
|
||||
{
|
||||
Form = Forms.EU;
|
||||
EU = d;
|
||||
MV = 0D;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// deserializes from a string suitable for db storage
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
public void FromDbSerializeString(string input)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(input))
|
||||
{
|
||||
Form = Forms.None;
|
||||
EU = 0;
|
||||
MV = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
var tokens = input.Split(new string[] { System.Globalization.CultureInfo.InvariantCulture.TextInfo.ListSeparator }, StringSplitOptions.None);
|
||||
|
||||
Forms form;
|
||||
|
||||
if (Enum.TryParse(tokens[0], out form))
|
||||
{
|
||||
Form = form;
|
||||
if (tokens.Length < 3)
|
||||
{
|
||||
throw new System.IO.InvalidDataException("Invalid InitialOffset number of parameters: " + input);
|
||||
}
|
||||
if (double.TryParse(tokens[1], System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out var d))
|
||||
{
|
||||
EU = d;
|
||||
}
|
||||
else { throw new FormatException("Invalid InitialOffset EU format: " + tokens[1]); }
|
||||
if (double.TryParse(tokens[2], System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out d))
|
||||
{
|
||||
MV = d;
|
||||
}
|
||||
else { throw new FormatException("Invalid InitialOffset MV format: " + tokens[2]); }
|
||||
}
|
||||
else { throw new System.IO.InvalidDataException("Invalid InitialOffset form: " + tokens[0]); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// the format Initial Offset is in
|
||||
/// </summary>
|
||||
public enum Forms
|
||||
{
|
||||
None = 0,
|
||||
EU = 1,
|
||||
EUAtMV = 2
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// the format this intial offset instance is in
|
||||
/// </summary>
|
||||
public Forms Form { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// EU value. In the case of Form == EU, this is the offset in EU
|
||||
/// In. the form of EU@mV, this is the EU@mV value, and offset in EU still needs to be calculated
|
||||
/// GetInitialEUValue calculates the offset in eu
|
||||
/// this value is not used for InitialOffset format None
|
||||
/// </summary>
|
||||
public double EU { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// mV value, only applies for the format EU@mV
|
||||
/// this is the value in mV that The value in EU is observed at by a calibrated instrument
|
||||
/// </summary>
|
||||
public double MV { get; set; } = 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user