/// <summary> /// Import an xml file /// </summary> private void Import() { try { var ofd = new OpenFileDialog(); ofd.FileOk += (sender, args) => args.Cancel = string.IsNullOrEmpty(ofd.FileName) || !Path.GetExtension(ofd.FileName.ToLower()).Equals(".xml"); var result = ofd.ShowDialog(); if (result.Value) { var deserializedLanguages = new LanguageFileParser().DeserializeLanguagesFile(ofd.FileName); _languages.Clear(); _possibleValues.Clear(); foreach (var possibleValue in deserializedLanguages.SelectMany(x => x.Second).Select(x => x.ResourceName).Distinct().ToList()) { _possibleValues.Add(possibleValue); } foreach (var pair in deserializedLanguages) { var language = new Pair <Language, ObservableCollection <LocaleStringResourceModel> >(); language.First = pair.First; language.Second = new ObservableCollection <LocaleStringResourceModel>(); foreach (var possibleValue in _possibleValues) { var resourceModel = new LocaleStringResourceModel(pair.Second.FirstOrDefault(x => x.ResourceName == possibleValue)); if (resourceModel.IsMissing) { resourceModel.ResourceName = possibleValue; } language.Second.Add(resourceModel); } _languages.Add(language); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } }
/// <summary> /// Import an xml file /// </summary> private void Import() { try { var ofd = new OpenFileDialog(); ofd.FileOk += (sender, args) => args.Cancel = string.IsNullOrEmpty(ofd.FileName) || !Path.GetExtension(ofd.FileName.ToLower()).Equals(".xml"); var result = ofd.ShowDialog(); if (result.Value) { var deserializedLanguages = new LanguageFileParser().DeserializeLanguagesFile(ofd.FileName); _languages.Clear(); _possibleValues.Clear(); foreach (var possibleValue in deserializedLanguages.SelectMany(x => x.Second).Select(x => x.ResourceName).Distinct().ToList()) { _possibleValues.Add(possibleValue); } foreach (var pair in deserializedLanguages) { var language = new Pair<Language, ObservableCollection<LocaleStringResourceModel>>(); language.First = pair.First; language.Second = new ObservableCollection<LocaleStringResourceModel>(); foreach (var possibleValue in _possibleValues) { var resourceModel = new LocaleStringResourceModel(pair.Second.FirstOrDefault(x => x.ResourceName == possibleValue)); if (resourceModel.IsMissing) resourceModel.ResourceName = possibleValue; language.Second.Add(resourceModel); } _languages.Add(language); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } }