public void PerformMigration(IDomainObjectDTORepository repoDto) { DataMigrationServices.CheckVersionNumber(repoDto, 7000043); if (repoDto.ProjectFolder != Path.GetTempPath()) { // Skip migrating the global repository if we're just running tests. Slow and may not be wanted. // In a real project we do this first; thus if by any chance a WS is differently renamed in // the two folders, the renaming that is right for this project wins. var globalWsFolder = LcmFileHelper.OldGlobalWritingSystemStoreDirectory; var globalMigrator = new LdmlInFolderWritingSystemRepositoryMigrator(globalWsFolder, NoteMigration, 2); globalMigrator.Migrate(); } var ldmlFolder = Path.Combine(repoDto.ProjectFolder, LcmFileHelper.ksWritingSystemsDir); var migrator = new LdmlInFolderWritingSystemRepositoryMigrator(ldmlFolder, NoteMigration, 2); migrator.Migrate(); var wsIdMigrator = new WritingSystemIdMigrator(repoDto, TryGetNewTag, "*_Layouts.xml"); wsIdMigrator.Migrate(); DataMigrationServices.IncrementVersionNumber(repoDto); }
// There's some confusion between the Palaso migrator and our version 19 migrator about whether an old language // tag should have multiple X's if it has more than one private-use component. Since such X's are not // significant, ignore them. private bool TryGetNewTag(string oldTag, out string newTag) { string key = RemoveMultipleX(oldTag.ToLowerInvariant()); if (m_tagMap.TryGetValue(key, out newTag)) { return(!newTag.Equals(oldTag, StringComparison.OrdinalIgnoreCase)); } var cleaner = new IetfLanguageTagCleaner(oldTag); cleaner.Clean(); // FieldWorks needs to handle this special case. if (cleaner.Language.ToLowerInvariant() == "cmn") { var region = cleaner.Region; if (string.IsNullOrEmpty(region)) { region = "CN"; } cleaner = new IetfLanguageTagCleaner("zh", cleaner.Script, region, cleaner.Variant, cleaner.PrivateUse); } newTag = cleaner.GetCompleteTag(); while (m_tagMap.Values.Contains(newTag, StringComparer.OrdinalIgnoreCase)) { // We can't use this tag because it would conflict with what we are mapping something else to. cleaner = new IetfLanguageTagCleaner(cleaner.Language, cleaner.Script, cleaner.Region, cleaner.Variant, WritingSystemIdMigrator.GetNextDuplPart(cleaner.PrivateUse)); newTag = cleaner.GetCompleteTag(); } m_tagMap[key] = newTag; return(!newTag.Equals(oldTag, StringComparison.OrdinalIgnoreCase)); }
public void GetNextDuplPart() { Assert.That(WritingSystemIdMigrator.GetNextDuplPart(null), Is.EqualTo("dupl1")); Assert.That(WritingSystemIdMigrator.GetNextDuplPart(""), Is.EqualTo("dupl1")); Assert.That(WritingSystemIdMigrator.GetNextDuplPart("abc"), Is.EqualTo("abc-dupl1")); Assert.That(WritingSystemIdMigrator.GetNextDuplPart("dupl1"), Is.EqualTo("dupl2")); Assert.That(WritingSystemIdMigrator.GetNextDuplPart("abc-def-dupl12"), Is.EqualTo("abc-def-dupl13")); }
private bool TryGetNewLangTag(string oldTag, out string newTag) { if (m_tagMap.TryGetValue(oldTag, out newTag)) { return(!newTag.Equals(oldTag)); } var cleaner = new IetfLanguageTagCleaner(oldTag); cleaner.Clean(); newTag = cleaner.GetCompleteTag(); while (m_tagMap.Values.Contains(newTag)) { // We can't use this tag because it would conflict with what we are mapping something else to. cleaner = new IetfLanguageTagCleaner(cleaner.Language, cleaner.Script, cleaner.Region, cleaner.Variant, WritingSystemIdMigrator.GetNextDuplPart(cleaner.PrivateUse)); newTag = cleaner.GetCompleteTag(); } m_tagMap[oldTag] = newTag; return(!newTag.Equals(oldTag)); }
public void PerformMigration(IDomainObjectDTORepository repoDto) { DataMigrationServices.CheckVersionNumber(repoDto, 7000070); // Skip migrating the global repository if we're just running tests. Slow and may not be wanted. // In a real project we do this first; thus if by any chance a WS is differently renamed in // the two folders, the renaming that is right for this project wins. if (!repoDto.ProjectFolder.StartsWith(Path.GetTempPath())) { var globalMigrator = new GlobalWritingSystemRepositoryMigrator(GlobalWritingSystemRepository.DefaultBasePath, versionToMigrateTo: 3); // first migrate any existing global writing systems in the new global writing system directory if (globalMigrator.NeedsMigration()) { globalMigrator.Migrate(); } string migratedFilePath = Path.Combine(LcmFileHelper.OldGlobalWritingSystemStoreDirectory, ".migrated"); if (Directory.Exists(LcmFileHelper.OldGlobalWritingSystemStoreDirectory) && !File.Exists(migratedFilePath)) { // copy over all FW global writing systems from the old directory to the new directory and migrate string globalRepoPath = Path.Combine(GlobalWritingSystemRepository.DefaultBasePath, "3"); if (!Directory.Exists(globalRepoPath)) { GlobalWritingSystemRepository.CreateGlobalWritingSystemRepositoryDirectory(globalRepoPath); } CopyDirectoryContents(LcmFileHelper.OldGlobalWritingSystemStoreDirectory, globalRepoPath); globalMigrator.Migrate(); // add ".migrated" file to indicate that this folder has been migrated already File.WriteAllText(migratedFilePath, string.Format("The writing systems in this directory have been migrated to {0}.", globalRepoPath)); } } string ldmlFolder = Path.Combine(repoDto.ProjectFolder, LcmFileHelper.ksWritingSystemsDir); var migrator = new LdmlInFolderWritingSystemRepositoryMigrator(ldmlFolder, NoteMigration, 3); migrator.Migrate(); string sharedSettingsPath = LexiconSettingsFileHelper.GetSharedSettingsPath(repoDto.ProjectFolder); if (!Directory.Exists(sharedSettingsPath)) { Directory.CreateDirectory(sharedSettingsPath); } var projectSettingsStore = new FileSettingsStore(LexiconSettingsFileHelper.GetProjectLexiconSettingsPath(repoDto.ProjectFolder)); var userSettingsStore = new FileSettingsStore(LexiconSettingsFileHelper.GetUserLexiconSettingsPath(repoDto.ProjectFolder)); var repo = new CoreLdmlInFolderWritingSystemRepository(ldmlFolder, projectSettingsStore, userSettingsStore); migrator.ResetRemovedProperties(repo); // migrate local keyboard settings from CoreImpl application settings to new lexicon user settings file // skip if we're running unit tests, could interfere with the test results string localKeyboards; if (!repoDto.ProjectFolder.StartsWith(Path.GetTempPath()) && TryGetLocalKeyboardsSetting(out localKeyboards)) { if (localKeyboards.Length > 0) { XElement keyboardsElem = XElement.Parse(localKeyboards); foreach (XElement keyboardElem in keyboardsElem.Elements("keyboard")) { var wsId = (string)keyboardElem.Attribute("ws"); CoreWritingSystemDefinition ws; if (repo.TryGet(wsId, out ws)) { var layout = (string)keyboardElem.Attribute("layout"); var locale = (string)keyboardElem.Attribute("locale"); string keyboardId = string.IsNullOrEmpty(locale) ? layout : $"{locale}_{layout}"; IKeyboardDefinition keyboard; if (!Keyboard.Controller.TryGetKeyboard(keyboardId, out keyboard)) { keyboard = Keyboard.Controller.CreateKeyboard(keyboardId, KeyboardFormat.Unknown, Enumerable.Empty <string>()); } ws.LocalKeyboard = keyboard; } } } repo.Save(); } var wsIdMigrator = new WritingSystemIdMigrator(repoDto, TryGetNewLangTag, "*.fwlayout"); wsIdMigrator.Migrate(); DataMigrationServices.IncrementVersionNumber(repoDto); }