Esempio n. 1
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;
        }
Esempio n. 2
0
 public RepositorySetup(string userName, string projectfolder)
 {
     Progress = new NullProgress();
     ProjectFolder = new TemporaryFolder(projectfolder);
     MakeRepositoryForTest(ProjectFolder.Path, userName, Progress);
     ProjectFolderConfig = new ProjectFolderConfiguration(ProjectFolder.Path);
 }
Esempio n. 3
0
 private void AddAndCommitFiles(string summary)
 {
     ProjectFolderConfiguration.EnsureCommonPatternsArePresent(_project);
     _project.IncludePatterns.Add("**.ChorusRescuedFile");
     Repository.AddAndCheckinFiles(_project.IncludePatterns, _project.ExcludePatterns,
                                   summary);
 }
Esempio n. 4
0
        private static void FilterFiles(HgRepository repository, ProjectFolderConfiguration configuration,
                                        IDictionary <string, uint> extensionToMaximumSize, StringBuilder messageBuilder, string repositoryBasePath,
                                        Dictionary <string, List <string> > extensionToFilesMap, string userNotificationMessageBase, bool forgetItIfTooLarge)
        {
            foreach (var filesOfOneExtension in extensionToFilesMap)
            {
                var maxForExtension = GetMaxSizeForExtension(extensionToMaximumSize, filesOfOneExtension.Key);
                foreach (var partialPathname in filesOfOneExtension.Value)
                {
                    var fullPathname = Path.Combine(repositoryBasePath, partialPathname);
                    var fileInfo     = new FileInfo(fullPathname);
                    var fileSize     = fileInfo.Length;
                    if (fileSize <= maxForExtension)
                    {
                        continue;
                    }

                    var fileSizeString = (fileSize / (float)Megabyte).ToString("0.00") + " Megabytes";
                    var maxSizeString  = (maxForExtension / (float)Megabyte).ToString("0.0") + " Megabytes";
                    messageBuilder.AppendLine(String.Format(userNotificationMessageBase, Path.GetFileName(fullPathname), fileSizeString, maxSizeString, fullPathname));

                    var shortPathname = fullPathname.Replace(repositoryBasePath, null);
                    configuration.ExcludePatterns.Add(shortPathname);
                    if (forgetItIfTooLarge)
                    {
                        repository.ForgetFile(shortPathname);
                    }
                }
            }
        }
Esempio n. 5
0
 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));
 }
Esempio n. 6
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;
        }
Esempio n. 7
0
 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 static void AddExcludedVideoExtensions(ProjectFolderConfiguration projectFolderConfiguration)
 {
     // Exclude these video extensions.
     // One can get a list of all sorts of extensions at: http://www.fileinfo.com/filetypes/video
     foreach (var videoExtension in VideoExtensions)
     {
         projectFolderConfiguration.ExcludePatterns.Add("**." + videoExtension);
     }
 }
 public static void AddExcludedVideoExtensions(ProjectFolderConfiguration projectFolderConfiguration)
 {
     // Exclude these video extensions.
     // One can get a list of all sorts of extensions at: http://www.fileinfo.com/filetypes/video
     foreach (var videoExtension in VideoExtensions)
     {
         projectFolderConfiguration.ExcludePatterns.Add("**." + videoExtension);
     }
 }
        public ProjectFolderConfiguration Clone()
        {
            var clone = new ProjectFolderConfiguration(this._folderPath);

            clone.IncludePatterns.Clear();
            clone.IncludePatterns.AddRange(_includePatterns);
            clone.ExcludePatterns.Clear();
            clone.ExcludePatterns.AddRange(_excludePatterns);
            return(clone);
        }
Esempio 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");
        }
 public static void EnsureCommonPatternsArePresent(ProjectFolderConfiguration projectFolderConfiguration)
 {
     if (!projectFolderConfiguration._includePatterns.Contains("**.ChorusNotes"))
     {
         projectFolderConfiguration._includePatterns.Add("**.ChorusNotes");
     }
     if (!projectFolderConfiguration._excludePatterns.Contains(BareFolderReadmeFileName))
     {
         projectFolderConfiguration._excludePatterns.Add(BareFolderReadmeFileName);
     }
     if (!projectFolderConfiguration._excludePatterns.Contains("**.NewChorusNotes"))
     {
         projectFolderConfiguration._excludePatterns.Add("**.NewChorusNotes");
     }
 }
Esempio n. 13
0
        //autofac uses this
        public SyncDialog(ProjectFolderConfiguration projectFolderConfiguration,
			SyncUIDialogBehaviors behavior, SyncUIFeatures uiFeatureFlags)
        {
            InitializeComponent();
            try
            {
                Behavior = behavior;
                _syncControl.Model = new SyncControlModel(projectFolderConfiguration, uiFeatureFlags, null/*to do*/);
                AcceptButton = _syncControl._cancelButton;
                // CancelButton =  _syncControl._cancelOrCloseButton;

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

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

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

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

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

                    _syncControl.Dock = DockStyle.Fill;//in designer, we don't want it to cover up everything, but we do at runtime
                    _syncStartControl.Visible = true;
                    _syncControl.Visible = false;
                    Height = _syncStartControl.DesiredHeight;
                }
                else
                {
                    _syncStartControl.Visible = false;
                    _syncControl.Visible = true;
                    Height = _syncControl.DesiredHeight;
                }
                ResumeLayout(true);
                this.Text = string.Format("Send/Receive ({0})", _syncControl.Model.UserName);
            }
            catch (Exception)
            {
                _syncStartControl.Dispose();//without this, the usbdetector just goes on and on
                throw;
            }
        }
Esempio n. 14
0
        ///<summary>
        /// Filter the files, before the commit. Files that are too large are added to the exclude section of the configuration.
        ///</summary>
        ///<returns>An empty string or a string with a listing of files that were not added/modified.</returns>
        public static string FilterFiles(HgRepository repository, ProjectFolderConfiguration configuration, ChorusFileTypeHandlerCollection handlerCollection)
        {
            var messageBuilder = new StringBuilder();
            Dictionary <string, Dictionary <string, List <string> > > fileStatusDictionary = GetStatusOfFilesOfInterest(repository, configuration);
            Dictionary <string, uint> extensionToMaximumSize = CacheMaxSizesOfExtension(handlerCollection);

            foreach (KeyValuePair <string, Dictionary <string, List <string> > > filesOfOneStatus in fileStatusDictionary)
            {
                var userNotificationMessageBase = "File '{0}' is too large to include in the Send/Receive system. It is {1}, but the maximum allowed is {2}. The file is at {3}.";
                var forgetItIfTooLarge          = false;

                switch (filesOfOneStatus.Key)
                {
                case "M":                         // modified
                    // May have grown too large.
                    // Untrack it (forget), if is too large and keep out.
                    forgetItIfTooLarge          = true;
                    userNotificationMessageBase = "File '{0}' has grown too large to include in the Send/Receive system.  It is {1}, but the maximum allowed is {2}. The file is at {3}.";
                    //FilterModifiedFiles(repository, configuration, extensionToMaximumSize, messageBuilder, PathToRepository(repository), statusCheckResultKvp.Value);
                    break;

                case "A":                         // marked for 'add' with; hg add
                    // Untrack it (forget), if is too large and keep out.
                    forgetItIfTooLarge = true;
                    //FilterAddedFiles(repository, configuration, extensionToMaximumSize, messageBuilder, PathToRepository(repository), statusCheckResultKvp.Value);
                    break;

                case "?":                         // untracked, but going to be added.
                    // Keep out, if too large.
                    //FilterUntrackedFiles(configuration, extensionToMaximumSize, messageBuilder, PathToRepository(repository), statusCheckResultKvp.Value);
                    break;

                    //case "!": // tracked but deleted. Fall through
                    //case "R": // tracked, and marked for removal with: hg rm
                    // No need to mess with these ones.
                    //	break;
                    // If there are other keys, we don't really care about them.
                }
                Dictionary <string, List <string> > extensionToFilesDictionary = filesOfOneStatus.Value;
                FilterFiles(repository, configuration, extensionToMaximumSize, messageBuilder, PathToRepository(repository),
                            extensionToFilesDictionary, userNotificationMessageBase, forgetItIfTooLarge);
            }

            var result = messageBuilder.ToString();

            return(string.IsNullOrEmpty(result) ? null : result);
        }
        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);
        }
Esempio n. 16
0
        ///<summary>
        /// Filter the files, before the commit. Files that are too large are added to the exclude section of the configuration.
        ///</summary>
        ///<returns>An empty string or a string with a listing of files that were not added/modified.</returns>
        public static string FilterFiles(HgRepository repository, ProjectFolderConfiguration configuration, ChorusFileTypeHandlerCollection handlerCollection)
        {
            var messageBuilder = new StringBuilder();
            Dictionary<string, Dictionary<string, List<string>>> fileStatusDictionary = GetStatusOfFilesOfInterest(repository, configuration);
            Dictionary<string, uint> extensionToMaximumSize = CacheMaxSizesOfExtension(handlerCollection);

            foreach (KeyValuePair<string, Dictionary<string, List<string>>> filesOfOneStatus in fileStatusDictionary)
            {
                var userNotificationMessageBase = "File '{0}' is too large to include in the Send/Receive system. It is {1}, but the maximum allowed is {2}. The file is at {3}.";
                var forgetItIfTooLarge = false;

                switch (filesOfOneStatus.Key)
                {
                    case "M": // modified
                        // May have grown too large.
                        // Untrack it (forget), if is too large and keep out.
                        forgetItIfTooLarge = true;
                        userNotificationMessageBase = "File '{0}' has grown too large to include in the Send/Receive system.  It is {1}, but the maximum allowed is {2}. The file is at {3}.";
                        //FilterModifiedFiles(repository, configuration, extensionToMaximumSize, messageBuilder, PathToRepository(repository), statusCheckResultKvp.Value);
                        break;
                    case "A": // marked for 'add' with; hg add
                        // Untrack it (forget), if is too large and keep out.
                        forgetItIfTooLarge = true;
                        //FilterAddedFiles(repository, configuration, extensionToMaximumSize, messageBuilder, PathToRepository(repository), statusCheckResultKvp.Value);
                        break;
                    case "?": // untracked, but going to be added.
                        // Keep out, if too large.
                        //FilterUntrackedFiles(configuration, extensionToMaximumSize, messageBuilder, PathToRepository(repository), statusCheckResultKvp.Value);
                        break;

                    //case "!": // tracked but deleted. Fall through
                    //case "R": // tracked, and marked for removal with: hg rm
                        // No need to mess with these ones.
                    //	break;
                    // If there are other keys, we don't really care about them.
                }
                Dictionary<string, List<string>> extensionToFilesDictionary = filesOfOneStatus.Value;
                FilterFiles(repository, configuration, extensionToMaximumSize, messageBuilder, PathToRepository(repository),
                            extensionToFilesDictionary, userNotificationMessageBase, forgetItIfTooLarge);
            }

            var result = messageBuilder.ToString();
            return string.IsNullOrEmpty(result) ? null : result;
        }
Esempio n. 17
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");
        }
Esempio n. 18
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));
        }
        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);
        }
Esempio n. 20
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);
        }
Esempio n. 21
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);
        }
Esempio n. 22
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();
            }
        }
Esempio n. 23
0
 public static Synchronizer FromProjectConfiguration(ProjectFolderConfiguration project, IProgress progress)
 {
     var hg = HgRepository.CreateOrUseExisting(project.FolderPath, progress);
     return new Synchronizer(hg.PathToRepo, project, progress);
 }
Esempio n. 24
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;
 }
Esempio n. 25
0
 public static void EnsureCommonPatternsArePresent(ProjectFolderConfiguration projectFolderConfiguration)
 {
     if (!projectFolderConfiguration._includePatterns.Contains("**.ChorusNotes"))
         projectFolderConfiguration._includePatterns.Add("**.ChorusNotes");
     if (!projectFolderConfiguration._excludePatterns.Contains(BareFolderReadmeFileName))
         projectFolderConfiguration._excludePatterns.Add(BareFolderReadmeFileName);
     if (!projectFolderConfiguration._excludePatterns.Contains("**.NewChorusNotes"))
         projectFolderConfiguration._excludePatterns.Add("**.NewChorusNotes");
 }
Esempio n. 26
0
 public ProjectFolderConfiguration Clone()
 {
     var clone = new ProjectFolderConfiguration(this._folderPath);
     clone.IncludePatterns.Clear();
     clone.IncludePatterns.AddRange(_includePatterns);
     clone.ExcludePatterns.Clear();
     clone.ExcludePatterns.AddRange(_excludePatterns);
     return clone;
 }
Esempio n. 27
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.IsFalse(bobContents.Contains("cat"), "'cat' should only be on Sally's branch.");
            Assert.IsTrue(bobContents.Contains("dog"));
            var sallyContents = File.ReadAllText(sallyPathToLift);
            //Debug.WriteLine("sally's: " + sallyContents);
            Assert.IsTrue(sallyContents.Contains("cat"));
            Assert.IsFalse(sallyContents.Contains("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.IsFalse(result, "Bob should be on default branch.");

            // Verify Sally is on the right branch
            result = synchronizer.Repository.BranchingHelper.IsLatestBranchDifferent(sallyNewVersion, out dummy);
            Assert.IsFalse(result, "Sally should be on LIFT0.13 branch.");
        }
Esempio n. 28
0
        private static void FilterFiles(HgRepository repository, ProjectFolderConfiguration configuration,
				IDictionary<string, uint> extensionToMaximumSize, StringBuilder messageBuilder, string repositoryBasePath,
				Dictionary<string, List<string>> extensionToFilesMap, string userNotificationMessageBase, bool forgetItIfTooLarge)
        {
            foreach (var filesOfOneExtension in extensionToFilesMap)
            {
                var maxForExtension = GetMaxSizeForExtension(extensionToMaximumSize, filesOfOneExtension.Key);
                foreach (var partialPathname in filesOfOneExtension.Value)
                {
                    var fullPathname = Path.Combine(repositoryBasePath, partialPathname);
                    var fileInfo = new FileInfo(fullPathname);
                    var fileSize = fileInfo.Length;
                    if (fileSize <= maxForExtension)
                        continue;

                    var fileSizeString = (fileSize / (float)Megabyte).ToString("0.00") + " Megabytes";
                    var maxSizeString = (maxForExtension / (float)Megabyte).ToString("0.0") + " Megabytes";
                    messageBuilder.AppendLine(String.Format(userNotificationMessageBase, Path.GetFileName(fullPathname), fileSizeString, maxSizeString, fullPathname));

                    var shortPathname = fullPathname.Replace(repositoryBasePath, null);
                    configuration.ExcludePatterns.Add(shortPathname);
                    if (forgetItIfTooLarge)
                        repository.ForgetFile(shortPathname);
                }
            }
        }
Esempio n. 29
0
        /// <summary>
        /// Gets the status for the files marked as 'modified', 'added', and 'unknown/untracked' (-mau option)
        /// </summary>
        /// <returns>A dictionary of hg status codes --> (a dictionary of file extensions --> a list of files)</returns>
        internal static Dictionary<string, Dictionary<string, List<string>>> GetStatusOfFilesOfInterest(HgRepository repository, ProjectFolderConfiguration configuration)
        {
            var statusOfFilesByExtension = new Dictionary<string, Dictionary<string, List<string>>>(StringComparer.InvariantCultureIgnoreCase);

            repository.CheckAndUpdateHgrc();
            var args = new StringBuilder();
            args.Append(" -mau "); // Only modified, added, and unknown (not tracked).

            // Don't use these, as they may mask some large files that are outside the included space, but that are too large, and already tracked.
            //foreach (var pattern in configuration.IncludePatterns) //.Select(pattern => Path.Combine(_pathToRepository, pattern)))
            //{
            //    args.Append(" -I " + SurroundWithQuotes(pattern));
            //}
            foreach (var pattern in configuration.ExcludePatterns) //.Select(pattern => Path.Combine(_pathToRepository, pattern)))
            {
                args.Append(" -X " + HgRepository.SurroundWithQuotes(pattern));
            }
            var result = repository.Execute(repository.SecondsBeforeTimeoutOnLocalOperation, "status", args.ToString());

            var lines = result.StandardOutput.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            foreach (var line in lines)
            {
                if (line.Trim() == string.Empty)
                    continue;

                var status = line.Substring(0, 1);
                Dictionary<string, List<string>> statusToFilesMap;
                if (!statusOfFilesByExtension.TryGetValue(status, out statusToFilesMap))
                {
                    statusToFilesMap = new Dictionary<string, List<string>>(StringComparer.InvariantCultureIgnoreCase);
                    statusOfFilesByExtension.Add(status, statusToFilesMap);
                }
                var filename = line.Substring(2); // ! data.txt
                var extension = Path.GetExtension(filename);
                if (string.IsNullOrEmpty(extension))
                    extension = "noextensionforfile";
                extension = extension.Replace(".", null).ToLowerInvariant();
                List<string> fileList;
                if (!statusToFilesMap.TryGetValue(extension, out fileList))
                {
                    fileList = new List<string>();
                    statusToFilesMap.Add(extension, fileList);
                }
                fileList.Add(filename);
            }

            return statusOfFilesByExtension;
        }
Esempio n. 30
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);
        }
Esempio n. 31
0
        public RepositorySetup(string userName, string projectName, bool makeRepository)
        {
            Init(userName);
            ProjectName = projectName;

            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);
        }
Esempio n. 32
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("**.fwbackup");
			projectFolderConfiguration.ExcludePatterns.Add("**.fwstub");
			projectFolderConfiguration.ExcludePatterns.Add("**.orig");
			projectFolderConfiguration.ExcludePatterns.Add("**.zip");
			projectFolderConfiguration.ExcludePatterns.Add("**.oxes");
			projectFolderConfiguration.ExcludePatterns.Add("**.oxesa");
			projectFolderConfiguration.ExcludePatterns.Add("**.oxekt");
			projectFolderConfiguration.ExcludePatterns.Add("**.lint");
			projectFolderConfiguration.ExcludePatterns.Add("**.flextext");
			projectFolderConfiguration.ExcludePatterns.Add("**.bak");
			projectFolderConfiguration.ExcludePatterns.Add("**.bad");
			projectFolderConfiguration.ExcludePatterns.Add("**" + SharedConstants.FwXmlLockExtension);
			projectFolderConfiguration.ExcludePatterns.Add("**.tmp");
			projectFolderConfiguration.ExcludePatterns.Add("**.xml");
			projectFolderConfiguration.ExcludePatterns.Add("**.log");
			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("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));
		}
Esempio n. 33
0
        /// <summary>
        /// Gets the status for the files marked as 'modified', 'added', and 'unknown/untracked' (-mau option)
        /// </summary>
        /// <returns>A dictionary of hg status codes --> (a dictionary of file extensions --> a list of files)</returns>
        internal static Dictionary <string, Dictionary <string, List <string> > > GetStatusOfFilesOfInterest(HgRepository repository, ProjectFolderConfiguration configuration)
        {
            var statusOfFilesByExtension = new Dictionary <string, Dictionary <string, List <string> > >(StringComparer.InvariantCultureIgnoreCase);

            repository.CheckAndUpdateHgrc();
            var args = new StringBuilder();

            args.Append(" -mau ");             // Only modified, added, and unknown (not tracked).

            // Don't use these, as they may mask some large files that are outside the included space, but that are too large, and already tracked.
            //foreach (var pattern in configuration.IncludePatterns) //.Select(pattern => Path.Combine(_pathToRepository, pattern)))
            //{
            //    args.Append(" -I " + SurroundWithQuotes(pattern));
            //}
            foreach (var pattern in configuration.ExcludePatterns)             //.Select(pattern => Path.Combine(_pathToRepository, pattern)))
            {
                args.Append(" -X " + HgRepository.SurroundWithQuotes(pattern));
            }
            var result = repository.Execute(repository.SecondsBeforeTimeoutOnLocalOperation, "status", args.ToString());

            var lines = result.StandardOutput.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            foreach (var line in lines)
            {
                if (line.Trim() == string.Empty)
                {
                    continue;
                }

                var status = line.Substring(0, 1);
                Dictionary <string, List <string> > statusToFilesMap;
                if (!statusOfFilesByExtension.TryGetValue(status, out statusToFilesMap))
                {
                    statusToFilesMap = new Dictionary <string, List <string> >(StringComparer.InvariantCultureIgnoreCase);
                    statusOfFilesByExtension.Add(status, statusToFilesMap);
                }
                var filename  = line.Substring(2);                // ! data.txt
                var extension = Path.GetExtension(filename);
                if (string.IsNullOrEmpty(extension))
                {
                    extension = "noextensionforfile";
                }
                extension = extension.Replace(".", null).ToLowerInvariant();
                List <string> fileList;
                if (!statusToFilesMap.TryGetValue(extension, out fileList))
                {
                    fileList = new List <string>();
                    statusToFilesMap.Add(extension, fileList);
                }
                fileList.Add(filename);
            }

            return(statusOfFilesByExtension);
        }
Esempio n. 34
0
        public static Synchronizer FromProjectConfiguration(ProjectFolderConfiguration project, IProgress progress)
        {
            var hg = HgRepository.CreateOrUseExisting(project.FolderPath, progress);

            return(new Synchronizer(hg.PathToRepo, project, progress));
        }
Esempio n. 35
0
        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.IsFalse(bobContents.Contains("cat"), "'cat' should only be on Sally's branch.");
            Assert.IsTrue(bobContents.Contains("dog"));
            var sallyContents = File.ReadAllText(sallyPathToLift);
            Assert.IsTrue(sallyContents.Contains("cat"));
            Assert.IsTrue(sallyContents.Contains("dog"), "Sally should have merged in older branch to hers.");
            Assert.IsFalse(sallyContents.Contains("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.IsTrue(bobContents.Contains("cat"), "'cat' survived the upgrade to Bob's repo.");
            Assert.IsTrue(bobContents.Contains("dog"));
            Assert.IsTrue(bobContents.Contains("pig"), "'pig' survived the upgrade to Bob's repo.");
            sallyContents = File.ReadAllText(sallyPathToLift);
            //Debug.Print("Sally's: " + sallyContents);
            Assert.IsTrue(sallyContents.Contains("cat"));
            Assert.IsTrue(sallyContents.Contains("dog"), "'dog' should be from Bob's older repo.");
            Assert.IsTrue(sallyContents.Contains("herring"), "Now we should have everything from Bob's repo.");
            Assert.IsTrue(sallyContents.Contains("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.IsFalse(result, "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.IsFalse(result, "Sally should be on the latest LIFT0.13 branch.");
        }
        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);
                }
            }
        }
Esempio n. 37
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.IsTrue(sallyContents.Contains("dog"), "'dog' should be in Sally repo.");
            var fredContents = File.ReadAllText(fredPathToLift);
            Assert.IsTrue(fredContents.Contains("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.IsFalse(fredContents.Contains("cat"), "'cat' should only be on Bob's branch.");
            Assert.IsTrue(fredContents.Contains("ant"));
            sallyContents = File.ReadAllText(sallyPathToLift);
            Assert.IsTrue(sallyContents.Contains("ant"), "'ant' was propogated to Sally's branch.");
            Assert.IsFalse(sallyContents.Contains("cat"), "'cat' should only be on Bob's branch.");
            var bobContents = File.ReadAllText(bobSetup._pathToLift);
            Assert.IsFalse(bobContents.Contains("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.IsFalse(result, "Bob should be on the new LIFT0.13 branch.");
            // And Fred isn't
            result = fredSyncer.Repository.BranchingHelper.IsLatestBranchDifferent(lift13version, out dummy);
            Assert.IsTrue(result, "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.IsTrue(bobContents.Contains("herring"), "'herring' should be pulled in from Sally's branch.");
            Assert.IsTrue(bobContents.Contains("ant"), "'ant' should be pulled in from Sally's branch.");
            sallyContents = File.ReadAllText(sallyPathToLift);
            Assert.IsTrue(sallyContents.Contains("cat"), "'cat' should be pulled in from Bob's branch.");
            Assert.IsTrue(sallyContents.Contains("dog"), "Everybody should have 'dog' from before.");
            fredContents = File.ReadAllText(fredPathToLift);
            Assert.IsFalse(fredContents.Contains("herring"), "The red herring is only in the new version for now.");
            Assert.IsFalse(fredContents.Contains("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.IsFalse(result, "Sally should be on the new LIFT0.13 branch.");
            // And Fred still shouldn't be
            result = fredSyncer.Repository.BranchingHelper.IsLatestBranchDifferent(lift13version, out dummy);
            Assert.IsTrue(result, "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.IsFalse(bobContents.Contains("pig"), "'pig' should only be on 'default' branch.");
            sallyContents = File.ReadAllText(sallyPathToLift);
            Assert.IsFalse(sallyContents.Contains("pig"), "'pig' should only be on 'default' branch.");
            fredContents = File.ReadAllText(fredPathToLift);
            Assert.IsFalse(fredContents.Contains("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.IsTrue(result, "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.IsFalse(fredContents.Contains("deer"), "'deer' should only be on new version.");
            result = fredSyncer.Repository.BranchingHelper.IsLatestBranchDifferent(lift13version, out dummy);
            Assert.IsTrue(result, "Fred should still be on the 'default' branch.");
            // Check that Sally got her 'deer'
            sallyContents = File.ReadAllText(sallyPathToLift);
            Assert.IsTrue(sallyContents.Contains("deer"), "'deer' should have propagated to Sally.");
            // Make sure that 'pig' hasn't migrated to the new version
            Assert.IsFalse(sallyContents.Contains("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.IsTrue(bobContents.Contains("cat"), "'cat' should survive the big hairy test in Bob's repo.");
            Assert.IsTrue(bobContents.Contains("dog"), "'dog' should survive the big hairy test in Bob's repo.");
            Assert.IsTrue(bobContents.Contains("pig"), "'pig' should survive the big hairy test in Bob's repo.");
            Assert.IsTrue(bobContents.Contains("herring"), "'herring' should survive the big hairy test in Bob's repo.");
            Assert.IsTrue(bobContents.Contains("deer"), "'deer' should survive the big hairy test in Bob's repo.");
            Assert.IsTrue(bobContents.Contains("ant"), "'ant' should survive the big hairy test in Bob's repo.");
            Assert.IsTrue(bobContents.Contains("fox"), "'fox' should survive the big hairy test in Bob's repo.");
            sallyContents = File.ReadAllText(sallyPathToLift);
            Assert.IsTrue(sallyContents.Contains("cat"), "'cat' should survive the big hairy test in Sally's repo.");
            Assert.IsTrue(sallyContents.Contains("dog"), "'dog' should survive the big hairy test in Sally's repo.");
            Assert.IsTrue(sallyContents.Contains("herring"), "'herring' should survive the big hairy test in Sally's repo.");
            Assert.IsTrue(sallyContents.Contains("pig"), "'pig' should survive the big hairy test in Sally's repo.");
            Assert.IsTrue(sallyContents.Contains("deer"), "'deer' should survive the big hairy test in Sally's repo.");
            Assert.IsTrue(sallyContents.Contains("ant"), "'ant' should survive the big hairy test in Sally's repo.");
            Assert.IsTrue(sallyContents.Contains("fox"), "'fox' should survive the big hairy test in Sally's repo.");
            fredContents = File.ReadAllText(fredPathToLift);
            Assert.IsTrue(fredContents.Contains("cat"), "'cat' should survive the big hairy test in Fred's repo.");
            Assert.IsTrue(fredContents.Contains("dog"), "'dog' should survive the big hairy test in Fred's repo.");
            Assert.IsTrue(fredContents.Contains("herring"), "'herring' should survive the big hairy test in Fred's repo.");
            Assert.IsTrue(fredContents.Contains("pig"), "'pig' should survive the big hairy test in Fred's repo.");
            Assert.IsTrue(fredContents.Contains("deer"), "'deer' should survive the big hairy test in Fred's repo.");
            Assert.IsTrue(fredContents.Contains("ant"), "'ant' should survive the big hairy test in Fred's repo.");
            Assert.IsTrue(fredContents.Contains("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.IsFalse(result, "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.IsFalse(result, "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.IsFalse(result, "Fred should finally be on the new LIFT0.13 branch.");
        }
Esempio n. 38
0
		public void BackupNow(string pathToProjectDirectory, string localizationLanguageId)
		{
			_timeOfLastBackupAttempt = DateTime.Now;

			//nb: we're not really using the message yet, at least, not showing it to the user
			if(!string.IsNullOrEmpty(RepositoryManager.GetEnvironmentReadinessMessage(localizationLanguageId)))
			{
				Palaso.Reporting.Logger.WriteEvent("Backup not possible: {0}", RepositoryManager.GetEnvironmentReadinessMessage("en"));
			}
			if (string.IsNullOrEmpty(PathToParentOfRepositories))
			{
				Palaso.Reporting.Logger.WriteMinorEvent("Backup location not specified, skipping backup.");
				return;
			}
			if (!Directory.Exists(PathToParentOfRepositories))
			{
				Palaso.Reporting.Logger.WriteEvent("Backup location not found, skipping backup.");
				return;
			}

			LiftRepository.RightToAccessLiftExternally rightToAccessLiftExternally = null;
			if (_lexEntryRepository != null)
			{
				rightToAccessLiftExternally = _lexEntryRepository.GetRightToAccessLiftExternally();
			}

			try
			{
				ProjectFolderConfiguration projectFolder = new ProjectFolderConfiguration(pathToProjectDirectory);
				projectFolder.ExcludePatterns.Add("**/cache");
				projectFolder.ExcludePatterns.Add("*.old");
				projectFolder.ExcludePatterns.Add("*.tmp");
				projectFolder.IncludePatterns.Add("*.*");
			   // projectFolder.IncludePatterns.Add(project.ProjectDirectoryPath);

				Chorus.sync.SyncOptions options = new SyncOptions();
				options.DoMergeWithOthers = false;
				options.DoPullFromOthers = false;
				options.DoPushToLocalSources = true;
				options.RepositorySourcesToTry.Clear();
				RepositorySource backupSource = RepositorySource.Create(PathToParentOfRepositories, "backup", false);
				options.RepositorySourcesToTry.Add(backupSource);

				RepositoryManager manager = RepositoryManager.FromRootOrChildFolder(projectFolder);


				if (!RepositoryManager.CheckEnvironmentAndShowMessageIfAppropriate("en"))//todo localization
				{
					Palaso.Reporting.Logger.WriteEvent("Backup not possible: {0}", RepositoryManager.GetEnvironmentReadinessMessage("en"));
					return;
				}


				//TODO: figure out how/what/when to show progress. THis is basically just throwing it away
				IProgress progress = new Chorus.Utilities.StringBuilderProgress();
				manager.SyncNow(options, progress);
			}
			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
			}
			finally
			{
				if(rightToAccessLiftExternally !=null)
				{
					rightToAccessLiftExternally.Dispose();
				}
			}
		}
Esempio n. 39
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);
            }