Exemplo n.º 1
0
 public void LoadFromLegacyWeSayFile(string PathToWritingSystemPrefsFile)
 {
     if (WeSayWritingSystemsPrefsExist(PathToWritingSystemPrefsFile))
     {
         NetReflectorReader r      = new NetReflectorReader(MakeTypeTable());
         XmlReader          reader = XmlReader.Create(PathToWritingSystemPrefsFile);
         var wesayWsFileCollection = new WritingSystemCollection_V1();
         try
         {
             r.Read(reader, wesayWsFileCollection);
         }
         finally
         {
             reader.Close();
         }
         foreach (KeyValuePair <string, WritingSystem_V1> pair in wesayWsFileCollection)
         {
             if (!ContainsKey(pair.Key))
             {
                 Add(pair.Key, pair.Value);
             }
         }
     }
 }
        public void Migrate(string sourceFilePath, string destinationFilePath)
        {
            var migrationInfo = new List <LdmlVersion0MigrationStrategy.MigrationInfo>();

            if (!Directory.Exists(destinationFilePath))
            {
                Directory.CreateDirectory(destinationFilePath);
            }
            var wesayWsCollection = new WritingSystemCollection_V1();

            wesayWsCollection.LoadFromLegacyWeSayFile(sourceFilePath);

            foreach (var writingSystem in wesayWsCollection.Values)
            {
                var currentMigrationInfo = new LdmlVersion0MigrationStrategy.MigrationInfo {
                    RfcTagBeforeMigration = writingSystem.ISO
                };
                var wsDef = new WritingSystemDefinitionV0();
                if (writingSystem.IsAudio)
                {
                    wsDef.Script  = WellKnownSubTags.Audio.Script;
                    wsDef.Variant = WellKnownSubTags.Audio.PrivateUseSubtag;
                }
                else
                {
                    var subtag = new SubTag();
                    subtag.AddToSubtag(writingSystem.ISO);
                    subtag.RemoveAllParts("audio");
                    writingSystem.ISO = subtag.CompleteTag;
                }

                wsDef.ISO639            = writingSystem.ISO;
                wsDef.DefaultFontName   = writingSystem.FontName;
                wsDef.DefaultFontSize   = writingSystem.FontSize;
                wsDef.Abbreviation      = writingSystem.Abbreviation;
                wsDef.IsLegacyEncoded   = !writingSystem.IsUnicode;
                wsDef.Keyboard          = writingSystem.KeyboardName;
                wsDef.RightToLeftScript = writingSystem.RightToLeft;
                wsDef.SpellCheckingId   = writingSystem.SpellCheckingId;
                wsDef.DateModified      = DateTime.Now;
                if (writingSystem.SortUsing.Equals("CustomICU"))
                {
                    wsDef.SortRules = writingSystem.CustomSortRules;
                    wsDef.SortUsing = WritingSystemDefinitionV0.SortRulesType.CustomICU;
                }
                else if (writingSystem.SortUsing.Equals("CustomSimple"))
                {
                    wsDef.SortRules = writingSystem.CustomSortRules;
                    wsDef.SortUsing = WritingSystemDefinitionV0.SortRulesType.CustomSimple;
                }
                else if (!String.IsNullOrEmpty(writingSystem.SortUsing))
                {
                    //when sorting like other language
                    wsDef.SortRules = writingSystem.SortUsing;
                    wsDef.SortUsing = WritingSystemDefinitionV0.SortRulesType.OtherLanguage;
                }

                //wsDef.VerboseDescription //not written out by ldmladaptor - flex?
                //wsDef.StoreID = ??? //what to do?
                //wsDef.NativeName //not written out by ldmladaptor - flex?

                string pathForNewLdmlFile = Path.Combine(destinationFilePath, wsDef.Rfc5646 + ".ldml");
                new LdmlAdaptorV0().Write(pathForNewLdmlFile, wsDef, null);

                currentMigrationInfo.RfcTagAfterMigration = wsDef.Rfc5646;
                if (currentMigrationInfo.RfcTagBeforeMigration != currentMigrationInfo.RfcTagAfterMigration)
                {
                    _changeLog.LogChange(currentMigrationInfo.RfcTagBeforeMigration, currentMigrationInfo.RfcTagAfterMigration);
                }
                migrationInfo.Add(currentMigrationInfo);
            }
            _onMigrationCallback(migrationInfo);
        }