Exemple #1
0
        public void CanSaveAndReadIsUnicode()
        {
            using (var environment = new TestEnvironment())
            {
                environment.WritingSystem.Language = "en";
                Assert.IsTrue(environment.WritingSystem.IsUnicodeEncoded);
                environment.WritingSystem.IsUnicodeEncoded = false;
                Assert.IsFalse(environment.WritingSystem.IsUnicodeEncoded);
                environment.Collection.SaveDefinition(environment.WritingSystem);

                var newCollection = LdmlInFolderWritingSystemRepository.Initialize(environment.TestPath, DummyWritingSystemHandler.onMigration, DummyWritingSystemHandler.onLoadProblem);
                var ws2           = newCollection.Get("en");
                Assert.IsFalse(ws2.IsUnicodeEncoded);
            }
        }
Exemple #2
0
        public void SaveDefinitionsThenLoad_CountEquals2()
        {
            using (var environment = new TestEnvironment())
            {
                environment.WritingSystem.Language = "one";
                environment.Collection.SaveDefinition(environment.WritingSystem);
                var ws2 = new WritingSystemDefinition
                {
                    Language = "two"
                };
                environment.Collection.SaveDefinition(ws2);
                var newStore = LdmlInFolderWritingSystemRepository.Initialize(environment.TestPath, DummyWritingSystemHandler.onMigration, DummyWritingSystemHandler.onLoadProblem);

                Assert.AreEqual(2, newStore.Count);
            }
        }
Exemple #3
0
        public void Get_WritingSystemContainedInFileWithfilenameThatDoesNotMatchRfc5646Tag_ReturnsWritingSystem()
        {
            using (var environment = new TestEnvironment())
            {
                //Make the filepath inconsistant
                environment.Collection             = LdmlInFolderWritingSystemRepository.Initialize(environment.TestPath, DummyWritingSystemHandler.onMigration, DummyWritingSystemHandler.onLoadProblem);
                environment.WritingSystem.Language = "en";
                environment.Collection.SaveDefinition(environment.WritingSystem);
                File.Move(Path.Combine(environment.TestPath, "en.ldml"), Path.Combine(environment.TestPath, "de.ldml"));

                // Now try to load up.
                environment.Collection = LdmlInFolderWritingSystemRepository.Initialize(environment.TestPath, DummyWritingSystemHandler.onMigration, DummyWritingSystemHandler.onLoadProblem);
                var ws = environment.Collection.Get("en");
                Assert.That(ws.Bcp47Tag, Is.EqualTo("en"));
            }
        }
Exemple #4
0
 protected void InitWritingSystems()
 {
     if (!Directory.Exists(GetPathToLdmlWritingSystemsFolder(ProjectDirectoryPath)))
     {
         CopyWritingSystemsFromApplicationCommonDirectoryToNewProject(ProjectDirectoryPath);
     }
     if (_writingSystems == null)
     {
         _writingSystems = LdmlInFolderWritingSystemRepository.Initialize(
             GetPathToLdmlWritingSystemsFolder(ProjectDirectoryPath),
             OnWritingSystemMigration,
             OnWritingSystemLoadProblem,
             WritingSystemCompatibility.Flex7V0Compatible
             );
     }
 }
Exemple #5
0
        public void DefaultLanguageNotAddedIfInTrash()
        {
            using (var environment = new TestEnvironment())
            {
                environment.Collection.SystemWritingSystemProvider = new DummyWritingSystemProvider();
                var list = environment.Collection.AllWritingSystems;
                Assert.IsTrue(ContainsLanguageWithName(list, "English"));
                var list2 = new List <IWritingSystemDefinition>(environment.Collection.AllWritingSystems);
                var ws2   = list2[0];
                environment.Collection.Remove(ws2.Language);

                var repository = LdmlInFolderWritingSystemRepository.Initialize(environment.TestPath, DummyWritingSystemHandler.onMigration, DummyWritingSystemHandler.onLoadProblem);
                //  repository.DontAddDefaultDefinitions = false;
                repository.SystemWritingSystemProvider = new DummyWritingSystemProvider();
                Assert.IsFalse(ContainsLanguageWithName(repository.AllWritingSystems, "English"));
            }
        }
Exemple #6
0
        /// <summary>
        /// See comment on BasilProject.InitializeForTests()
        /// </summary>
        public static WeSayWordsProject InitializeForTests()
        {
            WeSayWordsProject project = new WeSayWordsProject();

            try
            {
                File.Delete(WeSayWordsProject.PathToPretendLiftFile);
            }
            catch (Exception) { }
            DirectoryInfo projectDirectory   = Directory.CreateDirectory(Path.GetDirectoryName(WeSayWordsProject.PathToPretendLiftFile));
            string        pathToLdmlWsFolder = BasilProject.GetPathToLdmlWritingSystemsFolder(projectDirectory.FullName);

            if (File.Exists(WeSayWordsProject.PathToPretendWritingSystemPrefs))
            {
                File.Delete(WeSayWordsProject.PathToPretendWritingSystemPrefs);
            }

            if (Directory.Exists(pathToLdmlWsFolder))
            {
                Directory.Delete(pathToLdmlWsFolder, true);
            }

            Palaso.Lift.Utilities.CreateEmptyLiftFile(WeSayWordsProject.PathToPretendLiftFile, "InitializeForTests()", true);

            //setup writing systems
            Directory.CreateDirectory(pathToLdmlWsFolder);
            IWritingSystemRepository wsc = LdmlInFolderWritingSystemRepository.Initialize(
                pathToLdmlWsFolder,
                OnMigrationHandler,
                OnWritingSystemLoadProblem,
                WritingSystemCompatibility.Flex7V0Compatible
                );

            wsc.Set(WritingSystemDefinition.Parse(WritingSystemsIdsForTests.VernacularIdForTest));
            wsc.Set(WritingSystemDefinition.Parse(WritingSystemsIdsForTests.AnalysisIdForTest));
            wsc.Set(WritingSystemDefinition.Parse(WritingSystemsIdsForTests.OtherIdForTest));


            wsc.Save();

            project.SetupProjectDirForTests(WeSayWordsProject.PathToPretendLiftFile);
            project.BackupMaker = null;            //don't bother. Modern tests which might want to check backup won't be using this old approach anyways.
            return(project);
        }
Exemple #7
0
        /// ------------------------------------------------------------------------------------
        private IEnumerable <WritingSystemDefinition> GetAvailableWritingSystems()
        {
            // FLEx 9 uses C:\ProgramData\SIL\WritingSystemRepository
            var repoPath = Path.Combine(Program.SilCommonDataFolder, "WritingSystemRepository");

            if (Directory.Exists(repoPath))
            {
                var globalRepo = GlobalWritingSystemRepository.Initialize();
                return(globalRepo.AllWritingSystems);
            }

            var globalPath = Path.Combine(Program.SilCommonDataFolder, "WritingSystemStore");

            if (!Directory.Exists(globalPath))
            {
                var msg = LocalizationManager.GetString(
                    "DialogBoxes.Transcription.ExportToFieldWorksInterlinearDlg.CannotFindFLExWritingSystemsMsg1",
                    "In order to export, we need to find a writing system ID that FLEx will accept. SayMore " +
                    "tried to find a list of writing systems which FLEx knows about by looking in {0}, but it " +
                    "doesn't exist. We recommend that you let the code be 'en' (English), then change it inside of FLEx.",
                    "The parameter is a folder path");

                ErrorReport.NotifyUserOfProblem(msg, globalPath);
                return(new[] { new WritingSystemDefinition("en") });
            }

            try
            {
                var repo = LdmlInFolderWritingSystemRepository.Initialize(globalPath);
                return(repo.AllWritingSystems);
            }
            catch (Exception ex)
            {
                var msg = LocalizationManager.GetString(
                    "DialogBoxes.Transcription.ExportToFieldWorksInterlinearDlg.FLExWritingSystemRepositoryMsg",
                    "There was a problem initializing the Writing System Repository: \"{0}\"." +
                    "We recommend that you let the code be 'en' (English), then change it inside of FLEx.",
                    "The parameter is an error message");

                ErrorReport.NotifyUserOfProblem(msg, ex.Message);
                return(new[] { new WritingSystemDefinition("en") });
            }
        }
Exemple #8
0
        private void OnWritingSystemSetupDialogClicked(object sender, EventArgs e)
        {
            string tempPath = Path.GetTempPath() + "WS-Test";

            Directory.CreateDirectory(tempPath);
            if (!_KeyboardControllerInitialized)
            {
                KeyboardController.Initialize();
                _KeyboardControllerInitialized = true;
            }
            var wsRepo = LdmlInFolderWritingSystemRepository.Initialize(tempPath, onMigration, onLoadProblem);

            using (var dialog = new WritingSystemSetupDialog(wsRepo))
            {
                dialog.WritingSystems.LocalKeyboardSettings = Settings.Default.LocalKeyboards;
                dialog.ShowDialog();
                Settings.Default.LocalKeyboards = dialog.WritingSystems.LocalKeyboardSettings;
                Settings.Default.Save();
            }
        }
Exemple #9
0
        public void CanAddVariantToExistingLDML()
        {
            using (var environment = new TestEnvironment())
            {
                environment.WritingSystem.Language     = "en";
                environment.WritingSystem.Abbreviation = "bl";
                //crucially, abbreviation isn't part of the name of the file
                environment.Collection.SaveDefinition(environment.WritingSystem);

                var newCollection = LdmlInFolderWritingSystemRepository.Initialize(environment.TestPath, DummyWritingSystemHandler.onMigration, DummyWritingSystemHandler.onLoadProblem);
                var ws2           = newCollection.Get(environment.WritingSystem.StoreID);
                ws2.Variant = "x-piglatin";
                environment.Collection.SaveDefinition(ws2);
                string path = Path.Combine(environment.Collection.PathToWritingSystems,
                                           environment.GetPathForWsId(ws2.Bcp47Tag));
                AssertThatXmlIn.File(path).HasAtLeastOneMatchForXpath("ldml/identity/variant[@type='x-piglatin']");
                AssertThatXmlIn.File(path).HasAtLeastOneMatchForXpath("ldml/special/palaso:abbreviation[@value='bl']",
                                                                      environment.NamespaceManager);
            }
        }
Exemple #10
0
        public void WritingSystemSetupDialog()
        {
            var runner = new CrossThreadTestRunner();

            runner.RunInSTA(
                delegate
            {
                using (var folder = new TemporaryFolder("WS-Test"))
                {
                    //var dlg = new WritingSystemSetupDialog(folder.Path,
                    //	DummyWritingSystemHandler.onMigration,
                    //	DummyWritingSystemHandler.onLoadProblem);
                    //that constructor is now obsolete, create repo first
                    var repository = LdmlInFolderWritingSystemRepository.Initialize(folder.Path);
                    var dlg        = new WritingSystemSetupDialog(repository);
                    dlg.WritingSystemSuggestor.SuggestVoice = true;
                    dlg.ShowDialog();
                }
            });
        }
Exemple #11
0
        public void WritingSystemSetupViewWithComboAttached()
        {
            var runner = new CrossThreadTestRunner();

            runner.RunInSTA(
                delegate
            {
                using (var folder = new TemporaryFolder("WS-Test"))
                {
                    var f          = new Form();
                    f.Size         = new Size(800, 600);
                    var repository = LdmlInFolderWritingSystemRepository.Initialize(folder.Path);
                    var model      = new WritingSystemSetupModel(repository);
                    var v          = new WritingSystemSetupView(model);
                    var combo      = new WSPickerUsingComboBox(model);
                    f.Controls.Add(combo);
                    f.Controls.Add(v);
                    f.ShowDialog();
                }
            });
        }
Exemple #12
0
        public void Save_WritingSystemIdConflated_ChangeLogUpdatedAndDoesNotContainDelete()
        {
            using (var e = new TestEnvironment())
            {
                var repo = LdmlInFolderWritingSystemRepository.Initialize(Path.Combine(e.TestPath, "idchangedtest1"), DummyWritingSystemHandler.onMigration, DummyWritingSystemHandler.onLoadProblem);
                var ws   = WritingSystemDefinition.Parse("en");
                repo.Set(ws);
                repo.Save();

                var ws2 = WritingSystemDefinition.Parse("de");
                repo.Set(ws2);
                repo.Save();

                repo.Conflate(ws.Id, ws2.Id);
                repo.Save();

                string logFilePath = Path.Combine(repo.PathToWritingSystems, "idchangelog.xml");
                AssertThatXmlIn.File(logFilePath).HasAtLeastOneMatchForXpath("/WritingSystemChangeLog/Changes/Merge/From[text()='en']");
                AssertThatXmlIn.File(logFilePath).HasAtLeastOneMatchForXpath("/WritingSystemChangeLog/Changes/Merge/To[text()='de']");
                AssertThatXmlIn.File(logFilePath).HasNoMatchForXpath("/WritingSystemChangeLog/Changes/Delete/Id[text()='en']");
            }
        }
Exemple #13
0
        /// ------------------------------------------------------------------------------------
        private IEnumerable <WritingSystemDefinition> GetAvailableWritingSystems()
        {
            var globalPath = Path.Combine(Program.SilCommonDataFolder, "WritingSystemStore");

            //NB: flex 7.1 is using this. Palaso head has WritingSystemRepository/2 instead. Sigh...

            if (!Directory.Exists(globalPath))
            {
                var msg = LocalizationManager.GetString(
                    "DialogBoxes.Transcription.ExportToFieldWorksInterlinearDlg.CannotFindFLExWritingSystemsMsg1",
                    "In order to export, we need to find a writing system ID that FLEx will accept. SayMore " +
                    "tried to find a list of writing systems which FLEx knows about by looking in {0}, but it " +
                    "doesn't exist. We recommend that you let the code be 'en' (English), then change it inside of FLEx.",
                    "The parameter is a folder path");

                ErrorReport.NotifyUserOfProblem(msg, globalPath);
                return(new[] { new WritingSystemDefinition("en") });
            }
            var repo = LdmlInFolderWritingSystemRepository.Initialize(globalPath);

            return(repo.AllWritingSystems);
        }
        /// <summary> Exports main character set from a project to an ldml file </summary>
        private void LdmlExport(string filePath, string langTag)
        {
            // SLDR is the SIL Locale Data repository, it is necessary for reading/writing ldml
            // It is being initialized in offline mode here to only pull local data
            Sldr.Initialize(true);
            try
            {
                var wsr = LdmlInFolderWritingSystemRepository.Initialize(filePath);
                var wsf = new LdmlInFolderWritingSystemFactory(wsr);
                wsf.Create(langTag, out var wsDef);

                var proj = _projService.GetProject(_projectId).Result;

                // If there isn't already a main character set defined, make one and add it to the writing system
                // definition
                if (!wsDef.CharacterSets.TryGet("main", out var chars))
                {
                    chars = new CharacterSetDefinition("main");
                    wsDef.CharacterSets.Add(chars);
                }

                // Replace all the characters found with our copy of the character set
                chars.Characters.Clear();
                foreach (var character in proj.ValidCharacters)
                {
                    chars.Characters.Add(character);
                }

                // Write out the new definition
                wsr.Set(wsDef);
                wsr.Save();
            }
            finally
            {
                // If there was somehow an error above, we still want to cleanup to prevent unhelpful errors later
                Sldr.Cleanup();
            }
        }
        /// <summary> Imports main character set for a project from an ldml file </summary>
        public void LdmlImport(string filePath, string langTag)
        {
            // SLDR is the SIL locale data repository, it is necessary for reading/writing ldml
            // It is being initialized in offline mode here to only pull local data
            Sldr.Initialize(true);
            try
            {
                var wsr = LdmlInFolderWritingSystemRepository.Initialize(filePath);
                var wsf = new LdmlInFolderWritingSystemFactory(wsr);
                wsf.Create(langTag, out var wsDef);

                //if there is a main character set, import it to the project
                if (wsDef.CharacterSets.Contains("main"))
                {
                    var newProj = _projService.GetProject(_projectId).Result;
                    newProj.ValidCharacters = wsDef.CharacterSets["main"].Characters.ToList();
                    _projService.Update(_projectId, newProj);
                }
            }
            finally //if there was somehow an error above, we still want to cleanup to prevent unhelpful errors later
            {
                Sldr.Cleanup();
            }
        }
Exemple #16
0
 public void CreateLegacyFriendlyWritingSystemRepository()
 {
     WritingSystemRepository = LdmlInFolderWritingSystemRepository.Initialize(WritingSystemsPath, onMigration, onLoadProblem, WritingSystemCompatibility.Flex7V0Compatible);
 }
Exemple #17
0
 public void CreateWritingSystemRepository()
 {
     WritingSystemRepository = LdmlInFolderWritingSystemRepository.Initialize(WritingSystemsPath, onMigration, onLoadProblem, WritingSystemCompatibility.Strict);
 }