129 lines
6.9 KiB
Markdown
129 lines
6.9 KiB
Markdown
---
|
||
source_files:
|
||
- DataPRO/WPF.DbAPI/App.xaml.cs
|
||
- DataPRO/WPF.DbAPI/AssemblyInfo.cs
|
||
- DataPRO/WPF.DbAPI/MainWindow.xaml.cs
|
||
generated_at: "2026-04-16T03:45:15.876106+00:00"
|
||
model: "Qwen/Qwen3-Coder-Next-FP8"
|
||
schema_version: 1
|
||
sha256: "967f69bee832213e"
|
||
---
|
||
|
||
# WPF.DbAPI
|
||
|
||
## Documentation: `WpfAppCore` Module (WPF.DbAPI)
|
||
|
||
---
|
||
|
||
### 1. **Purpose**
|
||
|
||
This module is a minimal WPF-based diagnostic and testing UI for the `DTS.Core.DbAPIWrapper` database API layer. It provides a simple interactive interface to invoke and inspect asynchronous database queries—specifically `TestSetupsGetAsync` and `DASGetAsync`—and display results (or errors) in JSON format. Its primary role is to validate the behavior of the underlying `DbApiWrapper` during development or integration testing, not to serve as a production UI.
|
||
|
||
---
|
||
|
||
### 2. **Public Interface**
|
||
|
||
The module exposes only one public class: `MainWindow`, which inherits from `System.Windows.Window`. All other classes (`App`, `AssemblyInfo`) are standard WPF infrastructure and do not define custom public APIs.
|
||
|
||
#### `public partial class MainWindow : Window`
|
||
|
||
- **Constructor**:
|
||
```csharp
|
||
public MainWindow()
|
||
```
|
||
Initializes the WPF window, sets up the UI via `InitializeComponent()`, instantiates a `DbApiWrapper` with fixed connection parameters (`"Burrito-Supreme"`, `"DataPRO"`, empty credentials, and `useSsl: true`, `trustServerCertificate: true`), and performs synchronous authentication using hardcoded credentials (`"Admin"` / `"DTSAdmin"`).
|
||
|
||
- **`private void Clear()`**
|
||
Resets the `errors` and `result` text blocks (UI elements) by setting their `Text` to `string.Empty`.
|
||
|
||
- **`private void EnableButtons(bool enable)`**
|
||
Enables or disables four UI buttons: `testsetupget`, `dasget`, `testId`, and `dasSerial`. Used to prevent user input during async operations.
|
||
|
||
- **`private async void GetTestSetups_Button_Click(object sender, RoutedEventArgs e)`**
|
||
Event handler for the *TestSetups* button.
|
||
- Clears UI, disables buttons, sets status text.
|
||
- Parses `testId.Text` to an `int?` (`testSetupId`).
|
||
- Invokes `_dbApiWrapper.TestSetupsGetAsync(testSetupId)` asynchronously.
|
||
- On success:
|
||
- Re-enables buttons.
|
||
- Displays the first 10 results (from `ts.Item1`) as indented JSON in `result.Text`.
|
||
- Appends any errors from `ts.Item2` (a collection of strings) to `errors.Text`.
|
||
- On exception: Shows the exception message in a modal `MessageBox`.
|
||
|
||
- **`private async void GetDAS_Button_Click(object sender, RoutedEventArgs e)`**
|
||
Event handler for the *DAS* button.
|
||
- Clears UI, disables buttons, sets status text.
|
||
- Parses `dasSerial.Text` to `string?` (`dasSerailText`).
|
||
- Invokes `_dbApiWrapper.DASGetAsync(dasSerailText)` asynchronously.
|
||
- On success:
|
||
- Re-enables buttons.
|
||
- Displays the first 10 results (from `ds.Item1`) as indented JSON in `result.Text`.
|
||
- Shows a `MessageBox` with the error code (`ds.Item2`, an `int`) if non-zero.
|
||
- *Note*: No exception handling is present in this handler—unhandled exceptions will crash the UI.
|
||
|
||
- **`private void Responsive_Button_Click(object sender, RoutedEventArgs e)`**
|
||
Event handler for the *Responsive UI* button. Displays a static message `"Responsive UI"` in a `MessageBox`.
|
||
|
||
---
|
||
|
||
### 3. **Invariants**
|
||
|
||
- **Authentication is mandatory and hardcoded**: The `MainWindow` constructor *always* calls `AuthenticateUser("Admin", "DTSAdmin")` immediately after creating the `DbApiWrapper`. No fallback or conditional logic exists.
|
||
- **UI thread affinity**: All UI updates (`result.Text`, `errors.Text`, button states) occur on the UI thread (via `async void` handlers), but no explicit `Dispatcher.Invoke` is used—relying on WPF’s `async void` continuation behavior.
|
||
- **Partial result display**: Only the first 10 items of query results (`Take(10)`) are serialized and shown, regardless of total result size.
|
||
- **Error reporting is asymmetric**:
|
||
- `TestSetupsGetAsync` returns `(IEnumerable<T>, List<string>)` → errors are a list of strings.
|
||
- `DASGetAsync` returns `(IEnumerable<T>, int)` → error is an integer code.
|
||
- **No input validation beyond parsing**: Only `int.TryParse` is used for `testId`; `dasSerial.Text` is only checked for `null`/whitespace.
|
||
|
||
---
|
||
|
||
### 4. **Dependencies**
|
||
|
||
#### External Dependencies (via imports):
|
||
- `DTS.Core.DbAPIWrapper` → Provides `DbApiWrapper` class with methods:
|
||
- `Task<(IEnumerable<T>, List<string>)> TestSetupsGetAsync(int? id)`
|
||
- `Task<(IEnumerable<T>, int)> DASGetAsync(string? serial)`
|
||
- `System.Text.Json` → Used for JSON serialization (`JsonSerializer.Serialize`).
|
||
- `System.Windows` (WPF) → Core UI framework (`Window`, `RoutedEventArgs`, `MessageBox`, etc.).
|
||
|
||
#### Internal Dependencies:
|
||
- `App.xaml` and `MainWindow.xaml` (XAML files) define the UI layout and wire up event handlers (not included in source, but implied by `InitializeComponent()` and handler signatures).
|
||
- `AssemblyInfo.cs` configures WPF theme resources (no runtime logic impact beyond resource resolution).
|
||
|
||
#### What depends on this module?
|
||
- None inferred. This is a standalone diagnostic UI. No other modules reference `WpfAppCore`.
|
||
|
||
---
|
||
|
||
### 5. **Gotchas**
|
||
|
||
- **Hardcoded credentials and connection string**:
|
||
The `DbApiWrapper` is initialized with hardcoded values (`"Burrito-Supreme"`, `"DataPRO"`, `"Admin"`, `"DTSAdmin"`). This is unsafe for production and suggests this UI is strictly for local testing.
|
||
|
||
- **Inconsistent error handling**:
|
||
- `GetTestSetups_Button_Click` catches exceptions and shows a `MessageBox`.
|
||
- `GetDAS_Button_Click` does *not* catch exceptions—any failure in `DASGetAsync` will crash the app.
|
||
→ **High risk of unhandled exceptions in the DAS path.**
|
||
|
||
- **Typo in variable name**:
|
||
`dasSerailText` (instead of `dasSerialText`) is used in `GetDAS_Button_Click`. While harmless, it may cause confusion.
|
||
|
||
- **Misleading status text**:
|
||
In `GetDAS_Button_Click`, `result.Text` is set to `"Calling TestSetupsGetAsync"` instead of `"Calling DASGetAsync"`. Likely a copy-paste error.
|
||
|
||
- **No cancellation support**:
|
||
No `CancellationToken` is passed to async methods. Long-running queries may block UI responsiveness despite being `async`.
|
||
|
||
- **No validation of `testId`/`dasSerial` before calling API**:
|
||
Invalid input (e.g., non-numeric `testId`) is silently ignored (`testSetupId = null`), which may lead to unexpected API behavior (e.g., returning all test setups).
|
||
|
||
- **No logging**: Errors are only shown via `MessageBox.Show`, not persisted.
|
||
|
||
- **Assumes `Item1` is always non-null**: No null-checks before calling `.Take(10)` or `.Any()` on `ts.Item1`/`ds.Item1`. Could throw `NullReferenceException` if the API returns `null`.
|
||
|
||
- **No cleanup/disposal**: `DbApiWrapper` is not disposed, even if it implements `IDisposable`.
|
||
|
||
---
|
||
|
||
*Documentation generated from provided source files only. No external behavior of `DbApiWrapper` is assumed beyond what is observable in `MainWindow.xaml.cs`.* |