Exemple #1
0
        private void SendToOneOther(RepositoryAddress address, Dictionary<RepositoryAddress, bool> connectionAttempt, HgRepository repo)
        {
            try
            {
                string resolvedUri = address.GetPotentialRepoUri(Repository.Identifier, RepoProjectName, _progress);

                bool canConnect;
                if (connectionAttempt.ContainsKey(address))
                {
                    canConnect = connectionAttempt[address];
                }
                else
                {
                    canConnect = address.CanConnect(repo, RepoProjectName, _progress);
                    connectionAttempt.Add(address, canConnect);
                }
                if (canConnect)
                {
                    if(s_testingDoNotPush)
                    {
                        _progress.WriteWarning("**Skipping push because s_testingDoNotPush is true");
                    }
                    else
                    {
                        repo.Push(address, resolvedUri);
                    }

                    // For usb, it's safe and desireable to do an update (bring into the directory
                    // the latest files from the repo) for LAN, it could be... for now we assume it is.
                    // For me (RandyR) including the shared network folder
                    // failed to do the update and killed the process, which left a 'wlock' file
                    // in the shared folder's '.hg' folder. No more S/Rs could then be done,
                    // because the repo was locked.
                    // For now, at least, it is not a requirement to do the update on the shared folder.
                    // JDH Oct 2010: added this back in if it doesn't look like a shared folder
                    if (address is UsbKeyRepositorySource  ||
                        (address is DirectoryRepositorySource && ((DirectoryRepositorySource)address).LooksLikeLocalDirectory))
                    {
                        var otherRepo = new HgRepository(resolvedUri, _progress);
                        otherRepo.Update();
                    }
                }
                else if (address is UsbKeyRepositorySource || address is DirectoryRepositorySource)
                {
                    // If we cannot connect to a USB or Directory source (the repository doesn't exist),
                    // try to clone our repository onto the source
                    TryToMakeCloneForSource(address);
                    //nb: no need to push if we just made a clone
                }
            }
            catch (UserCancelledException)
            {
                throw;
            }
            catch (Exception error)
            {
                ExplainAndThrow(error, "Failed to send to {0} ({1}).", address.Name, address.URI);
            }
        }
Exemple #2
0
        /// <returns>true if there was a successful pull</returns>
        private bool PullFromOneSource(HgRepository repo, RepositoryAddress source, Dictionary<RepositoryAddress, bool> connectionAttempt)
        {
            string resolvedUri = source.GetPotentialRepoUri(repo.Identifier, RepoProjectName, _progress);

            if (source is UsbKeyRepositorySource)
            {
                _progress.WriteMessage("Looking for USB flash drives...");
                var potential = source.GetPotentialRepoUri(repo.Identifier, RepoProjectName, _progress);
                if (null == potential)
                {
                    _progress.WriteWarning("No USB flash drive found");
                }
                else if (string.Empty == potential)
                {
                    _progress.WriteMessage("Did not find this project on any USB flash drive.");
                }
            }
            else
            {
                _progress.WriteMessage("Connecting to {0}...", source.Name);
            }
            var canConnect = source.CanConnect(repo, RepoProjectName, _progress);
            if (!connectionAttempt.ContainsKey(source))
            {
                connectionAttempt.Add(source, canConnect);
            }
            if (canConnect)
            {
                try
                {
                    ThrowIfCancelPending();
                }
                catch(Exception error)
                {
                    throw new SynchronizationException(error, WhatToDo.CheckSettings, "Error while pulling {0} at {1}", source.Name, resolvedUri);
                }
                //NB: this returns false if there was nothing to get.
                try
                {
                    return repo.Pull(source, resolvedUri);
                }
                catch (HgCommonException err)
                {
                    // These kinds of errors are worth an immediate dialog, to make sure we get the user's attention.
                    ErrorReport.NotifyUserOfProblem(err.Message);
                    // The main sync routine will catch the exception, abort any other parts of the Send/Receive,
                    // and log the problem.
                    throw;
                }
                // Any other kind of exception will be caught and logged at a higher level.
            }
            else
            {
                if (source is UsbKeyRepositorySource)
                {
                    //already informed them, above
                     return false;
                }
                else
                {
                    _progress.WriteError("Could not connect to {0} at {1}", source.Name, resolvedUri);
                    return false;
                }
            }
        }
Exemple #3
0
 private bool IsSharedFolderRepositoryReachable(RepositoryAddress repoAddress, out string logString)
 {
     // We want to know if we can connect, but we don't want to bother the user with extraneous information.
     // But we DO want the diagnostic information available.
     logString = string.Empty;
     var progress = new StringBuilderProgress() { ShowVerbose = true };
     var result = repoAddress.CanConnect(_repository, "", progress);
     if (!result)
         logString = progress.Text;
     return result;
 }
Exemple #4
0
 private bool IsInternetRepositoryReachable(RepositoryAddress repoAddress, out string logString)
 {
     logString = string.Empty;
     var progress = new StringBuilderProgress(){ShowVerbose = true};
     var result = repoAddress.CanConnect(_repository, repoAddress.Name, progress);
     if (!result)
         logString = progress.Text;
     return result;
 }
Exemple #5
0
        /// <returns>true if there was a successful pull</returns>
        private bool PullFromOneSource(HgRepository repo, RepositoryAddress source, Dictionary<RepositoryAddress, bool> connectionAttempt)
        {
            string resolvedUri = source.GetPotentialRepoUri(repo.Identifier, RepoProjectName, _progress);

            if (source is UsbKeyRepositorySource)
            {
                _progress.WriteMessage("Looking for USB flash drives...");
                var potential = source.GetPotentialRepoUri(repo.Identifier, RepoProjectName, _progress);
                if (null ==potential)
                {
                    _progress.WriteWarning("No USB flash drive found");
                }
                else if (string.Empty == potential)
                {
                    _progress.WriteMessage("Did not find existing project on any USB flash drive.");
                }
            }
            else
            {
                _progress.WriteMessage("Connecting to {0}...", source.Name);
            }
            var canConnect = source.CanConnect(repo, RepoProjectName, _progress);
            if (!connectionAttempt.ContainsKey(source))
            {
                connectionAttempt.Add(source, canConnect);
            }
            if (canConnect)
            {
                try
                {
                    ThrowIfCancelPending();
                }
                catch(Exception error)
                {
                    throw new SynchronizationException(error, WhatToDo.CheckSettings, "Error while pulling {0} at {1}", source.Name, resolvedUri);
                }
                //NB: this returns false if there was nothing to get.
                try
                {
                    return repo.Pull(source, resolvedUri);
                }
                catch (HgCommonException err)
                {
                    ErrorReport.NotifyUserOfProblem(err.Message);
                    return false;
                }
                catch (UserCancelledException)
                {
                    // don't report anything
                    return false;
                }
                catch (Exception err)
                {
                    _progress.WriteException(err);
                    return false;
                }

            }
            else
            {
                if (source is UsbKeyRepositorySource)
                {
                    //already informed them, above
                     return false;
                }
                else
                {
                    _progress.WriteError("Could not connect to {0} at {1}", source.Name, resolvedUri);
                    return false;
                }
            }
        }
Exemple #6
0
        private void SendToOneOther(RepositoryAddress address, Dictionary<RepositoryAddress, bool> connectionAttempt, HgRepository repo)
        {
            try
            {
                string resolvedUri = address.GetPotentialRepoUri(Repository.Identifier, RepoProjectName, _progress);

                bool canConnect;
                if (connectionAttempt.ContainsKey(address))
                {
                    canConnect = connectionAttempt[address];
                }
                else
                {
                    canConnect = address.CanConnect(repo, RepoProjectName, _progress);
                    connectionAttempt.Add(address, canConnect);
                }
                if (canConnect)
                {
                    if(s_testingDoNotPush)
                    {
                        _progress.WriteWarning("**Skipping push because s_testingDoNotPush is true");
                    }
                    else
                    {
                        repo.Push(address, resolvedUri);
                    }

                    // For USB, we do not wish to do an update, since it can cause problems if the working
                    // files are available to the user.
                    // The update is only done for tests, since only tests now use "DirectoryRepositorySource".
                    if (address is DirectoryRepositorySource && ((DirectoryRepositorySource) address).LooksLikeLocalDirectory)
                    {
                        // passes false to avoid updating the hgrc on a send to preserve backward compatibility
                        var otherRepo = new HgRepository(resolvedUri, false, _progress);
                        otherRepo.Update();
                    }
                }
                else if (address is UsbKeyRepositorySource || address is DirectoryRepositorySource)
                {
                    // If we cannot connect to a USB or Directory source (the repository doesn't exist),
                    // try to clone our repository onto the source
                    TryToMakeCloneForSource(address);
                    //nb: no need to push if we just made a clone
                }
            }
            catch (UserCancelledException)
            {
                throw;
            }
            catch (Exception error)
            {
                ExplainAndThrow(error, "Failed to send to {0} ({1}).", address.Name, address.URI);
            }
        }