8.0 KiB
8.0 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | |
|---|---|---|---|---|---|
|
2026-04-16T04:40:45.205601+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | 197f884be4481037 |
ViewModel
Documentation: DBViewModel (DBImportExport Module)
1. Purpose
The DBViewModel class serves as the view model for database import and export functionality within the DataPRO application. It acts as a bridge between the UI (via IDBImportView and IDBExportView) and the underlying data layer, handling user interactions for selecting import/export files, validating data, and performing file I/O operations using XML strings. Due to architectural constraints (legacy DataPRO objects reside in a separate project), its functionality is currently limited to managing XML string data flow—not direct database manipulation.
2. Public Interface
Constructor
public DBViewModel(
IDBImportView importView,
IDBExportView exportView,
IRegionManager regionManager,
IEventAggregator eventAggregator,
IUnityContainer unityContainer)
- Initializes the view model with views, region/event management, and dependency injection containers.
- Sets
DataContextof both views tothis. - Subscribes to
RaiseNotificationandBusyIndicatorChangeNotificationevents.
Lifecycle Methods (No-op)
All lifecycle methods currently have empty implementations:
void Cleanup()Task CleanupAsync()void Initialize()void Initialize(object parameter)void Initialize(object parameter, object model)Task InitializeAsync()Task InitializeAsync(object parameter)void Activated()
Event Handlers (Internal)
private void OnBusyIndicatorNotification(bool eventArg)
SetsIsBusytoeventArg.private void OnRaiseNotification(NotificationContentEventArgs eventArgsWithTitle)
ConvertsNotificationContentEventArgstoNotificationand raisesNotificationRequest.
Public Methods
public void Export()
WritesExportData(XML string) toExportFileNameusingEncoding.Unicode.
Validation checks:- Fails early if
ExportFileNameorExportDatais null/whitespace, publishing aShowStatusevent with failure message. - If
ExportFileNamealready exists, deletes/moves it viaFileUtils.DeleteFileOrMove. - Writes file using
File.WriteAllText.
- Fails early if
Interaction Requests (Public)
public InteractionRequest<Notification> NotificationRequest { get; }
Used to trigger notification popups (e.g., success/error messages).public InteractionRequest<Confirmation> ConfirmationRequest { get; }
Reserved for confirmation dialogs (not used in current implementation).
Commands (Public)
public DelegateCommand ImportBrowseCommand { get; }
Opens anOpenFileDialogto select an import file. SetsImportFileNameand updatesImportStatusText.public DelegateCommand ExportBrowseCommand { get; }
Opens aSaveFileDialogto setExportFileName.
Properties (Public)
IDBImportView ImportView { get; set; }
Reference to the import view instance.IDBExportView ExportView { get; set; }
Reference to the export view instance.bool IsDirty { get; private set; }
Alwaysfalse(never set).bool IsBusy { get; set; }
Bound to busy indicator; updated viaOnBusyIndicatorNotification.bool IsMenuIncluded { get; set; }
Property exposed for UI binding (value never read/written beyond property setter).bool IsNavigationIncluded { get; set; }
Same as above.string HeaderInfo { get; }
Hardcoded to"MainRegion".string ImportData { get; set; }
XML string for imported data (no import logic implemented—only storage).string ExportData { get; set; }
XML string for exported data (no export logic implemented—only storage).string ExportFileName { get; set; }
Full path to export file.string ImportFileName { get; set; }
Full path to import file.string ImportStatusText { get; set; }
Status message for import UI (e.g., warning about database overwrite).event PropertyChangedEventHandler PropertyChanged
ImplementsINotifyPropertyChanged.void OnPropertyChanged(string propertyName)
RaisesPropertyChangedevent.
Nested Type
public enum PropertyNames
Lists property names used inOnPropertyChanged:
ExportFileName,ImportFileName,ImportStatusText.
3. Invariants
Export()requires:ExportFileNamemust be non-null/non-whitespace.ExportDatamust be non-null/non-whitespace.
Export()guarantees:- If file exists at
ExportFileName, it is deleted/moved before writing. - File is written using
Encoding.Unicode.
- If file exists at
ImportBrowseMethod():- Uses
OpenFileDialogwithCheckFileExists = trueandCheckPathExists = true. - Sets
ImportFileNameonly if dialog succeeds.
- Uses
ExportBrowseMethod():- Uses
SaveFileDialogwithOverwritePrompt = false. - Sets
ExportFileNameonly if dialog succeeds.
- Uses
IsBusyis updated synchronously via event subscription (on publisher thread).ImportStatusTextis updated only inImportBrowseMethod()(no import operation is triggered by this view model).
4. Dependencies
Imports/Usings
System.ComponentModel,System.ComponentModel.Composition,System.Threading.TasksDTS.Common.Events(e.g.,RaiseNotification,BusyIndicatorChangeNotification,ShowStatus,StatusInfo)Prism.Events,Prism.Regions,Prism.CommandsUnity(forIUnityContainer)DTS.Common.Interface(e.g.,IDBImportView,IDBExportView,IDBViewModel)DTS.Common.Utils(e.g.,FileUtils)DTS.Common.Interactivity(e.g.,InteractionRequest<T>)System.Text(forEncoding)System.Windows.Forms(forOpenFileDialog,SaveFileDialog)
Consumed Types
IDBImportView,IDBExportView,IDBViewModel(fromDBImportExportnamespace)NotificationContentEventArgs,StatusInfo,StatusInfo.StatusStateFileUtils.DeleteFileOrMoveResources.StringResources(for UI strings:ImportFileBrowse_Filter,ExportFileBrowse_Filter,ExportFileName_Empty,ExportFileData_Empty)
Depended Upon By
- Prism-based shell/shell regions (via
IRegionManager). - Event publishers (e.g.,
RaiseNotification,BusyIndicatorChangeNotification). - Views (
IDBImportView,IDBExportView) bound to this view model.
5. Gotchas
- No actual import/export logic:
ImportDataandExportDataare only storage properties. No code parses, validates, or processes the XML strings. Import/export is purely file I/O—no database interaction occurs in this class. Cleanup()/Initialize()are no-ops:
Lifecycle methods exist for interface compliance but perform no work.IsDirtyis never set:
Alwaysfalse; likely unused or incomplete.IsMenuIncluded/IsNavigationIncludedunused:
Properties exist but have no observed consumers in this file.- Hardcoded
HeaderInfo:
Always"MainRegion"—no dynamic behavior. LogDummyFuncdoes nothing:
Passed toFileUtils.DeleteFileOrMovebut never logs (silently ignores errors).- No import operation triggered:
ImportFileNameis set via browse dialog, but noImport()method exists to process the file. Export()writes directly without user confirmation:
Overwrites existing files silently (only usesFileUtils.DeleteFileOrMove).NotificationRequestconversion quirk:
OnRaiseNotificationconstructs a newNotificationContentEventArgswith empty strings forImageandCommandParameter—may lose data if callers rely on them.- Thread safety:
IsBusyupdates occur onPublisherThread(viaThreadOption.PublisherThread), but other properties lack thread-safety guarantees.
None identified from source alone for critical bugs or anti-patterns beyond the above architectural limitations.