Example #1
0
        //autofac uses this
        public SyncDialog(ProjectFolderConfiguration projectFolderConfiguration,
			SyncUIDialogBehaviors behavior, SyncUIFeatures uiFeatureFlags)
        {
            InitializeComponent();
            try
            {
                Behavior = behavior;
                _syncControl.Model = new SyncControlModel(projectFolderConfiguration, uiFeatureFlags, null/*to do*/);
                AcceptButton = _syncControl._cancelButton;
                // CancelButton =  _syncControl._cancelOrCloseButton;

                _syncControl.Model.SynchronizeOver += new EventHandler(_syncControl_SynchronizeOver);

                //we don't want clients digging down this deeply, so we present it as one of our properties
                FinalStatus = _syncControl.Model.StatusProgress;

                //set the default based on whether this looks like a backup or local commit operation
                UseTargetsAsSpecifiedInSyncOptions = (Behavior == SyncUIDialogBehaviors.StartImmediately ||
                                                      Behavior == SyncUIDialogBehaviors.StartImmediatelyAndCloseWhenFinished);

                //in case the user cancels before the sync and the client doesn't check to see if the result is null
                if ((uiFeatureFlags & SyncUIFeatures.SimpleRepositoryChooserInsteadOfAdvanced) == SyncUIFeatures.SimpleRepositoryChooserInsteadOfAdvanced)
                {
                    SyncResult = new SyncResults();
                    SyncResult.Succeeded = false;

                    _syncStartControl.Init(HgRepository.CreateOrUseExisting(projectFolderConfiguration.FolderPath, new NullProgress()));

                    _syncControl.Dock = DockStyle.Fill;//in designer, we don't want it to cover up everything, but we do at runtime
                    _syncStartControl.Visible = true;
                    _syncControl.Visible = false;
                    Height = _syncStartControl.DesiredHeight;
                }
                else
                {
                    _syncStartControl.Visible = false;
                    _syncControl.Visible = true;
                    Height = _syncControl.DesiredHeight;
                }
                ResumeLayout(true);
                this.Text = string.Format("Send/Receive ({0})", _syncControl.Model.UserName);
            }
            catch (Exception)
            {
                _syncStartControl.Dispose();//without this, the usbdetector just goes on and on
                throw;
            }
        }
Example #2
0
        public SyncResults SyncNow(SyncOptions options)
        {
            SyncResults results = new SyncResults();
            List <RepositoryAddress> sourcesToTry = options.RepositorySourcesToTry;
            //this just saves us from trying to connect twice to the same repo that is, for example, no there.
            Dictionary <RepositoryAddress, bool> connectionAttempts = new Dictionary <RepositoryAddress, bool>();

            try
            {
                if (_progress.ProgressIndicator != null)
                {
                    _progress.ProgressIndicator.IndicateUnknownProgress();
                }
                var repo = new HgRepository(_localRepositoryPath, _progress);

                RemoveLocks(repo);
                repo.RecoverFromInterruptedTransactionIfNeeded();
                repo.FixUnicodeAudio();
                string branchName = _sychronizerAdjunct.BranchName;
                ChangeBranchIfNecessary(branchName);
                Commit(options);

                var workingRevBeforeSync = repo.GetRevisionWorkingSetIsBasedOn();

                if (options.DoPullFromOthers)
                {
                    results.DidGetChangesFromOthers = PullFromOthers(repo, sourcesToTry, connectionAttempts);
                }

                if (options.DoMergeWithOthers)
                {
                    MergeHeadsOrRollbackAndThrow(repo, workingRevBeforeSync);
                }

                if (options.DoSendToOthers)
                {
                    SendToOthers(repo, sourcesToTry, connectionAttempts);
                }

                //If we did pull any data or a trivial merge succeeded we should call UpdateToTheDescendantRevision
                if (results.DidGetChangesFromOthers ||                                                             //we pulled something
                    (workingRevBeforeSync != null &&                //will be null if this is the 1st checkin ever, but no files were added so there was no actual rev created
                     !repo.GetRevisionWorkingSetIsBasedOn().Number.Hash.Equals(workingRevBeforeSync.Number.Hash))) //a merge happened
                {
                    UpdateToTheDescendantRevision(repo, workingRevBeforeSync);
                }
                _sychronizerAdjunct.CheckRepositoryBranches(repo.BranchingHelper.GetBranches(), _progress);

                results.Succeeded = true;
                _progress.WriteMessage("Done");
            }
            catch (SynchronizationException error)
            {
                error.DoNotifications(Repository, _progress);
                results.Succeeded        = false;
                results.ErrorEncountered = error;
            }
            catch (UserCancelledException error)
            {
                results.Succeeded        = false;
                results.Cancelled        = true;
                results.ErrorEncountered = null;
            }
            catch (Exception error)
            {
                if (error.InnerException != null)
                {
                    _progress.WriteVerbose("inner exception:");
                    _progress.WriteError(error.InnerException.Message);
                    _progress.WriteVerbose(error.InnerException.StackTrace);
                }

                _progress.WriteException(error);                //this preserves the whole exception for later retrieval by the client
                _progress.WriteError(error.Message);            //review still needed if we have this new WriteException?
                _progress.WriteVerbose(error.StackTrace);       //review still needed if we have this new WriteException?

                results.Succeeded        = false;
                results.ErrorEncountered = error;
            }
            return(results);
        }
Example #3
0
        void _backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (SynchronizeOver != null)
            {
                UnmanagedMemoryStream stream=null;

                if (_progress.ErrorEncountered)
                {
                    stream = Properties.Resources.errorSound;
                }
                else if (_progress.WarningsEncountered)
                {
                    stream = Properties.Resources.warningSound;
                }
                else
                {
                    if (HasFeature(SyncUIFeatures.PlaySoundIfSuccessful))
                        stream = Properties.Resources.finishedSound;
                }

                if (stream != null)
                {
                    using (SoundPlayer player = new SoundPlayer(stream))
                    {
                        player.PlaySync();
                    }
                    stream.Dispose();
                }

                if (e.Cancelled)
                {
                    var r = new SyncResults();
                    r.Succeeded = false;
                    r.Cancelled = true;
                    SynchronizeOver.Invoke(r, null);
                }
                else //checking e.Result if there was a cancellation causes an InvalidOperationException
                {
                    SynchronizeOver.Invoke(e.Result as SyncResults, null);
                }
            }
        }
Example #4
0
        public SyncResults SyncNow(SyncOptions options)
        {
            SyncResults results = new SyncResults();
            List<RepositoryAddress> sourcesToTry = options.RepositorySourcesToTry;
            //this just saves us from trying to connect twice to the same repo that is, for example, no there.
            Dictionary<RepositoryAddress, bool> connectionAttempts = new Dictionary<RepositoryAddress, bool>();

            try
            {
                if (_progress.ProgressIndicator != null)
                {
                    _progress.ProgressIndicator.IndicateUnknownProgress();
                }
                var repo = new HgRepository(_localRepositoryPath, _progress);

                RemoveLocks(repo);
                repo.RecoverFromInterruptedTransactionIfNeeded();
                repo.FixUnicodeAudio();
                string branchName = _sychronizerAdjunct.BranchName;
                ChangeBranchIfNecessary(branchName);
                Commit(options);

                var workingRevBeforeSync = repo.GetRevisionWorkingSetIsBasedOn();

                if (options.DoPullFromOthers)
                {
                    results.DidGetChangesFromOthers = PullFromOthers(repo, sourcesToTry, connectionAttempts);
                }

                if (options.DoMergeWithOthers)
                {
                    MergeHeadsOrRollbackAndThrow(repo, workingRevBeforeSync);
                }

                if (options.DoSendToOthers)
                {
                    SendToOthers(repo, sourcesToTry, connectionAttempts);
                }

                //If we did pull any data or a trivial merge succeeded we should call UpdateToTheDescendantRevision
                if (results.DidGetChangesFromOthers || //we pulled something
                    (workingRevBeforeSync!=null //will be null if this is the 1st checkin ever, but no files were added so there was no actual rev created
                    && !repo.GetRevisionWorkingSetIsBasedOn().Number.Hash.Equals(workingRevBeforeSync.Number.Hash))) //a merge happened
                {
                    UpdateToTheDescendantRevision(repo, workingRevBeforeSync);
                }
                _sychronizerAdjunct.CheckRepositoryBranches(repo.BranchingHelper.GetBranches(), _progress);

                results.Succeeded = true;
               _progress.WriteMessage("Done");
            }
            catch (SynchronizationException error)
            {
                error.DoNotifications(Repository, _progress);
                results.Succeeded = false;
                results.ErrorEncountered = error;
            }
            catch (UserCancelledException error)
            {
                results.Succeeded = false;
                results.Cancelled = true;
                results.ErrorEncountered = null;
            }
            catch (Exception error)
            {
                if (error.InnerException != null)
                {
                    _progress.WriteVerbose("inner exception:");
                    _progress.WriteError(error.InnerException.Message);
                    _progress.WriteVerbose(error.InnerException.StackTrace);
                }

                _progress.WriteException(error);//this preserves the whole exception for later retrieval by the client
                _progress.WriteError(error.Message);//review still needed if we have this new WriteException?
                _progress.WriteVerbose(error.StackTrace);//review still needed if we have this new WriteException?

                results.Succeeded = false;
                results.ErrorEncountered = error;
            }
            return results;
        }
 public SyncFinishedEventArgs(SyncResults syncResults)
 {
     if (syncResults == null) throw new ArgumentNullException("syncResults");
     Results = syncResults;
 }