8.6 KiB
8.6 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | ||||
|---|---|---|---|---|---|---|---|---|
|
2026-04-16T04:58:34.034818+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | d08339a454aa8af1 |
Users
Documentation: DatabaseExport.Users Module (Version 57)
1. Purpose
This module provides data models and utilities for representing and persisting user account information in a legacy database export context (specifically for database version 57). It defines core abstractions for users (User), tag-aware entities (TagAwareBase), UI item identification (IUIItems), and centralized tag management (Tags). Its primary role is to enable serialization of user data—including permissions, visibility settings, and tags—into XML-compatible formats, while leveraging an in-memory cache of tags for efficient lookup. It supports default system users (e.g., Admin, Guest) and enforces immutability constraints on default users’ roles.
2. Public Interface
Interface: IUIItems
string GetName()
Returns a unique string identifier for a UI item (e.g., tab or module name). Used as the key in permission/visibility dictionaries.
Abstract Class: TagAwareBase
byte[] TagsBlobBytes { get; set; }
Serializes/deserializes theTagIDsarray to/from a byte array usingBuffer.BlockCopy. Setter includes atry/catchthat silently discards exceptions (no logging in source).int[] TagIDs { get; set; }
Stores the list of tag IDs associated with the entity. Setter replaces with empty array ifnull.string GetTagsCommaSeperatedString()
Returns a comma-separated string of tag text values (e.g.,"Role:Admin,Version:1"), derived fromTagIDsviaGetTagsArray().virtual string[] GetTagsArray()
ConvertsTagIDsto human-readable tag strings usingTags.GetTagTextFromIDs(). Overridable.
Class: Tags
class Tag
Represents a single tag withID,Text, andIsObsoletefields. Includes:const int INVALID_ID = -1- Constructor from
DataRow(populates fields from DB columns; exceptions silently ignored). Clone()implementation (returns a newTaginstance with copied values).
static Tags TagsInstance { get; }
Singleton accessor (lazy-initialized on first access).static string GetTagTextFromID(int tagID)
Returns the tag text for a given ID from the in-memory cache. ReturnsnulliftagID < 0,INVALID_ID, or not found.static string[] GetTagTextFromIDs(int[] tagID)
Converts an array of tag IDs to an array of tag texts, skippingINVALID_IDandnull/whitespace results.private void UpdateList()
Populates/refreshes the_tagsLookupdictionary by querying the database (SELECT * FROM [Tags table]). Useslock(MyLock)for thread safety.
Class: User
- Nested Enums
DefaultRoles:Administrator,PowerUser,User,GuestUserPermissionLevels:Deny,Read,ReadAndExecute,Edit,AdminTags: Enumerates tag names used for user metadata (e.g.,Role,UserName,Password)XmlFields: Enumerates XML element names for serialization (e.g.,ID,UserName,IUIItemPermissions)
- Constants
DEFAULT_LAST_MODIFIED_BY = "---"DEFAULT_ADMIN_USERNAME = "Admin",DEFAULT_GUEST_USERNAME = "Guest", etc.INVALID_ID = -1
- Properties
bool IsADefaultUser→trueifUserNamematchesGetDefaultUserName(Role).string Name,string UserName,int Id,DefaultRoles Role,int Version,DateTime LastModified,string LastModifiedBy,bool LocalOnlyprivate readonly Dictionary<IUIItems, UserPermissionLevels> _tabPermissionsprivate readonly Dictionary<IUIItems, bool> _showTabs
- Methods
public override ConstraintHelper[] GetConstraints()
Returns a constraint forUserName(used for uniqueness validation).public override string LookupTable => DbOperations.Users.USERS_TABLE
Specifies the database table name.public User(DataRow row)
Constructor that initializes all properties from a databaseDataRow.public string GetPermissionSerialized()
Serializes_tabPermissionsas"UIItemName=PermissionLevelInt,..."(thread-safe vialock(TabPermissionsLock)).public static string GetDefaultUserName(DefaultRoles role)
MapsDefaultRolesto default usernames (e.g.,Administrator→"Admin").public string GetVisibilitySerialized()
Serializes_showTabsas"UIItemName=1/0,...".public Dictionary<string, string> GetValues()
Returns a dictionary of XML field names to values for serialization, including:- Basic fields (
ID,UserName,DisplayName,Password,Role, etc.) - Serialized permissions (
IUIItemPermissions) - Serialized visibility (
IUIItemVisibility) - Tag string (
UserTagsviaGetTagsCommaSeperatedString())
- Basic fields (
3. Invariants
TagIDsmust be non-null: TheTagIDssetter replacesnullwithnew int[0].INVALID_ID = -1is excluded from tag lookups:GetTagTextFromIDandGetTagTextFromIDsexplicitly skipINVALID_ID.- Default users are immutable by role: Setting
Roleon aUserwhereIsADefaultUser == truethrowsNotSupportedExceptionif the role changes. - Tag text lookup is case-sensitive and text-based:
_tagsLookupusesTag.Textas the dictionary key (inUpdateList()), butGetTagTextFromIdsearches byTag.ID(linear scan). TagsInstanceis a singleton: Initialized once on first access;_tagsLookupis populated only at construction and viaUpdateList()(not auto-refreshed).TagsBlobBytessize must be divisible bysizeof(int): The setter assumesvalue.Length % sizeof(int) == 0; otherwise,Buffer.BlockCopymay throw (caught silently).
4. Dependencies
- Imports/Usings:
System,System.Text,System.Collections.Generic,System.Linq,System.Data
- External Types Referenced (from source):
DbOperations.Tags(static class withTagFieldsenum andTableproperty)DbOperations.Users(static class withUserFieldsenum andUSERS_TABLEproperty)DbOperations.Connection(providesQueryDataSet)DbOperations.GetCommand()(returnsIDbCommand)DbTimeStampBase(base class ofTagAwareBase; not shown, assumed to provide timestamp fields)ConstraintHelper(used inGetConstraints())
- Depended Upon By:
Useris used by export/serialization logic (e.g.,GetValues()implies integration with XML export).Tags.TagsInstanceis used byTagAwareBase.GetTagsArray()andUser.GetValues().IUIItemsis used as a key inUser’s permission/visibility dictionaries (implementations not in this source).
5. Gotchas
- Silent exception handling: Multiple
catch (Exception)blocks (inTagAwareBase.TagsBlobBytes,Tagconstructor,Tags.UpdateList) log nothing—only commented-out logging stubs exist. Errors may go unnoticed. - Inefficient tag lookup:
GetTagTextFromIdperforms a linear scan over_tagsLookupto find by ID, despite_tagsLookupbeing keyed byText. This is O(n) per lookup. TagsBlobBytessetter is fragile: Assumes input byte array length is divisible bysizeof(int); otherwise,Buffer.BlockCopythrows (caught silently).TagsInstancenot thread-safe during initialization:_tagsInstanceis assigned without double-checked locking (onlynull == _tagsInstancecheck), risking multiple instantiations in multi-threaded scenarios.IsADefaultUseris role-dependent but role change is restricted: A user’s default status is computed at runtime, but changing the role of a default user is blocked—this may cause confusion if default usernames are reassigned.GetTagsCommaSeperatedString()has typo: Method name uses "Seperated" (missing 'a'), consistent with legacy naming.TagsBlobBytesandTagIDsare redundant:TagsBlobBytesis a byte-level serialization ofTagIDs, but onlyTagIDsis used inGetTagsArray().TagsBlobBytesmay be legacy or for external compatibility.- No validation of
UserNameuniqueness: WhileGetConstraints()defines a uniqueness constraint, enforcement is external (e.g., in DB or caller), and theUserclass does not validate this itself.
None identified beyond these.