13 KiB
13 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
2026-04-16T02:53:58.796981+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | 95511667ddecb834 |
DTS.Common.Utils Module Documentation
1. Purpose
This module provides a collection of utility classes and static helper methods for common operations across the DTS system. It serves as a foundational layer for low-level functionality including time measurement (ValueStopwatch, StopWatchQueue), data serialization/deserialization (SerializableDictionary, ByteConvertor), UI components (ImageButton, BusyWaitAnimation), network operations (NetworkUtils, IPUtils), and test/data processing (TestUtils, EnumUtil). The module exists to centralize reusable logic, reduce code duplication, and provide consistent behavior for cross-cutting concerns such as timing, byte-order conversion, IP address handling, and UI feedback mechanisms.
2. Public Interface
EnumUtil (static class)
public static IEnumerable<T> GetValues<T>()
Returns all enum values of typeTusingEnum.GetValues.public static ItemCollection GetValuesList<T>()
Returns anItemCollection(fromXceed.Wpf.Toolkit) containing enum values and their names, suitable for binding to property grids.
ValueStopwatch (readonly struct)
public static ValueStopwatch StartNew()
Creates and starts a newValueStopwatchinstance.public TimeSpan GetElapsedTime()
Returns the elapsed time since the stopwatch was started, computed usingStopwatch.GetTimestamp()andStopwatch.Frequency.
ImageButton (class)
- Inherits from
System.Windows.Controls.Button. public ImageSource Source { get; set; }
Gets/sets the image displayed in the button.public string ImageText { get; set; }
Gets/sets the text displayed below the image in the button.- Internally uses a
StackPanelwith vertical orientation to arrange anImageandTextBlock.
PNGImageUtil (static class)
public static void SaveImage(FrameworkElement view, string fileName)
Renders the givenFrameworkElementas a PNG image to the specified file path usingRenderTargetBitmapandPngBitmapEncoder.
MouseUtilities (class)
public static Point GetMousePosition(Visual relativeTo)
Returns the current mouse cursor position relative to a given WPFVisual. Uses Win32 API (GetCursorPos,ScreenToClient) and WPF transform logic to compute coordinates.
StopWatchQueue (class)
public StopWatchQueue(string name)
Constructor; initializes a queue for storing elapsed tick values (max ~5000 entries).public void Start()
Starts the internalStopwatch.public void Stop()
Stops theStopwatch, enqueues the elapsed ticks, and resets theStopwatch.public void DumpData()
Writes timing statistics (count, min, max, avg, stddev) and all recorded values (in milliseconds) to a CSV file named<name><FileTime>.csv.- Finalizer calls
DumpData()on disposal.
SerializableDictionary<TKey, TValue> (class)
- Inherits
Dictionary<TKey, TValue>and implementsIXmlSerializable. public void ReadXml(XmlReader reader)
Deserializes XML into the dictionary; expects<items><item><key>...</key><value>...</value></item>...</items>structure.public void WriteXml(XmlWriter writer)
Serializes the dictionary to XML in the same structure.- Uses
XmlSerializerfor key and value types.
TestUtils (static class)
public static Tuple<double, double> MinUnixTime(IEnumerable<TestModuleTimeStamp> basemodules)
Returns the earliest valid timestamp (as(sec, nanosec)) from a collection ofTestModuleTimeStampobjects, filtering out outliers beyondutcAverage - utcStandardDeviationand clamping stddev to ≤10ms. Returnsnullif input is null/empty.public static string ParseROISuffix(string test)
Extracts ROI suffix from a colon-separated test string. Tries multiple heuristics based onDTS.Common.Constants.EventNumber.
IPUtils (namespace)
public class IPRange
Holds a start and endIPAddressIntFormrepresenting an IP range.public class IPAddressIntForm
Represents an IPv4 address as four byte components (ByteOne–ByteFour).public static bool TryParse(string input, out IPAddressIntForm output)
Parses a dotted-decimal IP string into anIPAddressIntForm.public static string[] GetAllIPs(IPAddressIntForm a, IPAddressIntForm b)
Returns all IPs betweenaandb(inclusive), regardless of input order.internal class IPComparer : IComparer<IPAddressIntForm>
Lexicographic comparison of IP addresses by byte components.
SecureQueue<T> (class)
- Generic thread-safe queue with configurable null-handling policy (
NullPolicyenum:DenyNull,SkipNull,AllowNull). public void Enqueue(T[] newData)
Adds a byte array to the queue; enforces null policy and logs if enabled.public bool WaitForData(int timeoutMillisec)
Blocks for up totimeoutMillisecms waiting for data.public T[] Dequeue(bool resetEvent)
Dequeues and concatenates all queued arrays into a single array; resets internal event.public void Flush()
Clears the queue and resets the event.public bool IsEmpty()
Returnstrueif queue is empty.public WaitHandle QueueWaitHandle => ByteQueueEvent
Exposes the internalManualResetEventfor external wait operations.
ByteConvertor (class)
- Static class for converting between integral types and byte arrays in network byte order (big-endian).
public static void Convert(byte[] input, int offset, out T value)
Reads a value of typeT(e.g.,ushort,int,long,float,double,string) frominputatoffset, interpreting bytes in big-endian order.public static byte[] ToByteArray(T value)
Convertsvalueto a big-endian byte array (e.g.,ToByteArray(ushort)returns 2 bytes,ToByteArray(int)returns 4 bytes,ToByteArray(string)appends null terminator).
NetworkUtils (static class)
public static bool IsNetworkInterfaceUp(IPAddress ip)
Checks if a network interface with the given IP is active, supports multicast, and is not loopback or internal-only (unlessAllowInternalNICIPsistrue).public static List<HostInfo> GetAvailableHosts(bool supportMulticastOnly = false)
Returns a list ofHostInfoobjects for all available IPv4 network interfaces (filters out loopback, virtual, low-speed, and Npcap interfaces).public static bool TryParseConnectionString(string connectionString, out string ipAddress)
Attempts to extract an IP address from a DAS connection string (supports URI or colon-separated formats). Returnsfalsefor non-IP (e.g., USB) strings.public static bool AllowInternalNICIPs { get; set; }
Controls whether 169.254.x.x (link-local) addresses are included in interface filtering.
BusyWaitAnimation (class)
- WPF/WinForms-compatible busy indicator (spinning circle).
public bool Active { get; set; }
Starts/stops the animation timer.public StylePresets StylePreset { get; set; }
Sets appearance to presets:MacOsx,Firefox,Ie7, orCustom.public Color Color { get; set; }
Base color for the spinning spokes.public int OuterCircleRadius,InnerCircleRadius,NumberSpoke,SpokeThickness,RotationSpeed
Properties to customize appearance and behavior.- Requires
SetDrawArea(Rectangle)andhDCsetter for rendering; uses GDI+ for drawing.
3. Invariants
ByteConvertor: All multi-byte conversions use big-endian (network) order. Little-endian host systems must convert appropriately.ValueStopwatch: Elapsed time is computed usingStopwatch.FrequencyandTimeSpan.TicksPerSecond; precision is limited toStopwatchresolution.StopWatchQueue: Stores up to ~5000 tick values; older values are overwritten only when the queue is full (not explicitly implemented—queue grows untilDumpData()is called).SerializableDictionary: Keys and values must be serializable viaXmlSerializer; no validation of key uniqueness or type compatibility is performed during deserialization.SecureQueue<T>:Dequeue()always concatenates all queued arrays into a single array (not one per enqueue).Dequeue()andFlush()reset the internalManualResetEvent, breaking existing waiters.- Null/empty arrays are handled per
NullPolicy;Clone()is used for enqueue to prevent external mutation.
TestUtils.MinUnixTime:- Uses
Common.Constants.NANOS_PER_SECONDandCommon.Constants.TEN_MILLIS_IN_SEC(not defined in this module). - Filters out timestamps where
moduleTime ≤ utcAverage - utcStandardDeviation. - Returns the first module satisfying the filter, not necessarily the absolute earliest.
- Uses
NetworkUtils.IsNetworkInterfaceUp: Skips interfaces with 169.254.x.x addresses unlessAllowInternalNICIPsistrue.IPUtils.IPAddressIntForm.GetAllIPs: Iterates over all bytes in lexicographic order; may produce invalid IPs (e.g., 256.x.x.x) if input bytes exceed 0–255.
4. Dependencies
Internal Dependencies (within DTS.Common)
DTS.Common.Interface(forTestModuleTimeStampandTestUtils)DTS.Common.Utilities.Logging(forAPILogger)DTS.Common.Constants(referenced byTestUtilsandNetworkUtils)DTS.Common.Utilities(referenced bySecureQueue)
External Dependencies
- .NET Framework:
System,System.Collections.Generic,System.Diagnostics,System.IO,System.Linq,System.Net,System.Net.NetworkInformation,System.Net.Sockets,System.Runtime.InteropServices,System.Threading,System.Windows,System.Windows.Media,System.Windows.Media.Imaging,System.Windows.Threading,System.Xml,System.Xml.Serialization - WPF Toolkit:
Xceed.Wpf.Toolkit.PropertyGrid.Attributes(forItemCollection) - Win32 API:
user32.dll(GetCursorPos,GetPhysicalCursorPos,ScreenToClient) - Windows Forms:
System.Windows.Forms,System.Drawing,System.Drawing.Drawing2D(forBusyWaitAnimation)
Dependencies on This Module
DTS.Common.Interface(viaTestUtils)- Networking modules (via
NetworkUtils,IPUtils) - UI components (via
ImageButton,BusyWaitAnimation) - Data processing pipelines (via
ByteConvertor,SerializableDictionary,SecureQueue)
5. Gotchas
ByteConvertor: TheConvertmethods forfloat/doubleuseBitConverter(host-endian), not network byte order. Only integer/string conversions are big-endian.StopWatchQueue:- Finalizer calls
DumpData()but does not prevent multiple calls (e.g., explicitDumpData()+ finalizer). DumpData()dequeues all values, leaving the queue empty.- No explicit disposal pattern;
~StopWatchQueue()is the only cleanup.
- Finalizer calls
SecureQueue<T>:Dequeue()concatenates all queued arrays into one—this may be unexpected if callers expect per-enqueue chunks.Dequeue()andFlush()reset theManualResetEvent, invalidating any pendingWaitOne()calls.ByteQueueEventis recreated on eachDequeue()/Flush(), breaking external references to theWaitHandle.
TestUtils.MinUnixTime:- Uses
Common.Constants.NANOS_PER_SECONDandTEN_MILLIS_IN_SEC—these must be defined elsewhere. - The filtering logic (
moduleTime > utcAverage - utcStandardDeviation) may exclude valid early timestamps if they are statistical outliers.
- Uses
NetworkUtils.GetAvailableHosts:- Filters out interfaces with 169.254.x.x addresses by default (configurable via
AllowInternalNICIPs). - Skips interfaces with "Npcap" in description (Wireshark).
- Filters out interfaces with 169.254.x.x addresses by default (configurable via
IPUtils.IPAddressIntForm.GetAllIPs:- Iterates over all byte combinations (e.g., 256.0.0.0 if
ByteOne=256), which may produce invalid IPs. - No validation that
start ≤ endin IP order (handled viaIPComparer).
- Iterates over all byte combinations (e.g., 256.0.0.0 if
BusyWaitAnimation:- Requires manual setup:
SetDrawArea()andhDCsetter must be called before rendering. - Uses GDI+ (
Graphics.FromHdc), which is not thread-safe and requires a valid HDC.
- Requires manual setup:
ImageButton:- Uses
StackPanelwith fixedMargin=10; not configurable. - No support for horizontal layout or custom content beyond image + text.
- Uses
PNGImageUtil.SaveImage:- Uses
view.ActualWidth/ActualHeight, which may be zero if the element is not rendered. - Does not handle DPI scaling beyond hardcoded 96 DPI.
- Uses
EnumUtil.GetValuesList<T>:- Returns
ItemCollection(WPF Toolkit type), which may not be available in non-WPF contexts.
- Returns