public Form1(string testDirectory) { _testDirectory = testDirectory; InitializeComponent(); var serverDir = Path.Combine(testDirectory, "server"); UnZipToDirectory(serverDir); _serverRepository = new DirectoryRepositorySource("server", Path.Combine(serverDir,"ShoppingList"), false); _userPicker.SelectedIndex = 0; }
/// <summary> /// used for local sources (usb, sd media, etc) /// </summary> /// <returns>the uri of a successful clone</returns> private string TryToMakeCloneForSource(RepositoryAddress repoDescriptor) { List<string> possibleRepoCloneUris = repoDescriptor.GetPossibleCloneUris(Repository.Identifier, RepoProjectName, _progress); if (possibleRepoCloneUris == null) { _progress.WriteMessage("No Uris available for cloning to {0}", repoDescriptor.Name); return null; } else { foreach (string uri in possibleRepoCloneUris) { // target may be uri, or some other folder. var target = HgRepository.GetUniqueFolderPath( _progress, //"Folder at {0} already exists, so it can't be used. Creating clone in {1}, instead.", RepositoryAddress.DuplicateWarningMessage.Replace(RepositoryAddress.MediumVariable, "USB flash drive"), uri); try { _progress.WriteMessage("Copying repository to {0}...", repoDescriptor.GetFullName(target)); _progress.WriteVerbose("({0})", target); return HgHighLevel.MakeCloneFromLocalToLocal(_localRepositoryPath, target, false, // No update on USB or shared network clones as of 16 Jan 2012. _progress); } catch (Exception error) { _progress.WriteError("Could not create repository on {0}. Error follow:", target); _progress.WriteException(error); // keep looping } } } return null; }
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); } }
/// <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; } } }
public void SetIsOneOfDefaultSyncAddresses(RepositoryAddress address, bool enabled) { Repository.SetIsOneDefaultSyncAddresses(address, enabled); }
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; }
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; }
public void PathEnabledChanged(RepositoryAddress address, CheckState state) { address.Enabled = (state == CheckState.Checked); //NB: we may someday decide to distinguish between this chorus-app context of "what //repos I used last time" and the hgrc default which effect applications (e.g. wesay) _synchronizer.SetIsOneOfDefaultSyncAddresses(address, address.Enabled); }
public SyncStartArgs(RepositoryAddress address, string commitMessage) { Address = address; CommitMessage = commitMessage; }
/// <summary> /// used for local sources (usb, sd media, etc) /// </summary> /// <returns>the uri of a successful clone</returns> private string TryToMakeCloneForSource(RepositoryAddress repoDescriptor) { List<string> possibleRepoCloneUris = repoDescriptor.GetPossibleCloneUris(Repository.Identifier, RepoProjectName, _progress); if (possibleRepoCloneUris == null) { _progress.WriteMessage("No Uris available for cloning to {0}", repoDescriptor.Name); return null; } else { foreach (string uri in possibleRepoCloneUris) { // target may be uri, or some other folder. var target = HgRepository.GetUniqueFolderPath( _progress, //"Folder at {0} already exists, so it can't be used. Creating clone in {1}, instead.", "Warning: there is a project on the USB flash drive which has the right name ({0}), but it is actually unrelated to the one doing the Send/Receive. This usually indicates that the two repositories were created separately, which doesn't work. These repositories have to be descendants of each other, or else they can't be synchronized. This situation occurs when you create the repositories separately by accident. Instead, create one then use 'Get from USB' or 'Get from Internet' from other programs and computers. You may want to get some expert help." + " In the meantime, the program will create a repository at {1} so you can maybe keep collaborating while you wait for help.", uri); try { _progress.WriteMessage("Copying repository to {0}...", repoDescriptor.GetFullName(target)); _progress.WriteVerbose("({0})", target); return HgHighLevel.MakeCloneFromLocalToLocal(_localRepositoryPath, target, false, // No update on USB or shared network clones as of 16 Jan 2012. _progress); } catch (Exception error) { _progress.WriteError("Could not create repository on {0}. Error follow:", target); _progress.WriteException(error); continue; } } } return null; }
/// <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; } } }
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); } }