public void UpdateConnectionsFrom(string configFilePath, Action <Connection> added) { if (!string.IsNullOrEmpty(configFilePath) && File.Exists(configFilePath)) { try { var xml = new XmlDocument(); xml.LoadXml(File.ReadAllText(configFilePath)); var nodes = xml.SelectNodes("//configuration/connectionStrings/add"); foreach (XmlElement node in nodes) { var name = node.Attributes["name"]; var conn = node.Attributes["connectionString"]; var prov = node.Attributes["providerName"]; if (name != null && !string.IsNullOrWhiteSpace(name.Value) && conn != null && !string.IsNullOrWhiteSpace(conn.Value) && prov != null && !string.IsNullOrWhiteSpace(prov.Value)) { var connection = Connections.FirstOrDefault(x => String.Compare(x.Key, name.Value, StringComparison.OrdinalIgnoreCase) == 0); if (connection == null) { connection = new GeneratorConfig.Connection(); connection.Key = name.Value; Connections.Add(connection); connection.ConnectionString = conn.Value; connection.ProviderName = prov.Value; if (added != null) { added(connection); } } else { connection.ConnectionString = conn.Value; connection.ProviderName = prov.Value; } } } } catch (Exception ex) { } } }
private void Ekle_Click(object sender, RoutedEventArgs e) { var dlg = new AddConnectionStringWindow(); if (dlg.ShowDialog() == true) { var cstr = dlg.Key.Text.Trim(); if (cstr.Length < 0) { throw new ArgumentNullException("connectionKey"); } var connection = config.Connections.FirstOrDefault(x => String.Compare(x.Key, cstr, StringComparison.OrdinalIgnoreCase) == 0); if (connection == null) { connection = new GeneratorConfig.Connection { Key = cstr, ConnectionString = dlg.ConnectionString.Text.Trim(), ProviderName = dlg.Provider.Text.Trim(), Tables = new List <GeneratorConfig.Table> { } }; config.Connections.Add(connection); _connections.Clear(); _connections.AddRange(config.Connections); } else { connection.ConnectionString = dlg.ConnectionString.Text.Trim(); connection.ProviderName = dlg.Provider.Text.Trim(); } this.ConnectionsCombo.SelectedItem = connection; config.Save(); } }