Esempio n. 1
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Uncompress the FieldWorks project data file and the Questions files.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 private void UncompressDataFiles()
 {
     using (var zipIn = OpenFWBackupZipfile())
     {
         ZipEntry entry;
         while ((entry = zipIn.GetNextEntry()) != null)
         {
             var fileName = Path.GetFileName(entry.Name);
             if (fileName == FdoFileHelper.GetXmlDataFileName(m_restoreSettings.Backup.ProjectName))
             {
                 UnzipFileToRestoreFolder(zipIn, m_restoreSettings.DbFilename, entry.Size,
                                          m_restoreSettings.ProjectPath, entry.DateTime);
             }
             if (fileName == m_restoreSettings.QuestionNotesFilename)
             {
                 UnzipFileToRestoreFolder(zipIn, m_restoreSettings.QuestionNotesFilename, entry.Size,
                                          m_restoreSettings.ProjectPath, entry.DateTime);
             }
         }
         string bakFile = Path.Combine(m_restoreSettings.ProjectPath, m_restoreSettings.ProjectName)
                          + FdoFileHelper.ksFwDataFallbackFileExtension;
         if (FileUtils.TrySimilarFileExists(bakFile, out bakFile))
         {
             FileUtils.Delete(bakFile);                     // TODO: do something about the .Lock file.......
         }
     }
 }
Esempio n. 2
0
        public void IsValid_XML_True()
        {
            const string sProjectName = "monkey";
            string       sFile        = FdoFileHelper.GetXmlDataFileName(sProjectName);

            m_mockFileOs.AddExistingFile(GetXmlProjectFilename(sProjectName));
            ProjectId proj = new ProjectId("xml", sFile, null);

            Assert.IsTrue(proj.IsValid);
        }
Esempio n. 3
0
        public void AssertValid_Valid()
        {
            string projFile = GetXmlProjectFilename("monkey");

            m_mockFileOs.AddExistingFile(projFile);

            var proj = new ProjectId(FdoFileHelper.GetXmlDataFileName("monkey"), null);

            proj.AssertValid();             // no exception should be thrown here for a valid project.
        }
Esempio n. 4
0
        public void IsValid_NullType()
        {
            const string sProjectName = "monkey";
            string       sFile        = FdoFileHelper.GetXmlDataFileName(sProjectName);

            m_mockFileOs.AddExistingFile(GetXmlProjectFilename(sProjectName));
            ProjectId proj = new ProjectId(null, sFile, null);

            Assert.AreEqual(FDOBackendProviderType.kXML, proj.Type);
            Assert.IsTrue(proj.IsValid);
        }
Esempio n. 5
0
        public void NameAndPath()
        {
            string    myProjectFolder = Path.Combine(FwDirectoryFinder.ProjectsDirectory, "My.Project");
            ProjectId projId          = new ProjectId(FDOBackendProviderType.kXML, "My.Project", null);

            Assert.AreEqual(Path.Combine(myProjectFolder, FdoFileHelper.GetXmlDataFileName("My.Project")), projId.Path);
            Assert.AreEqual("My.Project", projId.Name);

            projId = new ProjectId(FDOBackendProviderType.kDb4oClientServer, "My.Project", null);
            Assert.AreEqual(Path.Combine(myProjectFolder, FdoFileHelper.GetDb4oDataFileName("My.Project")), projId.Path);
            Assert.AreEqual("My.Project", projId.Name);
        }
Esempio n. 6
0
        public void CleanUpNameForType_XML_FullPath()
        {
            string expectedPath = Path.Combine(FwDirectoryFinder.ProjectsDirectory, FdoFileHelper.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);
        }
Esempio n. 7
0
        public void CleanUpNameForType_XML_onlyNameWithExtension()
        {
            string expectedPath = GetXmlProjectFilename("monkey");

            m_mockFileOs.AddExistingFile(expectedPath);

            var proj = new ProjectId(FdoFileHelper.GetXmlDataFileName("monkey"), null);

            Assert.AreEqual(expectedPath, proj.Path);
            Assert.AreEqual(FDOBackendProviderType.kXML, proj.Type);
            Assert.IsTrue(proj.IsValid);
        }
Esempio n. 8
0
        public void AssertValid_InvalidProjectType()
        {
            var proj = new ProjectId(FDOBackendProviderType.kInvalid, FdoFileHelper.GetXmlDataFileName("invalid"), null);

            try
            {
                proj.AssertValid();
                Assert.Fail("FwStartupException expected");
            }
            catch (StartupException exception)
            {
                Assert.IsTrue(exception.ReportToUser);
            }
        }
Esempio n. 9
0
        public void AssertValid_Invalid_FileNotFound()
        {
            var proj = new ProjectId(FdoFileHelper.GetXmlDataFileName("notfound"), null);

            try
            {
                proj.AssertValid();
                Assert.Fail("FwStartupException expected");
            }
            catch (StartupException exception)
            {
                Assert.IsTrue(exception.ReportToUser);
            }
        }
Esempio n. 10
0
        public void CleanUpNameForType_XML_NameWithPeriod_FilesWithAndWithoutExtensionExist()
        {
            string myMonkeyProjectFolder = Path.Combine(FwDirectoryFinder.ProjectsDirectory, "my.monkey");
            string expectedPath          = Path.Combine(myMonkeyProjectFolder, FdoFileHelper.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);
        }
Esempio n. 11
0
        private BackendStartupParameter GenerateBackendStartupParameters(bool isTarget, FDOBackendProviderType type)
        {
            var    nameSuffix = (isTarget ? "_New" : "") + m_random.Next(1000);
            string name       = null;

            switch (type)
            {
            case FDOBackendProviderType.kXML:
                name = FdoFileHelper.GetXmlDataFileName("TLP" + nameSuffix);
                break;

            case FDOBackendProviderType.kDb4oClientServer:
                name = "TLPCS" + nameSuffix;
                break;
                //case FDOBackendProviderType.kMemoryOnly: name = null;
            }

            return(new BackendStartupParameter(true, BackendBulkLoadDomain.All, new TestProjectId(type, name)));
        }
Esempio n. 12
0
        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();
        }
Esempio n. 13
0
 /// ------------------------------------------------------------------------------------
 /// <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(FwDirectoryFinder.ProjectsDirectory, projectName),
                         FdoFileHelper.GetXmlDataFileName(projectName)));
 }
Esempio n. 14
0
 /// ------------------------------------------------------------------------------------
 /// <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(m_projectsDir);
             foreach (string dir in dirs)
             {
                 string file = Path.Combine(dir, FdoFileHelper.GetXmlDataFileName(Path.GetFileName(dir)));
                 if (FileUtils.SimilarFileExists(file))
                 {
                     m_projectFoundCallback(file);
                 }
                 else
                 {
                     string db4oFile = Path.Combine(dir, FdoFileHelper.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, FdoFileHelper.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();
     }
 }
Esempio n. 15
0
        /// ------------------------------------------------------------------------------------
        /// <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 == FdoFileHelper.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(FdoFileHelper.kBackupSettingsFilename))
                        {
                            if (foundBackupSettingsFile)
                            {
                                throw new InvalidOperationException("Zip file " + m_sZipFileName + " contained multiple " +
                                                                    FdoFileHelper.kBackupSettingsFilename + " files.");
                            }
                            foundBackupSettingsFile = true;
                            InitializeFromStream(zipIn);
                        }
                        else if (Path.GetExtension(fileName) == FdoFileHelper.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(FdoFileHelper.ksWritingSystemsDir + "/"))
                        {
                            foundWritingSystemFiles = true;
                        }
                    }

                    if (!foundBackupSettingsFile)
                    {
                        throw new InvalidOperationException("Zip file " + m_sZipFileName + " did not contain the " +
                                                            FdoFileHelper.kBackupSettingsFilename + " file.");
                    }
                    if (m_projectName == null)
                    {
                        throw new InvalidOperationException(FdoFileHelper.kBackupSettingsFilename + " in " +
                                                            m_sZipFileName + " did not contain a project name.");
                    }
                    string expectedProjectFile = FdoFileHelper.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;
                }
            }
        }
Esempio n. 16
0
 private static string DbFilename(string dbName)
 {
     return(Path.Combine(DbDirectory(dbName), FdoFileHelper.GetXmlDataFileName(dbName)));
 }
Esempio n. 17
0
        public void CreateNewLangProject_DbFilesExist()
        {
            var preExistingDirs = new List <string>(Directory.GetDirectories(FwDirectoryFinder.ProjectsDirectory));

            try
            {
                // Setup: Create "pre-existing" DB filenames
                using (new DummyFileMaker(Path.Combine(FwDirectoryFinder.ProjectsDirectory, "Gumby", FdoFileHelper.GetXmlDataFileName("Gumby"))))
                {
                    using (var threadHelper = new ThreadHelper())
                        FdoCache.CreateNewLangProj(new DummyProgressDlg(), "Gumby", FwDirectoryFinder.FdoDirectories, threadHelper);
                }
            }
            finally
            {
                RemoveTestDirs(preExistingDirs, Directory.GetDirectories(FwDirectoryFinder.ProjectsDirectory));
            }
        }