예제 #1
0
        private void ReverseTransliteration_Click(object sender, RoutedEventArgs e)
        {
            repository.SwapSourceAndDestination();
            Transliterator reverseTransliterator = new Transliterator(repository, repository.srcLanguage.Code, repository.dstLanguage.Code);
            RuleCollection ruleCollection        = (RuleCollection)(dataGridRules.ItemsSource);
            RuleCollection newRuleCollection     = new RuleCollection();

            var rules = repository.ListRules(true);

            foreach (var rule in rules)
            {
                if (rule.Destination.Length == 0)
                {
                    continue;
                }

                string newSource = rule.Destination, newDestination = rule.Source;

                if (newDestination.StartsWith("|"))
                {
                    newSource      = "|" + newSource;
                    newDestination = newDestination.Substring(1);
                }

                if (newDestination.EndsWith("|"))
                {
                    newSource      = newSource + "|";
                    newDestination = newDestination.Substring(0, newDestination.Length - 1);
                }

                if (!ruleCollection.All(r => newSource != r.Source))
                {
                    continue;
                }

                newRuleCollection.Add(new TransliterationRule(newSource,
                                                              newDestination,
                                                              reverseTransliterator.Transliterate(rule.Examples)
                                                              ));
            }

            // Show the dialog
            RuleCollection oldRules = (RuleCollection)(dataGridRules.ItemsSource);
            var            reverseTransliterationWindow = new ReverseTransliteration(newRuleCollection, oldRules);

            reverseTransliterationWindow.ShowDialog();

            repository.SwapSourceAndDestination();
        }