public BackupSetViewModel(IBackupSet backupSet, IUIVisualizerService uiVisualizerService)
        {
            Argument.IsNotNull(() => backupSet);
            Argument.IsNotNull(() => uiVisualizerService);
            BackupSet = backupSet;
            _uiVisualizerService = uiVisualizerService;
            _timer = new Timer(new TimerCallback((o)=>
            {
                RefreshLog();
            }), null, Timeout.Infinite, Timeout.Infinite);

            UpdateScheduleStatus();            
         
            BrowseSourceCommand = new Command(() => SourceDirectory = SetDirectory(SourceDirectory, "Select Source Directory"));
            BrowseDestinationCommand = new Command(() => DestinationDirectory = SetDirectory(DestinationDirectory, "Select Destination Directory"));
            ExcludeDirectoriesCommand = new Command(OnExcludeDirectoriesExecute, ()=>!String.IsNullOrEmpty(SourceDirectory));
            RunBackupCommand = new Command(() => 
                {
                    if(BackupSet.DestinationType == BackupDestinationType.ExternalDrive)
                    {
                        var typeFactory = this.GetTypeFactory();
                        var driveSelectionViewModel = typeFactory.CreateInstanceWithParametersAndAutoCompletion<DriveSelectionViewModel>();
                        driveSelectionViewModel.SetDefaultDrive(DestinationDirectory.Substring(0, 1));
                        if(_uiVisualizerService.ShowDialog(driveSelectionViewModel) == true )
                        {
                            UpdateDestinationDriveLetter(driveSelectionViewModel.SelectedDrive.Name);
                        }
                        else
                        {
                            return;
                        }
                        
                    }
                    _timer.Change(1000, 1000);
                    BackupSet.RunBackup();
                }  
                , () => CanRunBackup);

            CancelBackupCommand = new Command(() =>
                {
                    _timer.Change(Timeout.Infinite, Timeout.Infinite);
                    BackupSet.CancelBackup();
                }
                , () => CanCancelBackup);

            EditBackupSetCommand = new RelayCommand((o)=>
            {
                StateService.RequestBackupSetEdit((string)o);
            }
            ,(o) =>   ProcessingStatus == BackupProcessingStatus.NotStarted ||
                ProcessingStatus == BackupProcessingStatus.Cancelled ||
                ProcessingStatus == BackupProcessingStatus.Finished);

            FinishEditingBackupSetCommand = new RelayCommand((o) =>
            {
                StateService.RequestBackupSetEdit((string)o);
            });           
            
            BackupSet.PropertyChanged += BackupSetPropertyChanged;            
        }
Пример #2
0
        public BackupSetViewModel(IBackupSet backupSet, IUIVisualizerService uiVisualizerService)
        {
            Argument.IsNotNull(() => backupSet);
            Argument.IsNotNull(() => uiVisualizerService);
            BackupSet            = backupSet;
            _uiVisualizerService = uiVisualizerService;
            _timer = new Timer(new TimerCallback((o) =>
            {
                RefreshLog();
            }), null, Timeout.Infinite, Timeout.Infinite);

            UpdateScheduleStatus();

            BrowseSourceCommand       = new Command(() => SourceDirectory = SetDirectory(SourceDirectory, "Select Source Directory"));
            BrowseDestinationCommand  = new Command(() => DestinationDirectory = SetDirectory(DestinationDirectory, "Select Destination Directory"));
            ExcludeDirectoriesCommand = new Command(OnExcludeDirectoriesExecute, () => !String.IsNullOrEmpty(SourceDirectory));
            RunBackupCommand          = new Command(() =>
            {
                if (BackupSet.DestinationType == BackupDestinationType.ExternalDrive)
                {
                    var typeFactory             = this.GetTypeFactory();
                    var driveSelectionViewModel = typeFactory.CreateInstanceWithParametersAndAutoCompletion <DriveSelectionViewModel>();
                    driveSelectionViewModel.SetDefaultDrive(DestinationDirectory.Substring(0, 1));
                    if (_uiVisualizerService.ShowDialog(driveSelectionViewModel) == true)
                    {
                        UpdateDestinationDriveLetter(driveSelectionViewModel.SelectedDrive.Name);
                    }
                    else
                    {
                        return;
                    }
                }
                _timer.Change(1000, 1000);
                BackupSet.RunBackup();
            }
                                                    , () => CanRunBackup);

            CancelBackupCommand = new Command(() =>
            {
                _timer.Change(Timeout.Infinite, Timeout.Infinite);
                BackupSet.CancelBackup();
            }
                                              , () => CanCancelBackup);

            EditBackupSetCommand = new RelayCommand((o) =>
            {
                StateService.RequestBackupSetEdit((string)o);
            }
                                                    , (o) => ProcessingStatus == BackupProcessingStatus.NotStarted ||
                                                    ProcessingStatus == BackupProcessingStatus.Cancelled ||
                                                    ProcessingStatus == BackupProcessingStatus.Finished);

            FinishEditingBackupSetCommand = new RelayCommand((o) =>
            {
                StateService.RequestBackupSetEdit((string)o);
            });

            BackupSet.PropertyChanged += BackupSetPropertyChanged;
        }