public void OnlyOneCacheAllowed() { string filename = DirectoryFinder.GetXmlDataFileName("TestLangProj"); Assert.True(File.Exists(filename), "Test XML file not found"); using (FdoCache cache = OpenExistingFile(filename)) Assert.Fail("Able to open XML file that is already open"); }
public void IsValid_XML_True() { const string sProjectName = "monkey"; string sFile = DirectoryFinder.GetXmlDataFileName(sProjectName); m_mockFileOs.AddExistingFile(GetXmlProjectFilename(sProjectName)); ProjectId proj = new ProjectId("xml", sFile, null); Assert.IsTrue(proj.IsValid); }
public void AssertValid_Valid() { string projFile = GetXmlProjectFilename("monkey"); m_mockFileOs.AddExistingFile(projFile); var proj = new ProjectId(DirectoryFinder.GetXmlDataFileName("monkey"), null); proj.AssertValid(); // no exception should be thrown here for a valid project. }
public void IsValid_NullType() { const string sProjectName = "monkey"; string sFile = DirectoryFinder.GetXmlDataFileName(sProjectName); m_mockFileOs.AddExistingFile(GetXmlProjectFilename(sProjectName)); ProjectId proj = new ProjectId(null, sFile, null); Assert.AreEqual(FDOBackendProviderType.kXML, proj.Type); Assert.IsTrue(proj.IsValid); }
public void CleanUpNameForType_XML_FullPath() { string expectedPath = Path.Combine(DirectoryFinder.ProjectsDirectory, DirectoryFinder.GetXmlDataFileName("monkey")); m_mockFileOs.AddExistingFile(expectedPath); var proj = new ProjectId(expectedPath, null); Assert.AreEqual(expectedPath, proj.Path); Assert.AreEqual(FDOBackendProviderType.kXML, proj.Type); Assert.IsTrue(proj.IsValid); }
public void CleanUpNameForType_XML_onlyNameWithExtension() { string expectedPath = GetXmlProjectFilename("monkey"); m_mockFileOs.AddExistingFile(expectedPath); var proj = new ProjectId(DirectoryFinder.GetXmlDataFileName("monkey"), null); Assert.AreEqual(expectedPath, proj.Path); Assert.AreEqual(FDOBackendProviderType.kXML, proj.Type); Assert.IsTrue(proj.IsValid); }
public void NameAndPath() { string myProjectFolder = Path.Combine(DirectoryFinder.ProjectsDirectory, "My.Project"); ProjectId projId = new ProjectId(FDOBackendProviderType.kXML, "My.Project", null); Assert.AreEqual(Path.Combine(myProjectFolder, DirectoryFinder.GetXmlDataFileName("My.Project")), projId.Path); Assert.AreEqual("My.Project", projId.Name); projId = new ProjectId(FDOBackendProviderType.kDb4oClientServer, "My.Project", null); Assert.AreEqual(Path.Combine(myProjectFolder, DirectoryFinder.GetDb4oDataFileName("My.Project")), projId.Path); Assert.AreEqual("My.Project", projId.Name); }
public void AssertValid_InvalidProjectType() { var proj = new ProjectId(FDOBackendProviderType.kInvalid, DirectoryFinder.GetXmlDataFileName("invalid"), null); try { proj.AssertValid(); Assert.Fail("FwStartupException expected"); } catch (FwStartupException exception) { Assert.IsTrue(exception.ReportToUser); } }
public void CleanUpNameForType_XML_NameWithPeriod_FilesWithAndWithoutExtensionExist() { string myMonkeyProjectFolder = Path.Combine(DirectoryFinder.ProjectsDirectory, "my.monkey"); string expectedPath = Path.Combine(myMonkeyProjectFolder, DirectoryFinder.GetXmlDataFileName("my.monkey")); m_mockFileOs.AddExistingFile(expectedPath); m_mockFileOs.AddExistingFile(Path.Combine(myMonkeyProjectFolder, "my.monkey")); var proj = new ProjectId("my.monkey", null); Assert.AreEqual(expectedPath, proj.Path); Assert.AreEqual(FDOBackendProviderType.kXML, proj.Type); Assert.IsTrue(proj.IsValid); }
public void AssertValid_Invalid_FileNotFound() { var proj = new ProjectId(DirectoryFinder.GetXmlDataFileName("notfound"), null); try { proj.AssertValid(); Assert.Fail("FwStartupException expected"); } catch (FwStartupException exception) { Assert.IsTrue(exception.ReportToUser); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Override to create and load a very basic cache. /// </summary> /// ------------------------------------------------------------------------------------ protected override FdoCache CreateCache() { const string projName = "TestLangProj-test"; string filename = Path.Combine(DirectoryFinder.ProjectsDirectory, Path.Combine(projName, DirectoryFinder.GetXmlDataFileName(projName))); if (!m_internalRestart) { if (File.Exists(filename)) { File.Delete(filename); } } return(BootstrapSystem(new TestProjectId(FDOBackendProviderType.kXMLWithMemoryOnlyWsMgr, filename), m_loadType)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Uncompress the FieldWorks project data file. /// </summary> /// ------------------------------------------------------------------------------------ private void UncompressDataFile() { using (var zipIn = OpenFWBackupZipfile()) { ZipEntry entry; while ((entry = zipIn.GetNextEntry()) != null) { var fileName = Path.GetFileName(entry.Name); if (fileName == DirectoryFinder.GetXmlDataFileName(m_restoreSettings.Backup.ProjectName)) { UnzipFileToRestoreFolder(zipIn, m_restoreSettings.DbFilename, entry.Size, m_restoreSettings.ProjectPath, entry.DateTime); break; } } string bakFile = Path.Combine(m_restoreSettings.ProjectPath, m_restoreSettings.ProjectName) + FwFileExtensions.ksFwDataFallbackFileExtension; if (FileUtils.TrySimilarFileExists(bakFile, out bakFile)) { FileUtils.Delete(bakFile); // TODO: do something about the .Lock file....... } } }
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(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Check full path after first rename for the RenameDatabaseTest test. /// </summary> /// ------------------------------------------------------------------------------------ protected override void CheckAdditionalStuffAfterFirstRename() { Assert.AreEqual(Path.Combine(Path.Combine(DirectoryFinder.ProjectsDirectory, ksNewProjectName), DirectoryFinder.GetXmlDataFileName(ksNewProjectName)), Cache.ProjectId.Path); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="BEPPortTests"/> class. /// </summary> /// ------------------------------------------------------------------------------------ public BEPPortTests() { m_sourceInfo = new List <BackendStartupParameter> { new BackendStartupParameter(true, BackendBulkLoadDomain.All, new TestProjectId(FDOBackendProviderType.kXML, DirectoryFinder.GetXmlDataFileName("TLP"))), new BackendStartupParameter(true, BackendBulkLoadDomain.All, new TestProjectId(FDOBackendProviderType.kMemoryOnly, null)), new BackendStartupParameter(true, BackendBulkLoadDomain.All, new TestProjectId(FDOBackendProviderType.kDb4oClientServer, "TLPCS")) }; m_targetInfo = new List <BackendStartupParameter> { new BackendStartupParameter(true, BackendBulkLoadDomain.All, new TestProjectId(FDOBackendProviderType.kXML, DirectoryFinder.GetXmlDataFileName("TLP_New"))), new BackendStartupParameter(true, BackendBulkLoadDomain.All, new TestProjectId(FDOBackendProviderType.kMemoryOnly, null)), new BackendStartupParameter(true, BackendBulkLoadDomain.All, new TestProjectId(FDOBackendProviderType.kDb4oClientServer, "TLPCS_New")) }; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Searches the host for any projects. /// Any projects found fire the projectFoundCallback delegate. /// Any exception that is thrown is passed to the exceptionCallback delegate. /// </summary> /// ------------------------------------------------------------------------------------ private void FindProjects() { try { // if we were asked to (typically host is our local machine) show fwdata files. if (m_fShowLocalProjects) { // search sub dirs string[] dirs = Directory.GetDirectories(DirectoryFinder.ProjectsDirectory); foreach (string dir in dirs) { string file = Path.Combine(dir, DirectoryFinder.GetXmlDataFileName(Path.GetFileName(dir))); if (FileUtils.SimilarFileExists(file)) { m_projectFoundCallback(file); } else { string db4oFile = Path.Combine(dir, DirectoryFinder.GetDb4oDataFileName(Path.GetFileName(dir))); //If the db4o file exists it will be added to the list later and therefore we do not want to //show the .bak file to the user in the open project dialog if (!FileUtils.SimilarFileExists(db4oFile)) { // See if there is a .bak file string backupFile = Path.ChangeExtension(file, FwFileExtensions.ksFwDataFallbackFileExtension); //NOTE: RickM I think this probably should be changed to TrySimilarFileExists but don't want to try this //on a release build. if (FileUtils.SimilarFileExists(backupFile)) { m_projectFoundCallback(backupFile); } } } if (m_forceStop) { return; } } if (!ClientServerServices.Current.Local.ShareMyProjects) { return; } } // if host is not local machine OR ShareMyProjects is true show client server files. foreach (string fullServerPath in ClientServerServices.Current.ProjectNames(m_host, true)) { // The current strategy for handling directory seperator chars in a system where // client and servers are different platforms is to convert seperator chars back and // forth when crossing the platform boundary. string adjustedfullServerPath = fullServerPath.Replace(MiscUtils.IsUnix ? @"\" : @"/", Path.DirectorySeparatorChar.ToString()); m_projectFoundCallback(adjustedfullServerPath); if (m_forceStop) { return; } } } catch (Exception e) { if (m_exceptionCallback != null) { m_exceptionCallback(e); } } if (!m_forceStop && m_onCompletedCallback != null) { m_onCompletedCallback(); } }
public void CreateNewLangProject_DbFilesExist() { var preExistingDirs = new List <string>(Directory.GetDirectories(DirectoryFinder.ProjectsDirectory)); string[] postExistingDirs = null; try { // Setup: Create "pre-existing" DB filenames using (new DummyFileMaker(Path.Combine( Path.Combine(DirectoryFinder.ProjectsDirectory, "Gumby"), DirectoryFinder.GetXmlDataFileName("Gumby")))) { using (var threadHelper = new ThreadHelper()) FdoCache.CreateNewLangProj(new DummyProgressDlg(), "Gumby", threadHelper); } } finally { RemoveTestDirs(preExistingDirs, Directory.GetDirectories(DirectoryFinder.ProjectsDirectory)); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the XML project filename (in an appropriately named subfolder of the Projects /// folder). /// </summary> /// <param name="projectName">Name of the project.</param> /// ------------------------------------------------------------------------------------ public static string GetXmlProjectFilename(string projectName) { return(Path.Combine(Path.Combine(DirectoryFinder.ProjectsDirectory, projectName), DirectoryFinder.GetXmlDataFileName(projectName))); }
private static string DbFilename(string dbName) { return(Path.Combine(DbDirectory(dbName), DirectoryFinder.GetXmlDataFileName(dbName))); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Extract the backup settings from the zipfile. /// </summary> /// <exception cref="IOException">File does not exist, or some such problem</exception> /// <exception cref="InvalidBackupFileException">XML deserialization problem or required /// files not found in zip file</exception> /// ------------------------------------------------------------------------------------ private void PopulateSettingsFromZipFileIfNeeded() { if (m_projectName != null) { return; } string extension = Path.GetExtension(m_sZipFileName).ToLowerInvariant(); if (extension == FwFileExtensions.ksFw60BackupFileExtension) { ProcessOldZipFile(); return; } if (extension == ".xml") { ProcessOldXmlFile(); return; } using (var zipIn = new ZipInputStream(FileUtils.OpenStreamForRead(m_sZipFileName))) { try { ZipEntry entry; bool foundBackupSettingsFile = false; bool foundWritingSystemFiles = false; string dataFileName = null; while ((entry = zipIn.GetNextEntry()) != null) { string fileName = Path.GetFileName(entry.Name); if (String.IsNullOrEmpty(fileName)) { continue; } if (fileName.Equals(DirectoryFinder.kBackupSettingsFilename)) { if (foundBackupSettingsFile) { throw new InvalidOperationException("Zip file " + m_sZipFileName + " contained multiple " + DirectoryFinder.kBackupSettingsFilename + " files."); } foundBackupSettingsFile = true; InitializeFromStream(zipIn); } else if (Path.GetExtension(fileName) == FwFileExtensions.ksFwDataXmlFileExtension) { if (dataFileName != null) { throw new InvalidOperationException("Zip file " + m_sZipFileName + " contained multiple project data files."); } dataFileName = fileName; } else if (!entry.Name.EndsWith("/") && entry.Name.Contains(DirectoryFinder.ksWritingSystemsDir + "/")) { foundWritingSystemFiles = true; } } if (!foundBackupSettingsFile) { throw new InvalidOperationException("Zip file " + m_sZipFileName + " did not contain the " + DirectoryFinder.kBackupSettingsFilename + " file."); } if (m_projectName == null) { throw new InvalidOperationException(DirectoryFinder.kBackupSettingsFilename + " in " + m_sZipFileName + " did not contain a project name."); } string expectedProjectFile = DirectoryFinder.GetXmlDataFileName(m_projectName); if (dataFileName == null || dataFileName != expectedProjectFile) { throw new InvalidOperationException("Zip file " + m_sZipFileName + " did not contain the " + expectedProjectFile + " file."); } if (!foundWritingSystemFiles) { throw new InvalidOperationException("Zip file " + m_sZipFileName + " did not contain any writing system files."); } } catch (Exception e) { if (e is SharpZipBaseException || e is InvalidOperationException || e is SerializationException) { throw new InvalidBackupFileException(m_sZipFileName, e); } throw; } } }