12 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
2026-04-16T02:52:41.721329+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | b71265395aaf09cd |
DTS.Common Classes Documentation
1. Purpose
This module provides foundational infrastructure utilities for the DTS application platform, focusing on dependency injection (via Unity), UI state management (status/progress), singleton pattern enforcement, high-performance collection operations, service orchestration, database-backed tagging system, and robust data access helpers. It serves as a shared library across the application to standardize common patterns, reduce boilerplate, and ensure thread-safe, consistent behavior for core operations like service queuing, tag management, and database interaction.
2. Public Interface
UnityExtensions
T TryResolve<T>(this IUnityContainer container) where T : class
Safely resolves a service of typeTfrom the Unity container, returningnullinstead of throwing on failure.
StatusAndProgressBarEventArgs
- Properties
StatusColor:Color– UI color for status indication.StatusText:string– Human-readable status message.ProgressValue:double– Numeric progress (e.g., 0.0–1.0 or 0–100).ProgressBarVisibility:Visibility– Controls whether the progress bar is visible.Requester:IBaseViewModel– Originator of the status update.ErrorText:string– Optional error message to display.
Singleton<T>
protected Singleton()
Constructor enforces singleton usage: throwsInvalidOperationExceptionif called directly (i.e., vianew T()instead ofT.Instance).public static T Instance
Gets the singleton instance. Throws the exception captured during static initialization if instance creation failed.
BulkObservableCollection<T>
void AddRange(IEnumerable<T> items)
Adds multiple items to the collection and fires a singleNotifyCollectionChangedAction.Resetnotification instead of per-item notifications. Logs exceptions viaAPILogger.void RemoveRange(IEnumerable<T> itemsToRemove)
Removes multiple items and fires a singleResetnotification. Logs exceptions viaAPILogger.
RegionNames
- Constants
Static string constants defining Prism region names used for UI composition (e.g.,"FrontRegion","MainRegion","ViewerGraphMainRegion","MenuRegion"). No methods.
ImportData
enum ImportPageTypeImportSensor,ImportTestSetup
class SensorImportData
Holds parsed sensor import data:GroupNameSensorListLookup:Dictionary<string, List<string>>SensorGroupNameLookup,SensorGroupTypeLookup,GroupNameTestObjectLookup:Dictionary<string, string>Errors:List<string>SensorISOCode,SensorISOChannelName,SensorUserCode,SensorUserChannelName,SensorDASSerialNumber:Dictionary<string, string>SensorChannelIndex:Dictionary<string, int>
class TestSetupImportData
Holds parsed test setup import data:Name,Description:stringSamplesPerSecond,PosttriggerSeconds,PretriggerSeconds:doubleRecordingMode,CalibrationBehavior: Enum valuesVersion:intTestChannelOrders,Tags:List<string>- Clock configuration properties:
ClockMasterInput,ClockMasterOutput,ManageClocksOutsideOfDataPROMaster, etc. SampleRateForDAS,DomainIdForDAS,IsClockMaster:Dictionary<string, ...>
ServiceCall
bool Started
Indicates whether the call has been started.Action WorkAction
The work to execute.void MarkDone()
Signals completion by callingServiceQueue.MarkFinished(this).string Name
Human-readable identifier.ServiceCall(string name)
Constructor.
ServiceQueue
static void Enqueue(ServiceCall call)
Adds aServiceCallto the queue. Starts execution immediately if queue was empty.static void MarkFinished(ServiceCall call)
Removes the call from the queue and starts the next queued call if any. Handles non-active calls (not at head) by simple removal.
TagAwareBase
enum TagTypes
User,Group,Template,TestSetup,Sensors,SensorModelsabstract TagTypes TagType { get; }
Must be implemented by derived classes to specify tag type.byte[] TagsBlobBytes
Gets/setsTagIDsas a byte array (for DB storage). Logs exceptions on failure.int[] TagIDs
Gets/sets the list of tag IDs.void SetTagsFromCommaSeparatedString(string tagText, Tags.GetSqlCommandDelegate getSqlCommand)
Parses comma-separated tags and setsTagIDs.virtual void SetTags(string[] tagsText, Tags.GetSqlCommandDelegate getSqlCommand)
Adds tags to DB and updatesTagIDs. RaisesOnPropertyChanged("TagIDs").string GetTagsAsCommaSeparatedString(Tags.GetSqlCommandDelegate getSqlCommand)
Returns tags as comma-separated string.virtual string[] GetTagsArray(Tags.GetSqlCommandDelegate getSqlCommand)
Returns tag text array.virtual bool TagCompatible(string tags, ...)
Checks if any tag in the provided comma-separated string matches current tags.virtual bool TagCompatible(int[] tags)
Checks if any tag ID intagsintersects withTagIDs.virtual bool HasIntersectingTag(int[] tags)
ReturnstrueiftagsandTagIDsshare any ID.void InsertTagsFromCommaSeparatedString(int id, TagTypes tagType, string tags, ...)
Sets tags and commits assignments.void Commit(int id, TagTypes tagType, ...)
Deletes existing tag assignments for the object, then inserts new assignments forTagIDs. Uses stored proceduressp_TagAssignmentsDeleteandsp_TagAssignmentsInsert.List<int> GetTagIdList(int objectId, TagTypes tagType, ...)
Retrieves tag IDs for an object from DB viasp_TagAssignmentsGet. Logs failures.
Utility
static byte[] GetBytesFromStringArray(string[] array, string separator)
Joins array withseparator, returns UTF-8 bytes.static string GetAllErrorMessages(Exception ex)
Recursively aggregates exception messages (including inner exceptions).static bool PingNetwork(string hostNameOrAddress)
Pings host with 4s timeout and fixed buffer. Returnstrueon success.static T GetX(IDataReader reader, string column, T defaultValue = default)
Generic pattern for safe column extraction:GetUShort,GetUInt,GetString,GetStringArray,GetInt,GetDouble,GetShort,GetNullableDateTime,GetUlong,GetNullableInt,GetByteArray,GetBool,GetDateTime,GetLong
All returndefaultValueonDBNull, parse failure, or invalid column. Logs parse failures viaAPILogger.
Tags
class Tagconst int INVALID_ID = -1int ID,string Text,bool IsObsolete- Constructors:
(string, int),(Tag),(IDataRecord),(DataRow) object Clone()→new Tag(this)
delegate SqlCommand GetSqlCommandDelegate(bool bNewConnection)
Factory for database commands.static Tags GetTagsInstance(GetSqlCommandDelegate getSqlCommand)
Gets singleton instance (lazy-initialized).static bool AddTag(string tagText, ...)
Adds tag to DB if not present. Returnstrueif added.static bool MigrateTag(string tagText, ...)
Commits tag (used for DB migration).static bool[] AddRange(string[] tagText, ...)
Adds multiple tags. Trims leading whitespace before adding.static int GetIDFromTagText(string tagText, ...)
Gets tag ID from DB (returnsTag.INVALID_IDif not found).static int[] GetIDsFromTagText(string[] tagText, ...)
Gets tag IDs for array of texts. Filters outINVALID_ID.static string GetTagTextFromID(int tagID, ...)
Gets tag text from memory cache (returnsnullif invalid/missing).static string[] GetTagTextFromIDs(int[] tagId, ...)
Gets tag texts from IDs. Filters invalid/whitespace.bool ContainsTag(string text)
Checks if tag exists in memory cache.void UpdateList(GetSqlCommandDelegate getSqlCommand)
Refreshes memory cache from DB viasp_TagsGet.
3. Invariants
-
Singleton:
- Only one instance per
Texists. Attemptingnew T()throwsInvalidOperationException. - Static constructor exceptions are captured and rethrown on
Instanceaccess.
- Only one instance per
-
BulkObservableCollection:
AddRange/RemoveRangefire exactly oneResetnotification per call, regardless of item count.CheckReentrancy()is called before modifications to prevent reentrancy issues.
-
ServiceQueue:
- Only one
ServiceCallexecutes at a time (viaTask.Run). - Calls are processed in FIFO order.
MarkFinishedonly advances the queue if the finished call is the head of the queue.
- Only one
-
Tags:
- Tags are immutable (no rename/delete/obsolete support).
- Memory cache (
_tagsLookup) is lazily populated and updated only viaAddTag,MigrateTag, orUpdateList. Tag.INVALID_ID(-1) is used to indicate missing tags.
-
TagAwareBase:
TagIDsis nevernull(defaults tonew int[0]).Commitdeletes existing assignments before inserting new ones.
4. Dependencies
-
Imports/References:
Unity(Microsoft Unity Container)System.Windows(Color,Visibility)System.Data,System.Data.SqlClient(ADO.NET)DTS.Common.Base(BasePropertyChanged,IBaseViewModel)DTS.Common.Enums(RecordingModes,CalibrationBehaviors,InputClockSource,OutputClockSource)DTS.Common.Interface.Sensors(ISensor)DTS.Common.Utilities.Logging(APILogger)
-
Depended upon by:
- UI layers (via
RegionNames,StatusAndProgressBarEventArgs) - Data import modules (
ImportData) - Service orchestration consumers (
ServiceQueue) - Tag-aware entities (
TagAwareBase) - Database access layers (
Utility,Tags)
- UI layers (via
5. Gotchas
-
Singleton<T>:- Static initialization exceptions are logged to
Console.WriteLine(notAPILogger). - The singleton instance is created on first
Instanceaccess, not on module load.
- Static initialization exceptions are logged to
-
BulkObservableCollection<T>:AddRange/RemoveRangeuseNotifyCollectionChangedAction.Reset, which may cause UI controls to re-render entirely (not incremental updates).- Exceptions in
AddRange/RemoveRangeare silently logged and do not propagate.
-
ServiceQueue:ServiceCall.Startedis used to prevent duplicate execution, but there is no cancellation mechanism.- Non-active calls (not at head) are removed from the queue without execution.
-
Tags:- Memory cache (
_tagsLookup) is not automatically updated afterAddTag/MigrateTag(only updated onUpdateListor explicitCommit). GetTagTextFromIDreads from cache only; if cache is stale, it may returnnullfor valid IDs.
- Memory cache (
-
TagAwareBase:RemoveTagsis a stub (empty implementation).SetTagsFromCommaSeparatedStringdoes not skip empty strings (despite commented-out null check referencing FogBugz #7176).
-
Utility:PingNetworkuses a fixed 32-byte buffer and 4-second timeout.- All
GetXmethods returndefaultValueon parse failure without rethrowing.
-
ImportData.TestSetupImportData:- Clock master/slave properties (
ClockMasterInput,ClockMasterOutput, etc.) default toNoneandfalse.
- Clock master/slave properties (