예제 #1
0
 internal Presenter(ICopyEngine copyEngine, ICopyViewer copyViewer, DirectoryEngine directoryEngine, SynchronizeEngine synchronizeEngine, IProfileManager profileManager)
 {
     _copyEngine        = copyEngine;
     _copyViewer        = copyViewer;
     _directoryEngine   = directoryEngine;
     _synchronizeEngine = synchronizeEngine;
     _copyViewer.OnPreviousSelectionSelectedIndexChanged += new PreviousSelectionSelectedIndexChangedHandler(_copyViewer_OnPreviousSelectionSelectedIndexChanged);
     _copyViewer.OnRemovePreviousSelection += new RemovePreviousSelectionHandler(_copyViewer_OnRemovePreviousSelection);
     _copyViewer.OnChooseNewBaseDirectory  += new ChooseNewBaseDirectoryHandler(_copyViewer_OnChooseNewBaseDirectory);
     _copyViewer.OnChooseOldBaseDirectory  += new ChooseOldBaseDirectoryHandler(_copyViewer_OnChooseOldBaseDirectory);
     _copyViewer.OnCopyNewBaseDirectory    += new CopyNewBaseDirectoryHandler(_copyViewer_OnCopyNewBaseDirectory);
     _copyViewer.OnCopyOldBaseDirectory    += new CopyOldBaseDirectoryHandler(_copyViewer_OnCopyOldBaseDirectory);
     _copyViewer.OnCopyAction   += new CopyActionHandler(_copyViewer_OnCopyAction);
     _copyViewer.OnDeleteAction += new DeleteActionHandler(_copyViewer_OnDeleteAction);
     _copyViewer.OnSynchronizePreventDeleteAction += new SynchronizePreventDeleteActionHandler(_copyViewer_OnSynchronizePreventDeleteAction);
     _copyViewer.OnSynchronizeAction        += new SynchronizeActionHandler(_copyViewer_OnSynchronizeAction);
     _copyViewer.OnSynchronizeAllAction     += new SynchronizeAllActionHandler(_copyViewer_OnSynchronizeAllAction);
     _copyViewer.OnSynchronizePlusAction    += new SynchronizePlusActionHandler(_copyViewer_OnSynchronizePlusAction);
     _copyViewer.OnSynchronizePlusAllAction += new SynchronizePlusAllActionHandler(_copyViewer_OnSynchronizePlusAllAction);
     _copyViewer.OnCancelAction             += new CancelActionHandler(_copyViewer_OnCancelAction);
     _profileManager          = profileManager;
     _currentActivityProgress = new ProgressLink();
     _overallProgress         = new ProgressLink();
     _copyViewer.EnableControls(true);
     LoadParameters();
     RefreshCombo();
 }
예제 #2
0
        void _copyViewer_OnSynchronizePlusAction(EventArgs e)
        {
            Administrator.Reset();
            _copyViewer.EnableControls(false);
            _overallProgress                    = new ProgressLink();
            _copyViewer.OverallProgress         = _overallProgress;
            _currentActivityProgress            = new ProgressLink();
            _copyViewer.CurrentActivityProgress = _currentActivityProgress;

            //Validate all fields.
            int errorCount = ValidateFields();

            if (errorCount > 0)
            {
                return;
            }

            //Save Parameters.
            _profileManager.UserSettings.Select(_currentKey);
            _profileManager.Interrupt.Reason = "OK";
            SaveParameters();
            RefreshCombo();

            //Use directory engine to scan both directories to determine the differences.
            DateTime startAllDateTime = Administrator.Now;

            _directoryEngine                      = new DirectoryEngine();
            _directoryEngine.Interrupt            = _profileManager.Interrupt;
            _directoryEngine.EventBeginProgress  += new Copy8.EventDelegate(_directoryEngine_OnBeginDirectoryScan);
            _directoryEngine.EventUpdateProgress += new Copy8.EventDelegate(_directoryEngine_OnUpdateDirectoryScan);
            _directoryEngine.EventEndOfProgress  += new Copy8.EventDelegate(_directoryEngine_OnEndOfDirectoryScan);
            _directoryEngine.MonitoredTypesOnly   = _profileManager.UserSettings.SelectedItem.MonitoredTypesOnly;
            _directoryEngine.Interrupt            = _profileManager.Interrupt;
            _processingNew       = true;
            _NewDirectoryListing = _directoryEngine.DirList(_profileManager.UserSettings.SelectedItem.NewBaseDir, ref mnNewFilesEstimate);
            _TotalBytes          = mnNewFilesEstimate;
            //Delete log files older that the specified number of days.
            DeleteOldLogFiles();
            _processingNew = false;
            string targetDirectory = _profileManager.UserSettings.SelectedItem.OldBaseDir;

            if (!Directory.Exists(targetDirectory))
            {
                Directory.CreateDirectory(targetDirectory);
            }
            _directoryEngine.TargetHlq = targetDirectory;
            mnOldFilesEstimate         = mnNewFilesEstimate;
            // Instead of scanning the target directory.
            // Load the previously synchronized snapshot to compare against.
            if (File.Exists(getSnapshotFileSpec(targetDirectory)))
            {
                _OldDirectoryListing = new DirectoryEntries();
                _OldDirectoryListing.Load(getSnapshotFileSpec(targetDirectory), DirectoryEntries.InterpretationEnum.Target);
            }
            else
            {
                _OldDirectoryListing = _directoryEngine.DirList(targetDirectory, ref mnOldFilesEstimate);
            }
            _directoryEngine.Compare(ref _OldDirectoryListing, ref _NewDirectoryListing);
            _directoryEngine.Changes(_OldDirectoryListing, _NewDirectoryListing, ref _ChangedDirectoryListing, ref mnChgFilesEstimate);
            _comparisons          = _directoryEngine.Comparisons;
            _copyEngine.Interrupt = _profileManager.Interrupt;

            //Use the Synchronize engine to perform the synchronize.
            //TODO: Move the directory engine calls inside the Synchronize engine.
            _synchronizeEngine = new SynchronizeEngine();
            _synchronizeEngine.OnBeginSynchronize  += new SynchronizeEngine.BeginSynchronizeHandler(_SynchronizeEngine_OnBeginSynchronize);
            _synchronizeEngine.OnUpdateSynchronize += new SynchronizeEngine.UpdateSynchronizeHandler(_SynchronizeEngine_OnUpdateSynchronize);
            _synchronizeEngine.OnEndOfSynchronize  += new SynchronizeEngine.EndOfSynchronizeHandler(_SynchronizeEngine_OnEndOfSynchronize);
            _synchronizeEngine.CopyRule             = _profileManager.UserSettings.SelectedItem.CopyRule;
            _synchronizeEngine.MonitoredTypesOnly   = _profileManager.UserSettings.SelectedItem.MonitoredTypesOnly;
            _synchronizeEngine.Interrupt            = _profileManager.Interrupt;

            try
            {
                _synchronizeEngine.Process(_comparisons, startAllDateTime);
                //After synchronization the target directory is synchronized with the source directory.
                _NewDirectoryListing.Save(getSnapshotFileSpec(targetDirectory));
                Administrator.View();
            }
            catch (ParameterException pe)
            {
                _copyViewer.SetFieldError(pe.Parameter, pe.Message);
                //_copyViewer.DisplayMessageBox(ae.Message, _copyViewer.Caption, MsgButtons.OK, MsgIcon.Error);
            }
            finally
            {
                _copyViewer.EnableControls(true);
            }
        }