Пример #1
0
        public void RestoreProject_PutLinkedFilesInOldLocation_CancelSelected()
        {
            m_restoreSettings.IncludeLinkedFiles           = true;
            m_restoreSettings.IncludeConfigurationSettings = true;
            var nonStdLinkedFilesDir = m_restoreSettings.Backup.LinkedFilesPathActualPersisted;

            m_restoreProjectService = new ProjectRestoreTestService(m_restoreSettings);
            ((ProjectRestoreTestService)m_restoreProjectService).PutFilesInProject = true;
            ((ProjectRestoreTestService)m_restoreProjectService).SimulateOKResult  = false;

            var fullVersionOfRelativeNonStdDir = GetFullVersionOfRelativeNonStdDir(nonStdLinkedFilesDir);

            try
            {
                m_restoreProjectService.RestoreProject(new DummyProgressDlg());

                VerifyManditoryFilesUnzippedAndDeleteThem();

                VerifyConfigurationSettingsFilesUnzippedAndDeleteThem();

                var newDir = m_restoreProjectService.LinkDirChangedTo;
                Assert.IsNull(newDir, "Should have left the LinkedFiles directory in the non-standard location.");

                VerifyFileWasUnzippedThenDeleteIt(Path.Combine(fullVersionOfRelativeNonStdDir, "Pictures"), "PoolTable.JPG");
            }
            finally
            {
                RemoveAllFilesFromFolderAndSubfolders(fullVersionOfRelativeNonStdDir);
                RemoveTestRestoreFolder(fullVersionOfRelativeNonStdDir);
            }
        }
Пример #2
0
        public void RestoreProjectSettings_VerifyExistenceOfProject()
        {
            string restoreTestsZipFileDir = Path.Combine(FwDirectoryFinder.SourceDirectory,
                                                         "FDO/FDOTests/BackupRestore/RestoreServiceTestsZipFileDir");

            RestoreProjectSettings restoreSettings = new RestoreProjectSettings(FwDirectoryFinder.ProjectsDirectory)
            {
                Backup = new BackupFileSettings(Path.Combine(restoreTestsZipFileDir,
                                                             Path.ChangeExtension("TestRestoreFWProject", FdoFileHelper.ksFwBackupFileExtension))),
                IncludeConfigurationSettings = false,
                IncludeLinkedFiles           = false,
                IncludeSupportingFiles       = true,
                IncludeSpellCheckAdditions   = false,
                ProjectName = "TestRestoreFWProject 01",
                BackupOfExistingProjectRequested = false,
            };

            ProjectRestoreServiceTests.RemoveAnyFilesAndFoldersCreatedByTests(restoreSettings);
            ProjectRestoreService restoreProjectService = new ProjectRestoreService(restoreSettings, new DummyFdoUI(),
                                                                                    FwDirectoryFinder.ConverterConsoleExe, FwDirectoryFinder.DbExe);

            Assert.False(restoreSettings.ProjectExists, "Project exists but it should not.");

            try
            {
                // Restore the project and check to ensure that it exists.
                restoreProjectService.RestoreProject(new DummyProgressDlg());
                Assert.True(restoreSettings.ProjectExists, "Project does not exist but it should.");
            }
            finally
            {
                ProjectRestoreServiceTests.RemoveAnyFilesAndFoldersCreatedByTests(restoreSettings);
            }
        }
Пример #3
0
        private bool DoRestore()
        {
            m_restoreSettings.ProjectName = textBoxProjectName.Text;

            if (m_restoreSettings.ProjectExists)
            {
                using (var dlg = new ProjectExistsForm(m_restoreSettings.ProjectName))
                {
                    dlg.StartPosition = FormStartPosition.CenterParent;
                    DialogResult result = dlg.ShowDialog();
                    if (result == DialogResult.Cancel)
                    {
                        textBoxProjectName.SelectAll();
                        textBoxProjectName.Focus();
                        return(false);
                    }
                }
            }

            try
            {
                var restoreService = new ProjectRestoreService(m_restoreSettings, m_ui, null, null);
                restoreService.RestoreProject(new ParatextLexiconPluginThreadedProgress(m_ui.SynchronizeInvoke));

                m_selectedItem = new LanguageProjectInfo(m_restoreSettings.FullProjectPath);
            }
            catch
            {
                MessageBox.Show(Strings.ksRestoreProblemText);
                return(false);
            }

            return(true);
        }
Пример #4
0
        public void RestoreProject_CreateNew_OnlyDataFileAndWsFiles()
        {
            m_restoreSettings.ProjectName = "TestRestoreFWProject 01";

            m_restoreProjectService = new ProjectRestoreService(m_restoreSettings, new DummyFdoUI(),
                                                                FwDirectoryFinder.ConverterConsoleExe, FwDirectoryFinder.DbExe);

            m_restoreProjectService.RestoreProject(new DummyProgressDlg());

            VerifyManditoryFilesUnzippedAndDeleteThem();
        }
Пример #5
0
        public void RestoreProject_CreateNew_OnlyDataFileAndWsFiles()
        {
            m_restoreSettings.ProjectName = "TestRestoreFWProject 01";

            RemoveAnyFilesAndFoldersCreatedByTests(m_restoreSettings);
            m_restoreProjectService = new ProjectRestoreService(m_restoreSettings);

            m_restoreProjectService.RestoreProject(new DummyProgressDlg());

            VerifyManditoryFilesUnzippedAndDeleteThem();

            RemoveAnyFilesAndFoldersCreatedByTests(m_restoreSettings);
        }
        private void VerifyDateTimeOfFileMatchesThatOnDisk(ZipFile zip, String fileNameAndPath)
        {
            string   entryName = FileUtils.GetRelativePath(fileNameAndPath, null, m_backupSettings.ProjectPath);
            ZipEntry entry     = zip.GetEntry(entryName);

            var zipEntryDateTime     = entry.DateTime;
            var dateTimeOfFileOnDisk = File.GetLastWriteTime(fileNameAndPath);

            Assert.False(ProjectRestoreService.DateTimeIsMoreThanTwoSecondsNewer(dateTimeOfFileOnDisk, zipEntryDateTime),
                         "The DateTime stamp of file in zipFile should be closer to that on disk.");

            Assert.IsTrue(DateTimesAreWithinACoupleSecondsOfEachOther(zipEntryDateTime, dateTimeOfFileOnDisk),
                          "The DateTime stamp of file in zipFile should be closer to that on disk.");
        }
Пример #7
0
        public void RestoreProject_CreateNew_DataFileAndConfigurationSettings()
        {
            m_restoreSettings.ProjectName = "TestRestoreFWProject 01";
            m_restoreSettings.IncludeConfigurationSettings = true;
            RemoveAnyFilesAndFoldersCreatedByTests(m_restoreSettings);
            m_restoreProjectService = new ProjectRestoreService(m_restoreSettings);

            m_restoreProjectService.RestoreProject(new DummyProgressDlg());

            VerifyManditoryFilesUnzippedAndDeleteThem();

            VerifyConfigurationSettingsFilesUnzippedAndDeleteThem();

            RemoveAnyFilesAndFoldersCreatedByTests(m_restoreSettings);
        }
Пример #8
0
        public void RestoreProjectSettings_VerifyExistenceOfHgRepo()
        {
            string restoreTestsZipFileDir = Path.Combine(FwDirectoryFinder.SourceDirectory,
                                                         "FDO/FDOTests/BackupRestore/RestoreServiceTestsZipFileDir");

            RestoreProjectSettings restoreSettings = new RestoreProjectSettings(FwDirectoryFinder.ProjectsDirectory)
            {
                Backup = new BackupFileSettings(Path.Combine(restoreTestsZipFileDir,
                                                             Path.ChangeExtension("TestRestoreFWProject", FdoFileHelper.ksFwBackupFileExtension))),
                IncludeConfigurationSettings = false,
                IncludeLinkedFiles           = false,
                IncludeSupportingFiles       = true,
                IncludeSpellCheckAdditions   = false,
                ProjectName = "TestRestoreFWProject 01",
                BackupOfExistingProjectRequested = false,
            };

            ProjectRestoreService restoreProjectService = new ProjectRestoreService(restoreSettings, new DummyFdoUI(),
                                                                                    FwDirectoryFinder.ConverterConsoleExe, FwDirectoryFinder.DbExe);

            try
            {
                // Restore the project and check to ensure that it exists, but is not using Send/Receive.
                restoreProjectService.RestoreProject(new DummyProgressDlg());
                Assert.True(restoreSettings.ProjectExists, "Project does not exist but it should.");
                Assert.False(restoreSettings.UsingSendReceive, "Project is using S/R but it should not be.");

                string otherReposDir = Path.Combine(restoreSettings.ProjectPath, FdoFileHelper.OtherRepositories);

                // Create a non-repository folder in OtherRepositories and verify the project is not using Send/Receive
                Directory.CreateDirectory(Path.Combine(otherReposDir, "NotARepo_LIFT", "RandomSubdir"));
                Assert.False(restoreSettings.UsingSendReceive, "Project should not be using S/R if there is no hg repo in OtherRepositories.");

                // Create a hg repository in OtherRepositories and verify the project is using Send/Receive
                Directory.CreateDirectory(Path.Combine(otherReposDir, "IsARepo_ButNotNecessarilyLIFT", ".hg"));
                Assert.True(restoreSettings.UsingSendReceive, "Project should be using S/R if there is a hg repo in OtherRepositories.");
                Directory.Delete(otherReposDir, true);
                Assert.False(restoreSettings.UsingSendReceive, "Project should not be using S/R if there is no hg repo.  Deletion failed?");

                // Make the project directory a hg repo
                Directory.CreateDirectory(Path.Combine(restoreSettings.ProjectPath, ".hg"));
                Assert.True(restoreSettings.UsingSendReceive, "Project should be using S/R if the project directory is a hg repo.");
            }
            finally
            {
                ProjectRestoreServiceTests.RemoveAnyFilesAndFoldersCreatedByTests(restoreSettings);
            }
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Called when a backup version is chosen either by browsing to a zip file.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void OnBackupVersionChosen()
        {
            m_rdoUseOriginalName.Text  = String.Format(m_fmtUseOriginalName, String.Empty);
            m_txtOtherProjectName.Text = String.Empty;
            Settings.Backup            = null;
            if (String.IsNullOrEmpty(BackupZipFile))
            {
                EnableDisableDlgControlsForRestore(false);
                return;
            }

            if (ProjectRestoreService.HandleRestoreFileErrors(this, m_appName, BackupZipFile,
                                                              () => BackupFileSettings = new BackupFileSettings(BackupZipFile, true)))
            {
                SetOriginalNameFromSettings();
            }
            else
            {
                EnableDisableDlgControlsForRestore(false);
            }
        }
Пример #10
0
        public void RestoreProject_OverwriteOnlyDataRestored()
        {
            IThreadedProgress progressDlg = new DummyProgressDlg();

            m_restoreSettings.IncludeConfigurationSettings = false;

            RemoveAnyFilesAndFoldersCreatedByTests(m_restoreSettings);
            m_restoreProjectService = new ProjectRestoreService(m_restoreSettings);

            //Restore the project once and do not delete it so that we can restore the project over the previous one.
            m_restoreProjectService.RestoreProject(progressDlg);

            string restoreProjectDirectory = m_restoreSettings.ProjectPath;

            VerifyFileExists(restoreProjectDirectory, DirectoryFinder.GetXmlDataFileName("TestRestoreFWProject"));
            var dateTimeTicksOfFirstFile = GetLastWriteTimeOfRestoredFile(restoreProjectDirectory, DirectoryFinder.GetXmlDataFileName("TestRestoreFWProject"));

            // Linux filesystem modification time precision can be to the second, so wait a moment.
            if (MiscUtils.IsUnix)
            {
                Thread.Sleep(1000);
            }

            //Verify that the restoreProjectService indicates that the project already exists. The restoreProjectPresenter
            //can then inform the user that the project already exists on disk and gives them the chance to backup before
            //overwriting it.
            Assert.True(m_restoreSettings.ProjectExists, "Project does not exist but it should.");

            //Now do another restore then verify that the two files are not the same by comparing the LastWriteTime values.
            m_restoreProjectService.RestoreProject(progressDlg);

            var dateTimeTicksOfSecondFile = GetLastWriteTimeOfRestoredFile(restoreProjectDirectory, DirectoryFinder.GetXmlDataFileName("TestRestoreFWProject"));

            Assert.True(dateTimeTicksOfSecondFile.Equals(dateTimeTicksOfFirstFile), "The dates and times of the files should be the same since they are set to the timestamp of the file in the zip file.");

            VerifyManditoryFilesUnzippedAndDeleteThem();

            RemoveAnyFilesAndFoldersCreatedByTests(m_restoreSettings);
            RemotingServer.Stop();
        }
Пример #11
0
        public void RestoreProject_PutLinkedFilesInDefaultLocation()
        {
            m_restoreSettings.IncludeLinkedFiles           = true;
            m_restoreSettings.IncludeConfigurationSettings = true;
            var defaultLinkedFilesDir = m_restoreSettings.LinkedFilesPath;

            m_restoreProjectService = new ProjectRestoreTestService(m_restoreSettings);
            ((ProjectRestoreTestService)m_restoreProjectService).PutFilesInProject = true;

            m_restoreProjectService.RestoreProject(new DummyProgressDlg());

            VerifyManditoryFilesUnzippedAndDeleteThem();

            VerifyConfigurationSettingsFilesUnzippedAndDeleteThem();

            var newDir = m_restoreProjectService.LinkDirChangedTo;

            Assert.AreEqual(defaultLinkedFilesDir, newDir,
                            "Should have changed the LinkedFiles directory to the default location.");

            VerifyFileWasUnzippedThenDeleteIt(Path.Combine(m_restoreProjectService.LinkDirChangedTo, "Pictures"), "PoolTable.JPG");
        }