Ejemplo n.º 1
0
 public RepositorySetup(string userName, string projectfolder)
 {
     Progress      = new NullProgress();
     ProjectFolder = new TemporaryFolder(projectfolder + "-" + Guid.NewGuid());
     MakeRepositoryForTest(ProjectFolder.Path, userName, Progress);
     ProjectFolderConfig = new ProjectFolderConfiguration(ProjectFolder.Path);
 }
Ejemplo n.º 2
0
        public void Setup()
        {
            _progress       = new ConsoleProgress();
            _pathToTestRoot = Path.Combine(Path.GetTempPath(), "ChorusTest");
            if (Directory.Exists(_pathToTestRoot))
            {
                Directory.Delete(_pathToTestRoot, true);
            }
            Directory.CreateDirectory(_pathToTestRoot);

            //nb: the ".2" here is significant; there was an issue where anything after a "." got stripped
            _pathToProjectRoot = Path.Combine(_pathToTestRoot, "foo project.2");
            Directory.CreateDirectory(_pathToProjectRoot);

            string pathToText = WriteTestFile("version one");

            RepositorySetup.MakeRepositoryForTest(_pathToProjectRoot, "bob", _progress);
            _project = new ProjectFolderConfiguration(_pathToProjectRoot);
            _project.IncludePatterns.Add(pathToText);
            _project.FolderPath = _pathToProjectRoot;


            _synchronizer       = Synchronizer.FromProjectConfiguration(_project, _progress);
            _pathToBackupFolder = Path.Combine(_pathToTestRoot, "backup");
            Directory.CreateDirectory(_pathToBackupFolder);
            _directorySource = new DirectoryRepositorySource("SD Backup Card", Path.Combine(_pathToBackupFolder, RepositoryAddress.ProjectNameVariable), false);
        }
Ejemplo n.º 3
0
        public void Setup()
        {
            _progress       = new StringBuilderProgress();
            _pathToTestRoot = Path.Combine(Path.GetTempPath(), "ChorusHistoryPaneTest");             // Don't use 'standard' ChorusTest, since it will fial, if the tests are run in seperate processes (R# 6).
            if (Directory.Exists(_pathToTestRoot))
            {
                Directory.Delete(_pathToTestRoot, true);
            }
            Directory.CreateDirectory(_pathToTestRoot);

            string pathToText = WriteTestFile("version one of my pretend txt");

            RepositorySetup.MakeRepositoryForTest(_pathToTestRoot, "bob", _progress);

            _project            = new ProjectFolderConfiguration(_pathToTestRoot);
            _project.FolderPath = _pathToTestRoot;
            _project.IncludePatterns.Add(pathToText);
            _project.FolderPath = _pathToTestRoot;

            var revisionListOptions = new RevisionListOptions();

            revisionListOptions.RevisionsToShowFilter = ShowRevisionPredicate;

            _model = new RevisionInRepositoryModel(HgRepository.CreateOrUseExisting(_project.FolderPath, new NullProgress()),
                                                   null,
                                                   revisionListOptions);
            _model.ProgressDisplay = _progress;
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
            public Synchronizer GetSynchronizer()
            {
                ProjectFolderConfiguration project = CreateFolderConfig(_languageProjectPath);
                Synchronizer repo = Synchronizer.FromProjectConfiguration(project, _progress);

                repo.Repository.SetUserNameInIni("bob", _progress);
                return(repo);
            }
Ejemplo n.º 6
0
            public static ProjectFolderConfiguration CreateFolderConfig(string baseDir)
            {
                var config = new ProjectFolderConfiguration(baseDir);

                config.ExcludePatterns.Add(Path.Combine("**", "cache"));
                config.IncludePatterns.Add("**.abc");
                config.IncludePatterns.Add("**.lift");
                return(config);
            }
Ejemplo n.º 7
0
        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"));
        }
Ejemplo n.º 8
0
        public ChorusControl(ILogger logger, Chorus.sync.ProjectFolderConfiguration projectFolderConfiguration)
            : base("set up synchronization with team members", logger, "chorus")
        {
            _projectFolderConfiguration = projectFolderConfiguration;
            this.Font = SystemFonts.MessageBoxFont;            //use the default OS UI font
            InitializeComponent();

            readinessPanel1.ProjectFolderPath = projectFolderConfiguration.FolderPath;
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        public void MinimalCodeToLaunchSendReceiveUI()
        {
            var projectConfig = new ProjectFolderConfiguration("c:\\TokPisin");

            projectConfig.IncludePatterns.Add("*.lift");

            using (var dlg = new SyncDialog(projectConfig,
                                            SyncUIDialogBehaviors.Lazy,
                                            SyncUIFeatures.NormalRecommended))
            {
                dlg.ShowDialog();
            }
        }
Ejemplo n.º 11
0
        public static void AddFileInfoToFolderConfiguration(ProjectFolderConfiguration config)
        {
            config.ExcludePatterns.Add("**.back");
            config.ExcludePatterns.Add("**.js");
            config.ExcludePatterns.Add("**.bak");
            ProjectFolderConfiguration.AddExcludedVideoExtensions(config);             // For now at least.

            config.IncludePatterns.Add("**.html");
            config.IncludePatterns.Add("**.htm");
            config.IncludePatterns.Add("**.png");
            config.IncludePatterns.Add("**.jpg");
            config.IncludePatterns.Add("**.css");
            config.IncludePatterns.Add("**.txt");
            config.IncludePatterns.Add("*.bloomCollection");
        }
Ejemplo n.º 12
0
        public RepositorySetup(string cloneName, RepositorySetup sourceToClone)
        {
            Init(cloneName);
            string pathToProject = RootFolder.Combine(ProjectNameForTest);

            ProjectFolderConfig            = sourceToClone.ProjectFolderConfig.Clone();
            ProjectFolderConfig.FolderPath = pathToProject;

            sourceToClone.MakeClone(pathToProject);
            ProjectFolder = TemporaryFolder.TrackExisting(RootFolder.Combine(ProjectNameForTest));

            var hg = new HgRepository(pathToProject, Progress);

            hg.SetUserNameInIni(cloneName, Progress);
        }
Ejemplo n.º 13
0
        public delegate SyncDialog Factory(SyncUIDialogBehaviors behavior, SyncUIFeatures uiFeatureFlags);        //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;
            }
        }
Ejemplo n.º 14
0
        public RepositorySetup(string userName, bool makeRepository)
        {
            Init(userName);

            ProjectFolder = new TemporaryFolder(RootFolder, ProjectName);

            if (makeRepository)
            {
                RepositorySetup.MakeRepositoryForTest(ProjectFolder.Path, userName, Progress);
            }
            else
            {
                // Remove the folder to make way for a clone which requires the folder to be not present.
                Directory.Delete(ProjectFolder.Path);
            }
            ProjectFolderConfig = new ProjectFolderConfiguration(ProjectFolder.Path);
        }
Ejemplo n.º 15
0
        public static void AddLiftFileInfoToFolderConfiguration(ProjectFolderConfiguration config)
        {
            config.ExcludePatterns.Add(Path.Combine("**", "cache"));
            config.ExcludePatterns.Add(Path.Combine("**", "Cache"));
            config.ExcludePatterns.Add("autoFonts.css");
            config.ExcludePatterns.Add("autoLayout.css");
            config.ExcludePatterns.Add("defaultDictionary.css");
            config.ExcludePatterns.Add("*.old");
            config.ExcludePatterns.Add("*.WeSayUserMemory");
            config.ExcludePatterns.Add("*.tmp");
            config.ExcludePatterns.Add("*.bak");
            config.ExcludePatterns.Add("**.log");
            config.ExcludePatterns.Add("*-ImportLog.htm");
            config.ExcludePatterns.Add(Path.Combine("export", "*.lift"));
            config.ExcludePatterns.Add(Path.Combine("export", "*.plift"));
            config.ExcludePatterns.Add(Path.Combine("export", "*.pdf"));
            config.ExcludePatterns.Add(Path.Combine("export", "*.html"));
            config.ExcludePatterns.Add(Path.Combine("export", "*.odt"));
            config.ExcludePatterns.Add(Path.Combine("export", "*.xml"));
            config.ExcludePatterns.Add("*.ldml");                          // Supposed to be in 'WritingSystems' folder now.
            config.ExcludePatterns.Add("*.orig");                          // Lift Bridge creates this backup, which ought to be excluded.

            ProjectFolderConfiguration.AddExcludedVideoExtensions(config); // For now at least.

            config.IncludePatterns.Add("*.lift");
            config.IncludePatterns.Add("*.lift-ranges");
            config.IncludePatterns.Add(Path.Combine("audio", "**.*"));            // Including nested folders/files
            config.IncludePatterns.Add(Path.Combine("pictures", "**.*"));         // Including nested folders/files
            config.IncludePatterns.Add(Path.Combine("others", "**.*"));           // Including nested folders/files
            config.IncludePatterns.Add(Path.Combine("SharedSettings", "*.ulsx")); // Including user lexion settings
            config.IncludePatterns.Add(Path.Combine("SharedSettings", "*.plsx")); // Including project lexicon settings
            config.IncludePatterns.Add(Path.Combine("WritingSystems", "*.ldml"));
            config.IncludePatterns.Add("**.xml");                                 //hopefully the days of files ending in "xml" are numbered
            config.IncludePatterns.Add(".hgIgnore");

            config.IncludePatterns.Add(Path.Combine("export", "*.lpconfig"));            //lexique pro
            config.IncludePatterns.Add(Path.Combine("export", "custom*.css"));           //stylesheets
            config.IncludePatterns.Add(Path.Combine("export", "multigraphs.txt"));       //list of multigraphs

            //review (jh,jh): should these only be added when WeSay is the client?  Dunno.
            config.IncludePatterns.Add("**.WeSayConfig");
            config.IncludePatterns.Add("**.WeSayUserConfig");
        }
Ejemplo n.º 16
0
        public void Setup()
        {
            _progress       = new ConsoleProgress();
            _pathToTestRoot = Path.Combine(Path.GetTempPath(), "ChorusUsbRepositorySourceTests");
            Directory.CreateDirectory(_pathToTestRoot);

            _pathToProjectRoot = Path.Combine(_pathToTestRoot, "foo project");
            Directory.CreateDirectory(_pathToProjectRoot);

            string pathToText = WriteTestFile("version one");

            RepositorySetup.MakeRepositoryForTest(_pathToProjectRoot, "bob", _progress);
            _project = new ProjectFolderConfiguration(_pathToProjectRoot);
            _project.IncludePatterns.Add(pathToText);
            _project.FolderPath = _pathToProjectRoot;


            UsbKeyRepositorySource.SetRootDirForAllSourcesDuringUnitTest(_pathToTestRoot);
        }
Ejemplo n.º 17
0
        public void Setup()
        {
            _progress       = new StringBuilderProgress();
            _pathToTestRoot = Path.Combine(Path.GetTempPath(), "ChorusTest");
            Directory.CreateDirectory(_pathToTestRoot);


            _pathToText = Path.Combine(_pathToTestRoot, "foo.txt");
            File.WriteAllText(_pathToText, "version one of my pretend txt");

            RepositorySetup.MakeRepositoryForTest(_pathToTestRoot, "bob", _progress);

            _project            = new ProjectFolderConfiguration(_pathToTestRoot);
            _project.FolderPath = _pathToTestRoot;
            _project.IncludePatterns.Add(_pathToText);
            _project.FolderPath = _pathToTestRoot;

            _repository = new HgRepository(_project.FolderPath, _progress);
        }
Ejemplo n.º 18
0
        public void Setup()
        {
            _progress = new StringBuilderProgress();
            _pathToTestRoot = Path.Combine(Path.GetTempPath(), "ChorusTest");
            Directory.CreateDirectory(_pathToTestRoot);

            string pathToText = Path.Combine(_pathToTestRoot, "foo.txt");
            File.WriteAllText(pathToText, "version one of my pretend txt");

            RepositorySetup.MakeRepositoryForTest(_pathToTestRoot, "bob",_progress);

            _project = new ProjectFolderConfiguration(_pathToTestRoot);
            _project.FolderPath = _pathToTestRoot;
            _project.IncludePatterns.Add(pathToText);
            _project.FolderPath = _pathToTestRoot;

            _synchronizer = Synchronizer.FromProjectConfiguration(_project, new NullProgress());
            _model = new SyncControlModel(_project, SyncUIFeatures.Advanced,null);
            _model.AddMessagesDisplay(_progress);
        }
Ejemplo n.º 19
0
            public BobSetup(ConsoleProgress progress, string pathToTestRoot)
            {
                _progress     = progress;
                BobSourcePath = Path.Combine(pathToTestRoot, "Bob");
                Directory.CreateDirectory(BobSourcePath);
                string languageProjectPath = Path.Combine(BobSourcePath, ProjectFolderName);

                Directory.CreateDirectory(languageProjectPath);
                _languageProjectPath = languageProjectPath;
                _lexiconProjectPath  = Path.Combine(_languageProjectPath, "lexicon");
                Directory.CreateDirectory(_lexiconProjectPath);

                PathToText = Path.Combine(_lexiconProjectPath, "foo.abc");
                File.WriteAllText(PathToText, "version one of my pretend txt");

                _pathToLift = Path.Combine(_lexiconProjectPath, "foo.lift");
                File.WriteAllText(_pathToLift, "<lift version='0.12'></lift>");

                string picturesPath = Path.Combine(_lexiconProjectPath, "pictures");

                Directory.CreateDirectory(picturesPath);
                File.WriteAllText(Path.Combine(picturesPath, "dog.jpg"), "Not really a picture");

                string cachePath = Path.Combine(_lexiconProjectPath, "cache");

                Directory.CreateDirectory(cachePath);
                File.WriteAllText(Path.Combine(cachePath, "cache.abc"), "Some cache stuff");

                _projectFolderConfiguration = CreateFolderConfig(languageProjectPath);

                SyncOptions options = new SyncOptions();

                options.DoPullFromOthers   = false;
                options.DoMergeWithOthers  = false;
                options.CheckinDescription = "Added";

                RepositorySetup.MakeRepositoryForTest(languageProjectPath, "bob", _progress);

                SyncResults results = GetSynchronizer().SyncNow(options);
            }
Ejemplo n.º 20
0
        public SyncControlModel(ProjectFolderConfiguration projectFolderConfiguration,
                                SyncUIFeatures uiFeatureFlags,
                                IChorusUser user)
        {
            _user          = user;
            _progress      = new MultiProgress();
            StatusProgress = new SimpleStatusProgress();
            _progress.Add(StatusProgress);
            Features          = uiFeatureFlags;
            _synchronizer     = Synchronizer.FromProjectConfiguration(projectFolderConfiguration, _progress);
            _backgroundWorker = new BackgroundWorker();
            _backgroundWorker.WorkerSupportsCancellation = true;
            _backgroundWorker.RunWorkerCompleted        += new RunWorkerCompletedEventHandler(_backgroundWorker_RunWorkerCompleted);
            _backgroundWorker.DoWork += worker_DoWork;

            //clients will normally change these
            SyncOptions = new SyncOptions();
            SyncOptions.CheckinDescription = "[" + Application.ProductName + ": " + Application.ProductVersion + "] sync";
            SyncOptions.DoPullFromOthers   = true;
            SyncOptions.DoMergeWithOthers  = true;
            SyncOptions.RepositorySourcesToTry.AddRange(GetRepositoriesToList().Where(r => r.Enabled));
        }
Ejemplo n.º 21
0
        public static void TestThatALargeFileIsNotInRepository(string extension)
        {
            var pathToTestRoot = Path.Combine(Path.GetTempPath(), "LargeFileFilterTestFolder_" + extension + "_" + Guid.NewGuid());

            try
            {
                if (Directory.Exists(pathToTestRoot))
                {
                    Thread.Sleep(2000);
                    Directory.Delete(pathToTestRoot, true);
                }
                Directory.CreateDirectory(pathToTestRoot);

                var allHandlers = ChorusFileTypeHandlerCollection.CreateWithInstalledHandlers().Handlers.ToList();
                allHandlers.Add(new ChorusTestFileHandler());
                var handlerForExtension = allHandlers.FirstOrDefault(handler => handler.GetExtensionsOfKnownTextFileTypes().Contains(extension.ToLowerInvariant()))
                                          ?? new DefaultFileTypeHandler();

                var goodFileName = "smallfry." + extension;
                var goodPathname = Path.Combine(pathToTestRoot, goodFileName);
                var goodFile     = TempFile.WithFilename(goodPathname);
                File.WriteAllText(goodFile.Path, "Nice, short text.");

                var whopperFileName = "whopper." + extension;
                var whopperPathname = Path.Combine(pathToTestRoot, whopperFileName);
                var whopperFile     = TempFile.WithFilename(whopperPathname);
                var whopperData     = "whopperdata ";
                while (whopperData.Length < handlerForExtension.MaximumFileSize)
                {
                    whopperData += whopperData;
                }
                File.WriteAllText(whopperFile.Path, whopperData);

                var progress = new NullProgress();
                var projectFolderConfiguration = new ProjectFolderConfiguration(pathToTestRoot);
                projectFolderConfiguration.IncludePatterns.Clear();
                projectFolderConfiguration.ExcludePatterns.Clear();
                projectFolderConfiguration.IncludePatterns.Add("*.*");
                RepositorySetup.MakeRepositoryForTest(pathToTestRoot, "Pesky", progress);
                var synchronizer = Synchronizer.FromProjectConfiguration(projectFolderConfiguration, progress);
                synchronizer.Repository.SetUserNameInIni("Pesky", progress);
                var syncOptions = new SyncOptions
                {
                    // Basic commit. Nothing fancy.
                    DoPullFromOthers   = false,
                    DoMergeWithOthers  = false,
                    DoSendToOthers     = false,
                    CheckinDescription = "Added"
                };

                var syncResults = synchronizer.SyncNow(syncOptions);
                Assert.IsTrue(syncResults.Succeeded);

                projectFolderConfiguration.ExcludePatterns.Remove(ProjectFolderConfiguration.BareFolderReadmeFileName);
                Assert.AreEqual(2, projectFolderConfiguration.ExcludePatterns.Count);
                Assert.IsTrue(projectFolderConfiguration.ExcludePatterns[0].Contains(whopperFileName));

                var repo = new HgRepository(pathToTestRoot, progress);
                Assert.IsTrue(repo.GetFileExistsInRepo(goodFileName), goodFileName);
                Assert.IsFalse(repo.GetFileExistsInRepo(whopperFileName), whopperFileName);
            }
            finally
            {
                if (Directory.Exists(pathToTestRoot))
                {
                    Thread.Sleep(2000);
                    Directory.Delete(pathToTestRoot, true);
                }
            }
        }
Ejemplo n.º 22
0
        public void CanShareConflictingChangeViaUsb()
        {
            ConsoleProgress progress = new ConsoleProgress();
            BobSetup        bobSetup = new BobSetup(progress, _pathToTestRoot);

            bobSetup.ChangeTextFile();
            string usbSourcePath = Path.Combine(_pathToTestRoot, "USB-A");

            Directory.CreateDirectory(usbSourcePath);
            string       usbProjectPath = bobSetup.SetupClone(usbSourcePath);
            Synchronizer usbRepo        = Synchronizer.FromProjectConfiguration(BobSetup.CreateFolderConfig(usbProjectPath), progress);

            Synchronizer bobSynchronizer = bobSetup.GetSynchronizer();

            //Sally gets the usb and uses it to clone herself a repository
            string sallySourcePath = Path.Combine(_pathToTestRoot, "sally");

            Directory.CreateDirectory(sallySourcePath);
            //string sallyRepoPath = usbRepo.MakeClone(Path.Combine(sallySourcePath, BobSetup.ProjectFolderName), true);
            string sallyRepoPath = HgHighLevel.MakeCloneFromUsbToLocal(usbRepo.Repository.PathToRepo, Path.Combine(sallySourcePath, BobSetup.ProjectFolderName), progress);


            //Now bob sets up the conflict

            File.WriteAllText(bobSetup.PathToText, "Bob's new idea");
            SyncOptions bobOptions = new SyncOptions();

            bobOptions.CheckinDescription = "changed my mind";
            bobOptions.DoMergeWithOthers  = false;           // pretend the usb key isn't there
            bobOptions.DoPullFromOthers   = false;           // pretend the usb key isn't there
            bobOptions.DoSendToOthers     = false;
            RepositoryAddress usbPath = RepositoryAddress.Create("usba source", Path.Combine(usbSourcePath, RepositoryAddress.ProjectNameVariable), false);

            bobOptions.RepositorySourcesToTry.Add(usbPath);
            bobSynchronizer.SyncNow(bobOptions);

            ProjectFolderConfiguration sallyProject = BobSetup.CreateFolderConfig(sallyRepoPath);

            Synchronizer sallySynchronizer = Synchronizer.FromProjectConfiguration(sallyProject, progress);

            sallySynchronizer.Repository.SetUserNameInIni("sally", new NullProgress());

            //now she modifies a file
            File.WriteAllText(Path.Combine(sallyRepoPath, Path.Combine("lexicon", "foo.abc")), "Sally was here");

            //and syncs, which pushes back to the usb key
            SyncOptions sallyOptions = new SyncOptions();

            sallyOptions.CheckinDescription = "making sally's mark on foo.abc";
            sallyOptions.RepositorySourcesToTry.Add(usbPath);
            sallyOptions.DoPullFromOthers  = true;
            sallyOptions.DoMergeWithOthers = true;
            sallyOptions.DoSendToOthers    = true;
            sallySynchronizer.SyncNow(sallyOptions);

            //bob still doesn't have direct access to sally's repo... it's in some other city
            // but now the usb comes back to him
            // SyncOptions bobOptions = new SyncOptions();
            bobOptions.CheckinDescription = "Getting from sally, i hope";
            bobOptions.DoPullFromOthers   = true;
            bobOptions.DoSendToOthers     = true;
            bobOptions.DoMergeWithOthers  = true;
            bobSynchronizer.SyncNow(bobOptions);

            // With sync set as 'WeWin'
            Assert.AreEqual("Bob's new idea", File.ReadAllText(bobSetup.PathToText));
            var notesPath = Path.Combine(Path.Combine(Path.Combine(usbSourcePath, BobSetup.ProjectFolderName), "lexicon"), "foo.abc.ChorusNotes");

            AssertThatXmlIn.File(notesPath).HasSpecifiedNumberOfMatchesForXpath("//notes/annotation[@class='mergeConflict']", 1);

            //The conflict has now been created, in the merge with Bob, make a new conflict and make sure that when Sally does the next sync both conflicts are
            //present in the ChorusNotes.
            File.WriteAllText(Path.Combine(sallyRepoPath, Path.Combine("lexicon", "foo.abc")), "Sally changed her mind");
            File.WriteAllText(bobSetup.PathToText, "Bob changed his mind.");
            bobOptions.CheckinDescription = "Bob makes conflicting change.";
            bobSynchronizer.SyncNow(bobOptions);
            sallyOptions.CheckinDescription = "Sally makes conflicting change.";
            sallySynchronizer.SyncNow(sallyOptions);
            AssertThatXmlIn.File(notesPath).HasSpecifiedNumberOfMatchesForXpath("//notes/annotation[@class='mergeConflict']", 2);
        }
Ejemplo n.º 23
0
        public void TestNewVersion_SallyAndBobUpgradeButFredDelays()
        {
            ConsoleProgress progress = new ConsoleProgress();
            BobSetup        bobSetup = new BobSetup(progress, _pathToTestRoot);

            // clone Bob onto Sally
            string sallyMachineRoot = Path.Combine(_pathToTestRoot, "sally");

            Directory.CreateDirectory(sallyMachineRoot);
            string sallyProjectRoot = bobSetup.SetupClone(sallyMachineRoot);
            ProjectFolderConfiguration sallyProject = new ProjectFolderConfiguration(sallyProjectRoot);

            sallyProject.IncludePatterns.Add("**.abc");
            sallyProject.IncludePatterns.Add("**.lift");

            // clone Bob onto Fred
            string fredMachineRoot = Path.Combine(_pathToTestRoot, "fred");

            Directory.CreateDirectory(fredMachineRoot);
            string fredProjectRoot = bobSetup.SetupClone(fredMachineRoot);
            ProjectFolderConfiguration fredProject = new ProjectFolderConfiguration(fredProjectRoot);

            fredProject.IncludePatterns.Add("**.abc");
            fredProject.IncludePatterns.Add("**.lift");

            // Setup Sally and Fred repositories
            var sallyRepository = HgRepository.CreateOrUseExisting(sallyProject.FolderPath, progress);

            sallyRepository.SetUserNameInIni("sally", progress);
            var fredRepository = HgRepository.CreateOrUseExisting(fredProject.FolderPath, progress);

            fredRepository.SetUserNameInIni("fred", progress);
            var sallyRepoAddress = RepositoryAddress.Create("sally's machine", sallyProjectRoot, false);
            var fredRepoAddress  = RepositoryAddress.Create("fred's machine", fredProjectRoot, false);
            var bobRepoAddress   = RepositoryAddress.Create("bob's machine", bobSetup.BobProjectPath, false);

            // bob makes a change and syncs to everybody
            File.WriteAllText(bobSetup._pathToLift, LiftFileStrings.lift12Dog);
            var bobOptions = GetFullSyncOptions("added 'dog'");

            bobOptions.RepositorySourcesToTry.Add(sallyRepoAddress);
            bobOptions.RepositorySourcesToTry.Add(fredRepoAddress);

            var bobSyncer = bobSetup.GetSynchronizer();

            bobSyncer.SyncNow(bobOptions);             // Bob syncs with everybody on 'default' branch

            // Verification Step 1
            var sallyPathToLift = Path.Combine(sallyProject.FolderPath, "lexicon/foo.lift");
            var fredPathToLift  = Path.Combine(fredProject.FolderPath, "lexicon/foo.lift");
            var sallyContents   = File.ReadAllText(sallyPathToLift);

            Assert.That(sallyContents, Does.Contain("dog"), "'dog' should be in Sally repo.");
            var fredContents = File.ReadAllText(fredPathToLift);

            Assert.That(fredContents, Does.Contain("dog"), "'dog' should be in Fred repo.");

            // bob makes another change and syncs to new version
            File.WriteAllText(bobSetup._pathToLift, LiftFileStrings.lift13DogCat);
            var newBobOptions = GetFullSyncOptions("added 'cat'");

            newBobOptions.DoMergeWithOthers = false;          // just want a fast checkin
            newBobOptions.DoPullFromOthers  = false;          // just want a fast checkin
            newBobOptions.DoSendToOthers    = false;          // just want a fast checkin
            const string lift13version = "LIFT0.13";

            SetAdjunctModelVersion(bobSyncer, lift13version);             // Bob is now on the new version of LIFT
            bobSyncer.SyncNow(newBobOptions);

            // now Fred modifies default branch to add 'ant'
            File.WriteAllText(fredPathToLift, LiftFileStrings.lift12DogAnt);
            var fredOptions = GetFullSyncOptions("added 'ant'");

            fredOptions.RepositorySourcesToTry.Add(bobRepoAddress);
            fredOptions.RepositorySourcesToTry.Add(sallyRepoAddress);
            var fredSyncer = Synchronizer.FromProjectConfiguration(fredProject, progress);

            fredSyncer.SyncNow(fredOptions);

            // Verification Step 2
            fredContents = File.ReadAllText(fredPathToLift);
            Assert.That(fredContents, Does.Not.Contain("cat"), "'cat' should only be on Bob's branch.");
            Assert.That(fredContents, Does.Contain("ant"));
            sallyContents = File.ReadAllText(sallyPathToLift);
            Assert.That(sallyContents, Does.Contain("ant"), "'ant' was propogated to Sally's branch.");
            Assert.That(sallyContents, Does.Not.Contain("cat"), "'cat' should only be on Bob's branch.");
            var bobContents = File.ReadAllText(bobSetup._pathToLift);

            Assert.That(bobContents, Does.Not.Contain("ant"), "'ant' is only on 'default' branch.");
            // Verify Bob is on the latest branch
            string dummy;
            var    result = bobSyncer.Repository.BranchingHelper.IsLatestBranchDifferent(lift13version, out dummy);

            Assert.That(result, Is.False, "Bob should be on the new LIFT0.13 branch.");
            // And Fred isn't
            result = fredSyncer.Repository.BranchingHelper.IsLatestBranchDifferent(lift13version, out dummy);
            Assert.That(result, Is.True, "Fred should still be on the 'default' branch.");

            // Now Sally modifies the file, not having seen Bob's changes yet, but having seen Fred's changes.
            // She adds 'herring' and has upgraded to Bob's version of LIFT
            File.WriteAllText(sallyPathToLift, LiftFileStrings.lift13DogAntHerring);

            //Sally syncs, pulling in Bob's 1st change, and encountering a need to merge (no conflicts)
            var sallyOptions = GetFullSyncOptions("adding 'herring'");

            sallyOptions.RepositorySourcesToTry.Add(bobRepoAddress);
            sallyOptions.RepositorySourcesToTry.Add(fredRepoAddress);             // Why not? Even though he's still on 'default' branch

            var sallySyncer = Synchronizer.FromProjectConfiguration(sallyProject, progress);

            SetAdjunctModelVersion(sallySyncer, lift13version);             // Sally is now on the Bob's later version
            // Below is the line with the hg error
            sallySyncer.SyncNow(sallyOptions);

            // Verification Step 3
            bobContents = File.ReadAllText(bobSetup._pathToLift);
            Assert.That(bobContents, Does.Contain("herring"), "'herring' should be pulled in from Sally's branch.");
            Assert.That(bobContents, Does.Contain("ant"), "'ant' should be pulled in from Sally's branch.");
            sallyContents = File.ReadAllText(sallyPathToLift);
            Assert.That(sallyContents, Does.Contain("cat"), "'cat' should be pulled in from Bob's branch.");
            Assert.That(sallyContents, Does.Contain("dog"), "Everybody should have 'dog' from before.");
            fredContents = File.ReadAllText(fredPathToLift);
            Assert.That(fredContents, Does.Not.Contain("herring"), "The red herring is only in the new version for now.");
            Assert.That(fredContents, Does.Not.Contain("cat"), "'cat' is only in the new version for now.");
            // Verify Sally is now on the latest branch
            result = sallySyncer.Repository.BranchingHelper.IsLatestBranchDifferent(lift13version, out dummy);
            Assert.That(result, Is.False, "Sally should be on the new LIFT0.13 branch.");
            // And Fred still shouldn't be
            result = fredSyncer.Repository.BranchingHelper.IsLatestBranchDifferent(lift13version, out dummy);
            Assert.That(result, Is.True, "Fred should still be on the 'default' branch.");

            // Now Fred checks in 'pig' to the 'default' branch
            File.WriteAllText(fredPathToLift, LiftFileStrings.lift12DogAntPig);

            // Fred syncs, not finding anybody else's changes
            fredOptions.CheckinDescription = "adding 'pig'";
            fredSyncer.SyncNow(fredOptions);

            // Verification Step 4
            bobContents = File.ReadAllText(bobSetup._pathToLift);
            Assert.That(bobContents, Does.Not.Contain("pig"), "'pig' should only be on 'default' branch.");
            sallyContents = File.ReadAllText(sallyPathToLift);
            Assert.That(sallyContents, Does.Not.Contain("pig"), "'pig' should only be on 'default' branch.");
            fredContents = File.ReadAllText(fredPathToLift);
            Assert.That(fredContents, Does.Not.Contain("herring"), "'herring' should still only be in the new version.");
            // Just check Fred hasn't changed branches
            result = fredSyncer.Repository.BranchingHelper.IsLatestBranchDifferent(lift13version, out dummy);
            Assert.That(result, Is.True, "Fred should still be on the 'default' branch.");

            // Now Bob checks in 'deer' in the new version
            File.WriteAllText(bobSetup._pathToLift, LiftFileStrings.lift13DogCatHerringAntDeer);
            bobOptions.CheckinDescription = "adding 'deer'";
            bobSyncer.SyncNow(bobOptions);

            // Verification Step 5
            // Check that Fred hasn't changed
            fredContents = File.ReadAllText(fredPathToLift);
            Assert.That(fredContents, Does.Not.Contain("deer"), "'deer' should only be on new version.");
            result = fredSyncer.Repository.BranchingHelper.IsLatestBranchDifferent(lift13version, out dummy);
            Assert.That(result, Is.True, "Fred should still be on the 'default' branch.");
            // Check that Sally got her 'deer'
            sallyContents = File.ReadAllText(sallyPathToLift);
            Assert.That(sallyContents, Does.Contain("deer"), "'deer' should have propagated to Sally.");
            // Make sure that 'pig' hasn't migrated to the new version
            Assert.That(sallyContents, Does.Not.Contain("pig"), "'pig' should still only be on 'default' branch.");

            // Now Fred has finally upgraded and will check in 'fox' -- LAST CHECK-IN FOR THIS TEST!
            File.WriteAllText(fredPathToLift, LiftFileStrings.lift13DogAntPigFox);
            fredOptions.CheckinDescription = "adding 'fox'";
            SetAdjunctModelVersion(fredSyncer, lift13version);             // Fred finally updates to the new version (branch)
            fredSyncer.SyncNow(fredOptions);

            // Verification Step 6 (Last)
            bobContents = File.ReadAllText(bobSetup._pathToLift);
            Assert.That(bobContents, Does.Contain("cat"), "'cat' should survive the big hairy test in Bob's repo.");
            Assert.That(bobContents, Does.Contain("dog"), "'dog' should survive the big hairy test in Bob's repo.");
            Assert.That(bobContents, Does.Contain("pig"), "'pig' should survive the big hairy test in Bob's repo.");
            Assert.That(bobContents, Does.Contain("herring"), "'herring' should survive the big hairy test in Bob's repo.");
            Assert.That(bobContents, Does.Contain("deer"), "'deer' should survive the big hairy test in Bob's repo.");
            Assert.That(bobContents, Does.Contain("ant"), "'ant' should survive the big hairy test in Bob's repo.");
            Assert.That(bobContents, Does.Contain("fox"), "'fox' should survive the big hairy test in Bob's repo.");
            sallyContents = File.ReadAllText(sallyPathToLift);
            Assert.That(sallyContents, Does.Contain("cat"), "'cat' should survive the big hairy test in Sally's repo.");
            Assert.That(sallyContents, Does.Contain("dog"), "'dog' should survive the big hairy test in Sally's repo.");
            Assert.That(sallyContents, Does.Contain("herring"), "'herring' should survive the big hairy test in Sally's repo.");
            Assert.That(sallyContents, Does.Contain("pig"), "'pig' should survive the big hairy test in Sally's repo.");
            Assert.That(sallyContents, Does.Contain("deer"), "'deer' should survive the big hairy test in Sally's repo.");
            Assert.That(sallyContents, Does.Contain("ant"), "'ant' should survive the big hairy test in Sally's repo.");
            Assert.That(sallyContents, Does.Contain("fox"), "'fox' should survive the big hairy test in Sally's repo.");
            fredContents = File.ReadAllText(fredPathToLift);
            Assert.That(fredContents, Does.Contain("cat"), "'cat' should survive the big hairy test in Fred's repo.");
            Assert.That(fredContents, Does.Contain("dog"), "'dog' should survive the big hairy test in Fred's repo.");
            Assert.That(fredContents, Does.Contain("herring"), "'herring' should survive the big hairy test in Fred's repo.");
            Assert.That(fredContents, Does.Contain("pig"), "'pig' should survive the big hairy test in Fred's repo.");
            Assert.That(fredContents, Does.Contain("deer"), "'deer' should survive the big hairy test in Fred's repo.");
            Assert.That(fredContents, Does.Contain("ant"), "'ant' should survive the big hairy test in Fred's repo.");
            Assert.That(fredContents, Does.Contain("fox"), "'fox' should survive the big hairy test in Fred's repo.");

            // Verify Bob is on the latest branch
            result = bobSyncer.Repository.BranchingHelper.IsLatestBranchDifferent(lift13version, out dummy);
            Assert.That(result, Is.False, "Bob should be on the new LIFT0.13 branch.");

            // Verify Sally is on the right branch
            result = sallySyncer.Repository.BranchingHelper.IsLatestBranchDifferent(lift13version, out dummy);
            Assert.That(result, Is.False, "Sally should be on the new LIFT0.13 branch.");

            // Verify Fred is finally on the new branch
            result = fredSyncer.Repository.BranchingHelper.IsLatestBranchDifferent(lift13version, out dummy);
            Assert.That(result, Is.False, "Fred should finally be on the new LIFT0.13 branch.");
        }
Ejemplo n.º 24
0
        [Category("KnownMonoIssue")]         // Actually, it is an unknown mono issue.
        public void TestNewVersion_SallyUpgradesToBobVersion()
        {
            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 = new ProjectFolderConfiguration(sallyProjectRoot);

            sallyProject.IncludePatterns.Add("**.abc");
            sallyProject.IncludePatterns.Add("**.lift");

            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 = GetFullSyncOptions("added dog");

            bobOptions.DoMergeWithOthers = false;          // just want a fast checkin
            bobOptions.DoSendToOthers    = false;          // just want a fast checkin
            bobOptions.DoPullFromOthers  = false;          // just want a fast checkin

            var bobsyncer = bobSetup.GetSynchronizer();

            SetAdjunctModelVersion(bobsyncer, "LIFT0.12");             // Bob is still on an older branch
            bobsyncer.SyncNow(bobOptions);

            // bob makes another change and syncs
            File.WriteAllText(bobSetup._pathToLift, LiftFileStrings.lift13DogHerring);
            bobOptions.CheckinDescription = "added 'herring'";         // still just want a fast checkin

            SetAdjunctModelVersion(bobsyncer, "LIFT0.13");             // Bob is now on a new branch
            bobsyncer.SyncNow(bobOptions);

            //now Sally modifies the original file, not having seen Bob's changes yet
            var sallyPathToLift = Path.Combine(sallyProject.FolderPath, "lexicon/foo.lift");

            File.WriteAllText(sallyPathToLift, LiftFileStrings.lift12Cat);

            //Sally syncs, pulling in Bob's 1st change, and encountering a need to merge (no conflicts)
            var sallyOptions = GetFullSyncOptions("adding cat");

            sallyOptions.RepositorySourcesToTry.Add(RepositoryAddress.Create("bob's machine", bobSetup.BobProjectPath, false));

            var synchronizer = Synchronizer.FromProjectConfiguration(sallyProject, progress);

            SetAdjunctModelVersion(synchronizer, "LIFT0.12");             // Sally is still on the initial branch

            // SUT
            synchronizer.SyncNow(sallyOptions);

            // Verification stage 1
            var bobContents = File.ReadAllText(bobSetup._pathToLift);

            Assert.That(bobContents, Does.Not.Contain("cat"), "'cat' should only be on Sally's branch.");
            Assert.That(bobContents, Does.Contain("dog"));
            var sallyContents = File.ReadAllText(sallyPathToLift);

            Assert.That(sallyContents, Does.Contain("cat"));
            Assert.That(sallyContents, Does.Contain("dog"), "Sally should have merged in older branch to hers.");
            Assert.That(sallyContents, Does.Not.Contain("herring"), "The red herring is only in Bob's repo; 2nd branch.");

            // Now Sally upgrades her LIFT-capable program to Bob's version!
            File.WriteAllText(sallyPathToLift, LiftFileStrings.lift13PigDogCat);

            //Sally syncs, pulling in Bob's change, and encountering a need to merge (no conflicts)
            sallyOptions = GetFullSyncOptions("adding pig");

            const string lift13version = "LIFT0.13";

            SetAdjunctModelVersion(synchronizer, lift13version);             // Sally updates to the new version (branch)
            synchronizer.SyncNow(sallyOptions);
            bobOptions.DoPullFromOthers = true;
            bobOptions.RepositorySourcesToTry.Add(RepositoryAddress.Create("sally's machine", sallyProjectRoot, false));

            // SUT
            bobsyncer.SyncNow(bobOptions);

            // Verification stage 2
            bobContents = File.ReadAllText(bobSetup._pathToLift);
            //Debug.Print("Bob's: " + bobContents);
            Assert.That(bobContents, Does.Contain("cat"), "'cat' survived the upgrade to Bob's repo.");
            Assert.That(bobContents, Does.Contain("dog"));
            Assert.That(bobContents, Does.Contain("pig"), "'pig' survived the upgrade to Bob's repo.");
            sallyContents = File.ReadAllText(sallyPathToLift);
            //Debug.Print("Sally's: " + sallyContents);
            Assert.That(sallyContents, Does.Contain("cat"));
            Assert.That(sallyContents, Does.Contain("dog"), "'dog' should be from Bob's older repo.");
            Assert.That(sallyContents, Does.Contain("herring"), "Now we should have everything from Bob's repo.");
            Assert.That(sallyContents, Does.Contain("pig"), "'pig' should have survived the upgrade.");

            // Verify Bob is on the latest branch
            string dummy;
            var    result = bobsyncer.Repository.BranchingHelper.IsLatestBranchDifferent(lift13version, out dummy);

            Assert.That(result, Is.False, "Bob should be on the latest LIFT0.13 branch.");

            // Verify Sally is on the right branch
            result = synchronizer.Repository.BranchingHelper.IsLatestBranchDifferent(lift13version, out dummy);
            Assert.That(result, Is.False, "Sally should be on the latest LIFT0.13 branch.");
        }
Ejemplo n.º 25
0
        public void TestNewVersion_SallyUpgrades_BobNotYet()
        {
            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 = new ProjectFolderConfiguration(sallyProjectRoot);

            sallyProject.IncludePatterns.Add("**.abc");
            sallyProject.IncludePatterns.Add("**.lift");

            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 = GetFullSyncOptions("added dog");

            bobOptions.DoMergeWithOthers = false;          // just want a fast checkin
            bobOptions.DoSendToOthers    = false;          // just want a fast checkin
            bobOptions.DoPullFromOthers  = false;          // just want a fast checkin

            var bobSyncer = bobSetup.GetSynchronizer();

            SetAdjunctModelVersion(bobSyncer, "");             // Bob is on 'default' branch
            bobSyncer.SyncNow(bobOptions);

            //now Sally modifies the original file, not having seen Bob's changes yet
            var sallyPathToLift = Path.Combine(sallyProject.FolderPath, "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 = GetFullSyncOptions("adding cat");
            var bobAddress   = RepositoryAddress.Create("bob's machine", bobSetup.BobProjectPath, false);

            sallyOptions.RepositorySourcesToTry.Add(bobAddress);

            var          synchronizer    = Synchronizer.FromProjectConfiguration(sallyProject, progress);
            const string sallyNewVersion = "LIFT0.13";

            SetAdjunctModelVersion(synchronizer, sallyNewVersion);
            synchronizer.SyncNow(sallyOptions);

            // Verification
            var bobContents = File.ReadAllText(bobSetup._pathToLift);

            Assert.That(bobContents, Does.Not.Contain("cat"), "'cat' should only be on Sally's branch.");
            Assert.That(bobContents, Does.Contain("dog"));
            var sallyContents = File.ReadAllText(sallyPathToLift);

            //Debug.WriteLine("sally's: " + sallyContents);
            Assert.That(sallyContents, Does.Contain("cat"));
            Assert.That(sallyContents, Does.Not.Contain("dog"), "'dog' should only be in Bob's repo.");

            // Verify Bob is still on the default branch (empty string)
            string dummy;
            var    result = bobSyncer.Repository.BranchingHelper.IsLatestBranchDifferent("", out dummy);

            Assert.That(result, Is.False, "Bob should be on default branch.");

            // Verify Sally is on the right branch
            result = synchronizer.Repository.BranchingHelper.IsLatestBranchDifferent(sallyNewVersion, out dummy);
            Assert.That(result, Is.False, "Sally should be on LIFT0.13 branch.");
        }
Ejemplo n.º 26
0
        public static void ConfigureChorusProjectFolder(ProjectFolderConfiguration projectFolderConfiguration)
        {
            // Exclude has precedence, but these are redundant as long as we're using the policy
            // that we explicitly include all the files we understand. At least someday, when these
            // affect what happens in a more persistent way (e.g. be stored in the hgrc), these would protect
            // us a bit from other apps that might try to do a *.* include.
            projectFolderConfiguration.ExcludePatterns.Add("**" + Utilities.FwXmlExtension);
            projectFolderConfiguration.ExcludePatterns.Add("**" + Utilities.FwXmlExtension + "-replaced");
            projectFolderConfiguration.ExcludePatterns.Add("**" + Utilities.FwXmlExtension + "-x");
            projectFolderConfiguration.ExcludePatterns.Add("**" + Utilities.FwDb4oExtension);
            projectFolderConfiguration.ExcludePatterns.Add("**.bad");
            projectFolderConfiguration.ExcludePatterns.Add("**.bak");
            projectFolderConfiguration.ExcludePatterns.Add("**.flextext");
            projectFolderConfiguration.ExcludePatterns.Add("**.fwbackup");
            projectFolderConfiguration.ExcludePatterns.Add("**.fwstub");
            projectFolderConfiguration.ExcludePatterns.Add("**.lint");
            projectFolderConfiguration.ExcludePatterns.Add("**.log");
            projectFolderConfiguration.ExcludePatterns.Add("**.orig");
            projectFolderConfiguration.ExcludePatterns.Add("**.oxekt");
            projectFolderConfiguration.ExcludePatterns.Add("**.oxes");
            projectFolderConfiguration.ExcludePatterns.Add("**.oxesa");
            projectFolderConfiguration.ExcludePatterns.Add("**.tmp");
            projectFolderConfiguration.ExcludePatterns.Add("**.xml");
            projectFolderConfiguration.ExcludePatterns.Add("**.zip");
            projectFolderConfiguration.ExcludePatterns.Add("**" + SharedConstants.FwXmlLockExtension);
            projectFolderConfiguration.ExcludePatterns.Add("**." + SharedConstants.dupid);
            projectFolderConfiguration.ExcludePatterns.Add(Path.Combine("Temp", "**.*"));
            projectFolderConfiguration.ExcludePatterns.Add(Path.Combine("BackupSettings", "**.*"));
            projectFolderConfiguration.ExcludePatterns.Add(Path.Combine("WritingSystemStore", "trash", "**.*"));
            projectFolderConfiguration.ExcludePatterns.Add(Path.Combine("WritingSystemStore", "WritingSystemsToIgnore.xml.ChorusNotes"));
            projectFolderConfiguration.ExcludePatterns.Add(Path.Combine(Utilities.OtherRepositories, "**.*"));             // Folder for contined LIFT and PT-FLEx repos.
            if (!projectFolderConfiguration.ExcludePatterns.Contains("**.NewChorusNotes"))
            {
                projectFolderConfiguration.ExcludePatterns.Add("**.NewChorusNotes");                 // Not really needed, since Chorus adds them. But, knows for how long?
            }
            ProjectFolderConfiguration.AddExcludedVideoExtensions(projectFolderConfiguration);

            projectFolderConfiguration.IncludePatterns.Add("FLExProject.ModelVersion");             // Hope this forces the version file to be done first.
            projectFolderConfiguration.IncludePatterns.Add("FLExProject.CustomProperties");         // Hope this forces the custom props to be done next.

            // Overhead files.
            projectFolderConfiguration.IncludePatterns.Add("do_not_share_project.txt");
            projectFolderConfiguration.IncludePatterns.Add(".hgignore");

            // Common at all levels.
            if (!projectFolderConfiguration.IncludePatterns.Contains("**.ChorusNotes"))
            {
                projectFolderConfiguration.IncludePatterns.Add("**.ChorusNotes");                 // Not really needed, since Chorus adds them. But, knows for how long?
            }
            projectFolderConfiguration.IncludePatterns.Add("**.list");
            projectFolderConfiguration.IncludePatterns.Add("**.style");

            // Misc required files.
            projectFolderConfiguration.IncludePatterns.Add(Path.Combine("ConfigurationSettings", "*.fwlayout"));
            projectFolderConfiguration.IncludePatterns.Add(Path.Combine("ConfigurationSettings", "**.fwdictconfig"));
            projectFolderConfiguration.IncludePatterns.Add(Path.Combine("ConfigurationSettings", "**Overrides.css"));
            projectFolderConfiguration.IncludePatterns.Add(Path.Combine("WritingSystemStore", "*.ldml"));
            projectFolderConfiguration.IncludePatterns.Add(Path.Combine("LinkedFiles", "AudioVisual", "**.*"));
            projectFolderConfiguration.IncludePatterns.Add(Path.Combine("LinkedFiles", "Others", "**.*"));
            projectFolderConfiguration.IncludePatterns.Add(Path.Combine("LinkedFiles", "Pictures", "**.*"));
            projectFolderConfiguration.IncludePatterns.Add(Path.Combine("SupportingFiles", "**.*"));

            // Linguistics
            projectFolderConfiguration.IncludePatterns.Add(Path.Combine("Linguistics", "Reversals", "**.reversal"));
            projectFolderConfiguration.IncludePatterns.Add(Path.Combine("Linguistics", "Lexicon", "*.lexdb"));
            projectFolderConfiguration.IncludePatterns.Add(Path.Combine("Linguistics", "TextCorpus", "*.textincorpus"));
            projectFolderConfiguration.IncludePatterns.Add(Path.Combine("Linguistics", "Inventory", "*.inventory"));
            projectFolderConfiguration.IncludePatterns.Add(Path.Combine("Linguistics", "Discourse", SharedConstants.DiscourseChartFilename));
            projectFolderConfiguration.IncludePatterns.Add(Path.Combine("Linguistics", "**.featsys"));
            projectFolderConfiguration.IncludePatterns.Add(Path.Combine("Linguistics", "MorphologyAndSyntax", SharedConstants.AnalyzingAgentsFilename));
            projectFolderConfiguration.IncludePatterns.Add(Path.Combine("Linguistics", "MorphologyAndSyntax", SharedConstants.MorphAndSynDataFilename));
            projectFolderConfiguration.IncludePatterns.Add(Path.Combine("Linguistics", "Phonology", SharedConstants.PhonologicalDataFilename));

            // Anthropology
            projectFolderConfiguration.IncludePatterns.Add(Path.Combine("Anthropology", SharedConstants.DataNotebookFilename));

            // Scripture
            projectFolderConfiguration.IncludePatterns.Add(Path.Combine("Other", SharedConstants.ScriptureReferenceSystemFilename));
            projectFolderConfiguration.IncludePatterns.Add(Path.Combine("Other", "*.ArchivedDraft"));
            projectFolderConfiguration.IncludePatterns.Add(Path.Combine("Other", SharedConstants.ScriptureTransFilename));
            projectFolderConfiguration.IncludePatterns.Add(Path.Combine("Other", SharedConstants.ImportSettingsFilename));
            projectFolderConfiguration.IncludePatterns.Add(Path.Combine("Other", "Books", "*.bookannotations"));
            projectFolderConfiguration.IncludePatterns.Add(Path.Combine("Other", "Books", "*.book"));

            // Leftovers
            // Style file and user-defined lists ought to be covered, above.
            projectFolderConfiguration.IncludePatterns.Add(Path.Combine("General", SharedConstants.FLExFiltersFilename));
            projectFolderConfiguration.IncludePatterns.Add(Path.Combine("General", SharedConstants.FLExAnnotationsFilename));
            projectFolderConfiguration.IncludePatterns.Add(Path.Combine("General", SharedConstants.LanguageProjectFilename));
            projectFolderConfiguration.IncludePatterns.Add(Path.Combine("General", SharedConstants.FLExUnownedPicturesFilename));
            projectFolderConfiguration.IncludePatterns.Add(Path.Combine("General", SharedConstants.FLExVirtualOrderingFilename));
        }
Ejemplo n.º 27
0
        public void BackupNow(string pathToProjectDirectory, string localizationLanguageId, string pathToLiftFile)
        {
            if (pathToProjectDirectory.ToLower().IndexOf(@"sampleprojects\pretend") >= 0)
            {
                return;                 //no way... if you want a unit test that includes CHorus, do it without
                //that now deprecated monstrosity.
            }
            _timeOfLastBackupAttempt = DateTime.Now;

            //nb: we're not really using the message yet, at least, not showing it to the user
            if (!string.IsNullOrEmpty(HgRepository.GetEnvironmentReadinessMessage(localizationLanguageId)))
            {
                Palaso.Reporting.Logger.WriteEvent("Backup not possible: {0}", HgRepository.GetEnvironmentReadinessMessage("en"));
            }

            try
            {
                var configuration = new ProjectFolderConfiguration(pathToProjectDirectory);
                LiftFolder.AddLiftFileInfoToFolderConfiguration(configuration);

                // projectFolder.IncludePatterns.Add(project.ProjectDirectoryPath);

//                  if (!string.IsNullOrEmpty(PathToParentOfRepositories))
//                {
//                    if (!Directory.Exists(PathToParentOfRepositories))
//                    {
//                        ErrorReport.NotifyUserOfProblem(new ShowOncePerSessionBasedOnExactMessagePolicy(), "There was a problem during auto backup: Could not Access the backup path, {0}", PathToParentOfRepositories);
//                        //no, we still want to check in... return;
//                    }
//                    else
//                    {
//                        var projectName = Path.GetFileName(pathToProjectDirectory);
//                        var backupSource = Chorus.VcsDrivers.RepositoryAddress.Create("backup", Path.Combine(PathToParentOfRepositories, projectName),
//                                                                                false);
//                        options.RepositorySourcesToTry.Add(backupSource);
//                    }
//                }

                using (var dlg = new SyncDialog(configuration,
                                                SyncUIDialogBehaviors.StartImmediatelyAndCloseWhenFinished,
                                                SyncUIFeatures.Minimal))
                {
                    dlg.Text = "WeSay Automatic Backup";
                    dlg.SyncOptions.DoMergeWithOthers = false;
                    dlg.SyncOptions.DoPullFromOthers  = false;
                    dlg.SyncOptions.DoSendToOthers    = true;
                    dlg.SyncOptions.RepositorySourcesToTry.Clear();
                    dlg.SyncOptions.CheckinDescription     = CheckinDescriptionBuilder.GetDescription();
                    dlg.UseTargetsAsSpecifiedInSyncOptions = true;
                    dlg.SetSynchronizerAdjunct(new LiftSynchronizerAdjunct(pathToLiftFile));

                    //in addition to checking in, will we be doing a backup to another media (e.g. sd card)?
                    if (!string.IsNullOrEmpty(PathToParentOfRepositories))
                    {
                        var projectName  = Path.GetFileName(pathToProjectDirectory);
                        var backupSource = Chorus.VcsDrivers.RepositoryAddress.Create("test-backup-media", Path.Combine(PathToParentOfRepositories, projectName),
                                                                                      false);
                        dlg.SyncOptions.RepositorySourcesToTry.Add(backupSource);
                    }

                    dlg.ShowDialog();

                    if (dlg.FinalStatus.WarningEncountered ||                      //not finding the backup media only counts as a warning
                        dlg.FinalStatus.ErrorEncountered)
                    {
                        ErrorReport.NotifyUserOfProblem(new ShowOncePerSessionBasedOnExactMessagePolicy(),
                                                        "There was a problem during auto backup. Chorus said:\r\n\r\n" +
                                                        dlg.FinalStatus.LastWarning + "\r\n" +
                                                        dlg.FinalStatus.LastError);
                    }
                }
                CheckinDescriptionBuilder.Clear();
            }
            catch (Exception error)
            {
                Palaso.Reporting.Logger.WriteEvent("Error during Backup: {0}", error.Message);
                //TODO we need some passive way indicating the health of the backup system
            }
        }
        public void StartWorking(Dictionary <string, string> commandLineArgs)
        {
            // As per the API, -p will be the main FW data file.
            // REVIEW (RandyR): What if it is the DB4o file?
            // REVIEW (RandyR): What is sent if the user is a client of the DB4o server?
            // -p <$fwroot>\foo\foo.fwdata
            var pathToLiftProject = Utilities.LiftOffset(Path.GetDirectoryName(commandLineArgs["-p"]));

            using (var chorusSystem = Utilities.InitializeChorusSystem(pathToLiftProject, commandLineArgs["-u"], LiftFolder.AddLiftFileInfoToFolderConfiguration))
            {
                var newlyCreated = false;
                if (chorusSystem.Repository.Identifier == null)
                {
                    // First do a commit, since the repo is brand new.
                    var projectConfig = chorusSystem.ProjectFolderConfiguration;
                    ProjectFolderConfiguration.EnsureCommonPatternsArePresent(projectConfig);
                    projectConfig.IncludePatterns.Add("**.ChorusRescuedFile");

                    chorusSystem.Repository.AddAndCheckinFiles(projectConfig.IncludePatterns, projectConfig.ExcludePatterns, "Initial commit");
                    newlyCreated = true;
                }
                chorusSystem.EnsureAllNotesRepositoriesLoaded();

                // Do the Chorus business.
                using (var syncDlg = (SyncDialog)chorusSystem.WinForms.CreateSynchronizationDialog(SyncUIDialogBehaviors.Lazy, SyncUIFeatures.NormalRecommended | SyncUIFeatures.PlaySoundIfSuccessful))
                {
                    var syncAdjunt = new LiftSynchronizerAdjunct(LiftUtilties.PathToFirstLiftFile(pathToLiftProject));
                    syncDlg.SetSynchronizerAdjunct(syncAdjunt);

                    // Chorus does it in this order:
                    // Local Commit
                    // Pull
                    // Merge (Only if anything came in with the pull from other sources, and commit of merged results)
                    // Push
                    syncDlg.SyncOptions.DoPullFromOthers  = true;
                    syncDlg.SyncOptions.DoMergeWithOthers = true;
                    syncDlg.SyncOptions.DoSendToOthers    = true;
                    syncDlg.Text          = Resources.SendReceiveView_DialogTitleLift;
                    syncDlg.StartPosition = FormStartPosition.CenterScreen;
                    syncDlg.BringToFront();
                    var dlgResult = syncDlg.ShowDialog();

                    if (dlgResult == DialogResult.OK)
                    {
                        if (newlyCreated && (!syncDlg.SyncResult.Succeeded || syncDlg.SyncResult.ErrorEncountered != null))
                        {
                            _gotChanges = false;
                            // Wipe out new repo, since something bad happened in S/R,
                            // and we don't want to leave the user in a sad state (cf. LT-14751).
                            Directory.Delete(pathToLiftProject, true);
                        }
                        else if (syncDlg.SyncResult.DidGetChangesFromOthers || syncAdjunt.WasUpdated)
                        {
                            _gotChanges = true;
                        }
                    }
                    else
                    {
                        // User probably bailed out of S/R using the "X" to close the dlg.
                        if (newlyCreated)
                        {
                            _gotChanges = false;
                            // Wipe out new repo, since the user cancelled without even trying the S/R,
                            // and we don't want to leave the user in a sad state (cf. LT-14751).
                            Directory.Delete(pathToLiftProject, true);
                        }
                    }
                }
            }
        }