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,7 @@
using DTS.Common.Base;
// ReSharper disable CheckNamespace
namespace DTS.Common.Interface
{
public interface IAddCalculatedChannelView : IBaseView { }
}

View File

@@ -0,0 +1,38 @@
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace DTS.Common.Utils
{
/// <summary>
/// this class holds PNG image functions
/// </summary>
public static class PNGImageUtil
{
/// <summary>
/// renders the given element as a png to the given filepath
/// </summary>
/// <param name="view"></param>
/// <param name="fileName"></param>
public static void SaveImage(FrameworkElement view, string fileName)
{
var size = new Size(view.ActualWidth, view.ActualHeight);
var rtb = new RenderTargetBitmap((int)size.Width, (int)size.Height, 96, 96, PixelFormats.Pbgra32);
var visual = new DrawingVisual();
using (var context = visual.RenderOpen())
{
context.DrawRectangle(new VisualBrush(view), null, new Rect(new Point(), size));
context.Close();
}
rtb.Render(visual);
var encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(rtb));
using (var stream = new System.IO.FileStream(fileName, System.IO.FileMode.CreateNew))
{
encoder.Save(stream);
}
}
}
}

View File

@@ -0,0 +1,304 @@
using System;
using System.Text;
using System.Xml.Linq;
using System.ComponentModel;
using DTS.Common.Utilities.Logging;
using DTS.Common.Enums.Sensors;
using DTS.Common.Interface.Sensors;
using System.Collections.Generic;
namespace DTS.Common.Classes.Sensors
{
public class ZeroMethod : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected bool SetProperty<T>(ref T storage, T value, String propertyName = null)
{
if (Equals(storage, value)) return false;
storage = value;
OnPropertyChanged(propertyName);
return true;
}
protected void OnPropertyChanged(string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public override int GetHashCode()
{
return Method.GetHashCode() + Start.GetHashCode() + End.GetHashCode();
}
public ZeroMethodType Method { get; set; } = SensorConstants.DefaultZeroMethodType; // FB12764: Belt-and-suspenders, fetch default from SensorConstants
public double Start { get; set; } = SensorConstants.DefaultZeroMethodStart; // FB12764: Belt-and-suspenders, fetch default from SensorConstants
public double End { get; set; } = SensorConstants.DefaultZeroMethodEnd; // FB12764: Belt-and-suspenders, fetch default from SensorConstants
#region Tags
internal const string ZERO_METHOD_TAG = "ZeroMethod";
internal const string METHOD_TAG = "Method";
internal const string START_TAG = "Start";
internal const string END_TAG = "End";
#endregion
public ZeroMethod(ZeroMethodType zm, double start, double end)
{
Method = zm;
Start = start;
End = end;
}
public ZeroMethod(string zm, System.Globalization.CultureInfo culture)
{
Initialize(zm, culture);
}
public ZeroMethod(string zm)
{
Initialize(zm, System.Globalization.CultureInfo.InvariantCulture);
}
/// <summary>
/// do a deep copy
/// </summary>
/// <param name="copy"></param>
public ZeroMethod(ZeroMethod copy)
{
Method = copy.Method;
Start = copy.Start;
End = copy.End;
}
private void Initialize(string zm, System.Globalization.CultureInfo culture)
{
var tokens = zm.Split(',');
if (tokens.Length < 3) { return; }
Start = Convert.ToDouble(tokens[1], culture);
End = Convert.ToDouble(tokens[2], culture);
if (tokens[0].Contains("PreCalZero"))
{
Method = ZeroMethodType.UsePreEventDiagnosticsZero;
}
else
{
Method = (ZeroMethodType)
Enum.Parse(typeof(ZeroMethodType), tokens[0]);
}
}
public string ToDbString()
{
return $"{Method.ToString()},{Start},{End}";
}
private readonly string _tableName;
public ZeroMethod(XElement elem, string prefix, string tblName, string id)
{
_tableName = tblName;
XElement inner;
try
{
inner = elem.Element(mkTag(prefix));
}
catch (ArgumentNullException)
{
if (!string.IsNullOrEmpty(id))
{
throw new Exception($"{_tableName}: Can't find tag {prefix + "-" + ZERO_METHOD_TAG} for entry {id}");
}
throw new Exception($"{_tableName}: Can't find tag {prefix + "-" + ZERO_METHOD_TAG} in file");
}
try
{
// this is a special case to remain compatible with older TDM
// I moved this to avoid the exception
// 6/8/2010 - dtm
if (inner.Value == "UsePreCalZero")
{
Method = ZeroMethodType.UsePreEventDiagnosticsZero;
}
else if (inner.Value == ZeroMethodType.UsePreEventDiagnosticsZero.ToString())
{
inner.Value = "UsePreCalZero";
Method = ZeroMethodType.UsePreEventDiagnosticsZero;
}
else
{
Method = (ZeroMethodType)Enum.Parse(typeof(ZeroMethodType), inner.Value);
}
}
catch (ArgumentException ex)
{
APILogger.Log(ex);
throw;
}
Start = double.Parse(inner.Attribute(START_TAG).Value, System.Globalization.CultureInfo.InvariantCulture);
End = double.Parse(inner.Attribute(END_TAG).Value, System.Globalization.CultureInfo.InvariantCulture);
}
internal XElement ToXElement(string prefix)
{
string value;
switch (Method)
{
case ZeroMethodType.UsePreEventDiagnosticsZero:
value = "UsePreCalZero";
break;
default:
value = Method.ToString();
break;
}
var element = new XElement(mkTag(prefix), value);
element.SetAttributeValue(START_TAG, Start);
element.SetAttributeValue(END_TAG, End);
return element;
}
internal void Update(XElement elem, string prefix)
{
elem.SetElementValue(mkTag(prefix), Method.ToString());
var element = elem.Element(mkTag(prefix));
element.SetAttributeValue(START_TAG, Start);
element.SetAttributeValue(END_TAG, End);
}
internal static string mkTag(string prefix)
{
return prefix + "-" + ZERO_METHOD_TAG;
}
public string ToSerializeString()
{
return $"{Method.ToString()},{Start.ToString(System.Globalization.CultureInfo.InvariantCulture)},{End.ToString(System.Globalization.CultureInfo.InvariantCulture)}";
}
public string ToDisplayString(string averageOverTimeFormatString, string diagnosticLevelFormatString, string absoluteZeroFormatString)
{
var sb = new StringBuilder();
switch (Method)
{
case ZeroMethodType.AverageOverTime:
sb.AppendFormat("{0} from {1} to {2}", averageOverTimeFormatString, Start, End);
break;
case ZeroMethodType.UsePreEventDiagnosticsZero:
sb.AppendFormat("{0}", diagnosticLevelFormatString);
break;
case ZeroMethodType.None:
sb.AppendFormat("{0}", absoluteZeroFormatString);
break;
}
return sb.ToString();
}
public override bool Equals(object obj)
{
if (obj is ZeroMethod zm)
{
return zm.Method == Method && zm.Start == Start && zm.End == End;
}
return base.Equals(obj);
}
}
public class ZeroMethods : IZeroMethods
{
public ZeroMethod[] Methods { get; set; } = new ZeroMethod[] { };
public ZeroMethods(ZeroMethods copy) : this(copy.Methods)
{
}
public ZeroMethods(ZeroMethod[] copyMethods)
{
ZeroMethod[] methods = new ZeroMethod[copyMethods.Length];
for (int i = 0; i < copyMethods.Length; i++)
{
methods[i] = new ZeroMethod(copyMethods[i]);
}
Methods = methods;
}
public ZeroMethods()
{
Methods = new ZeroMethod[] { };
}
public ZeroMethods(string methods)
{
FromSerializedString(methods);
}
public ZeroMethods(ZeroMethod startingMethod)
{
Methods = new ZeroMethod[] { startingMethod };
}
public override bool Equals(object obj)
{
if (obj is ZeroMethods r)
{
if (r.Methods.Length != Methods.Length) { return false; }
for (int i = 0; i < r.Methods.Length; i++)
{
if (!r.Methods[i].Equals(Methods[i])) { return false; }
}
return true;
}
return base.Equals(obj);
}
public void FromSerializedString(string s)
{
string[] tokens = s.Split(new string[] { MySeparator }, StringSplitOptions.None);
for (int i = 0; i < tokens.Length; i++) { tokens[i] = tokens[i].Replace(MySeparatorBackup, MySeparator); }
List<ZeroMethod> methods = new List<ZeroMethod>();
foreach (string token in tokens)
{
methods.Add(new ZeroMethod(token));
}
Methods = methods.ToArray();
}
private const string MySeparator = "__x__";
private const string MySeparatorBackup = "___xx___";
public string ToSerializedString()
{
List<string> methods = new List<string>();
foreach (var r in Methods) { methods.Add(r.ToSerializeString()); }
for (int i = 0; i < methods.Count; i++)
{
System.Diagnostics.Trace.Assert(!methods[i].Contains(MySeparatorBackup));
methods[i] = methods[i].Replace(MySeparator, MySeparatorBackup);
}
return string.Join(MySeparator, methods.ToArray());
}
public string ToDisplayString(string averageOverTimeFormatString, string diagnosticLevelFormatString, string absoluteZeroFormatString)
{
StringBuilder sb = new StringBuilder();
/*foreach (var r in Methods)
{
if (currentMethod > 1) { sb.AppendLine(); }
sb.AppendFormat("{0}: {1}", currentMethod++, r.ToDisplayString(sc));
}*/
for (int i = 0; i < Methods.Length; i++)
{
if (i > 0) { sb.AppendLine(); }
string s = Methods[i].ToDisplayString(averageOverTimeFormatString, diagnosticLevelFormatString, absoluteZeroFormatString);
if (!string.IsNullOrEmpty(s))
{
sb.Append(s);
}
}
return sb.ToString();
}
public override string ToString()
{
return ToDisplayString(Strings.Strings.SensorFields_InitialOffset_AverageOverTimeFormat, Strings.Strings.SensorFields_InitialOffset_DiagnosticLevelFormat,
Strings.Strings.SensorFields_InitialOffset_AbsoluteZeroFormat);
}
}
}

View File

@@ -0,0 +1,17 @@
using DTS.Common.Base;
using DTS.Common.Enums;
namespace DTS.Common.Interface
{
public interface IISOSettingsData : IBaseClass
{
bool UniqueISOCodesRequired { get; set; }
IsoViewMode ISOViewMode { get; set; }
bool ShowISOStringBuilder { get; set; }
bool ShowChannelCodeLookupHelper { get; set; }
bool UseISOCodeFilterMapping { get; set; }
bool ShowISOCodes { get; }
bool ShowUserCodes { get; }
bool ChannelNamesOnly { get; }
}
}

View File

@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Channels;
using System.Text;
using System.Threading.Tasks;
namespace DTS.Common.Classes.Sensors.StreamOut
{
public class UDPStreamProfilePacket
{
public int TransHeader { get; set; } = 4;
public int TimeHeader { get; set; } = 24;
public int SecondTimeHeader { get; set; } = 0;
public int ChannelSpecificDataWord { get; set; } = 0;
public int PCMChannelSpecificDataWord { get; set; } = 0;
public int Id { get; set; } = 0;
public int SampleTime { get; set; } = 0;
public int PayloadFactor { get; set; } = 2;
public int Trailer { get; set; } = 0;
}
}

View File

@@ -0,0 +1,216 @@
using DTS.Common.Base;
using DTS.Common.Enums.Sensors;
using DTS.Common.Interface.Sensors;
using DTS.Common.Utilities.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data;
using System.Globalization;
using System.Linq;
namespace DTS.Common.Classes.Sensors
{
public class SensorCalDbRecord : BasePropertyChanged, ISensorCalDbRecord
{
public bool LinearAdded
{
get => NonLinear && Records.Records[0].Poly.NonLinearStyle == NonLinearStyles.Polynomial &&
Records.Records.Length > 1 && ZeroMethods.Methods.Length > 1;
}
private int? _calibrationId = null;
/// <summary>
/// database id, if known, for calibration, null indicates not known
/// 13065 Sensor "First Use" Date
/// </summary>
[Key]
public int? CalibrationId
{
get => _calibrationId;
set => SetProperty(ref _calibrationId, value, "CalibrationId");
}
protected string _serialNumber;
public string SerialNumber
{
get => _serialNumber;
set => SetProperty(ref _serialNumber, value, "SerialNumber");
}
protected DateTime _calibrationDate;
[Column(TypeName = "datetime")]
public DateTime CalibrationDate
{
get => _calibrationDate;
set => SetProperty(ref _calibrationDate, value, "CalibrationDate");
}
protected string _userName = "";
[Required]
[StringLength(50)]
public string Username
{
get => _userName;
set => SetProperty(ref _userName, value, "Username");
}
private bool _localOnly;
public bool LocalOnly
{
get => _localOnly;
set => SetProperty(ref _localOnly, value, "LocalOnly");
}
private bool _nonLinear;
public bool NonLinear
{
get => _nonLinear;
set
{
SetProperty(ref _nonLinear, value, "NonLinear");
if (!value) return;
Records.Records[0].Sensitivity = 1D;
//FB 29728 don't make IsProportinal false
//IsProportional = false;
RemoveOffset = false;
}
}
private ICalibrationRecords _records = new CalibrationRecords();
[Required]
[StringLength(255)]
public ICalibrationRecords Records
{
get => _records;
set => SetProperty(ref _records, value, "Records");
}
private DateTime _modifyDate;
[Column(TypeName = "datetime")]
public DateTime ModifyDate
{
get => _modifyDate;
set => SetProperty(ref _modifyDate, value, "ModifyDate");
}
private bool _isProportional;
public bool IsProportional
{
get => _isProportional;
set => SetProperty(ref _isProportional, value, "IsProportional");
}
private bool _removeOffset;
public bool RemoveOffset
{
get => _removeOffset;
set => SetProperty(ref _removeOffset, value, "RemoveOffset");
}
//FB 43152
private SensitivityInspectionType _sensitivityInspection;
public SensitivityInspectionType SensitivityInspection
{
get => _sensitivityInspection;
set => SetProperty(ref _sensitivityInspection, value, "SensitivityInspection");
}
//FB 43141
private string _calibrationNote = string.Empty;
[StringLength(2048)]
public string CalibrationNote
{
get => _calibrationNote;
set => SetProperty(ref _calibrationNote, value, "CalibrationNote");
}
//FB 43265
private int _usageCount;
public int UsageCount
{
get => _usageCount;
set => SetProperty(ref _usageCount, value, "UsageCount");
}
private ZeroMethods _zeroMethods = new ZeroMethods();
[Required]
[StringLength(255)]
public ZeroMethods ZeroMethods
{
get => _zeroMethods;
set => SetProperty(ref _zeroMethods, value, "ZeroMethods");
}
private string[] _certificationDocuments = new string[0];
[Required]
[StringLength(2048)]
public string[] CertificationDocuments
{
get => _certificationDocuments;
set => SetProperty(ref _certificationDocuments, value, "CertificationDocuments");
}
//FB18158 It's None the default now not EU
private InitialOffsets _initialOffsets = new InitialOffsets(new InitialOffset());
public InitialOffsets InitialOffsets
{
get => _initialOffsets;
set => SetProperty(ref _initialOffsets, value, "InitialOffsets");
}
public SensorCalDbRecord() { }
public SensorCalDbRecord(ISensorCalDbRecord copy)
{
CalibrationDate = copy.CalibrationDate;
LocalOnly = copy.LocalOnly;
SerialNumber = copy.SerialNumber;
Username = copy.Username;
Records = new CalibrationRecords(copy.Records);
NonLinear = copy.NonLinear;
IsProportional = copy.IsProportional;
ModifyDate = copy.ModifyDate;
var list = new List<string>(copy.CertificationDocuments);
CertificationDocuments = list.ToArray();
RemoveOffset = copy.RemoveOffset;
ZeroMethods = new ZeroMethods(copy.ZeroMethods);
InitialOffsets = new InitialOffsets(copy.InitialOffsets);
CalibrationId = copy.CalibrationId;
//43152
SensitivityInspection = copy.SensitivityInspection;
//43265
UsageCount = copy.UsageCount;
//43141
CalibrationNote = copy.CalibrationNote;
//this is downright silly, but because the linearization formula marks itself valid when it deserializes with data in it, we go and correct it here.
Records.Records[0].Poly.MarkValid(NonLinear);
}
public SensorCalDbRecord(IDataReader reader, int actualDbVersion)
{
try
{
CalibrationDate = Utility.GetDateTime(reader, "CalibrationDate", DateTime.MinValue);
LocalOnly = Utility.GetBool(reader, "LocalOnly", false);
SerialNumber = Utility.GetString(reader, "SerialNumber");
Username = Utility.GetString(reader, "Username");
Records = new CalibrationRecords(Utility.GetString(reader, "CalibrationRecords"));
NonLinear = Utility.GetBool(reader, "NonLinear");
IsProportional = Utility.GetBool(reader, "IsProportional");
ModifyDate = Utility.GetDateTime(reader, "ModifyDate", DateTime.MinValue);
CertificationDocuments = Utility.GetString(reader, "CertificationDocuments").Split(new[] { CultureInfo.InvariantCulture.TextInfo.ListSeparator }, StringSplitOptions.None).ToArray();
RemoveOffset = Utility.GetBool(reader, "RemoveOffset");
ZeroMethods = new ZeroMethods(Utility.GetString(reader, "ZeroMethod"));
InitialOffsets = new InitialOffsets(Utility.GetString(reader, "InitialOffset"));
if (actualDbVersion >= Constants.SENSOR_ASSEMBLY_DB_VERSION)
{
SensitivityInspection = (SensitivityInspectionType)Utility.GetInt(reader, "SensitivityInspection", 0);
CalibrationNote = Utility.GetString(reader, "CalibrationNote");
UsageCount = Utility.GetInt(reader, "UsageCount", 0);
}
CalibrationId = Utility.GetNullableInt(reader, "SensorCalibrationId");
//this is downright silly, but because the linearization formula marks itself valid when it deserializes with data in it, we go and correct it here.
Records.Records[0].Poly.MarkValid(NonLinear);
}
catch (Exception ex)
{
APILogger.Log("Failed to process Sensor Calibration record", ex);
}
}
}
}

View File

@@ -0,0 +1,16 @@
using DTS.Common.Enums;
namespace DTS.Common.Interface.Sensors
{
public interface IStreamInputSettingDefaults
{
///<summary>
/// udp address setting value for the channel
///</summary>
string UDPAddress { get; set; }
/// <summary>
/// </summary>
/// <returns></returns>
bool Validate();
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 448 B