public void SetAddresses(string text, IProgress progress) { var oldPaths = _repository.GetRepositoryPathsInHgrc(); var aliases = new List <RepositoryAddress>(); var lines = text.Split('\n'); foreach (var line in lines) { var parts = line.Split('='); if (parts.Length != 2) { continue; } aliases.Add(RepositoryAddress.Create(parts[0].Trim(), parts[1].Trim())); } if (oldPaths.Count() > 0 && aliases.Count() == 0) { var response = MessageBox.Show( LocalizationManager.GetString("Messages.RepositoryPathCleared", "Repository Paths is being cleared. If you did that on purpose, fine, click 'Yes'. If not, please click 'No' and report this to [email protected] (we're trying to track down a bug)."), LocalizationManager.GetString("Common.PleaseConfirm", "Please confirm"), MessageBoxButtons.YesNo); if (response == DialogResult.No) { return; } } _repository.SetKnownRepositoryAddresses(aliases); }
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)) { // passes false to avoid updating the hgrc on a usb 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); } }
public static void SetHgParametersNetworkDrive(string strProjectFolder, string strProjectName, string strUrl) { System.Diagnostics.Debug.Assert(_mapProjectNameToHgNetworkUrl != null); _mapProjectNameToHgNetworkUrl[strProjectName] = strUrl; Properties.Settings.Default.ProjectNameToHgNetworkUrl = DictionaryToArray(_mapProjectNameToHgNetworkUrl); Properties.Settings.Default.Save(); var repo = new HgRepository(strProjectFolder, new NullProgress()); var address = RepositoryAddress.Create(CstrNetworkDriveName, strUrl); var addresses = repo.GetRepositoryPathsInHgrc(); foreach (var addr in addresses) { if (addr.URI == address.URI) { return; } } var lstAddrs = new List <RepositoryAddress>(addresses); lstAddrs.Add(address); repo.SetKnownRepositoryAddresses(lstAddrs); }
/// <summary> /// used for local sources (usb, sd media, etc) /// </summary> private void TryToMakeCloneForSource(RepositoryAddress repoDescriptor) { var possibleRepoCloneUris = repoDescriptor.GetPossibleCloneUris(Repository.Identifier, RepoProjectName, _progress); if (possibleRepoCloneUris == null) { _progress.WriteMessage("No Uris available for cloning to {0}", repoDescriptor.Name); return; } foreach (var 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); HgHighLevel.MakeCloneFromLocalToUsb(_localRepositoryPath, target, _progress); return; } catch (Exception error) { _progress.WriteError("Could not create repository on {0}. Error follow:", target); _progress.WriteException(error); // keep looping } } }
public void CanGetNewFileFromAnotherRep() { ConsoleProgress progress = new ConsoleProgress(); BobSetup bobSetup = new BobSetup(progress, _pathToTestRoot); bobSetup.ChangeTextFile(); string usbPath = Path.Combine(_pathToTestRoot, "USB-A"); Directory.CreateDirectory(usbPath); bobSetup.SetupClone(usbPath); RepositoryAddress otherDirPath = RepositoryAddress.Create("USBA", Path.Combine(usbPath, RepositoryAddress.ProjectNameVariable), false); Synchronizer bob = bobSetup.GetSynchronizer(); bob.ExtraRepositorySources.Add(otherDirPath); //now stick a new file over in the "usb", so we can see if it comes back to us File.WriteAllText(Path.Combine(otherDirPath.GetPotentialRepoUri(bob.Repository.Identifier, BobSetup.ProjectFolderName, progress), "incoming.abc"), "this would be a file coming in"); var options = GetFullSyncOptions("adding a file to the usb for some reason"); ProjectFolderConfiguration usbProject = BobSetup.CreateFolderConfig(Path.Combine(usbPath, BobSetup.ProjectFolderName)); var synchronizer = Synchronizer.FromProjectConfiguration(usbProject, progress); synchronizer.Repository.SetUserNameInIni("usba", progress); synchronizer.SyncNow(options); //now we should get that file options = GetFullSyncOptions("test getting new file from usb"); options.DoMergeWithOthers = false; options.DoSendToOthers = false; options.RepositorySourcesToTry.Add(otherDirPath); bob.SyncNow(options); Assert.That(Path.Combine(bobSetup._languageProjectPath, "incoming.abc"), Does.Exist); }
private List <PackageInfo> ObtainAndFillMetadata(List <PackageInfo> infos) { foreach (var packageInfo in infos) { foreach (var instPair in packageInfo.VersionedInstances) { foreach (var inst in instPair.Value) { var addr = new Uri(RepositoryAddress); var address = RepositoryAddress + (RepositoryAddress.EndsWith("/")?"":"/") + packageInfo.PackageName + "/" + instPair.Key + "/" + (inst.VersionName == null ? "trunk" : "tags/" + inst.VersionName) + "/" + MetadataFileName; string filePath = null; Common.Utility.ExceptionablePlaceWrapper(() => { filePath = Utility.DownloadFileFromSVN(address); }, string.Format("Attempt to get metadata by Address: {0} failed", address), "", false); if (filePath == null) { continue; } MetadataProcessor.Process(filePath, inst); } } } return(infos); }
///<summary> ///</summary> ///<returns>true of successful; false if failed</returns> public bool SetRepositoryAddress() { try { var repo = new HgRepository(TargetDestination, _progress); var name = new Uri(URL).Host; if (String.IsNullOrEmpty(name)) //This happens for repos on the local machine { name = @"LocalRepository"; } if (name.ToLower().Contains(@"languagedepot")) { name = @"LanguageDepot"; } var address = RepositoryAddress.Create(name, URL); //this will also remove the "default" one that hg puts in, which we don't really want. repo.SetKnownRepositoryAddresses(new[] { address }); repo.SetIsOneDefaultSyncAddresses(address, true); return(true); } catch (Exception error) { _progress.WriteError(error.Message); return(false); } }
public RepositoryAddress GetRepositoryAddress() { var x = RepositoryAddress.Create("unknownname", ProjectFolder.Path, false); x.Enabled = true; return(x); }
public void Sync_NonExistantLangDepotProject_ExitsGracefullyWithCorrectErrorResult() { _model = new SyncControlModel(_project, SyncUIFeatures.Minimal, null); _model.SyncOptions.RepositorySourcesToTry.Add(RepositoryAddress.Create("languageforge", "http://hg-public.languagedepot.org/dummy")); var progress = new ConsoleProgress() { ShowVerbose = true }; _model.AddMessagesDisplay(progress); SyncResults results = null; _model.SynchronizeOver += new EventHandler((sender, e) => results = (sender as SyncResults)); _model.Sync(true); var start = DateTime.Now; while (results == null) { Thread.Sleep(100); Application.DoEvents(); //else the background worker may starve if ((DateTime.Now.Subtract(start).Minutes > 1)) { Assert.Fail("Gave up waiting."); } } Assert.IsFalse(results.Succeeded); Assert.IsNotNull(results.ErrorEncountered); }
private void _useUSBButton_Click(object sender, EventArgs e) { if (RepositoryChosen != null) { var address = RepositoryAddress.Create(RepositoryAddress.HardWiredSources.UsbKey, "USB flash drive", false); RepositoryChosen.Invoke(this, new SyncStartArgs(address, _commitMessageText.Text)); } }
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 Synchronizer(string localRepositoryPath, ProjectFolderConfiguration project, IProgress progress) { _progress = progress; _project = project; _localRepositoryPath = localRepositoryPath; _handlers = ChorusFileTypeHandlerCollection.CreateWithInstalledHandlers(); ExtraRepositorySources = new List <RepositoryAddress>(); ExtraRepositorySources.Add(RepositoryAddress.Create(RepositoryAddress.HardWiredSources.UsbKey, "USB flash drive", false)); }
public void CanCollaborateOnLift() { ConsoleProgress progress = new ConsoleProgress(); BobSetup bobSetup = new BobSetup(progress, _pathToTestRoot); bobSetup.ChangeTextFile(); //Ok, this is unrealistic, but we just clone Bob onto Sally string sallyMachineRoot = Path.Combine(_pathToTestRoot, "sally"); Directory.CreateDirectory(sallyMachineRoot); string sallyProjectRoot = bobSetup.SetupClone(sallyMachineRoot); ProjectFolderConfiguration sallyProject = BobSetup.CreateFolderConfig(sallyProjectRoot); var repository = HgRepository.CreateOrUseExisting(sallyProject.FolderPath, progress); repository.SetUserNameInIni("sally", progress); // bob makes a change and syncs File.WriteAllText(bobSetup._pathToLift, LiftFileStrings.lift12Dog); var bobOptions = new SyncOptions { CheckinDescription = "added 'dog'", DoMergeWithOthers = false, // just want a fast checkin DoSendToOthers = false, // just want a fast checkin DoPullFromOthers = false // just want a fast checkin }; bobSetup.GetSynchronizer().SyncNow(bobOptions); //now Sally modifies the original file, not having seen Bob's changes yet var sallyPathToLift = Path.Combine(sallyProject.FolderPath, Path.Combine("lexicon", "foo.lift")); File.WriteAllText(sallyPathToLift, LiftFileStrings.lift12Cat); //Sally syncs, pulling in Bob's change, and encountering a need to merge (no conflicts) var sallyOptions = new SyncOptions { CheckinDescription = "adding cat", DoPullFromOthers = true, DoSendToOthers = true, DoMergeWithOthers = true }; sallyOptions.RepositorySourcesToTry.Add(RepositoryAddress.Create("bob's machine", bobSetup.BobProjectPath, false)); var synchronizer = Synchronizer.FromProjectConfiguration(sallyProject, progress); synchronizer.SyncNow(sallyOptions); //Debug.WriteLine("bob's: " + File.ReadAllText(bobSetup._pathToLift)); var contents = File.ReadAllText(sallyPathToLift); //Debug.WriteLine("sally's: " + contents); Assert.That(contents, Does.Contain("cat")); Assert.That(contents, Does.Contain("dog")); }
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); } }
private void Init(string userName) { ProjectConfiguration = new ProjectFolderConfiguration(ProjectFolder.Path); ProjectConfiguration.IncludePatterns.Add(UserFile.Path); ProjectConfiguration.FolderPath = ProjectFolder.Path; _repository = new HgRepository(ProjectFolder.Path, Progress); RepoPath = RepositoryAddress.Create(userName, ProjectFolder.Path, false); Synchronizer = Synchronizer.FromProjectConfiguration(ProjectConfiguration, Progress); Synchronizer.Repository.SetUserNameInIni(userName, Progress); }
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; }
public void SetTheOnlyAddressOfThisType_WasEmtpy_HasNewAddress() { using (new MercurialIniForTests()) using (var setup = new RepositorySetup("Dan")) { setup.EnsureNoHgrcExists(); var repository = setup.CreateSynchronizer().Repository; var y1 = RepositoryAddress.Create("aPath1", @"\\someone1\someFolder"); repository.SetTheOnlyAddressOfThisType(y1); Assert.AreEqual(1, repository.GetRepositoryPathsInHgrc().Count()); Assert.AreEqual(y1.URI, repository.GetRepositoryPathsInHgrc().ToArray()[0].URI); } }
public bool CreateBankClient(ModelAddress modelAddress, ModelClient modelClient, ModelAccounts modelAccounts) { int addressId = new RepositoryAddress().AddAddress(modelAddress); if (addressId > 0) { int clientId = new RepositoryClient().AddClient(modelClient, addressId); if (clientId > 0) { return(new RepositoryAccount().AddAccount(modelAccounts, clientId)); } } return(false); }
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 IHttpActionResult GetAddress(int?Id) { var response = new DataResponse <EntityPracticeAddress>(); var repository = new RepositoryAddress(); if (CurrentBusinessId.HasValue) { response = repository.GetAddressById(Id.Value); } else { response.Model = new EntityPracticeAddress(); } return(Ok <DataResponse>(response)); }
public void LaunchDialog_BogusTarget_AdmitsError() { using (var setup = new RepositorySetup("pedro")) { Application.EnableVisualStyles(); using (var dlg = new SyncDialog(setup.ProjectFolderConfig, SyncUIDialogBehaviors.StartImmediatelyAndCloseWhenFinished, SyncUIFeatures.Minimal)) { dlg.SyncOptions.RepositorySourcesToTry.Add(RepositoryAddress.Create("bogus", @"z:/")); dlg.ShowDialog(); Assert.That(dlg.FinalStatus.WarningEncountered, Is.True); } } }
public void SetTheOnlyAddressOfThisType_HadAnotherType_HasOldAddressAndNew() { using (new MercurialIniForTests()) using (var setup = new RepositorySetup("Dan")) { setup.EnsureNoHgrcExists(); var repository = setup.CreateSynchronizer().Repository; var x = RepositoryAddress.Create("theInterent", @"http://two.org"); repository.SetKnownRepositoryAddresses(new List <RepositoryAddress>(new RepositoryAddress[] { x })); var y2 = RepositoryAddress.Create("aPath2", @"\\someoneElse2\someOtherFolder"); repository.SetTheOnlyAddressOfThisType(y2); Assert.AreEqual(2, repository.GetRepositoryPathsInHgrc().Count()); AssertHgrcNowContainsUri(repository, x.URI); AssertHgrcNowContainsUri(repository, y2.URI); } }
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); }
public void SetTheOnlyAddressOfThisType_SettingLANPathHadSameType_IsReplacedByNew() { using (new MercurialIniForTests()) using (var setup = new RepositorySetup("Dan")) { setup.EnsureNoHgrcExists(); var repository = setup.CreateSynchronizer().Repository; var x = RepositoryAddress.Create("theInterent", @"http://two.org"); var y1 = RepositoryAddress.Create("aPath1", @"\\someone1\someFolder"); repository.SetKnownRepositoryAddresses(new List <RepositoryAddress>(new RepositoryAddress[] { x, y1 })); Assert.AreEqual(y1.URI, repository.GetRepositoryPathsInHgrc().ToArray()[1].URI, "Test setup is wrong"); var y2 = RepositoryAddress.Create("aPath2", @"\\someoneElse2\someOtherFolder"); repository.SetTheOnlyAddressOfThisType(y2); Assert.AreEqual(2, repository.GetRepositoryPathsInHgrc().Count()); AssertHgrcNowContainsUri(repository, x.URI); AssertHgrcNowContainsUri(repository, y2.URI); } }
public void SetTheOnlyAddressOfThisType_SettingInternetPathHadSameType_IsReplacedByNew() { using (new MercurialIniForTests()) using (var setup = new RepositorySetup("Dan")) { setup.EnsureNoHgrcExists(); var repository = setup.CreateSynchronizer().Repository; var x1 = RepositoryAddress.Create("interent1", @"http://one.org"); var y = RepositoryAddress.Create("aPath", @"\\someone1\someFolder"); repository.SetKnownRepositoryAddresses(new List <RepositoryAddress>(new RepositoryAddress[] { x1, y })); Assert.AreEqual(x1.URI, repository.GetRepositoryPathsInHgrc().ToArray()[0].URI, "Test setup is wrong"); var x2 = RepositoryAddress.Create("internet2", @"http://two.org"); repository.SetTheOnlyAddressOfThisType(x2); Assert.AreEqual(2, repository.GetRepositoryPathsInHgrc().Count()); AssertHgrcNowContainsUri(repository, y.URI); AssertHgrcNowContainsUri(repository, x2.URI); } }
public void Sync_Cancelled_ResultsHaveCancelledEqualsTrue() { _model = new SyncControlModel(_project, SyncUIFeatures.Minimal, null); _model.SyncOptions.RepositorySourcesToTry.Add(RepositoryAddress.Create("languageforge", "https://hg-public.languageforge.org/dummy")); var progress = new ConsoleProgress(); _model.AddMessagesDisplay(progress); SyncResults results = null; _model.SynchronizeOver += (sender, e) => results = sender as SyncResults; _model.Sync(true); Thread.Sleep(100); _model.Cancel(); // NOTE: we can't use AutoResetEvent with Sync() - for some reason this doesn't work WaitForSyncToFinish(ref results); Assert.That(results.Succeeded, Is.False); Assert.That(results.Cancelled, Is.True); Assert.That(results.ErrorEncountered, Is.Null); }
public void LaunchDialog_ExampleForBob() { using (var setup = new RepositorySetup("pedro")) { Application.EnableVisualStyles(); setup.Repository.SetKnownRepositoryAddresses(new RepositoryAddress[] { RepositoryAddress.Create("language forge", "https://*****:*****@hg-public.languageforge.org"), }); setup.Repository.SetDefaultSyncRepositoryAliases(new[] { "language forge" }); using (var dlg = new SyncDialog(setup.ProjectFolderConfig, SyncUIDialogBehaviors.StartImmediatelyAndCloseWhenFinished, SyncUIFeatures.Minimal)) { dlg.ShowDialog(); } } }
public void LaunchDialog_GoodForCancelTesting() { using (var setup = new RepositorySetup("pedro")) { Application.EnableVisualStyles(); setup.Repository.SetKnownRepositoryAddresses(new RepositoryAddress[] { RepositoryAddress.Create("language forge", "https://*****:*****@hg-public.languageforge.org/tpi"), }); setup.Repository.SetDefaultSyncRepositoryAliases(new[] { "language forge" }); using (var dlg = new SyncDialog(setup.ProjectFolderConfig, SyncUIDialogBehaviors.StartImmediately, SyncUIFeatures.NormalRecommended)) { dlg.ShowDialog(); } } }
public void Sync_NonExistentLangForgeProject_ExitsGracefullyWithCorrectErrorResult() { _model = new SyncControlModel(_project, SyncUIFeatures.Minimal, null); _model.SyncOptions.RepositorySourcesToTry.Add(RepositoryAddress.Create("languageforge", "https://hg-public.languageforge.org/dummy")); var progress = new ConsoleProgress() { ShowVerbose = true }; _model.AddMessagesDisplay(progress); SyncResults results = null; _model.SynchronizeOver += (sender, e) => results = sender as SyncResults; _model.Sync(true); // NOTE: we can't use AutoResetEvent with Sync() - for some reason this doesn't work WaitForSyncToFinish(ref results); Assert.That(results.Succeeded, Is.False); Assert.That(results.ErrorEncountered, Is.Not.Null); }
public void SetAndGetDefaultSyncRepositories() { using (new MercurialIniForTests()) using (var setup = new RepositorySetup("Dan")) { setup.EnsureNoHgrcExists(); var repository = setup.CreateSynchronizer().Repository; var x = RepositoryAddress.Create("one", @"c:\one"); var y = RepositoryAddress.Create("two", @"http://two.org"); var z = RepositoryAddress.Create("three", @"http://three.org"); repository.SetKnownRepositoryAddresses(new List <RepositoryAddress>(new RepositoryAddress[] { x, y, z })); repository.SetDefaultSyncRepositoryAliases(new string[] { "one", "three" }); Assert.AreEqual(2, repository.GetDefaultSyncAliases().Count()); repository.SetDefaultSyncRepositoryAliases(new string[] { "two" }); Assert.AreEqual(1, repository.GetDefaultSyncAliases().Count()); } }