Files
DP44/enriched-qwen3-coder-next/DataPRO/Modules/Groups/GroupImport/View.md
2026-04-17 14:55:32 -04:00

7.6 KiB

source_files, generated_at, model, schema_version, sha256
source_files generated_at model schema_version sha256
DataPRO/Modules/Groups/GroupImport/View/GroupImportImportView.xaml.cs
DataPRO/Modules/Groups/GroupImport/View/GroupImportOptionsView.xaml.cs
DataPRO/Modules/Groups/GroupImport/View/GroupImportPreviewView.xaml.cs
2026-04-16T04:46:11.528450+00:00 Qwen/Qwen3-Coder-Next-FP8 1 4920dece220dd9a5

View

Purpose

This module provides the WPF UI views for the group import workflow within the DataPRO system, specifically handling user interaction for selecting source files, configuring import options, previewing imported groups and channels, and validating the import state before proceeding. It serves as the presentation layer for the group import functionality, coordinating with a shared GroupImportViewModel to manage state and business logic, while enforcing UI-specific validation rules and user privilege checks (e.g., admin-only tag editing).


Public Interface

GroupImportImportView

  • Type: partial class implementing IGroupImportImportView
  • Constructor: GroupImportImportView()
    • Initializes the WPF component via InitializeComponent().
    • No additional logic or public members exposed beyond initialization.

GroupImportOptionsView

  • Type: partial class implementing IGroupImportOptionsView
  • Constructor: GroupImportOptionsView()
    • Initializes the WPF component via InitializeComponent().
  • Validate(out List<string> errors, out List<string> warnings)
    • Signature: public bool Validate(out List<string> errors, out List<string> warnings)
    • Behavior: Validates that at least one source file is selected.
      • Returns true if vm.SourceFiles.Length >= 1.
      • Returns false and populates errors with StringResources.Preview_NoFilesSelected if no files are selected.
    • Note: Does not validate file contents or other options—only file presence.

GroupImportPreviewView

  • Type: partial class implementing IGroupImportPreviewView
  • Constructor: GroupImportPreviewView()
    • Initializes the WPF component via InitializeComponent().
  • Event Handlers (WPF event wiring, not public API but critical for behavior):
    • GroupName_Changed(object sender, TextChangedEventArgs e)
      • Updates the GroupName property of the bound GroupGRPImportGroup instance.
      • Calls GroupNameInvalidate() on all channels in the group.
      • Triggers vm.CheckGroupName() on the GroupImportViewModel.
    • GroupTags_Changed(object sender, TextChangedEventArgs e)
      • Updates the GroupTags property of the bound GroupGRPImportGroup instance.
    • IncludedChecked(object sender, RoutedEventArgs e)
      • Calls vm.InvalidateChannels() on the GroupImportViewModel.
    • IncludedUnchecked(object sender, RoutedEventArgs e)
      • Calls vm.InvalidateChannels() on the GroupImportViewModel.
  • Validate(bool userIsAdmin, out List<string> errors, out List<string> warnings)
    • Signature: public bool Validate(bool userIsAdmin, out List<string> errors, out List<string> warnings)
    • Behavior: Performs comprehensive validation of groups and channels for import.
      • Checks admin-only tag compatibility: if !userIsAdmin and GroupTags contains tags not in ImportingUserTags, adds a formatted error and returns false.
      • Checks GroupNameHasError: adds StringResources.Preview_InvalidName error and returns false.
      • Checks GroupErrors: adds all ExtraInfo strings as errors and returns false.
      • Checks if group exists (vm.CheckGroupExists) and !Overwrite: adds StringResources.Preview_InvalidName error and returns false.
      • Iterates channels:
        • On ch.Error != null:
          • Adds warnings or errors based on ErrorCode (e.g., InvalidISOCodeInput, InvalidFullScaleInput, SensorNotFound).
          • Some errors (FileEmpty, InvalidISOCodeInput) set bAnyValidChannels = true but do not fail validation.
        • On ch.Error == null: sets bValid = true and bAnyValidChannels = true.
      • If no valid channels exist (!bAnyValidChannels), adds StringResources.Preview_NoGroupsToImport to errors and returns false.
      • Returns true only if no fatal errors occurred and at least one valid channel exists.

Invariants

  • File Selection: GroupImportOptionsView.Validate() requires SourceFiles.Length >= 1 for success; otherwise, it fails with a specific error.
  • Admin Tag Enforcement: Non-admin users cannot set GroupTags that include tags not present in ImportingUserTags; this causes immediate validation failure with a detailed error message.
  • Group Name Validity: A group with GroupNameHasError == true, existing group name without Overwrite == true, or non-empty GroupErrors causes immediate validation failure in GroupImportPreviewView.Validate().
  • Channel-Level Errors:
    • FileEmpty and InvalidISOCodeInput errors do not prevent import (but may indicate partial failure).
    • InvalidFullScaleInput, InvalidInvertInput, InvalidSensorInput, and SensorNotFound produce warnings but do not block import.
  • No-Import Guard: If no channels are valid (bAnyValidChannels == false), validation fails with StringResources.Preview_NoGroupsToImport.

Dependencies

  • External Dependencies:
    • DTS.Common.Interface.Groups: Defines interfaces IGroupImportImportView, IGroupImportOptionsView, IGroupImportPreviewView.
    • DTS.Common.Classes.Groups: Provides concrete types GroupGRPImportGroup, GroupGRPImportError.
    • DTS.Common.Strings: Provides StringResources for localized error/warning messages.
    • GroupImport.Resources: Contains StringResources (likely auto-generated .resx-based resources).
  • Internal Dependencies:
    • GroupImportViewModel: Used as DataContext in all three views; its methods (CheckGroupName, InvalidateChannels, CheckGroupExists) are called directly.
    • WPF framework (System.Windows.Controls, System.Windows.RoutedEventArgs, etc.).

Gotchas

  • Typo in XML comment: GroupImportPreviewView.xaml.cs has /// <summary> Interaction logic for GroupImportOptionsView.xaml </summary> instead of GroupImportPreviewView.xaml.
  • Ambiguous bValid logic: In GroupImportPreviewView.Validate(), bValid is initialized to true, then set to false before checking channels, and only set to true if a channel has no error. This may be confusing—bValid is ultimately determined by whether at least one channel is valid and no fatal errors occurred.
  • Tag validation is strict: Non-admin users are blocked if any tag in GroupTags is not in ImportingUserTags. The error message lists both sets explicitly.
  • Duplicate error suppression: Errors/warnings are deduplicated via !errors.Contains(...) checks, but this is linear-time and may be inefficient for large error sets.
  • No explicit handling for null vm: All views cast DataContext to GroupImportViewModel without null checks; a null DataContext will cause a NullReferenceException.
  • GroupNameInvalidate() and InvalidateChannels() are called on UI thread changes: These likely trigger re-validation or UI refreshes; callers must ensure thread-safety if invoked off-thread (though WPF data binding typically handles this).
  • Split() extension method: Used on ImportingUserTags and GroupTags (e.g., g.ImportingUserTags.Split()), implying a custom extension method (not standard string.Split()); behavior depends on its implementation (e.g., whitespace delimiters? empty entries?).