12 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
2026-04-16T04:27:03.727990+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | 7a6cc3dcbca85c45 |
Documentation: TestSetups Module (DbAPI)
1. Purpose
This module provides data access layer (DAL) interfaces and implementations for managing test setup–related entities in the database: graphs, calculated channels, regions of interest (ROIs), and test setups themselves (including hardware metadata and group associations). It acts as a bridge between higher-level application logic and SQL Server stored procedures, enforcing user authentication, validating input parameters, and translating database errors into standardized error codes. The module is part of the DbAPI.TestSetups namespace and is used to persist and retrieve configuration data for physical test setups (e.g., in data acquisition systems), supporting CRUD operations and domain-specific logic such as ROI generation defaults and test setup completeness flags.
2. Public Interface
All interfaces define public contracts; implementations are internal (CalculatedChannels, Graphs, RegionsOfInterest, TestSetups classes). Only interface methods are documented here.
IGraphs
-
ulong GraphsGet(IUserDbRecord user, IConnectionDetails connection, int? graphId, int? testSetupId, out IGraphRecord[] records)
Retrieves graph records matching optionalgraphIdandtestSetupId. Returns array ofIGraphRecord.graphId: specific graph ID (nullable);nullmeans all graphs for giventestSetupId.testSetupId: required to filter graphs by test setup.
-
ulong GraphsUpdate(IUserDbRecord user, IConnectionDetails connection, IGraphRecord record)
Updates an existing graph record in the database.- Requires
record.GraphIdto be non-null and valid.
- Requires
-
ulong GraphsInsert(IUserDbRecord user, IConnectionDetails connection, ref IGraphRecord record)
Inserts a new graph record. After successful insert,record.GraphIdis updated with the database-generated ID. -
ulong GraphsDelete(IUserDbRecord user, IConnectionDetails connection, int graphId)
Deletes the graph with the specifiedgraphId.
ICalculatedChannels
-
ulong CalculatedChannelsDelete(IUserDbRecord user, IConnectionDetails connection, int calculatedChannelId)
Deletes the calculated channel with the specifiedcalculatedChannelId. -
ulong CalculatedChannelsGet(IUserDbRecord user, IConnectionDetails connection, int? calculatedChannelId, string testSetupName, out ICalculatedChannelRecord[] records)
Retrieves calculated channel records matching optionalcalculatedChannelIdandtestSetupName.testSetupNamemay be empty string ("") to match no test setup.
-
ulong CalculatedChannelsInsert(IUserDbRecord user, IConnectionDetails connection, ref ICalculatedChannelRecord record)
Inserts a new calculated channel. After successful insert,record.Idis updated with the database-generated ID. -
ulong CalculatedChannelsUpdate(IUserDbRecord user, IConnectionDetails connection, ICalculatedChannelRecord record)
Updates an existing calculated channel. Requiresrecord.Idto be set.
IRegionsOfInterest
-
ulong RegionsOfInterestDelete(IUserDbRecord user, IConnectionDetails connection, int testSetupId)
Deletes all ROI records associated with the giventestSetupIdfrom bothTestSetupROIsandROIPeriodChannelstables. -
ulong RegionsOfInterestInsert(IUserDbRecord user, IConnectionDetails connection, int clientDbVersion, int testSetupId, IRegionOfInterest regionOfInterest)
Inserts ROI data intoTestSetupROIsandROIPeriodChannelstables.clientDbVersion: passed to stored procedure (likely for version-specific logic).
-
ulong RegionsOfInterestGet(IUserDbRecord user, IConnectionDetails connection, int clientDbVersion, int testSetupId, out IRegionOfInterest[] records)
Retrieves all ROI records for the giventestSetupId, combining data fromTestSetupROIsandROIPeriodChannels. -
ulong TestSetupROIsDelete(...)
Deletes only fromTestSetupROIstable (notROIPeriodChannels). Signature matchesRegionsOfInterestDelete. -
ulong TestSetupROIsInsert(..., out int testSetupROIId)
Inserts intoTestSetupROIsonly; outputs the newtestSetupROIId. -
ulong TestSetupROIsGet(..., out ITestSetupROIRecord[] records)
Retrieves onlyTestSetupROIsrecords (not joined withROIPeriodChannels). -
ulong ROIPeriodChannelsInsert(...)
Inserts a singleROIPeriodChannelsrecord (channel mapping for an ROI period). -
ulong ROIPeriodChannelsGet(..., out IROIPeriodChannelRecord[] roiPeriodChannelRecords)
RetrievesROIPeriodChannelsrecords for a giventestSetupROIId.
ITestSetups
-
ulong TestSetupHardwareDelete(..., int? Id, int? dasId, int? testSetupId)
Deletes hardware metadata records. At least one ofId,dasId, ortestSetupIdmust be non-null. -
ulong TestSetupHardwareUpdate(..., ITestSetupHardwareRecord record)
Updates a hardware metadata record. -
ulong TestSetupHardwareInsert(..., ITestSetupHardwareRecord record)
Inserts a hardware metadata record. -
ulong TestSetupHardwareGet(..., int clientDbVersion, int? testSetupId, out ITestSetupHardwareRecord[] records)
Retrieves hardware metadata (e.g., sample rate, anti-aliasing filter settings) for giventestSetupIdor all. -
ulong TestSetupGroupsInsert(..., ITestSetupGroupRecord record)
Inserts a group–test setup association. -
ulong TestSetupGroupsUpdate(..., ITestSetupGroupRecord record)
Updates a group–test setup association. -
ulong TestSetupGroupsGet(..., int? groupId, int? testSetupId, string testSetupName, out ITestSetupGroupRecord[] groups)
Retrieves group–test setup associations matching criteria. -
ulong TestSetupsMarkIsDirtyIsComplete(..., string name, bool dirty, bool complete, string error)
UpdatesIsDirtyandIsCompleteflags for a test setup namedname.errormay contain validation messages. -
ulong TestSetupsDeleteByDate(..., DateTime date)
Deletes all test setups older thandate. -
ulong TestSetupsAndGroupsDeleteAll(...)
Deletes all test setups and associated group associations. -
ulong TestSetupsDeleteById(..., int[] ids)
Deletes test setups by their IDs. -
ulong TestSetupsDeleteByName(..., string[] names)
Deletes test setups by their names. -
ulong TestSetupsUpdateInsert(..., int clientDbVersion, ref ITestSetupRecord record)
Inserts or updates a test setup record.recordis passed by reference and may be modified (e.g., ID populated on insert). -
ulong TestSetupsGet(..., int clientDbVersion, int? testSetupId, string testSetupName, double defaultROIStart, double defaultROIEnd, bool defaultIgnoreShortedStart, bool defaultIgnoreShortedTrigger, out ITestSetupRecord[] records, out string[] errors)
Retrieves test setup records. Includes logic to generate default ROIs if missing (usingdefaultROIStart/defaultROIEnd).defaultIgnoreShortedStart/defaultIgnoreShortedTrigger: flags for backward compatibility with older DB versions (e.g., v91) that lack these fields.
3. Invariants
- Authentication: All methods first check
IsUserLoggedIn(user, connection); if false, returnERROR_ACCESS_DENIED. - Error Handling: All methods return
ERROR_SUCCESS(0) on success; non-zero values are error codes. Errors are logged viaLogManager. - Null/Empty Handling:
- Nullable parameters (
int?,string) acceptnullor""(where applicable) to mean "no filter". CalculatedChannelsGetallows emptytestSetupName.GraphsGetrequirestestSetupIdto be non-null if filtering by test setup (butgraphIdmay be null).
- Nullable parameters (
- Input Validation:
GraphsInsert,CalculatedChannelsInsert,CalculatedChannelsUpdate,CalculatedChannelsDeletevalidaterecord != null.TestSetupHardwareDeleterequires at least one ID parameter (Id,dasId,testSetupId) to be non-null.
- Output Parameters:
refparameters (recordinInsertmethods) are updated with database-generated IDs after successful insert.outparameters (records,errors) are always initialized (e.g.,records = new T[0]on failure).
- Resource Cleanup: All methods dispose
SqlCommandand connection infinallyblocks.
4. Dependencies
Module Dependencies
DbAPI.Connections: ProvidesIsUserLoggedIn,ConnectionManager.GetSqlCommand.DbAPI.Errors: DefinesErrorCodes.ERROR_*constants.DbAPI.Logging: ProvidesLogManager.DTS.Common.Interface.*:Database:IUserDbRecord,IConnectionDetails.Graphs:IGraphRecord,GraphRecord.TestSetups:ICalculatedChannelRecord,ITestSetupRecord,ITestSetupHardwareRecord,ITestSetupGroupRecord,IRegionOfInterest,ITestSetupROIRecord,IROIPeriodChannelRecord.RegionOfInterest:IRegionOfInterest.
System.Data.SqlClient: Used forSqlCommand,SqlDbType,SqlParameter.System.Globalization: Used forCultureInfo.InvariantCulture.TextInfo.ListSeparator(inCalculatedChannels).
Inferred Usage
- Higher-level services (e.g., test setup management UI/backend) depend on these interfaces.
- The
TestSetupsclass (not shown) likely orchestrates calls toIGraphs,ICalculatedChannels,IRegionsOfInterest, andITestSetups.
5. Gotchas
-
GraphsDeletebug: InGraphs.cs,GraphsDeletepasses@TestSetupId = nulltosp_TestGraphsDeleteregardless of input. This likely ignores thetestSetupIdparameter from the interface and may delete graphs incorrectly (only filters by@GraphId).
→ Observed in source:cmd.Parameters.Add(new SqlParameter("@TestSetupId", SqlDbType.Int) { Value = null }); -
Logging inconsistency: In
CalculatedChannelsGet, errors are logged underLogManager.LogEvents.Graphsinstead ofLogManager.LogEvents.CalculatedChannels.
→ Likely copy-paste error. -
TestSetupROIsInsertvsRegionsOfInterestInsert:RegionsOfInterestInsertinserts into bothTestSetupROIsandROIPeriodChannels, whileTestSetupROIsInsertinserts only intoTestSetupROIs. Confusing naming—RegionsOfInterest*implies full ROI handling, butTestSetupROIs*is a partial subset. -
TestSetupsGetside effects: ThedefaultROIStart/defaultROIEndparameters suggest the method may generate default ROIs on retrieval (not just read them). This could cause unexpected behavior if callers expect pure read-only behavior. -
CalculatedChannelsInsert/Updateinput encoding:InputChannelIdsis converted tobyte[]usingUtility.GetBytesFromStringArray(..., ListSeparator). The separator is hardcoded toCultureInfo.InvariantCulture.TextInfo.ListSeparator(typically","), but ifrecord.InputChannelIdscontains commas, parsing may fail. No validation or escaping is visible. -
Missing
clientDbVersioninGraphs*methods: UnlikeRegionsOfInterestandTestSetups, theGraphsmethods do not accept aclientDbVersionparameter, suggesting version-specific logic is not supported for graphs. -
No transaction support: All operations are executed individually. If a logical operation requires multiple DB calls (e.g., insert ROI + period channels), callers must manage transactions externally.
-
No explicit validation of
testSetupIdexistence: Methods likeRegionsOfInterestInsertaccepttestSetupIdbut do not verify it exists in the database before inserting. This may cause FK violations if the test setup is missing.