Пример #1
0
        public void LargeMp3FileIsNotAllowed()
        {
            using (var bob = new RepositorySetup("bob"))
            {
                const string fileName         = "whopper.Mp3";
                var          megabyteLongData = "long" + Environment.NewLine;
                while (megabyteLongData.Length < LargeFileFilter.Megabyte)
                {
                    megabyteLongData += megabyteLongData;
                }
                bob.ChangeFile(fileName, megabyteLongData);
                var fullPathname = Path.Combine(bob.ProjectFolderConfig.FolderPath, fileName);
                var pathToRepo   = bob.Repository.PathToRepo + Path.DirectorySeparatorChar;
                bob.Repository.TestOnlyAddSansCommit(fileName);
                var config = bob.ProjectFolderConfig;
                config.ExcludePatterns.Clear();
                config.IncludePatterns.Clear();
                LiftFolder.AddLiftFileInfoToFolderConfiguration(config);

                var result = LargeFileFilter.FilterFiles(
                    bob.Repository,
                    config,
                    ChorusFileTypeHandlerCollection.CreateWithInstalledHandlers());
                Assert.IsFalse(string.IsNullOrEmpty(result));
                var shortpath = fullPathname.Replace(pathToRepo, "");
                Assert.IsTrue(config.ExcludePatterns.Contains(shortpath));
                Assert.IsFalse(config.IncludePatterns.Contains(shortpath));
            }
        }
Пример #2
0
        public void IncludeFilesInSubFolders()
        {
            using (var setup = new RepositorySetup("Dan"))
            {
                var subpictures = setup.ProjectFolder.Combine("pictures", "subpictures");
                Directory.CreateDirectory(subpictures);
                var goodpicture = setup.ProjectFolder.Combine(subpictures, "good.picture");
                File.WriteAllText(goodpicture, "hello");                 // Not a real jpeg file

                var subaudio = setup.ProjectFolder.Combine("audio", "subaudio");
                Directory.CreateDirectory(subaudio);
                var goodaudio = setup.ProjectFolder.Combine(subaudio, "good.audio");
                File.WriteAllText(goodaudio, "hello");                 // Not a real mp3 file

                var subothers = setup.ProjectFolder.Combine("others", "subothers");
                Directory.CreateDirectory(subothers);
                var goodother = setup.ProjectFolder.Combine(subothers, "good.other");
                File.WriteAllText(goodother, "hello");

                setup.ProjectFolderConfig.ExcludePatterns.Clear();
                setup.ProjectFolderConfig.IncludePatterns.Clear();

                LiftFolder.AddLiftFileInfoToFolderConfiguration(setup.ProjectFolderConfig);

                setup.AddAndCheckIn();
                setup.AssertFileExistsInRepository("pictures/subpictures/good.picture");
                setup.AssertFileExistsInRepository("audio/subaudio/good.audio");
                setup.AssertFileExistsInRepository("others/subothers/good.other");
            }
        }
Пример #3
0
        public void ExcludedVideosFileNotAdded()
        {
            using (var setup = new RepositorySetup("Dan"))
            {
                var atRoot = setup.ProjectFolder.Combine("first.wmv");
                File.WriteAllText(atRoot, "hello");

                var pictures = setup.ProjectFolder.Combine("pictures");
                Directory.CreateDirectory(pictures);
                var videoExtensions = ProjectFolderConfiguration.VideoExtensions.ToList();
                foreach (var videoExtension in videoExtensions)
                {
                    var bad = Path.Combine(pictures, "nested." + videoExtension);
                    File.WriteAllText(bad, "hello");
                }

                setup.ProjectFolderConfig.ExcludePatterns.Clear();
                setup.ProjectFolderConfig.IncludePatterns.Clear();

                LiftFolder.AddLiftFileInfoToFolderConfiguration(setup.ProjectFolderConfig);

                setup.AddAndCheckIn();
                setup.AssertFileDoesNotExistInRepository("first.wmv");
                foreach (var videoExtension in videoExtensions)
                {
                    setup.AssertFileDoesNotExistInRepository("pictures/nested." + videoExtension);
                }
            }
        }
        private void InstallExistingSystemControl()
        {
            if (_startupNewView != null)
            {
                _startupNewView.Startup -= Startup;
            }

            var chorusSystem = new ChorusSystem(LiftProjectServices.PathToProject(Liftproject), Environment.UserName);

            LiftFolder.AddLiftFileInfoToFolderConfiguration(chorusSystem.ProjectFolderConfiguration);
            _existingSystemView.SetSystem(chorusSystem, Liftproject);
            _liftBridgeView.ActivateView(_existingSystemView);
            _existingSystemView.ImportLexicon      += OnImportLexicon;
            _existingSystemView.ExportLexicon      += OnExportLexicon;
            _existingSystemView.BasicImportLexicon += OnBasicImport;
        }
Пример #5
0
        public void IncludeInGeneralButExcludeInSubfolder_FileNotAdded()
        {
            using (var setup = new RepositorySetup("Dan"))
            {
                var good = setup.ProjectFolder.Combine("good.lift");
                File.WriteAllText(good, "hello");

                var export = setup.ProjectFolder.Combine("export");
                Directory.CreateDirectory(export);
                var bad = Path.Combine(export, "bad.lift");
                File.WriteAllText(bad, "hello");

                var goodFontCss = Path.Combine(export, "customFonts.css");
                File.WriteAllText(goodFontCss, "hello");

                var goodLayoutCss = Path.Combine(export, "customLayout.css");
                File.WriteAllText(goodLayoutCss, "hello");

                var other = setup.ProjectFolder.Combine("other");
                Directory.CreateDirectory(other);
                var otherBad = Path.Combine(export, "otherBad.lift");
                File.WriteAllText(otherBad, "hello");

                setup.ProjectFolderConfig.ExcludePatterns.Clear();
                setup.ProjectFolderConfig.IncludePatterns.Clear();

                LiftFolder.AddLiftFileInfoToFolderConfiguration(setup.ProjectFolderConfig);

                setup.AddAndCheckIn();
                setup.AssertFileExistsInRepository("good.lift");
                setup.AssertFileExistsInRepository("export/customFonts.css");
                setup.AssertFileExistsInRepository("export/customLayout.css");
                setup.AssertFileDoesNotExistInRepository("export/bad.lift");
                setup.AssertFileDoesNotExistInRepository("other/otherBad.lift");
            }
        }
Пример #6
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
            }
        }