This commit is contained in:
2026-04-17 14:55:32 -04:00
commit bc3ac1d4c9
18017 changed files with 4371742 additions and 0 deletions

View File

@@ -0,0 +1,91 @@
using System;
namespace DatabaseImport
{
/// <summary>
/// the scaler is a bit different than an ordinary scaler, so the name here is inaccurate, however the idea is
/// that we allow the user to transform collected data, primarly by allowing them to define the 0,1 value of the digital output
/// </summary>
public class DigitalInputScaleMultiplier
{
/// <summary>
/// the format the scaler is in
/// </summary>
public enum Forms { ArbitraryLowAndHigh };
public Forms Form { get; set; } = Forms.ArbitraryLowAndHigh;
/// <summary>
/// for arbirary low/high, this is the low value, the value 0 should be displayed as (OFF)
/// </summary>
public double DefaultValue { get; set; }
/// <summary>
/// for arbitrary low/high, this is the high value, the value 1 should be displayed as (ON)
/// </summary>
public double ActiveValue { get; set; } = 1D;
/// <summary>
/// constructor and copy constructor
/// </summary>
public DigitalInputScaleMultiplier()
{
DefaultValue = 0D;
}
public DigitalInputScaleMultiplier(DigitalInputScaleMultiplier copy)
{
Form = copy.Form;
DefaultValue = copy.DefaultValue;
ActiveValue = copy.ActiveValue;
}
/// <summary>
/// deserializes an arbitrary low/high from a string
/// </summary>
/// <param name="tokens"></param>
private void FromDbSerializeStringLowAndHigh(string[] tokens)
{
if (tokens.Length < 3) { throw new NotSupportedException("DigitalInputScaleMultiplier::FromDbSerializeStringLowAndHigh invalid format for scale multiplier"); }
double d;
if (double.TryParse(tokens[1], System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out d))
{
DefaultValue = d;
}
else { throw new NotSupportedException("DigitalInputScaleMultiplier::FromDbSerializeStringLowAndHigh invalid format for low value: " + tokens[1]); }
if (double.TryParse(tokens[2], System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out d))
{
ActiveValue = d;
}
else { throw new NotSupportedException("DigitalInputScaleMultiplier::FromDbSerializeStringLowAndHigh invalid format for high value: " + tokens[2]); }
}
/// <summary>
/// deserializes a scaler from a string, regardless of format
/// </summary>
/// <param name="s"></param>
public void FromDbSerializeString(string s)
{
if (null == s)
{
//Utilities.Logging.APILogger.Log("Unable to serialize Db. String is null.");
//FIXME is this the right thing to do?
return;
//throw new NotSupportedException("DigitalINputScaleMultiplier::FromDbSerializeString nothing to parse");
}
var tokens = s.Split(new[] { System.Globalization.CultureInfo.InvariantCulture.TextInfo.ListSeparator }, StringSplitOptions.None);
if (Enum.TryParse(tokens[0], out Forms form))
{
Form = form;
switch (form)
{
case Forms.ArbitraryLowAndHigh: FromDbSerializeStringLowAndHigh(tokens); break;
default: throw new NotSupportedException("DigitalInputScaleMultiplier::FromDbSerializeString unsupported form " + form);
}
}
else { throw new NotSupportedException("DigitalINputScaleMultiplier::FromDbSerializeString unsupported format: " + s); }
}
}
}