Class SqlServerConnectionStore
- Namespace
- ItTiger.TigerQuery.Core
- Assembly
- ItTiger.TigerQuery.Core.dll
public sealed class SqlServerConnectionStore
- Inheritance
-
SqlServerConnectionStore
- Inherited Members
Remarks
Every operation uses the file named by the options this instance was constructed with, resolved once to an absolute path and exposed as FilePath. Nothing in the store probes another location or falls back to a default when the selected file is missing, malformed, or inaccessible: an application that selects a store selects it for lookup, filtering, copy, add, update, save, and delete alike. There is deliberately no universal default store; a host chooses Shared(string, string), AppSpecific(string, string, string), or an explicit FilePath once and injects the resulting instance everywhere.
Mutating operations (Add(SqlServerConnectionProfile), AddOrUpdate(SqlServerConnectionProfile), Copy(string, SqlServerConnectionCopyOptions, SqlServerConnectionValidationPolicy?), Delete(string), and Save(IEnumerable<SqlServerConnectionProfile>)) are coordinated by normalized path and replace the file in one step. Concurrent mutations therefore cannot lose one another's updates within a process, and a mutation that fails leaves the previous file intact rather than truncated. See MutationTimeout for the wait budget and the guarantee's exact boundaries. Reads are not coordinated because the atomic replacement never exposes a partially written file.
Returned profiles are detached mutable objects, so changes require an explicit AddOrUpdate(SqlServerConnectionProfile) or Save(IEnumerable<SqlServerConnectionProfile>) call.
Existing JSON without metadata remains compatible. Empty metadata is omitted, and metadata keys are written in ordinal order.
Constructors
SqlServerConnectionStore(SqlServerConnectionStoreOptions)
public SqlServerConnectionStore(SqlServerConnectionStoreOptions options)
Parameters
optionsSqlServerConnectionStoreOptions- The JSON file location.
Exceptions
- ArgumentNullException
optionsis null.
SqlServerConnectionStore(SqlServerConnectionStoreOptions, IConnectionPasswordProtector)
public SqlServerConnectionStore(SqlServerConnectionStoreOptions options, IConnectionPasswordProtector passwordProtector)
Parameters
optionsSqlServerConnectionStoreOptions- The JSON file location.
passwordProtectorIConnectionPasswordProtector- The strategy invoked around serialization and deserialization.
Exceptions
- ArgumentNullException
optionsorpasswordProtectoris null.
Properties
FilePath
public string FilePath { get; }
Property Value
Remarks
Methods
Add(SqlServerConnectionProfile)
public void Add(SqlServerConnectionProfile connection)
Parameters
connectionSqlServerConnectionProfile- The profile to append.
Remarks
Exceptions
- ArgumentNullException
connectionis null.- InvalidOperationException
- A profile with exactly the same Name already exists.
- TimeoutException
- Mutation coordination for FilePath could not be acquired within MutationTimeout.
AddOrUpdate(SqlServerConnectionProfile)
public void AddOrUpdate(SqlServerConnectionProfile connection)
Parameters
connectionSqlServerConnectionProfile- The profile to persist.
Remarks
Exceptions
- ArgumentNullException
connectionis null.- TimeoutException
- Mutation coordination for FilePath could not be acquired within MutationTimeout.
Copy(string, SqlServerConnectionCopyOptions, SqlServerConnectionValidationPolicy?)
public SqlServerConnectionProfile Copy(string sourceName, SqlServerConnectionCopyOptions options, SqlServerConnectionValidationPolicy? validationPolicy = null)
Parameters
sourceNamestring- The nonblank, case-sensitive name of the profile to copy.
optionsSqlServerConnectionCopyOptions- The target name and the controlled overrides to apply.
validationPolicySqlServerConnectionValidationPolicy- The policy the resulting profile is validated against; DatabaseOptional when null.
Returns
- SqlServerConnectionProfile
- The detached profile exactly as it was persisted. It can be resolved, edited, and later removed through the ordinary Find(string), AddOrUpdate(SqlServerConnectionProfile), and Delete(string) APIs.
Remarks
The operation is same-store by construction: it is an instance method with no destination parameter, so a copy cannot silently cross stores. Source lookup, duplicate-name detection, validation, and persistence all happen while one mutation scope is held, so a concurrent mutation cannot slip a conflicting name in between the check and the write.
The copy is taken from the at-rest representation, so the source's protected password is duplicated exactly as stored. The password is never decrypted, reconstructed, logged, or handed to the caller as plaintext, and the copy succeeds even when the current user cannot decrypt the blob; whether the copy is usable afterwards follows the normal resolver and protector behavior. Neither the source nor any unrelated profile is re-protected, so their stored ciphertext is unchanged.
Every persisted field is carried by the profile's own JSON contract rather than a hand-written property list, so a field added in a later release is copied without a caller change. Overrides are limited to the profile name, the initial catalog, and the named metadata entries; all other metadata is preserved. Copy is never an upsert and never opens a SQL connection.
Exceptions
- ArgumentException
sourceNameis null, empty, or whitespace (parameter namesourceName), oroptionshas a blank target name or invalid metadata mutations (parameter nameoptions).- ArgumentNullException
optionsis null.- InvalidOperationException
- The source profile does not exist, a profile already uses TargetName, or the resulting profile fails validation. The store is left unchanged in every case.
- TimeoutException
- Mutation coordination for FilePath could not be acquired within MutationTimeout.
Delete(string)
public bool Delete(string name)
Parameters
namestring- The nonblank, case-sensitive profile name.
Returns
Remarks
Exceptions
- ArgumentException
nameis null, empty, or whitespace. The parameter name isname.- TimeoutException
- Mutation coordination for FilePath could not be acquired within MutationTimeout.
Exists(string)
public bool Exists(string name)
Parameters
namestring- The nonblank, case-sensitive profile name.
Returns
Exceptions
- ArgumentException
nameis null, empty, or whitespace. The parameter name isname.
Find(string)
public SqlServerConnectionProfile? Find(string name)
Parameters
namestring- The nonblank, case-sensitive profile name.
Returns
- SqlServerConnectionProfile
- A detached mutable profile, or null when absent.
Exceptions
- ArgumentException
nameis null, empty, or whitespace. The parameter name isname.
GetConnectionNamesAsync(CancellationToken)
public Task<IReadOnlyList<string>> GetConnectionNamesAsync(CancellationToken _)
Parameters
_CancellationToken- A compatibility cancellation token; the current synchronous file load does not observe it.
Returns
- Task<IReadOnlyList<string>>
- A task containing a read-only list of profile names.
Load()
public IReadOnlyList<SqlServerConnectionProfile> Load()
Returns
- IReadOnlyList<SqlServerConnectionProfile>
- A newly materialized list, or an empty list when the file does not exist or contains JSON null.
Remarks
QueryByMetadata(IEnumerable<SqlServerConnectionMetadataFilter>)
public IReadOnlyList<SqlServerConnectionProfile> QueryByMetadata(IEnumerable<SqlServerConnectionMetadataFilter> filters)
Parameters
filtersIEnumerable<SqlServerConnectionMetadataFilter>- The metadata predicates combined using AND semantics.
Returns
- IReadOnlyList<SqlServerConnectionProfile>
- Matching detached profiles in their persisted order.
Remarks
Equals requires
the key to exist with the exact value; IsSet requires the key to
exist even when its value is empty; IsNotSet requires absence.Exceptions
- ArgumentNullException
filtersis null. The parameter name isfilters.- ArgumentException
- A filter entry is null, has an empty key or unsupported operator, lacks a
value for
Equals, or supplies a value forIsSet/IsNotSet. The parameter name isfilter.
Save(IEnumerable<SqlServerConnectionProfile>)
public void Save(IEnumerable<SqlServerConnectionProfile> connections)
Parameters
connectionsIEnumerable<SqlServerConnectionProfile>- The profiles to persist in enumeration order.
Remarks
Exceptions
- ArgumentNullException
connectionsis null.- TimeoutException
- Mutation coordination for FilePath could not be acquired within MutationTimeout.