Files

165 lines
10 KiB
Markdown
Raw Permalink Normal View History

2026-04-17 14:55:32 -04:00
---
source_files:
- DTS Viewer/DTS.Viewer/Settings.cs
- DTS Viewer/DTS.Viewer/ExportModule.cs
- DTS Viewer/DTS.Viewer/ViewerModule.cs
- DTS Viewer/DTS.Viewer/ViewerSession.cs
- DTS Viewer/DTS.Viewer/Bootstrapper.cs
generated_at: "2026-04-16T13:36:04.363120+00:00"
model: "zai-org/GLM-5-FP8"
schema_version: 1
sha256: "f841428d718c70bf"
---
# DTS.Viewer Module Documentation
## 1. Purpose
The `DTS.Viewer` namespace provides the core infrastructure for a modular, Prism-based WPF viewer application. It implements a plugin architecture using Unity dependency injection and Prism's modularity framework. The module manages application bootstrapping, session lifecycle, region management, and dynamic plugin loading. It supports both standalone and embedded operational modes, allowing the viewer to function as an independent application or as a component within a larger host system.
---
## 2. Public Interface
### Settings (DTS.Viewer.Properties)
```csharp
internal sealed partial class Settings
```
- **Settings()** - Default constructor. Contains commented-out event handler registrations.
- **SettingChangingEventHandler(object sender, System.Configuration.SettingChangingEventArgs e)** - Private method stub for handling setting change events.
- **SettingsSavingEventHandler(object sender, System.ComponentModel.CancelEventArgs e)** - Private method stub for handling settings save events.
### ExportModule
```csharp
[Module(ModuleName = "Export")]
public class ExportModule : IExportModule
```
- **ExportModule(IUnityContainer unityContainer)** - Constructor accepting an injected `IUnityContainer`.
- **bool SessionStarted { get; private set; }** - Property indicating whether a session has been started.
- **void Initialize()** - Registers `IExportModule` to `ExportModule` with container-controlled lifetime.
- **void StartSession()** - Resolves `IEventAggregator` and publishes `LoadExportModuleEvent` with `LoadExportModuleArg`; sets `SessionStarted` to `true`.
- **void RegisterTypes(IContainerRegistry containerRegistry)** - Calls `Initialize()`.
- **void OnInitialized(IContainerProvider containerProvider)** - Empty implementation.
### ExportNameAttribute
```csharp
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false)]
public class ExportNameAttribute : TextAttribute
```
- **ExportNameAttribute()** - Default constructor; sets internal `_assemblyName` to `"Export"`.
- **ExportNameAttribute(string s)** - Overloaded constructor; ignores parameter and sets `_assemblyName` to `"Export"`.
- **string AssemblyName { get; }** - Returns `_assemblyName`.
- **Type GetAttributeType()** - Returns `typeof(TextAttribute)`.
- **string GetAssemblyName()** - Returns `AssemblyName`.
### ViewerModule
```csharp
[Module(ModuleName = "Viewer")]
public class ViewerModule : IViewerModule
```
- **ViewerModule(IUnityContainer unityContainer)** - Constructor accepting an injected `IUnityContainer`.
- **bool SessionStarted { get; private set; }** - Property indicating whether a session has been started.
- **void Initialize()** - Registers `IViewerModule` to `ViewerModule` with container-controlled lifetime.
- **void StartSession()** - Resolves `IEventAggregator` and publishes `LoadViewModulEvent` with `LoadViewModulArg`; sets `SessionStarted` to `true`.
- **void RegisterTypes(IContainerRegistry containerRegistry)** - Calls `Initialize()`.
- **void OnInitialized(IContainerProvider containerProvider)** - Empty implementation.
### ViewerNameAttribute
```csharp
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false)]
public class ViewerNameAttribute : TextAttribute
```
- **ViewerNameAttribute()** - Default constructor; sets internal `_assemblyName` to `"Viewer"`.
- **ViewerNameAttribute(string s)** - Overloaded constructor; ignores parameter and sets `_assemblyName` to `"Viewer"`.
- **string AssemblyName { get; }** - Returns `_assemblyName`.
- **Type GetAttributeType()** - Returns `typeof(TextAttribute)`.
- **string GetAssemblyName()** - Returns `AssemblyName`.
### ViewerSession
```csharp
public class ViewerSession
```
- **ViewerSession()** - Empty constructor.
- **IUnityContainer Container { get; private set; }** - Exposes the Unity container from the bootstrapper.
- **IServiceLocator _serviceLocator { get; private set; }** - Exposes the service locator.
- **IEventAggregator _eventAggregator { get; private set; }** - Exposes the event aggregator.
- **IRegionManager _regionManager { get; private set; }** - Exposes the region manager.
- **string CustomConfigPath { get; set; }** - Gets or sets a custom configuration path.
- **void CreateSession(bool standalone, string customConfigPath = "")** - Creates the bootstrapper, resolves core services, loads plugins via `PluginManager`, and publishes `AssemblyListNotificationViewer` event.
- **void Terminate()** - Empty method intended for shutdown cleanup.
### Bootstrapper
```csharp
public class Bootstrapper : UnityBootstrapper
```
- **Bootstrapper(bool standalone, string customConfigPath = "")** - Constructor accepting standalone mode flag and optional custom config path.
- **bool Standalone { get; set; }** - Indicates whether the application runs in standalone mode.
- **string CustomConfigPath { get; set; }** - Custom configuration path.
- **IServiceLocator _ServiceLocator { get; private set; }** - Resolved service locator.
- **IEventAggregator _EventAggregator { get; private set; }** - Resolved event aggregator.
- **void ConfigureContainer()** - Overrides base to register `IViewerMainViewGrid`, `IViewerMainViewModel`, and calls `base.ConfigureContainer()`.
- **RegionAdapterMappings ConfigureRegionAdapterMappings()** - Registers region adapters for `Selector`, `ItemsControl`, `ContentControl`, and conditionally `StackPanel` (standalone only).
- **DependencyObject CreateShell()** - Creates the main shell, registers regions, initializes the view model, and returns the view.
- **IModuleCatalog CreateModuleCatalog()** - Returns resolved `IModuleCatalog` or new `AggregateModuleCatalog`.
- **void ConfigureModuleCatalog()** - For standalone mode only, reads plugin folders from configuration and adds a `DirectoryModuleCatalog`.
- **void InitializeModules()** - For standalone mode only, registers `IDTSViewRegionManager` to `DTSViewRegionManager` and calls `base.InitializeModules()`.
---
## 3. Invariants
1. **Bootstrapper Singleton**: The `_bootstrapper` field in `ViewerSession` should only be created once. Re-creation is explicitly discouraged in comments due to module loading behavior.
2. **Module Self-Registration**: Both `ExportModule` and `ViewerModule` register themselves as implementations of their respective interfaces during `Initialize()`/`RegisterTypes()`.
3. **Standalone Mode Controls Behavior**:
- `ConfigureModuleCatalog()` only adds directory modules when `Standalone` is `true`.
- `InitializeModules()` only executes when `Standalone` is `true`.
- `StackPanelRegionAdapter` is only registered when `Standalone` is `true`.
4. **Region Registration Safety**: In `CreateShell()`, regions are only added if they don't already exist (`ContainsRegionWithName` check).
5. **Attribute Constructor Parameter Ignored**: Both `ExportNameAttribute` and `ViewerNameAttribute` ignore the string parameter `s` in their constructors, always returning hardcoded values.
---
## 4. Dependencies
### External Dependencies (Imports)
- **Prism Framework**: `Prism.Events`, `Prism.Ioc`, `Prism.Modularity` - Module system and dependency injection.
- **Unity Container**: `Unity`, `Unity.Lifetime` - IoC container implementation.
- **Microsoft.Practices (Legacy Prism)**: `Microsoft.Practices.Prism.Events`, `Microsoft.Practices.Prism.Modularity`, `Microsoft.Practices.Prism.Regions`, `Microsoft.Practices.Prism.UnityExtensions`, `Microsoft.Practices.ServiceLocation`, `Microsoft.Practices.Unity` - Legacy Prism APIs used in `ViewerSession` and `Bootstrapper`.
- **System.Configuration**: Application configuration handling.
- **System.ComponentModel.Composition.Hosting**: MEF composition support (used for `DirectoryModuleCatalog`).
### Internal Dependencies (Inferred)
- **DTS.Common.Events**: `LoadExportModuleEvent`, `LoadExportModuleArg`, `LoadViewModulEvent`, `LoadViewModulArg`, `AssemblyListNotificationViewer`, `AssemblyListInfo`.
- **DTS.Common.Interface**: `IExportModule`, `IViewerModule`, `IViewerMainViewGrid`, `IViewerMainViewModel`, `IShellViewModel`, `IDTSViewRegionManager`.
- **DTS.Common.Base**: `TextAttribute`.
- **DTS.Common.Core.PluginLib**: `PluginManager`, `PluginConfigSectionHandler`, `FilterHashElement`.
- **DTS.Common**: General utilities.
### Consumers
- The module appears designed to be consumed by a host application (referenced as "JMPS" in comments) or run standalone.
---
## 5. Gotchas
1. **Mixed Prism Versions**: The codebase uses both modern Prism namespaces (`Prism.*`) and legacy Microsoft.Practices namespaces (`Microsoft.Practices.Prism.*`). This mixing of versions could cause compatibility issues or confusion.
2. **Bootstrapper Memory Footprint**: Comments indicate the bootstrapper loads ~40 MB into memory and cannot be easily unloaded. The comment explicitly warns: "Do not try to re-create the bootstrapper."
3. **Attribute Constructor Parameter Ignored**: The `ExportNameAttribute(string s)` and `ViewerNameAttribute(string s)` constructors accept a parameter that is completely ignored. The `_assemblyName` is always set to a hardcoded value regardless of input.
4. **Empty Event Handlers**: The `Settings` class has empty event handler stubs that do nothing. The constructor has commented-out code to wire these up.
5. **Try-Catch Swallowing in ConfigureRegionAdapterMappings**: Region adapter registrations are wrapped in empty try-catch blocks that silently ignore failures.
6. **Exception Handling in CreateShell**: The `CreateShell()` method catches all exceptions, stores the message in a local variable `s` that is never used, and returns `null`. This silently suppresses errors.
7. **Non-Stand-alone Module Initialization**: When `Standalone` is `false`, `InitializeModules()` returns early without registering `IDTSViewRegionManager` or calling `base.InitializeModules()`. This may leave modules uninitialized.
8. **Commented-Out Code in ConfigureContainer**: There is significant commented-out code regarding conditional view registration based on `Standalone` mode, suggesting incomplete refactoring.
9. **Redundant Resolver Calls**: In `CreateShell()`, `Container` is resolved from `ServiceLocator.Current` despite already being available via inheritance from `UnityBootstrapper`.