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();
		}
		public void RestoreProject_OverwriteOnlyDataRestored()
		{
			IThreadedProgress progressDlg = new DummyProgressDlg();
			m_restoreSettings.IncludeConfigurationSettings = false;

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

			//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, FdoFileHelper.GetXmlDataFileName("TestRestoreFWProject"));
			var dateTimeTicksOfFirstFile = GetLastWriteTimeOfRestoredFile(restoreProjectDirectory, FdoFileHelper.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, FdoFileHelper.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();

			RemotingServer.Stop();
		}
		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");
		}
		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);
			}
		}
Exemplo n.º 5
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;
		}
Exemplo n.º 6
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Does the restore.
		/// </summary>
		/// <param name="restoreService">The restore service.</param>
		/// ------------------------------------------------------------------------------------
		private static void DoRestore(ProjectRestoreService restoreService)
		{
			using (var progressDlg = new ProgressDialogWithTask(s_threadHelper))
				restoreService.RestoreProject(progressDlg);
		}
Exemplo n.º 7
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Restores from the backup specified in restoreSettings, replacing the current version
		/// of this project (requires restarting apps and the cache).
		/// </summary>
		/// <param name="restoreSettings">The restore settings.</param>
		/// <param name="dialogOwner">A form that can be used as an owner for progress dialog/
		/// message box.</param>
		/// ------------------------------------------------------------------------------------
		private static void RestoreCurrentProject(FwRestoreProjectSettings restoreSettings,
			Form dialogOwner)
		{
			// When we get here we can safely do the backup of the project because we either
			// have no cache (and no other process has this project open), or we are the
			// process that has this project open. (FWR-3344)
			if (restoreSettings.Settings.BackupOfExistingProjectRequested &&
				!BackupProjectForRestore(restoreSettings, Cache, dialogOwner))
			{
				return;
			}

			ExecuteWithAppsShutDown(restoreSettings.FwAppCommandLineAbbrev, () =>
			{
				bool retry;
				do
				{
					retry = false;
					try
					{
						var restoreService = new ProjectRestoreService(restoreSettings.Settings, s_ui, FwDirectoryFinder.ConverterConsoleExe, FwDirectoryFinder.DbExe);
						Logger.WriteEvent("Restoring from " + restoreSettings.Settings.Backup.File);
						if (RestoreProjectDlg.HandleRestoreFileErrors(null, ResourceHelper.GetResourceString("ksRestoreFailed"),
							restoreSettings.Settings.Backup.File, () => DoRestore(restoreService)))
						{
							s_LinkDirChangedTo = restoreService.LinkDirChangedTo;
							return s_projectId ??
								new ProjectId(ClientServerServices.Current.Local.IdForLocalProject(restoreSettings.Settings.ProjectName), null);
						}
					}
					catch (CannotConvertException e)
					{
						MessageBoxUtils.Show(e.Message, ResourceHelper.GetResourceString("ksRestoreFailed"));
					}
					catch (MissingOldFwException e)
					{
						using (var dlg = new MissingOldFieldWorksDlg(restoreSettings.Settings,
							e.HaveOldFieldWorks, e.HaveFwSqlServer))
						{
							retry = (dlg.ShowDialog() == DialogResult.Retry);
						}
					}
					catch (FailedFwRestoreException e)
					{
						MessageBoxUtils.Show(Properties.Resources.ksRestoringOldFwBackupFailed, Properties.Resources.ksFailed);
					}
				}
				while (retry);

				return null;
			});
		}
		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);
			}
		}
		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);
			}
		}