This commit is contained in:
2026-04-17 14:55:32 -04:00
commit bc3ac1d4c9
18017 changed files with 4371742 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
---
source_files:
- DataPRO/Modules/Database/DatabaseServices/Converters/DbTypeToVisibilityConverter.cs
generated_at: "2026-04-17T16:44:02.991131+00:00"
model: "zai-org/GLM-5-FP8"
schema_version: 1
sha256: "f33cb579dbf56959"
---
# Documentation: DbTypeToVisibilityConverter
## 1. Purpose
`DbTypeToVisibilityConverter` is a WPF `IMultiValueConverter` that determines the visibility of UI elements based on database connection type state. It bridges the view layer (`DatabaseStatusBarView`) and view model layer (`DatabaseStatusBarViewModel`) to conditionally show or hide elements depending on the current `DbType` configuration and connection status. This converter is specifically designed for the database status bar component in the application.
## 2. Public Interface
### `DbTypeToVisibilityConverter` (class)
Implements: `IMultiValueConverter`
#### `Convert(object[] values, Type targetType, object parameter, CultureInfo culture)`
**Signature:**
```csharp
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
```
**Behavior:** Converts database type information to a `Visibility` value.
- **`values[0]`**: Expected to be an integer value castable to `DbType` enum (the target database type being evaluated for visibility).
- **`values[1]`**: Expected to be a `DatabaseStatusBarView` instance.
- **Returns:** `Visibility.Visible` or `Visibility.Collapsed` based on the following logic:
- If `view.DataContext` is `null`, returns `Visibility.Collapsed`.
- If `vm.DatabaseType` is `DbType.RemoteOnly`: Visible only when `dbType == DbType.RemoteOnly`.
- If `vm.DatabaseType` is `DbType.LocalOnly`: Visible only when `dbType == DbType.LocalOnly`.
- If `vm.DatabaseType` is `DbType.RemoteLocalHybrid`:
- When `vm.RemoteConnected` is `true`: Visible only when `dbType == DbType.RemoteOnly`.
- When `vm.RemoteConnected` is `false`: Visible only when `dbType == DbType.RemoteLocalHybrid`.
- All other cases: Returns `Visibility.Collapsed`.
#### `ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)`
**Signature:**
```csharp

View File

@@ -0,0 +1,35 @@
---
source_files:
- DataPRO/Modules/Database/DatabaseServices/Properties/Settings.Designer.cs
- DataPRO/Modules/Database/DatabaseServices/Properties/AssemblyInfo.cs
generated_at: "2026-04-17T16:25:38.816580+00:00"
model: "zai-org/GLM-5-FP8"
schema_version: 1
sha256: "9c93cde3415ea476"
---
# Properties
### Purpose
This module provides assembly metadata and application settings infrastructure for the `DatabaseServices` assembly. It is a standard .NET properties folder containing auto-generated settings and assembly-level attributes. The settings class is currently minimal, suggesting either a placeholder or that configuration is managed elsewhere in the solution.
### Public Interface
**`DatabaseServices.Properties.Settings`** (internal sealed partial class)
- Inherits from `global::System.Configuration.ApplicationSettingsBase`
- `public static Settings Default { get; }` - Returns a synchronized singleton instance of the settings class. This is the entry point for accessing any application-scoped or user-scoped settings defined for this assembly.
### Invariants
- The `Settings` class is marked `internal sealed`, meaning it cannot be inherited and is only accessible within the `DatabaseServices` assembly.
- The `defaultInstance` field is synchronized via `ApplicationSettingsBase.Synchronized()`, ensuring thread-safe access to the singleton.
- The settings class is auto-generated (via `SettingsSingleFileGenerator`); manual changes will be overwritten on regeneration.
### Dependencies
- **Depends on**: `System.Configuration.ApplicationSettingsBase` (from `System.Configuration` assembly)
- **Depended on by**: Cannot be determined from source alone (internal class, likely used by other classes within DatabaseServices assembly)
### Gotchas
- The `Settings` class contains no actual setting properties beyond the `Default` accessor. This is unusual for a settings file—either settings are defined in an external `.config` file not shown here, or this assembly does not require persistent configuration.
- The file is auto-generated by Visual Studio tooling (version 17.10.0.0); do not edit manually.
---

View File

@@ -0,0 +1,48 @@
---
source_files:
- DataPRO/Modules/Database/DatabaseServices/Resources/TranslateExtension.cs
- DataPRO/Modules/Database/DatabaseServices/Resources/StringResources.Designer.cs
generated_at: "2026-04-17T16:07:59.007705+00:00"
model: "zai-org/GLM-5-FP8"
schema_version: 1
sha256: "63cd62f694267ff8"
---
# Resources
### Purpose
This module provides localization resources and a XAML markup extension for the `DatabaseServices` assembly. It enables the resolution of user-facing strings (such as status messages regarding database operations) within the UI layer, supporting both direct code access via a resource manager and declarative access within XAML files.
### Public Interface
**Class: `TranslateExtension`**
* **Signature:** `public class TranslateExtension : MarkupExtension`
* **Constructor:** `TranslateExtension(string key)` - Initializes the extension with the resource key to be looked up.
* **Method:** `public override object ProvideValue(IServiceProvider serviceProvider)` - Resolves the `_key` to a localized string. Returns `#stringnotfound#` if the key is null/empty, or `#stringnotfound# <key>` if the lookup fails.
**Class: `StringResources` (Internal)**
* **Signature:** `internal class StringResources`
* **Property:** `static ResourceManager ResourceManager` - Provides access to the resource cache.
* **Property:** `static CultureInfo Culture` - Gets or sets the current UI culture for resource lookups.
* **Static Properties (Localized Strings):**
* `string ClearingLocalDb` ("Clearing local db")
* `string ConnectedTo` ("Connected to: ")
* `string CopyFromRemoteServer` ("Copy from remote server to local")
* `string CopyingTable` ("Copying")
* `string EnablingConstraints` ("Finishing up")
* `string Local` ("Local")
* `string Remote` ("Remote")
* `string SwitchFileNotFound` ("Could not switch to local - File not found:")
* `string SwitchToLocal` ("Switch to local")
* `string SwitchToRemote` ("Switch to remote")
### Invariants
* `TranslateExtension` never returns `null`. It guarantees a string return, falling back to error indicators (`#stringnotfound#`) if the resource key is missing.
* `StringResources` is an auto-generated class; manual modifications will be overwritten by tooling (Visual Studio/ResGen).
### Dependencies
* **Depends on:** `System`, `System.Windows.Markup`, `System.Resources`, `System.Globalization`.
* **Dependents:** Any XAML UI components within the `DatabaseServices` scope that require localized text.
### Gotchas
* The `StringResources` class is marked `internal`, making it inaccessible outside the `DatabaseServices` assembly.
* The `Translate

View File

@@ -0,0 +1,72 @@
---
source_files:
- DataPRO/Modules/Database/DatabaseServices/View/DatabaseStatusBarView.xaml.cs
- DataPRO/Modules/Database/DatabaseServices/View/DatabaseCopyView.xaml.cs
- DataPRO/Modules/Database/DatabaseServices/View/DatabaseSwitchView.xaml.cs
generated_at: "2026-04-17T16:36:18.725754+00:00"
model: "zai-org/GLM-5-FP8"
schema_version: 1
sha256: "9b3e32201b851fc1"
---
# Documentation: Database View Components
## 1. Purpose
This module provides WPF view components for database-related UI operations within the DatabaseServices namespace. It contains three code-behind classes—`DatabaseStatusBarView`, `DatabaseCopyView`, and `DatabaseSwitchView`—that serve as the visual layer for displaying database status, copying databases, and switching between local/remote database connections respectively. These views implement interfaces from `DTS.Common.Interface.Database` and delegate business logic to associated ViewModels via WPF data binding.
---
## 2. Public Interface
### `DatabaseStatusBarView`
**Namespace:** `DatabaseServices`
**Implements:** `IDatabaseStatusBarView`
```csharp
public DatabaseStatusBarView()
```
Default constructor. Calls `InitializeComponent()` to load the associated XAML layout. No additional public members are exposed beyond the interface implementation.
---
### `DatabaseCopyView`
**Namespace:** `DatabaseServices`
**Implements:** `IDatabaseCopyView`
```csharp
public DatabaseCopyView()
```
Default constructor. Calls `InitializeComponent()` to load the associated XAML layout.
```csharp
private void Copy_Click(object sender, RoutedEventArgs e)
```
Event handler for the copy button click. Casts `sender` to `Control`, retrieves the `DataContext` as `IDatabaseCopyViewModel`, and invokes `vm.CopyDatabase()`.
---
### `DatabaseSwitchView`
**Namespace:** `DatabaseServices`
**Implements:** `IDatabaseSwitchView`
```csharp
public DatabaseSwitchView()
```
Default constructor. Calls `InitializeComponent()` to load the associated XAML layout.
```csharp
private void SwitchToLocal_Click(object sender, RoutedEventArgs e)
```
Event handler for switching to local database. Casts `sender` to `Control`, retrieves the `DataContext` as `IDatabaseSwitchViewModel`, and invokes `vm.SwitchLocal()`.
```csharp
private void SwitchToRemote_Click(object sender, RoutedEventArgs e)
```
Event handler for switching to remote database. Casts `sender` to `Control`, retrieves the `DataContext` as `IDatabaseSwitchViewModel`, and invokes `vm.SwitchRemote()`.
---
## 3. Invariants
- **DataContext Contract:** `DatabaseCopyView` requires its `DataContext` to be an instance of `IDatabaseCopyViewModel`. `DatabaseSwitchView` requires its `DataContext` to be an instance of `IDatabaseSwitchViewModel`. Event handlers will fail with invalid

View File

@@ -0,0 +1,193 @@
---
source_files:
- DataPRO/Modules/Database/DatabaseServices/ViewModel/DatabaseStatusBarViewModel.cs
- DataPRO/Modules/Database/DatabaseServices/ViewModel/DatabaseSwitchViewModel.cs
- DataPRO/Modules/Database/DatabaseServices/ViewModel/DatabaseCopyViewModel.cs
generated_at: "2026-04-17T15:41:29.202299+00:00"
model: "zai-org/GLM-5-FP8"
schema_version: 1
sha256: "f011aeacca70c45c"
---
# Database ViewModels Documentation
## 1. Purpose
This module provides three MVVM ViewModels for database management within the `DatabaseServices` namespace:
- **DatabaseStatusBarViewModel**: Manages the database status bar UI, displaying the active database connection (Local vs Remote) and providing visual feedback (red background when disconnected from remote in hybrid mode).
- **DatabaseSwitchViewModel**: Handles switching between local and remote database connections, including connection testing, authentication setup, and forcing user re-login after database switches.
- **DatabaseCopyViewModel**: Implements database copy functionality to synchronize a remote database to a local database, including table-by-table copying with identity column handling and constraint management.
All three ViewModels follow the Prism MVVM pattern, use MEF for dependency injection with shared creation policy, and integrate with the application's event aggregation system.
---
## 2. Public Interface
### DatabaseStatusBarViewModel
**Implements:** `IDatabaseStatusBarViewModel`
| Member | Signature | Description |
|--------|-----------|-------------|
| `View` | `public IDatabaseStatusBarView View { get; set; }` | The associated view instance; DataContext is set to `this` in constructor. |
| `DatabaseType` | `public DbType DatabaseType { get; private set; }` | The configured database type (LocalOnly, RemoteOnly, RemoteLocalHybrid). |
| `ServerName` | `public string ServerName { get; private set; }` | Name of the database server; "Local" when not remote connected. |
| `RemoteConnected` | `public bool RemoteConnected => DbOperations._usingCentralizedDB;` | Indicates if currently connected to centralized/remote database. |
| `ActiveDbName` | `public string ActiveDbName { get; }` | Computed display name based on DatabaseType and connection state. Returns localized "Local" string or server name. |
| `BackgroundBrush` | `public Brush BackgroundBrush { get; }` | Returns `Brushes.Red` when hybrid mode is disconnected from remote; otherwise `Brushes.Transparent`. |
| `InitializeValues` | `public void InitializeValues(DbType dbType, string serverName, bool remoteConnected)` | Initializes the ViewModel's state and triggers PropertyChanged for `ActiveDbName` and `BackgroundBrush`. |
| `OnPropertyChanged` | `public void OnPropertyChanged(string propertyName)` | Raises the `PropertyChanged` event. |
| `NotificationRequest` | `public InteractionRequest<Notification> NotificationRequest { get; }` | Prism interaction request for notifications. |
| `ConfirmationRequest` | `public InteractionRequest<Confirmation> ConfirmationRequest { get; }` | Prism interaction request for confirmations. |
| `IsBusy` | `public bool IsBusy { get; set; }` | Bound to busy indicator state. |
| `IsMenuIncluded` | `public bool IsMenuIncluded { get; set; }` | Controls menu visibility. |
| `IsNavigationIncluded` | `public bool IsNavigationIncluded { get; set; }` | Controls navigation visibility. |
| `IsDirty` | `public bool IsDirty { get; private set; }` | Tracks unsaved changes state. |
| `Cleanup` / `CleanupAsync` | `public void Cleanup()` / `public Task CleanupAsync()` | No-op cleanup methods. |
| `Initialize` overloads | `void Initialize()`, `void Initialize(object)`, `void Initialize(object, object)` | No-op initialization methods. |
| `InitializeAsync` overloads | `Task InitializeAsync()`, `Task InitializeAsync(object)` | Return `Task.CompletedTask`. |
| `Activated` | `public void Activated()` | No-op activation method. |
| `Unset` | `public void Unset()` | No-op unset method. |
**Constructor:**
```csharp
public DatabaseStatusBarViewModel(
IDatabaseStatusBarView view,
IRegionManager regionManager,
IEventAggregator eventAggregator,
IUnityContainer unityContainer)
```
---
### DatabaseSwitchViewModel
**Implements:** `IDatabaseSwitchViewModel`
| Member | Signature | Description |
|--------|-----------|-------------|
| `View` | `public IDatabaseSwitchView View { get; set; }` | The associated view instance. |
| `DefaultDbName` | `public string DefaultDbName { get; private set; }` | Default database name for connections. |
| `DbHost` | `public string DbHost { get; private set; }` | Remote database host address. |
| `NTLMAuthentication` | `public bool NTLMAuthentication { get; private set; }` | Whether NTLM authentication is enabled. |
| `DbUser` | `public string DbUser { get; private set; }` | Database username for SQL authentication. |
| `DbPassword` | `public string DbPassword { get; private set; }` | Database password for SQL authentication. |
| `RemoteIsActive` | `public bool RemoteIsActive => DbOperations._usingCentralizedDB;` | Indicates if remote database is currently active. |
| `SwitchRemote` | `public void SwitchRemote()` | Switches to remote database connection. Tests connection, falls back to local on failure, publishes `DbStatusEvent` and `LogoutUserEvent`. |
| `SwitchLocal` | `public void SwitchLocal()` | Switches to local database. Validates local files exist, publishes status events and forces logout. |
| `InitializeDbSettings` | `public void InitializeDbSettings(string defaultDbName, string dbHost, bool ntlmAuthentication, string dbUser, string dbPassword)` | Stores database connection settings for use by switch methods. |
| `IsBusy`, `IsMenuIncluded`, `IsNavigationIncluded`, `IsDirty` | Same as DatabaseStatusBarViewModel | Standard ViewModel properties. |
| `NotificationRequest`, `ConfirmationRequest` | Same as DatabaseStatusBarViewModel | Prism interaction requests. |
| Lifecycle methods | Same pattern as DatabaseStatusBarViewModel | `Cleanup`, `CleanupAsync`, `Initialize*`, `Activated`, `Unset` are no-ops or return completed tasks. |
**Constructor:**
```csharp
public DatabaseSwitchViewModel(
IDatabaseSwitchView view,
IRegionManager regionManager,
IEventAggregator eventAggregator,
IUnityContainer unityContainer)
```
---
### DatabaseCopyViewModel
**Implements:** `IDatabaseCopyViewModel`
| Member | Signature | Description |
|--------|-----------|-------------|
| `View` | `public IDatabaseCopyView View { get; set; }` | The associated view instance. |
| `DatabaseType` | `public DTS.Common.Enums.Database.DbType DatabaseType { get; private set; }` | Current database type configuration. |
| `DbName` | `public string DbName { get; private set; }` | Name of the database being copied. |
| `CopyEnabled` | `public bool CopyEnabled => DatabaseType == DbType.RemoteLocalHybrid && DbOperations._usingCentralizedDB;` | Copy is only enabled in hybrid mode when connected to remote. |
| `IsCopyVisible` | `public bool IsCopyVisible { get; set; }` | Controls visibility of copy UI; defaults to `true`. |
| `OverallProgressBarView` | `public IStatusAndProgressBarView OverallProgressBarView { get; private set; }` | Progress bar view for overall copy progress. |
| `CurrentTaskProgressBarView` | `public IStatusAndProgressBarView CurrentTaskProgressBarView { get; private set; }` | Progress bar view for current table copy progress. |
| `CopyDatabase` | `public void CopyDatabase()` | Initiates async database copy via `Task.Run(() => CopyFunc())`. Publishes `AppStatusEvent.Busy`. |
| `InitializeState` | `public void InitializeState(DTS.Common.Enums.Database.DbType dbType, string dbName)` | Sets up initial state, resets progress bars, triggers `OnPropertyChanged("CopyEnabled")`. |
| `InitializeAsync` | `public Task InitializeAsync()` | Resolves and initializes progress bar views via Unity container. |
| `_allDBTables` | `private static readonly List<string>` | Hardcoded list of 73 database table names to copy. |
| `_tablesWithIdentities` | `private static readonly HashSet<string>` | Hardcoded set of 48 table names that have identity columns. |
| `MAX_BATCH_SIZE` | `private const int MAX_BATCH_SIZE = 20;` | Maximum rows per batch insert to avoid SQL Server's 2100 parameter limit. |
| `CurrentTaskBar` | `private const string CurrentTaskBar = "CurrentTaskStatus";` | Identifier for current task progress bar. |
| `OverallTaskBar` | `private const string OverallTaskBar = "OverallStatus";` | Identifier for overall progress bar. |
| Lifecycle methods | Same pattern as other ViewModels | Standard no-op implementations except `InitializeAsync`. |
**Constructor:**
```csharp
public DatabaseCopyViewModel(
IDatabaseCopyView view,
IRegionManager regionManager,
IEventAggregator eventAggregator,
IUnityContainer unityContainer)
```
---
## 3. Invariants
### DatabaseStatusBarViewModel
- `ActiveDbName` returns empty string for unhandled `DbType` values (not LocalOnly, RemoteOnly, or RemoteLocalHybrid).
- `BackgroundBrush` only returns `Brushes.Red` for `DbType.RemoteLocalHybrid` when `RemoteConnected` is false; all other cases return `Brushes.Transparent`.
- `RemoteConnected` is directly coupled to `DbOperations._usingCentralizedDB` static field.
### DatabaseSwitchViewModel
- `SwitchRemote` always publishes `LogoutUserEvent` with reason `DatabaseSwitch` on success.
- `SwitchRemote` calls `SwitchLocal()` as fallback if connection test fails.
- `SwitchLocal` checks for local database file existence before proceeding; returns early with error if files not found.
- `SwitchLocal` always publishes `LogoutUserEvent` with reason `DatabaseSwitch` on success.
### DatabaseCopyViewModel
- `CopyEnabled` is only true when `DatabaseType == DbType.RemoteLocalHybrid` AND `DbOperations._usingCentralizedDB` is true.
- Copy operation disables constraints before copying and re-enables them after.
- If copy fails, attempts to restore from backup via `DTS.Common.Storage.DatabaseServices.RestoreLocalDatabase(DbName)`.
- Batch inserts are limited to `MAX_BATCH_SIZE` (20 rows) or when parameter count would exceed 2100.
- Identity insert is enabled/disabled per batch for tables in `_tablesWithIdentities`.
- `DASId` columns with value 0 are explicitly set to NULL in the Channels table after copy.
---
## 4. Dependencies
### External Dependencies (from imports)
- **Prism Framework:** `Prism.Events`, `Prism.Regions`, `Prism.Commands` - Event aggregation, region management, commanding
- **Unity Container:** `Unity` - Dependency injection container
- **MEF:** `System.ComponentModel.Composition` - Part creation policy
- **WPF:** `System.Windows.Media`, `System.ComponentModel` - UI types, INotifyPropertyChanged
- **DTS.Common.Enums.Database:** `DbType` enum
- **DTS.Common.Events:** `RaiseNotification`, `BusyIndicatorChangeNotification`, `AppStatusEvent`, `AppStatusArg`, `ProgressBarEvent`, `ProgressBarEventArg`, `PageErrorEvent`, `PageErrorArg`
- **DTS.Common.Events.Database:** `DbStatusEvent`, `DbStatusArg`, `LogoutUserEvent`, `LogoutUserArg`
- **DTS.Common.Interactivity:** `InteractionRequest<T>`, `Notification`, `Confirmation`, `NotificationContentEventArgs`
- **DTS.Common.Interface.Database:** `IDatabaseStatusBarView`, `IDatabaseSwitchView`, `IDatabaseCopyView`, `IDatabaseStatusBarViewModel`, `IDatabaseSwitchViewModel`, `IDatabaseCopyViewModel`
- **DTS.Common.Interface:** `IStatusAndProgressBarView`, `IStatusAndProgressBarViewModel`
- **DTS.Common.Storage:** `DbOperations`, `LocalOnlyOperations`, `DatabaseServices` (static class)
- **DTS.Common.Utilities.Logging:** `APILogger`
- **DTS.Common.Utils.Database:** `CheckLocalDatabaseFilesExist`
- **Resources.StringResources:** Localized strings
### Static Couplings
- `DbOperations._usingCentralizedDB` - Static field accessed directly by all three ViewModels
- `DbOperations.Connection.Server` - Server name accessed directly
- `DbOperations.GetSQLCommand()` - SQL command creation for remote DB
- `LocalOnlyOperations.GetSQLCommand()` - SQL command creation for local DB
- `LocalOnlyOperations.BeginStatement`, `LocalOnlyOperations.CommitStatement` - Transaction statements
- `LocalOnlyOperations.CreateParam()` - Parameter creation helper
---
## 5. Gotchas
### XML Documentation Mismatch
- `DatabaseStatusBarViewModel` and `DatabaseSwitchViewModel` XML summary comments state "this class handles DatabaseCopy functionality" which is incorrect (copy-paste error from `DatabaseCopyViewModel`).
### Parameterless Constructors
- All three ViewModels have public parameterless constructors in addition to the DI constructor. The parameterless constructors perform no initialization, which could lead to null reference exceptions if used incorrectly.
### Static Table Lists
- `DatabaseCopyViewModel._allDBTables` and `_tablesWithIdentities` are hardcoded lists. Any database schema changes require code updates. Comment in source states: "I'd like to do this through SQL, but ran into problems".
### Thread Safety Concerns
- `DatabaseCopyViewModel.CopyDatabase()` uses `Task.Run()` to execute `CopyFunc()` on a background thread, but `SetStatus()` publishes UI events directly. The `BusyIndicatorChangeNotification` subscription in `DatabaseStatusBarViewModel` uses `ThreadOption.PublisherThread` with `keepSubscriberReferenceAlive: true