private void saveConnectionsToolStripMenuItem_Click_1(object sender, EventArgs e) { if (this.ConnectionsIsValid()) { var connections = new Connections { ConnectionList = CreateConnections() }; try { var openFileDialog = new SaveFileDialog { RestoreDirectory = true, Filter = "All Connection Xml files (*.PXML)|*.PXML" }; if (openFileDialog.ShowDialog() == DialogResult.OK) { var fileName = openFileDialog.FileName; ObjectToXml<Connections>.Save(connections, fileName); MessageBox.Show("Customer saved to XML file '" + fileName + "'!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("File can not be saved. Please try again.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show("Unable to save connection object!" + Environment.NewLine + Environment.NewLine + ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void LoadConnections(Connections connections) { foreach (Connection connection in connections.ConnectionList) { if (connection.name != "Server" && connection.ip != "unknown" && connection.port != 0) { IPHostEntry he = Dns.GetHostEntry(connection.ip); var dns = he.AddressList[1].ToString(); var ip = NetworkOps.GetIpString(dns); NetworkOps.SetUpClientConnectionConfig(ip, connection.port, _ip, _port); } } }