private void btn_SearchesImport_Click(object sender, EventArgs e) { Searches searches = Properties.Settings.Default.searches; ImportDialog id = new ImportDialog(); var result = id.ShowDialog(); if (result == DialogResult.OK) { string injson = File.ReadAllText(id.GetFileName()); Searches insearches = new Searches(); insearches.Dict = JsonConvert.DeserializeObject <Dictionary <string, Search> >(injson); switch (id.GetMode()) { case ImportDialog.Modes.MERGE: foreach (var kvpair in insearches.Dict) { if (searches.Dict.ContainsKey(kvpair.Key)) { searches.Dict[kvpair.Key] = kvpair.Value; } else { searches.Dict.Add(kvpair.Key, kvpair.Value); } } break; case ImportDialog.Modes.NEW: foreach (var kvpair in insearches.Dict) { if (searches.Dict.ContainsKey(kvpair.Key)) { continue; } else { searches.Dict.Add(kvpair.Key, kvpair.Value); } } break; case ImportDialog.Modes.REPLACE: searches = insearches; break; default: throw new ArgumentOutOfRangeException("Unrecognized import mode. Aborting."); } Properties.Settings.Default.searches = searches; Properties.Settings.Default.Save(); RefreshDisplay(); MessageBox.Show("Import complete."); } else { MessageBox.Show("Import cancelled."); } }
private void button1_Click(object sender, RibbonControlEventArgs e) { ImportDialog id = new ImportDialog(); id.ShowDialog(); loadBoilerplate(); }