Skip to content

Latest commit

 

History

History
560 lines (424 loc) · 19.6 KB

File metadata and controls

560 lines (424 loc) · 19.6 KB

Class Diagram — EasySave 3.0

This class diagram illustrates the complete architecture of the EasySave application according to the MVVM (Model-View-ViewModel) pattern, featuring a clear separation of concerns.

Class Diagram

Class Diagram v3.0 - MVVM Architecture


General Structure

The diagram is organized into several thematic packages according to the MVVM architecture:

  • Enums: Enumerations for types and states
  • Models: Business data models
  • Context: Execution context shared between services
  • Interfaces: Contracts defining behaviors
  • Services: Business implementations and application logic
  • Strategies: Backup strategies (Strategy Pattern)
  • EasyLog.dll: External logging library
  • Commands: Command implementations (ICommand for WPF)
  • ViewModels: Presentation logic and data binding with views
  • Views: User interfaces (Console and WPF Graphical)

1. Enumerations (Enums)

BackupType

Defines the available backup types:

  • Full: Complete backup
  • Differential: Differential backup

JobState

Represents the possible states of a backup job:

  • INACTIVE: Waiting for execution
  • ACTIVE: Currently running
  • END: Successfully completed
  • ERROR: Failed with error

Language

Represents the languages supported by the application:

  • FR: French
  • EN: English

LogFormat

Available logging formats:

  • JSON: JSON format
  • XML: XML format

2. Models (Models)

BackupJob

Represents a backup job with its attributes:

  • Id: int — Unique identifier
  • Name: string — Job name
  • SourcePath: string — Source path
  • TargetPath: string — Destination path
  • Type: BackupType — Backup type

StateEntry

Captures the real-time state of a backup:

  • Name: string — Job name
  • SourceFilePath: string — Current source file
  • TargetFilePath: string — Current target file
  • State: JobState — Current state
  • TotalFilesToCopy: int — Total number of files
  • TotalFilesSize: long — Total size in bytes
  • NbFilesLeftToDo: int — Remaining files
  • SizeLeftToDo: long — Remaining size
  • Progression: int — Progression percentage
  • Timestamp: DateTime — Timestamp

AppConfig

Global application configuration:

  • BackupJobs: List<BackupJob> — List of jobs (max 5)
  • CurrentLanguage: Language — Active language
  • LogFormat: LogFormat — Log format
  • LogPath: string — Path to the log file
  • StatePath: string — Path to the state file

FileTransferResult

Result of a file transfer:

  • Success: bool — Success or failure
  • FileSize: long — File size
  • TransferTimeMs: long — Transfer time in milliseconds
  • ErrorMessage: string — Eventual error message

ValidationResult

Result of a job validation:

  • IsValid: bool — Job validity
  • Errors: List<string> — List of detected errors

BackupProgressEventArgs

Tracks backup progress without creating strong coupling:

  • JobName: string — Name of the current job
  • ProgressPercent: int — Progression percentage
  • CurrentFile: string — File currently being copied
  • FilesRemaining: int — Remaining files
  • TotalFiles: int — Total number of files

3. Context

BackupContext

Shared context during a backup execution, gathering dependencies required by strategies:

  • TransferService: IFileTransferService — File transfer service
  • StateManager: IStateManager — State manager
  • Logger: ILogger — Logging service

Method:

  • BackupContext(transferService, stateManager, logger): Constructor via injection

4. Interfaces

IBackupEngine

Contract for the backup engine:

  • ExecuteBackup(job: BackupJob) : void — Executes an individual backup
  • ExecuteAllBackups(jobs: List<BackupJob>) : void — Executes all backups

IBackupJobManager

Manages the CRUD of backup jobs:

  • CreateJob(job: BackupJob) : void — Create a job
  • GetJob(id: int) : BackupJob — Retrieve a job by its identifier
  • GetAllJobs() : List<BackupJob> — List all jobs
  • UpdateJob(job: BackupJob) : void — Update an existing job
  • DeleteJob(id: int) : void — Delete a job
  • CanAddJob() : bool — Checks if the 5-job limit is reached
  • GetJobCount() : int — Returns the number of registered jobs

IFileTransferService

Contract for the file transfer service:

  • CopyFile(source: string, target: string) : FileTransferResult — Copies a file
  • GetAllFiles(directory: string) : List<string> — Recursive list of files in a directory
  • GetTotalSize(files: List<string>) : long — Calculates the total size of a list of files
  • ShouldCopyFile(source: string, target: string) : bool — Determines if a file should be copied (differential backup)

IBackupStrategy

Contract for the Strategy Design Pattern:

  • Execute(job: BackupJob, context: BackupContext) : void — Executes the backup strategy

IStateManager

Manages the lifecycle of backup states:

  • InitializeStates(jobs: List<BackupJob>) : void — Initializes states
  • SetJobActive(jobName: string) : void — Marks a job as active
  • UpdateProgress(jobName, sourceFile, targetFile, progress, remaining, sizeLeft) : void — Updates progress
  • SetJobComplete(jobName: string) : void — Marks a job as completed
  • SetJobError(jobName: string) : void — Marks a job as failed
  • SetJobInactive(jobName: string) : void — Marks a job as inactive
  • GetJobState(jobName: string) : StateEntry — Retrieves the current state of a job
  • SaveState() : void — Persists the state to disk

IConfigService

Manages configuration persistence:

  • LoadConfig() : AppConfig — Loads configuration from the JSON file
  • SaveConfig(config: AppConfig) : void — Saves the configuration

ITranslationService

Multilingual translation service:

  • GetString(key: string) : string — Retrieves the translated string for a given key
  • SetLanguage(language: Language) : void — Changes the active language
  • GetCurrentLanguage() : Language — Returns the currently active language

IBackupJobValidator

Validates job data before creation or modification:

  • Validate(job: BackupJob) : ValidationResult — Full validation of a BackupJob object
  • ValidateJobData(name: string, source: string, target: string) : ValidationResult — Partial validation of raw data

5. Services

BackupEngine

Implements: IBackupEngine

Main backup engine:

Attributes:

  • _strategies : Dictionary<BackupType, IBackupStrategy> — Dictionary of strategies indexed by type
  • _transferService : IFileTransferService — Transfer service
  • _stateManager : IStateManager — State manager
  • _logger : ILogger — Logging service

Methods:

  • BackupEngine(transferService, stateManager, logger): Constructor with dependency injection
  • ExecuteBackup(job: BackupJob) : void — Selects the appropriate strategy and executes the backup
  • ExecuteAllBackups(jobs: List<BackupJob>) : void — Iterates through all jobs and executes them

Responsibilities:

  • Applies the Strategy Pattern via its strategy dictionary
  • Builds the BackupContext and passes it to the strategies
  • Coordinates transferService, stateManager, and logger

FileTransferService

Implements: IFileTransferService

Manages low-level file copy operations:

Methods:

  • CopyFile(source: string, target: string) : FileTransferResult — Copies a file with error handling
  • GetAllFiles(directory: string) : List<string> — Recursive directory traversal
  • GetTotalSize(files: List<string>) : long — Sum of file sizes
  • ShouldCopyFile(source: string, target: string) : bool — Comparison of modification dates for differential mode

BackupJobManager

Implements: IBackupJobManager

Job manager with a 5-job limitation:

Attributes:

  • _config : AppConfig — Active configuration in memory
  • _configService : IConfigService — Configuration persistence service
  • _validator : IBackupJobValidator — Job validator

Responsibilities:

  • Delegates validation to IBackupJobValidator
  • Delegates persistence to IConfigService
  • Ensures the 5-job limit is respected via CanAddJob()

BackupJobValidator

Implements: IBackupJobValidator

Validates data before any job creation or modification:

Methods:

  • Validate(job: BackupJob) : ValidationResult — Full object validation
  • ValidateJobData(name: string, source: string, target: string) : ValidationResult — Individual field validation

Performed Validations:

  • Existence of source and target paths
  • Non-emptiness and uniqueness of the job name
  • Returns a detailed ValidationResult with the list of errors

StateManager

Implements: IStateManager

Manages real-time state with safe concurrent access:

Attributes:

  • _states : List<StateEntry> — List of current states
  • _statePath : string — Path to the JSON state file
  • _lockObject : object — Lock for thread-safety

Responsibilities:

  • Initializes and updates real-time states during backups
  • Persists the state in a JSON file after each update
  • Guarantees thread-safety through the use of a lock

ConfigService

Implements: IConfigService

Responsible for persisting the configuration in JSON:

Attributes:

  • _configPath : string — Path to the configuration file

Methods:

  • LoadConfig() : AppConfig — Deserializes configuration from the JSON file
  • SaveConfig(config: AppConfig) : void — Serializes and writes configuration to disk

Responsibilities:

  • Provides a default configuration if the file is missing
  • Isolates all JSON read/write logic within this service

TranslationService

Implements: ITranslationService

Translation service based on an in-memory dictionary:

Attributes:

  • _translations : Dictionary<Language, Dictionary<string, string>> — Translations indexed by language and key
  • _currentLanguage : Language — Active language

Methods:

  • GetString(key: string) : string — Returns the translation or the key if missing
  • SetLanguage(language: Language) : void — Changes the language on the fly
  • GetCurrentLanguage() : Language — Returns the active language

ArgumentParser

Utility for analyzing command-line arguments:

Methods:

  • ParseRange(input: string) : List<int> — Interprets a range (e.g.: "1-3"[1, 2, 3])
  • ParseSelection(input: string) : List<int> — Interprets a selection (e.g.: "1,3,5"[1, 3, 5])

6. Commands (Command Pattern for MVVM)

ICommand (WPF Interface)

Standard WPF interface for command binding:

  • Execute(parameter: object) : void — Executes the command
  • CanExecute(parameter: object) : bool — Indicates if the command can execute
  • CanExecuteChanged : EventHandler — Event triggered upon state change

RelayCommand

Generic and reusable implementation of ICommand:

Attributes:

  • _execute : Action<object> — Delegate representing the action to execute
  • _canExecute : Func<object, bool> — Predicate determining the enabled/disabled state

Methods:

  • RelayCommand(execute, canExecute) — Constructor
  • Execute(parameter: object) : void — Invokes the _execute delegate
  • CanExecute(parameter: object) : bool — Evaluates the _canExecute predicate
  • RaiseCanExecuteChanged() : void — Manually triggers CanExecuteChanged

Responsibilities:

  • Encapsulates any user action within an ICommand object
  • Allows declarative binding of buttons and controls in XAML
  • Dynamically manages the enabled/disabled state of UI controls

Business Commands

Instantiated in MainViewModel as RelayCommand:

  • CreateJobCommand: Create a new backup job
  • UpdateJobCommand: Modify an existing job
  • DeleteJobCommand: Delete the selected job
  • ExecuteBackupCommand: Execute the backup of the selected job
  • ExecuteAllBackupsCommand: Execute all backups
  • PauseBackupCommand: Pause a running backup
  • ResumeBackupCommand: Resume a paused backup
  • ChangeLanguageCommand: Change application language
  • ChangeLogFormatCommand: Toggle between JSON and XML formats

7. Strategies (Strategies)

FullBackupStrategy

Implements: IBackupStrategy

Implements full backup:

Method:

  • Execute(job: BackupJob, context: BackupContext) : void

Behavior:

  • Copies all files from the source directory to the destination
  • Faithfully recreates the complete directory structure

DifferentialBackupStrategy

Implements: IBackupStrategy

Implements differential backup:

Method:

  • Execute(job: BackupJob, context: BackupContext) : void

Behavior:

  • Copies only new or modified files since the last full backup
  • Relies on ShouldCopyFile() from IFileTransferService to detect changes

8. External DLL: EasyLog.dll

ILogger

Logging interface exposed by the DLL:

  • Log(entry: LogEntry) : void — Records a log entry
  • GetLogPath() : string — Returns the current log file path

ILogFormatter

Interface defining the formatting of log entries:

  • Format(entry: LogEntry) : string — Formates a single entry
  • FormatBatch(entries: List<LogEntry>) : string — Formates a set of entries
  • FileExtension : string { get; } — Extension of the produced file (.json or .xml)

LogEntry

Model for a log entry:

  • Name: string — Name of the backed-up file
  • SourceFilePath: string — Source path
  • TargetFilePath: string — Target path
  • FileSize: long — Size in bytes
  • TransferTimeMs: long — Transfer duration in milliseconds
  • Timestamp: DateTime — Operation timestamp

EasyLogger

Implements: ILogger

Concrete implementation of the logger:

Attributes:

  • _formatter : ILogFormatter — Currently used formatter
  • _logDirectory : string — Storage directory for log files
  • _lockObject : object — Lock for thread-safety

Methods:

  • EasyLogger(formatter, logDirectory): Constructor
  • Log(entry: LogEntry) : void — Writes the entry into the daily log file
  • GetLogPath() : string — Returns the current file path

Responsibilities:

  • Daily logging with file rotation (one file per day)
  • Thread-safe through the use of a lock
  • Interchangeable based on the injected formatter (JSON or XML)

JsonLogFormatter

Implements: ILogFormatter

Formatter producing logs in JSON format:

  • FileExtension : string { get; } = ".json"
  • Serializes entries into structured JSON

XmlLogFormatter

Implements: ILogFormatter

Formatter producing logs in XML format:

  • FileExtension : string { get; } = ".xml"
  • Serializes entries into structured XML

9. Views (Views)

ConsoleView

User interface in console mode:

Attributes:

  • _viewModel : ConsoleViewModel — Associated ViewModel

Methods:

  • ConsoleView(viewModel): Constructor
  • DisplayMainMenu() : void — Displays the main menu
  • DisplayJobs(jobs: List<BackupJob>) : void — Displays the list of jobs
  • GetUserChoice() : string — Reads the choice entered by the user
  • DisplayMessage(message: string) : void — Displays an informative message
  • DisplayError(error: string) : void — Displays an error message

Responsibilities:

  • Pure display, without any business logic
  • Delegates all actions to the ConsoleViewModel
  • Lightweight and readable interface in the terminal

MainWindow — GraphicView (New v3.0)

WPF graphical interface with XAML binding:

Attributes:

  • DataContext : MainViewModel — ViewModel linked via WPF's DataContext property

Declared XAML Bindings:

  • ItemsSource="{Binding Jobs}" — Data source for the backup jobs list
  • SelectedItem="{Binding SelectedJob}" — Real-time selected job
  • Command="{Binding CreateJobCommand}" — Commands linked to action buttons
  • Value="{Binding ProgressPercent}" — Value for the progress bar
  • Text="{Binding StatusMessage}" — Displayed status message

UI Components:

  • DataGrid — Display table for backup jobs
  • ProgressBar — Real-time progression indicator
  • Button — Action buttons linked to ViewModel commands
  • TextBox — Input fields for job creation and modification
  • ComboBox — Selectors for language and log format
  • StatusBar — Status bar at the bottom of the window

Responsibilities:

  • Purely declarative interface definition in XAML
  • Automatic two-way binding with the ViewModel via INotifyPropertyChanged
  • Minimal code-behind, without business logic

10. ViewModels

MainViewModel

Main ViewModel for the WPF graphical interface:

Attributes:

  • _jobManager : IBackupJobManager — Backup job manager
  • _engine : IBackupEngine — Backup execution engine
  • _stateManager : IStateManager — Real-time state manager
  • _configService : IConfigService — Configuration service
  • _translator : ITranslationService — Translation service
  • _logger : ILogger — Logging service
  • _config : AppConfig — Active configuration in memory
  • Jobs : ObservableCollection<BackupJob> — Observable collection of jobs (automatic binding)
  • SelectedJob : BackupJob — Currently selected job in the UI
  • ProgressPercent : int — Current progression value (0-100)
  • StatusMessage : string — Status message displayed to the user
  • IsRunning : bool — Indicates if a backup is currently running

Commands (ICommand):

  • CreateJobCommand, UpdateJobCommand, DeleteJobCommand
  • ExecuteBackupCommand, ExecuteAllBackupsCommand
  • ChangeLanguageCommand, ChangeLogFormatCommand

Events:

  • PropertyChanged : PropertyChangedEventHandler — Property change notification via INotifyPropertyChanged

Responsibilities:

  • Implements INotifyPropertyChanged for automatic two-way binding
  • Exposes data and commands to the view without direct display logic
  • Orchestrates presentation logic and handles user interactions
  • Updates the UI in real-time via observable properties

ConsoleViewModel

ViewModel dedicated to the console interface:

Attributes:

  • _jobManager, _engine, _stateManager, _configService, _translator, _logger — Same dependencies as MainViewModel
  • _argumentParser : ArgumentParser — Command-line argument parser
  • _config : AppConfig — Active configuration

Methods:

  • ConsoleViewModel(...) — Constructor with injection of all dependencies
  • Run(args: string[]) : void — Main entry point, manages the application loop
  • ShowMainMenu() : void — Displays and processes the interactive menu
  • CreateJob() : void, ListJobs() : void, ExecuteBackups() : void
  • ChangeLanguage() : void, ChangeLogFormat() : void

Responsibilities:

  • Adapts business logic for the console interface without reactive binding
  • Manages the main interaction loop and the menu
  • Processes command-line arguments via ArgumentParser
  • Does not require INotifyPropertyChanged (no XAML binding)

11. Entry Points

Program (Console)

Entry point for the console application:

Methods:

  • Main(args: string[]) : void — Main method
  • ConfigureServices() : ServiceProvider — Configures the dependency injection container

Responsibilities:

  • Initializes the console application and the IoC container
  • Instantiates ConsoleViewModel and ConsoleView, then starts the main loop

App.xaml.cs (WPF)

Entry point for the graphical application:

Methods:

  • OnStartup(e: StartupEventArgs) : void — WPF startup event
  • ConfigureServices() : ServiceProvider — Configures the dependency injection container

Responsibilities:

  • Initializes the WPF application and the IoC container
  • Instantiates MainViewModel, creates MainWindow, and configures its DataContext