17 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
2026-04-16T11:32:34.054047+00:00 | zai-org/GLM-5-FP8 | 1 | a50bc074e645dae7 |
DTS.Common.Utilities Documentation
1. Purpose
DTS.Common.Utilities is a general-purpose utility library providing common functionality for DTS applications. It includes mathematical operations (standard deviation, SNR calculation, degree conversion), data structures (sortable binding lists, average queues, notifying lists), Windows Forms helpers (enum dropdowns, exceptional base classes), file/memory operations (CRC32, memory-mapped file support via Win32 APIs), XML serialization helpers, and various framework extensions (property comparers, attribute coders). The library serves as a foundational layer reused across multiple DTS projects.
2. Public Interface
Mathematical Utilities
DTS.Common.Utilities.DegreesFromADC
public static double GetDegrees(double Sxyz, double SG)— Converts ADC values to degrees using arcsin formula:(180/π) * asin(Sxyz / SG).
DTS.Common.Utilities.SignalToNoiseRatio
public static double CalculateSNR(IEnumerable<double> values, double fullScalePP = 65536.0)— Calculates signal-to-noise ratio given a dataset and full scale peak-to-peak value (defaults to 65536.0 for ADC data).
DTS.Common.Utilities.StandardDev
public static double StandardDeviation(IEnumerable<double> values)— Calculates sample standard deviation using Bessel's correction (n-1 denominator). Returns 0 for empty collections.
DTS.Common.Utilities.Math.DoubleListOperation (abstract)
public DoubleListOperation(IList<double> domain)— Abstract base class for mathematical operations onIList<double>data. Inherits fromOperation<IList<double>, IList<double>>.
DTS.Common.Utilities.Crc32
public Crc32()— Constructor that builds the CRC32 lookup table.public uint Get<T>(IEnumerable<T> byteStream)— Calculates 32-bit reversed CRC checksum. ThrowsFormatException,InvalidCastException, orOverflowExceptionif conversion to byte fails.
DTS.Common.Utilities.AverageQueue
public AverageQueue(int length)— Constructs a fixed-length queue for running average calculation.public double Push(double newValue)— Adds a value to the queue, returns current average. Thread-safe.public double GetAverage()— Returns current average. Thread-safe.public void Reset()— Clears the queue. Thread-safe.public double GetMin()— Returns minimum value in queue. Thread-safe.public double GetMax()— Returns maximum value in queue. Thread-safe.
Time Utilities
DTS.Common.Utilities.Time
public static UInt32 DateTimeToUnixTimestamp(DateTime dateTime)— Converts DateTime to Unix timestamp (seconds since 1970-01-01). No timezone correction.public static UInt32 CurrentUtcUnixTimestamp()— Returns current UTC time as Unix timestamp.public static UInt32 CurrentLocalUnixTimestamp()— Returns current time as Unix timestamp (calculated from UtcNow but with Local kind in epoch).public static DateTime ToDateTime(UInt32 seconds)— Converts Unix timestamp back to DateTime.public static UInt32 ToUnixTime(DateTime dateTime)— Alias forDateTimeToUnixTimestamp.public static bool IsBeginningOfTime(DateTime dateTime)— Returns true if DateTime equals Unix epoch (1970-01-01).
String/Version Utilities
DTS.Common.Utilities.FirmwareVersionToLong
public static long Query(string version)— Converts firmware version string to long by taking first 4 characters and bit-shifting each character into 16-bit positions (shifts: 48, 32, 16, 0).
DTS.Common.Utilities.NaturalStringComparer : IComparer<string>
public int Compare(string x, string y)— Natural string comparison (like Windows Explorer). Returns -1 if x < y, 1 if x > y, 0 if equal. Null strings sort first.public static int StaticCompare(string x, string y)— Static version ofCompare.
XML Utilities
DTS.Common.Utilities.Xml.XmlToObject<T>
public static T FromXml(string xml)— Deserializes XML string to object of type T. Returnsdefault(T)on any exception (includingInvalidOperationExceptionfrom deserialization).
DTS.Common.Utilities.Xml.XmlSerializationTagAttribute : Attribute, IComparable<XmlSerializationTagAttribute>
public string Value { get; }— The tag string value.public int Order { get; }— Sort order for multiple tags.public XmlSerializationTagAttribute(string value)— Constructor with default order 0.public XmlSerializationTagAttribute(string value, int order)— Constructor with explicit order.public int CompareTo(XmlSerializationTagAttribute that)— Compares by Order property.
Windows/OS Integration
DTS.Utilities.TaskbarHelper
public static extern int SetCurrentProcessExplicitAppUserModelID([MarshalAs(UnmanagedType.LPWStr)] string AppID)— P/Invoke toshell32.dllto set Windows taskbar AppUserModelID. Reference: FB 45077.
Logging
DTS.Common.Utilities.LTLogging.LevelTriggerLogging
public static void LevelTriggerLog(string msg)— Thread-safe append toLogs\LevelTriggerSettings.txt.
Collections/Data Structures
DTS.Common.Utilities.SortableBindingList<T> : BindingList<T>
public SortableBindingList()— Default constructor.public SortableBindingList(IEnumerable<T> enumeration)— Construct from enumeration.- Protected sorting/searching overrides:
SupportsSortingCore,IsSortedCore,SortPropertyCore,SortDirectionCore,SupportsSearchingCore,ApplySortCore,RemoveSortCore,FindCore.
DTS.Common.Utilities.PropertyComparer<T> : IComparer<T>
public PropertyComparer(PropertyDescriptor property, ListSortDirection direction)— Constructs comparer for specified property and sort direction.public int Compare(T x, T y)— Compares two objects by the configured property.public void SetPropertyAndDirection(PropertyDescriptor descriptor, ListSortDirection direction)— Updates property and sort direction.
DTS.Common.Utilities.UpdateNotifyingList<T> : Exceptional
public List<T> Items { get; set; }— Gets/sets the list contents; setter triggersOnUpdateevent.public delegate void OnUpdateCallback(List<T> updatedContents)— Callback delegate type.public event OnUpdateCallback OnUpdate— Event fired when Items is set.
DTS.Common.Utilities.ExceptionalList<T> : List<T>
public ExceptionalList(),ExceptionalList(int capacity),ExceptionalList(IEnumerable<T> collection)— Standard list constructors.- Nested
public class Exception : ApplicationException— List-specific exception type.
Windows Forms Components
DTS.Common.Utilities.EnumDropDown<T> : System.Windows.Forms.ComboBox where T : struct, IComparable
public class EnumListEntry : IComparable<EnumListEntry>— Wrapper for enum values with DescriptionAttribute decoding.public T Value { get; set; }public override string ToString()— Returns decoded description.
public delegate bool Filter(T enumEntry)— Filter delegate type.public Filter EnumFilter { set; }— Sets filter and repopulates list.public EnumDropDown(Filter defaultFilter)— Constructor with filter.public void PopulateList()— Clears and repopulates items based on filter.public EnumListEntry SelectedEntry { get; set; }— Currently selected entry.public T? SelectedEnum { get; set; }— Currently selected enum value.
DTS.Common.Utilities.ExceptionalForm : Form
- Nested
public class Exception : ApplicationException— Form-specific exception type with standard constructors.
DTS.Common.Utilities.ExceptionalUserControl : UserControl
- Nested
public class Exception : ApplicationException— UserControl-specific exception type with standard constructors.
Enums and Attributes
DTS.Common.Utilities.DataFlag (enum)
None(0),Normal(1),Saturated(2),ZeroCrossing(3),BrokenWire(4),Other(-1)- Each value has
[Description("...")]and[Flag(int)]attributes.
DTS.Common.Utilities.FlagAttribute : Attribute
public int Flag { get; }— The flag value.public FlagAttribute(int flag)— Constructor.
DTS.Common.Utilities.DataFlagAttributeCoder : AttributeCoder<DataFlag, FlagAttribute, int>
public DataFlagAttributeCoder()— Constructor for encoding/decoding DataFlag values.
DTS.Common.Utilities.DescriptionAttributeCoder<TTargetType> : AttributeCoder<TTargetType, DescriptionAttribute, string>
public DescriptionAttributeCoder()— Constructor for encoding/decoding DescriptionAttribute values. Uses case-insensitive comparison.
Keyword Processing
DTS.Common.Utilities.KeywordAlert (sealed, singleton)
public static KeywordAlert Instance { get; }— Singleton instance.public void ProcessMsg(string msg)— Queues message for async keyword matching againstKeywords.txt. Uses PLINQ for parallel matching. Note: Matched keys are joined but result is not persisted or returned anywhere visible in source.
Memory-Mapped File Support
DTS.Common.Utilities.IO.MemoryMap.Win32MapApis (internal)
- P/Invoke declarations for
kernel32.dll:CreateFile,CreateFileMapping,FlushViewOfFile,MapViewOfFile,OpenFileMapping,UnmapViewOfFile,CloseHandle,GetLastError.
DTS.Common.Utilities.IO.MemoryMap.LargeArray<T> (partial)
protected class NameGeneratorLock— Locking object for scratch file name generation.private class MissingScratchFileException : ApplicationExceptionprivate class ScratchFileAlreadyExistsException : ApplicationExceptionprivate class LargeOverflowException : ApplicationException
Exception Types (Various)
DTS.Common.Utilities.DataWindowAverager.WindowDoesNotExistException : ApplicationException
- Standard exception constructors for invalid window access.
DTS.Common.Utilities.DotNetProgrammingConstructs.Property<Type>.ConstructionException : Exception
- Exception for property construction failures.
DTS.Common.Utilities.DotNetProgrammingConstructs.Property<Type>.InvalidValueException : Exception
- Exception for invalid property values.
DTS.Common.Utilities.DotNetProgrammingConstructs.Property<Type>.NotInitializedException : Exception
- Exception for uninitialized property access.
DTS.Common.Utilities.DotNetProgrammingConstructs.RangeRestrictedIntProperty.InvalidRangeException : Exception
- Exception for integer range violations.
DTS.Common.Utilities.DotNetProgrammingConstructs.RangeRestrictedDoubleProperty.InvalidRangeException : Exception
- Exception for double range violations.
DTS.Common.Utilities.Logging.TextLogger.LogPathnameNotInitializedException : ApplicationException (private)
- Exception for uninitialized log pathname.
3. Invariants
- StandardDev.StandardDeviation: Returns 0 for empty collections; uses sample standard deviation (n-1 divisor).
- AverageQueue: Always maintains
_queueSumas the sum of current queue contents;Queue.Countnever exceedsQueueLength. - XmlToObject.FromXml: Always returns
default(T)on any failure (never throws to caller). - NaturalStringComparer.Compare: Null values are always sorted first (null x returns -1, null y returns 1).
- FirmwareVersionToLong.Query: Only processes first 4 characters of version string; shorter strings use available characters.
- KeywordAlert: Singleton pattern;
alertslist is only populated ifKeywords.txtexists and is readable. - Time conversions: All Unix timestamp methods use
UInt32(32-bit), limiting date range to 1970–2106. - LargeArray exceptions: All nested exception classes are
privatetoLargeArray<T>.
4. Dependencies
External Dependencies (Imports)
System(core types,Math,DateTime,Exception)System.Collections.Generic(List<T>,IEnumerable<T>,IList<T>,Queue<T>,Dictionary<TKey,TValue>)System.ComponentModel(PropertyDescriptor,ListSortDirection,DescriptionAttribute,BindingList<T>)System.Linq(LINQ extensions,AsParallel())System.Runtime.InteropServices(P/Invoke,DllImport,MarshalAs)System.Runtime.Serialization(SerializationInfo,StreamingContext)System.Text(StringBuilder)System.Threading(ThreadPool,WaitCallback)System.Threading.Tasks(Task)System.Windows.Forms(Form,UserControl,ComboBox)System.Xml.Serialization(XmlSerializer)System.IO(TextReader,StringReader,File)
Internal Dependencies
DTS.Common.Utilities.DotNetProgrammingConstructs— Referenced byProperty<T>,RangeRestrictedIntProperty,RangeRestrictedDoubleProperty,Exceptional,Operation<TInput,TOutput>.DTS.Common.Utilities.IO.MemoryMap— ContainsLargeArray<T>andWin32MapApis.DTS.Common.Utilities.LTLogging— ContainsLevelTriggerLogging.DTS.Common.Utilities.Logging— ContainsTextLogger.DTS.Common.Utilities.Xml— ContainsXmlToObject<T>,XmlSerializationTagAttribute.DTS.Common.Utilities.Math— ContainsDoubleListOperation.
Referenced but Not Provided
DTS.Common.Utilities.Property<T>— Referenced byUpdateNotifyingList<T>and exception partial classes.DTS.Common.Utilities.RangeRestrictedIntProperty— Referenced by exception partial class.DTS.Common.Utilities.RangeRestrictedDoubleProperty— Referenced by exception partial class.DTS.Common.Utilities.Exceptional— Base class forUpdateNotifyingList<T>.DTS.Common.Utilities.Operation<TInput, TOutput>— Base class forDoubleListOperation.DTS.Common.Utilities.AttributeCoder<TTarget, TAttribute, TValue>— Base class forDescriptionAttributeCoderandDataFlagAttributeCoder.DTS.Common.Utilities.DataWindowAverager— Referenced byWindowDoesNotExistExceptionpartial class.DTS.Common.Utilities.LargeArray<T>— Main class referenced by partial exception files.DTS.Common.Utilities.TextLogger— Referenced byLogPathnameNotInitializedExceptionpartial class.DTS.Common.Utilities.Properties.Resources— Referenced byXmlSerializationTagAttributefor error message.
5. Gotchas
-
KeywordAlert.DoWork has no observable output: The
DoWorkmethod buildsfoundKeysstring from matches but never writes, logs, or returns it. The matched keywords are effectively discarded. -
Time.CurrentLocalUnixTimestamp naming is misleading: The method calculates
DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Local). Subtracting UTC now from a Local-kind epoch produces a counterintuitive result that doesn't represent true local Unix time. -
StandardDev.StandardDeviation uses Count()-1 for empty check: The method calls
values.Any()to check for emptiness, then later callsvalues.Count() - 1as divisor. If the enumerable has exactly one element, this causes division by zero (resulting inInfinityorNaN). -
XmlToObject.FromXml silently swallows all exceptions: Any exception during XML deserialization returns
default(T)without any indication of failure. Callers cannot distinguish between "deserialization failed" and "deserialized to default value." -
**FirmwareVersionToLong.Query uses character values