Пример #1
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Constructor for normal mode where the user can pick a backup to restore
		/// </summary>
		/// <param name="restoreProjectView">The restore project view.</param>
		/// <param name="defaultProjectName">Default name of the project.</param>
		/// ------------------------------------------------------------------------------------
		public RestoreProjectPresenter(RestoreProjectDlg restoreProjectView,
			string defaultProjectName) : this(restoreProjectView)
		{
			m_backupFiles = new BackupFileRepository(FwDirectoryFinder.DefaultBackupDirectory);
			m_defaultProjectName = defaultProjectName;
			m_fEmptyProjectName = false;
		}
Пример #2
0
		private void get_Last_Backup()
		{
			BackupFileRepository backups = new BackupFileRepository(FwDirectoryFinder.DefaultBackupDirectory);
			var projName = backups.AvailableProjectNames.FirstOrDefault(s => s == m_cache.ProjectId.Name);

			if (!string.IsNullOrEmpty(projName))
			{
				var fileDate = backups.GetAvailableVersions(projName).FirstOrDefault();
				if (fileDate != default(DateTime))
				{
					var backup = backups.GetBackupFile(projName, fileDate, true);

					if (backup != null)
					{
						m_lblMostRecentBackup.Text = fileDate.ToString(Thread.CurrentThread.CurrentCulture);
						m_lastBackupFile = backup.File;
						return;
					}
				}
			}

			// no backup found if you are here
			m_rbNewBackup.Checked = true;
			m_rbExistingBackup.Visible = false;
			m_lblMostRecentBackup.Visible = false;
		}
		public void NoBackupFilesAvailable()
		{
			m_fileOs.ExistingDirectories.Add(FwDirectoryFinder.DefaultBackupDirectory);

			BackupFileRepository repo = new BackupFileRepository(FwDirectoryFinder.DefaultBackupDirectory);
			Assert.AreEqual(0, repo.AvailableProjectNames.Count());
			Assert.Throws(typeof(KeyNotFoundException), () => repo.GetAvailableVersions("monkey"));
			Assert.Throws(typeof(KeyNotFoundException), () => repo.GetBackupFile("monkey", DateTime.Now, false));
			Assert.IsNull(repo.GetMostRecentBackup("monkey"));
		}
		public void BackupsForSingleProjectExists()
		{
			DummyBackupProjectSettings backupSettings = new DummyBackupProjectSettings("monkey",
				"Floozy", null, FDOBackendProviderType.kXML);
			string backupFileName1 = backupSettings.ZipFileName;
			m_fileOs.AddExistingFile(backupFileName1);
			// Force the second backup to appear to be older
			backupSettings.BackupTime = backupSettings.BackupTime.AddHours(-3);
			string backupFileName2 = backupSettings.ZipFileName;
			m_fileOs.AddExistingFile(backupFileName2);

			BackupFileRepository repo = new BackupFileRepository(FwDirectoryFinder.DefaultBackupDirectory);
			Assert.AreEqual(1, repo.AvailableProjectNames.Count());
			Assert.AreEqual(2, repo.GetAvailableVersions("Floozy").Count());
			Assert.AreEqual(backupFileName2, repo.GetBackupFile("Floozy", backupSettings.BackupTime, false).File);
			Assert.AreEqual(backupFileName1, repo.GetMostRecentBackup("Floozy").File);

			Assert.Throws(typeof(KeyNotFoundException), () => repo.GetAvailableVersions("monkey"));
			Assert.Throws(typeof(KeyNotFoundException), () => repo.GetBackupFile("monkey", backupSettings.BackupTime, false));
			Assert.Throws(typeof(KeyNotFoundException), () => repo.GetBackupFile("Floozy", DateTime.MinValue, false));
			Assert.IsNull(repo.GetMostRecentBackup("monkey"));
		}
		public void BackupHasOldStyleDatetimeFormat()
		{
			DummyBackupProjectSettings backupSettings = new DummyBackupProjectSettings("monkey",
				"Floozy", null, FDOBackendProviderType.kXML);
			string backupFileName1 = Path.Combine(FwDirectoryFinder.DefaultBackupDirectory,
				Path.ChangeExtension("Floozy 2010-8-21-0506", FdoFileHelper.ksFwBackupFileExtension));
			m_fileOs.AddExistingFile(backupFileName1);

			BackupFileRepository repo = new BackupFileRepository(FwDirectoryFinder.DefaultBackupDirectory);
			Assert.AreEqual(1, repo.AvailableProjectNames.Count());
			Assert.AreEqual(1, repo.GetAvailableVersions("Floozy").Count());
			Assert.AreEqual(backupFileName1, repo.GetMostRecentBackup("Floozy").File);
		}
		public void BackupsForMultipleProjects()
		{
			DummyBackupProjectSettings backupSettings = new DummyBackupProjectSettings("monkey",
				"AAA", null, FDOBackendProviderType.kXML);
			backupSettings.Comment = "thing1";
			string backupFileName1 = backupSettings.ZipFileName;
			m_fileOs.AddExistingFile(backupFileName1);
			backupSettings.ProjectName = "ZZZ";
			backupSettings.Comment = "thing2";
			string backupFileName2 = backupSettings.ZipFileName;
			m_fileOs.AddExistingFile(backupFileName2);
			// Add another backup for "AAA" that appears to be older
			backupSettings.ProjectName = "AAA";
			backupSettings.Comment = null;
			backupSettings.BackupTime = backupSettings.BackupTime.AddHours(-3);
			string backupFileName3 = backupSettings.ZipFileName;
			m_fileOs.AddExistingFile(backupFileName3);

			BackupFileRepository repo = new BackupFileRepository(FwDirectoryFinder.DefaultBackupDirectory);
			Assert.AreEqual(2, repo.AvailableProjectNames.Count());
			Assert.AreEqual(2, repo.GetAvailableVersions("AAA").Count());
			Assert.AreEqual(1, repo.GetAvailableVersions("ZZZ").Count());
			BackupFileSettings fileSettings = repo.GetBackupFile("AAA", backupSettings.BackupTime, false);
			Assert.AreEqual(backupFileName3, fileSettings.File);
			Assert.AreEqual(string.Empty, fileSettings.Comment);
			fileSettings = repo.GetMostRecentBackup("AAA");
			Assert.AreEqual(backupFileName1, fileSettings.File);
			Assert.AreEqual("thing1", fileSettings.Comment);
			fileSettings = repo.GetMostRecentBackup("ZZZ");
			Assert.AreEqual(backupFileName2, fileSettings.File);
			Assert.AreEqual("thing2", fileSettings.Comment);
		}
		public void InavlidBackupFile()
		{
			DummyBackupProjectSettings backupSettings = new DummyBackupProjectSettings("monkey",
				"Floozy", null, FDOBackendProviderType.kXML);
			string backupFileName1 = backupSettings.ZipFileName;
			m_fileOs.AddExistingFile(backupFileName1);
			// Force the second backup to appear to be older
			backupSettings.BackupTime = backupSettings.BackupTime.AddHours(-3);
			string backupFileName2 = backupSettings.ZipFileName;
			m_fileOs.AddExistingFile(backupFileName2);

			BackupFileRepository repo = new BackupFileRepository(FwDirectoryFinder.DefaultBackupDirectory);
			BackupFileSettings invalidFileSettings = repo.GetMostRecentBackup("Floozy");
			BackupFileSettings validFileSettings = repo.GetBackupFile("Floozy", backupSettings.BackupTime, false);
			ReflectionHelper.SetProperty(validFileSettings, "ProjectName", "Floozy"); // Force it to think it's already loaded and happy.

			Assert.AreEqual(2, repo.GetAvailableVersions("Floozy").Count());
			Assert.IsNull(repo.GetBackupFile("Floozy", invalidFileSettings.BackupTime, true));
			Assert.AreEqual(1, repo.GetAvailableVersions("Floozy").Count());
			Assert.AreEqual(validFileSettings, repo.GetBackupFile("Floozy", validFileSettings.BackupTime, true));
			Assert.AreEqual(1, repo.GetAvailableVersions("Floozy").Count());
		}