private void buttonOK_Click(object sender, EventArgs e) { string key = textBoxOcrFixKey.Text.Trim(); string value = textBoxOcrFixValue.Text.Trim(); if (key.Length == 0 || value.Length == 0 || key == value) { return; } try { var ci = new CultureInfo(LanguageString.Replace("_", "-")); _threeLetterIsoLanguageName = ci.ThreeLetterISOLanguageName; } catch (Exception exception) { MessageBox.Show(exception.Message); return; } var ocrFixReplaceList = OcrFixReplaceList.FromLanguageId(_threeLetterIsoLanguageName); ocrFixReplaceList.AddWordOrPartial(key, value); DialogResult = DialogResult.OK; NewSource = key; NewTarget = value; }
private void buttonOK_Click(object sender, EventArgs e) { string key = textBoxOcrFixKey.Text.Trim(); string value = textBoxOcrFixValue.Text.Trim(); if (key.Length == 0 || value.Length == 0) { return; } if (key == value) { return; } var ocrFixWords = new Dictionary <string, string>(); var ocrFixPartialLines = new Dictionary <string, string>(); try { var ci = new CultureInfo(LanguageString.Replace("_", "-")); _threeLetterISOLanguageName = ci.ThreeLetterISOLanguageName; } catch { } string replaceListXmlFileName = Utilities.DictionaryFolder + _threeLetterISOLanguageName + "_OCRFixReplaceList.xml"; if (File.Exists(replaceListXmlFileName)) { var xml = new XmlDocument(); xml.Load(replaceListXmlFileName); ocrFixWords = Logic.Ocr.OcrFixEngine.LoadReplaceList(xml, "WholeWords"); ocrFixPartialLines = Logic.Ocr.OcrFixEngine.LoadReplaceList(xml, "PartialLines"); } Dictionary <string, string> dictionary = ocrFixWords; string elementName = "Word"; string parentName = "WholeWords"; if (key.Contains(" ")) { dictionary = ocrFixPartialLines; elementName = "LinePart"; parentName = "PartialLines"; } if (dictionary.ContainsKey(key)) { MessageBox.Show(Configuration.Settings.Language.Settings.WordAlreadyExists); return; } dictionary.Add(key, value); //Sort var sortedDictionary = new SortedDictionary <string, string>(); foreach (var pair in dictionary) { if (!sortedDictionary.ContainsKey(pair.Key)) { sortedDictionary.Add(pair.Key, pair.Value); } } var doc = new XmlDocument(); if (File.Exists(replaceListXmlFileName)) { doc.Load(replaceListXmlFileName); } else { doc.LoadXml("<OCRFixReplaceList><WholeWords/><PartialWords/><PartialLines/><BeginLines/><EndLines/><WholeLines/></OCRFixReplaceList>"); } XmlNode wholeWords = doc.DocumentElement.SelectSingleNode(parentName); wholeWords.RemoveAll(); foreach (var pair in sortedDictionary) { XmlNode node = doc.CreateElement(elementName); XmlAttribute wordFrom = doc.CreateAttribute("from"); wordFrom.InnerText = pair.Key; node.Attributes.Append(wordFrom); XmlAttribute wordTo = doc.CreateAttribute("to"); wordTo.InnerText = pair.Value; node.Attributes.Append(wordTo); wholeWords.AppendChild(node); } doc.Save(replaceListXmlFileName); DialogResult = DialogResult.OK; NewSource = key; NewTarget = value; }