10 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
2026-04-16T12:01:02.629774+00:00 | zai-org/GLM-5-FP8 | 1 | 0a10ccd507cef203 |
DTS.CommonCore.Utils Documentation
1. Purpose
This module provides a collection of utility classes and helper methods for the DTS system, including thread-safe data structures (SecureQueue), byte manipulation with network byte order conversion (ByteConvertor), WPF UI components (ImageButton, BusyWaitAnimation), network interface utilities (NetworkUtils), XML serialization helpers (SerializableDictionary), performance profiling (StopWatchQueue), and various other utility functions for enums, timestamps, mouse positioning, and image rendering.
2. Public Interface
EnumUtil (static class)
IEnumerable<T> GetValues<T>()— Returns all values of enum typeTas an enumerable.ItemCollection GetValuesList<T>()— Returns anItemCollectionpopulated with enum values and their names, suitable for use with Xceed WPF Toolkit PropertyGrid.
ImageButton (extends Button)
ImageSource Source— Gets or sets the image source displayed on the button.string ImageText— Gets or sets the text displayed below the image.
PNGImageUtil (static class)
void SaveImage(FrameworkElement view, string fileName)— Renders aFrameworkElementto a PNG file at the specified path. Uses 96 DPI andPbgra32pixel format.
MouseUtilities
static Point GetMousePosition(Visual relativeTo)— Returns the mouse cursor position relative to the specifiedVisual, using Win32 API calls (GetCursorPos,ScreenToClient).
StopWatchQueue
StopWatchQueue(string name)— Constructor accepting a name used for output file naming.void Start()— Starts the internal stopwatch.void Stop()— Stops the stopwatch, records elapsed ticks to an internal queue, and resets the stopwatch.void DumpData()— Writes all recorded timing data to a CSV file with statistics (max, min, average, standard deviation in milliseconds).
SerializableDictionary<TKey, TValue> (extends Dictionary<TKey, TValue>, implements IXmlSerializable)
XmlSchema GetSchema()— Returnsnull.void ReadXml(XmlReader reader)— Deserializes the dictionary from XML format with<items>,<item>,<key>, and<value>elements.void WriteXml(XmlWriter writer)— Serializes the dictionary to XML format.
XmlDictionary
SerializableDictionary<string, object> Dictionary— A pre-configured serializable dictionary for string-to-object mappings.
TestModuleTimeStamp
int TriggerTimestampSec— Seconds component of timestamp.int TriggerTimestampNanoSec— Nanoseconds component of timestamp.
TestUtils (static class)
Tuple<double, double> MinUnixTime(IEnumerable<TestModuleTimeStamp> basemodules)— Calculates the minimum Unix timestamp from a collection, using statistical filtering (average minus standard deviation, capped at 10ms). Returnsnullif input is null or empty.string ParseROISuffix(string test)— Parses a test string to extract an ROI suffix based on event number markers.
SecureQueue<T> (implements IDisposable, constrained to new())
enum NullPolicy—DenyNull,SkipNull,AllowNull.SecureQueue(NullPolicy policy, string name)— Constructor.void ResetEvent()— Resets the internalManualResetEvent.void Enqueue(T[] newData)— Thread-safe enqueue; behavior depends onNullPolicy. Clones data before storing.bool WaitForData(int timeoutMillisec)— Blocks until data arrives or timeout; returnstrueif data available.WaitHandle QueueWaitHandle— Exposes the internal wait handle.T[] Dequeue(bool resetEvent)— Thread-safe dequeue; concatenates all queued arrays into a single array if multiple entries exist.void Flush()— Clears the queue and resets the event.bool IsEmpty()— Returnstrueif queue is empty.void Dispose()— Implementation ofIDisposable(currently empty).
ByteConvertor (static class)
void Convert(byte[] input, int offset, out byte/ushort/short/uint/int/ulong/long/float/double/string value)— Converts bytes at offset to the specified type. Multi-byte integers are interpreted in big-endian (network) byte order. Strings are null-terminated.byte[] ToByteArray(byte/ushort/short/uint/int/ulong/float/double/string input)— Converts the specified type to a byte array. Multi-byte integers are output in big-endian (network) byte order. Strings are null-terminated.
NetworkUtils (static class)
bool IsNetworkInterfaceUp(IPAddress ip)— Returnstrueif the network interface for the given IP is up and operational.List<HostInfo> GetAvailableHosts(bool supportMulticastOnly = false)— Returns a list of available network hosts with IP, MAC, and address range information. Filters out VPN, virtual adapters, loopback, and Npcap interfaces.bool TryParseConnectionString(string connectionString, out string ipAddress)— Attempts to extract an IP address from a connection string; returnsfalsefor USB connections.
BusyWaitAnimation
Color Color— Gets or sets the spoke color.Color BgColor— Gets or sets the background color.int OuterCircleRadius— Gets or sets the outer circle radius.int InnerCircleRadius— Gets or sets the inner circle radius.int NumberSpoke— Gets or sets the number of spokes.bool Active— Gets or sets whether the animation is running.int SpokeThickness— Gets or sets the spoke thickness.long RotationSpeed— Gets or sets the rotation speed (higher = slower).StylePresets StylePreset— Gets or sets a preset style (MacOsx,Firefox,Ie7,Custom).Graphics GDIGraphics— Gets the internal GDI+ graphics object.int hDC— Gets or sets the device context handle.void SetDrawArea(Rectangle rect)— Sets the drawing area and initializes internal bitmaps.void SetCircleAppearance(int numberSpoke, int spokeThickness, int innerCircleRadius, int outerCircleRadius)— Configures the circle appearance.
XMLUtils
- Empty class — No public members defined.
3. Invariants
- ByteConvertor: All multi-byte integer conversions use big-endian (network) byte order. The
Convertmethods assume the input byte array is sufficiently sized for the requested type at the given offset. - SecureQueue: The queue is thread-safe; all operations use locking on
ByteQueueLock. WhenNullPolicy.DenyNullis set, enqueuing null or empty arrays throwsArgumentException. - SerializableDictionary: XML structure must follow
<items><item><key>...</key><value>...</value></item>...</items>format. - StopWatchQueue:
Stop()records elapsed ticks since the lastStart()call and resets the stopwatch; callingStop()withoutStart()will record whatever the stopwatch state is (including zero if never started). - PNGImageUtil.SaveImage: Requires the
FrameworkElementto have validActualWidthandActualHeight(must be rendered/measured). UsesFileMode.CreateNew— will throw if file already exists. - TestUtils.MinUnixTime: Returns
nullif input collection is null or empty. Standard deviation is capped atCommon.Constants.TEN_MILLIS_IN_SEC. - BusyWaitAnimation: Requires
SetDrawArea()andhDCto be set before animation can render.
4. Dependencies
External Dependencies (from imports)
- Xceed.Wpf.Toolkit.PropertyGrid.Attributes —
EnumUtil.GetValuesList<T>()returnsItemCollection. - System.Windows.Forms — Used in
SecureQueue(though not directly referenced in visible code, imported). - System.Drawing — Used in
BusyWaitAnimationfor GDI+ graphics. - System.Windows.Threading —
BusyWaitAnimationusesDispatcherTimer.
Internal Dependencies
DTS.Common.Utilities.Logging.APILogger— Used bySecureQueuefor logging.DTS.Common.Interface— Imported inTestUtils(usage unclear from source alone).DTS.Common.Constants— ConstantsNANOS_PER_SECOND,TEN_MILLIS_IN_SEC,EventNumberreferenced inTestUtils.Enums.DASFactory.DFConstantsAndEnums.ExtraCommunicationLogging— Used inSecureQueue.Enqueue.
Namespace Inconsistency
SerializableDictionaryandXmlDictionaryare in namespaceDTS.DASLib.Utility, while all other utilities are inDTS.Common.Utils.
5. Gotchas
-
ByteConvertor float/double conversions: Unlike integer types,
Convertmethods forfloatanddoubleuseBitConverter.ToSingle/ToDouble, which respects system endianness — inconsistent with the big-endian behavior of integer conversions. -
PNGImageUtil.SaveImage file mode: Uses
FileMode.CreateNew, which will throw an exception if the file already exists. Caller must ensure the file does not exist or handle the exception. -
SecureQueue.Dequeue event handling: The method creates a new
ManualResetEvent(false)on every call, which may cause issues if multiple consumers are waiting on the original event handle. -
SecureQueue.Dispose: The
Dispose()method is empty and does not release theManualResetEventor other resources. -
MouseUtilities.GetMousePosition DPI handling: The calculation
var factor = 2D - presentationSource.CompositionTarget.TransformToDevice.M22is non-obvious and may produce incorrect results for certain DPI configurations. -
StopWatchQueue finalizer: The destructor
~StopWatchQueue()callsDumpData(), which writes a file to disk. This could cause unexpected file I/O during garbage collection. -
BusyWaitAnimation static field: Contains
static int _xxx = 0;that is incremented in the constructor but never used — appears to be debug/legacy code. -
XMLUtils: The class is entirely empty — unclear if this is placeholder or deprecated code.
-
SerializableDictionary.ReadXml: Creates new
XmlSerializerinstances for each key and value type on every call, which could cause performance issues and memory leaks (XmlSerializer caching issues).