Пример #1
0
        /// <summary>
        /// Constructor taking sync pair repository, and workspace commands.
        /// </summary>
        /// <param name="p_syncPairRepository"></param>
        /// <param name="wsCommands"></param>
        public AllSyncPairsViewModel(SyncPairRepository p_syncPairRepository, IWorkspaceCommands wsCommands)
        {
            // Store commands locally.
            _wsCommands = wsCommands;

            // Throw exception if parameter supplied is null
            if (p_syncPairRepository == null)
            {
                throw new ArgumentNullException("syncPairRepository");
            }

            // Set name displayed on tab
            base.DisplayName = Strings.AllSyncPairsViewModel_DisplayName;

            // Store sync pair repository locally.
            _syncPairRepository = p_syncPairRepository;

            // Subscribe for notifications of when a new SyncPair is saved.
            _syncPairRepository.SyncPairAdded += OnSyncPairAddedToRepository;

            // Subscribe for notifications of when a SyncPair is deleted
            _syncPairRepository.SyncPairRemoved += OnSyncPairRemovedFromRepository;

            // Populate the AllSyncPairs collection with SyncPairViewModels.
            CreateAllSyncPairs();

            // Attach relay command.
            EditSyncPairCommand = new SharpToolsMVVMRelayCommand(EditSyncPair);
        }
Пример #2
0
        public MainWindowViewModel(string syncPairDataFile)
        {
            base.DisplayName    = Strings.MainWindowViewModel_DisplayName;
            _syncPairRepository = new SyncPairRepository(syncPairDataFile);
            GetTestCommand      = new SharpToolsMVVMRelayCommand(GetTest);

            //SharpToolsMVVMMediator.Register("update", AddUpdate ); // Listener for change events
        }
Пример #3
0
        /// <summary>
        /// Constructor created from supplied args.
        /// </summary>
        /// <param name="p_syncPair"></param>
        /// <param name="p_syncPairRepository"></param>
        /// <param name="wsCommands"></param>
        public SyncPairViewModel(SyncPair p_syncPair, SyncPairRepository p_syncPairRepository, IWorkspaceCommands wsCommands)
        {
            // Create local commands.
            _wsCommands = wsCommands;

            // Check sync pair exists.
            if (p_syncPair == null)
            {
                throw new ArgumentNullException("p_syncPair");
            }

            // Check sync repository exists.
            if (p_syncPairRepository == null)
            {
                throw new ArgumentNullException("p_syncPairRepository");
            }

            // Set sync pair.
            _syncPair = p_syncPair;
            // Set sync pair repository.
            _syncPairRepository = p_syncPairRepository;

            // Set sync type if specified.
            if (_syncPair.SyncType == null)
            {
                _syncPairType = Strings.SyncPairViewModel_SyncPairTypeOption_NotSpecified;
            }
            else
            {
                _syncPairType = _syncPair.SyncType;
            }

            // Initialise source root retrieval.
            GetSrcRootCommand = new SharpToolsMVVMRelayCommand(GetSrcRoot);

            // Initialise destination root retrieval.
            GetDstRootCommand = new SharpToolsMVVMRelayCommand(GetDstRoot);

            // Initialise source root browser.
            BrowseSrcRootCommand = new SharpToolsMVVMRelayCommand(BrowseSrcRoot);

            // Initialise destination root browser.
            BrowseDstRootCommand = new SharpToolsMVVMRelayCommand(BrowseDstRoot);

            // Initialise delete sync pair.
            DeleteSyncPairCommand = new SharpToolsMVVMRelayCommand(Delete);

            SharpToolsMVVMMediator.Register("update", AddUpdate); // Listener for change events
            // LOG
            _log.Debug("Mediator Registered");
            //
            ResultLog = new ObservableCollection <string>();
        }
Пример #4
0
        /// <summary>
        /// Saves the Syncpair to the repository.  This method is invoked by the SaveCommand.
        /// </summary>
        public void Save()
        {
            // Check state for saving.
            if (!_syncPair.IsValid)
            {
                throw new InvalidOperationException(Strings.SyncPairViewModel_Exception_CannotSave);
            }

            // Save sync pair.
            if (IsNewSyncPair)
            {
                _syncPairRepository.AddSyncPair(_syncPair);
            }

            // Raise event that display name property has changed.
            base.OnPropertyChanged("DisplayName");

            // Update data store.
            SyncPairRepository.SaveSyncPairs(_syncPairRepository, MainWindowViewModel.DATA_PATH);
        }
Пример #5
0
        /// <summary>
        /// Deletes the Syncpair from the repository.  This method is invoked by the DeleteCommand.
        /// </summary>
        public void Delete(object syncpair)
        {
            // Check if sync pair has been saved.
            if (!IsNewSyncPair)
            {
                // Check if user is certain.
                MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Are you sure?", "Delete Confirmation", System.Windows.MessageBoxButton.YesNo);
                if (messageBoxResult == MessageBoxResult.Yes)
                {
                    // Remove sync pair.
                    _syncPairRepository.DeleteSyncPair(_syncPair);
                    // Remove workspace.
                    _wsCommands.RemoveWorkspace(this);
                }
            }

            // Update data store.
            SyncPairRepository.SaveSyncPairs(_syncPairRepository, MainWindowViewModel.DATA_PATH);

            // Destroy base.
            base.Dispose();
        }