Exemple #1
0
        public void CreateNewLangProject_AnthropologyCategoriesExist()
        {
            const string dbName = "AnthropologicalTest";

            SureRemoveDb(dbName);
            var preExistingDirs = new List <string>(Directory.GetDirectories(FwDirectoryFinder.ProjectsDirectory));

            try
            {
                // create project
                string dbFileName;
                using (var threadHelper = new ThreadHelper())
                    dbFileName = FdoCache.CreateNewLangProj(new DummyProgressDlg(), dbName, FwDirectoryFinder.FdoDirectories, threadHelper);

                using (var cache = FdoCache.CreateCacheFromLocalProjectFile(dbFileName, "en", m_ui, FwDirectoryFinder.FdoDirectories, new FdoSettings(), new DummyProgressDlg()))
                {
                    Assert.AreEqual(Strings.ksAnthropologyCategories, cache.LangProject.AnthroListOA.Name.UiString,
                                    "Anthropology Categories list was not properly initialized.");
                    Assert.AreEqual(Strings.ksAnth, cache.LangProject.AnthroListOA.Abbreviation.UiString,
                                    "Anthropology Categories list abrv was not properly initialized.");
                    Assert.AreNotEqual(0, cache.LangProject.AnthroListOA.ItemClsid,
                                       "Anthropology Categories list class ID was not properly initialized.");
                    Assert.AreNotEqual(0, cache.LangProject.AnthroListOA.Depth,
                                       "Anthropology Categories list depth was not properly initialized.");
                }
            }
            finally
            {
                RemoveTestDirs(preExistingDirs, Directory.GetDirectories(FwDirectoryFinder.ProjectsDirectory));
            }
        }
Exemple #2
0
        public void CreateNewLangProject_NameWithSingleQuote()
        {
            const string dbName   = "!!t'st";
            string       dbDir    = Path.Combine(DirectoryFinder.ProjectsDirectory, dbName);
            var          tmpDbDir = Path.Combine(Path.Combine(DirectoryFinder.ProjectsDirectory, ".."), dbName);

            if (Directory.Exists(dbDir))
            {
                // it might seem strange to move the directory first before deleting it.
                // However, this solves the problem that the Delete() returns before
                // everything is deleted.
                Directory.Move(dbDir, tmpDbDir);
                Directory.Delete(tmpDbDir, true);
            }
            Assert.IsFalse(Directory.Exists(dbDir), "Can't delete directory of test project: " + dbDir);

            var expectedDirs = new List <string>(Directory.GetDirectories(DirectoryFinder.ProjectsDirectory))
            {
                dbDir
            };
            var writingSystemsCommonDir = Path.Combine(DirectoryFinder.ProjectsDirectory, DirectoryFinder.ksWritingSystemsDir);

            List <string> currentDirs = null;

            try
            {
                string dbFileName;
                using (var threadHelper = new ThreadHelper())
                    dbFileName = FdoCache.CreateNewLangProj(new DummyProgressDlg(), dbName, threadHelper);

                currentDirs = new List <string>(Directory.GetDirectories(DirectoryFinder.ProjectsDirectory));
                if (currentDirs.Contains(writingSystemsCommonDir) && !expectedDirs.Contains(writingSystemsCommonDir))
                {
                    expectedDirs.Add(writingSystemsCommonDir);
                }
                CollectionAssert.AreEquivalent(expectedDirs, currentDirs);
                string dbFileBase = Path.GetFileNameWithoutExtension(dbFileName);
                Assert.AreEqual(dbName, dbFileBase);
            }
            finally
            {
                if (currentDirs != null)
                {
                    RemoveTestDirs(expectedDirs, currentDirs);
                }
            }
        }
Exemple #3
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));
            }
        }
        /// <summary>
        /// Method with signature required by ProgressDialogWithTask.RunTask to create the project (and a cache for it)
        /// as a background task while showing the dialog.
        /// </summary>
        /// <param name="progress"></param>
        /// <param name="parameters">A specific list is required...see the first few lines of the method.</param>
        /// <returns></returns>
        private static object CreateProjectTask(IThreadedProgress progress, object[] parameters)
        {
            // Get required parameters. Ideally these would just be the signature of the method, but RunTask requires object[].
            string liftPath      = (string)parameters[0];
            string projectName   = (string)parameters[1];
            var    helper        = (ThreadHelper)parameters[2];
            var    cacheReceiver = (FdoCache[])parameters[3];

            IWritingSystem wsVern, wsAnalysis;

            RetrieveDefaultWritingSystemsFromLift(liftPath, out wsVern, out wsAnalysis);

            string projectPath = FdoCache.CreateNewLangProj(progress, projectName, helper, wsAnalysis, wsVern);

            // This is a temporary cache, just to do the import, and AFAIK we have no access to the current
            // user WS. So create it as "English". Put it in the array to return to the caller.
            cacheReceiver[0] = FdoCache.CreateCacheFromLocalProjectFile(projectPath, "en", progress);
            return(projectPath);
        }
        /// <summary>
        /// Method with signature required by ProgressDialogWithTask.RunTask to create the project (and a cache for it)
        /// as a background task while showing the dialog.
        /// </summary>
        /// <param name="progress"></param>
        /// <param name="parameters">A specific list is required...see the first few lines of the method.</param>
        /// <returns></returns>
        private static object CreateProjectTask(IThreadedProgress progress, object[] parameters)
        {
            // Get required parameters. Ideally these would just be the signature of the method, but RunTask requires object[].
            var liftPathname      = (string)parameters[0];
            var synchronizeInvoke = (ISynchronizeInvoke)parameters[1];
            var anthroFile        = (string)parameters[2];
            var cacheReceiver     = (FdoCache[])parameters[3];

            IWritingSystem wsVern, wsAnalysis;

            RetrieveDefaultWritingSystemsFromLift(liftPathname, out wsVern, out wsAnalysis);

            string projectPath = FdoCache.CreateNewLangProj(progress,
                                                            Directory.GetParent(Path.GetDirectoryName(liftPathname)).Parent.Name, // Get the new Flex project name from the Lift pathname.
                                                            FwDirectoryFinder.FdoDirectories, synchronizeInvoke, wsAnalysis, wsVern, null, null, null, anthroFile);

            // This is a temporary cache, just to do the import, and AFAIK we have no access to the current
            // user WS. So create it as "English". Put it in the array to return to the caller.
            cacheReceiver[0] = FdoCache.CreateCacheFromLocalProjectFile(projectPath, "en", new SilentFdoUI(synchronizeInvoke), FwDirectoryFinder.FdoDirectories, new FdoSettings(), progress);
            return(projectPath);
        }
Exemple #6
0
        public void CreateNewLangProject_NameWithSingleQuote()
        {
            const string dbName = "!!t'st";
            string       dbDir  = Path.Combine(FwDirectoryFinder.ProjectsDirectory, dbName);

            SureRemoveDb(dbName);

            var expectedDirs = new List <string>(Directory.GetDirectories(FwDirectoryFinder.ProjectsDirectory))
            {
                dbDir
            };
            var writingSystemsCommonDir = Path.Combine(FwDirectoryFinder.ProjectsDirectory, FdoFileHelper.ksWritingSystemsDir);

            List <string> currentDirs = null;

            try
            {
                string dbFileName;
                using (var threadHelper = new ThreadHelper())
                    dbFileName = FdoCache.CreateNewLangProj(new DummyProgressDlg(), dbName, FwDirectoryFinder.FdoDirectories, threadHelper);

                currentDirs = new List <string>(Directory.GetDirectories(FwDirectoryFinder.ProjectsDirectory));
                if (currentDirs.Contains(writingSystemsCommonDir) && !expectedDirs.Contains(writingSystemsCommonDir))
                {
                    expectedDirs.Add(writingSystemsCommonDir);
                }
                CollectionAssert.AreEquivalent(expectedDirs, currentDirs);
                string dbFileBase = Path.GetFileNameWithoutExtension(dbFileName);
                Assert.AreEqual(dbName, dbFileBase);
            }
            finally
            {
                if (currentDirs != null)
                {
                    RemoveTestDirs(expectedDirs, currentDirs);
                }
            }
        }