// Create a new configuration private void NewConfiguration() { // Make sure to save any existing configuration before creating another if (SaveConfiguration(true) == SaveState.Canceled) { return; } m_configurationFileName = null; ProxyConnections = ProxyConnectionCollection.LoadConfiguration(null); ConfigurationSaved = true; // Change form title to include working file name UpdateFormTitle(); ShowToolTipHelpForEmptyConfiguration(); }
// Load existing configuration private void LoadConfiguration(string configurationFileName = null) { // Make to save any existing configuration before loading another if (SaveConfiguration(true) == SaveState.Canceled) { return; } // Make sure a file name is defined for the configuration if (string.IsNullOrEmpty(configurationFileName)) { openFileDialog.FileName = null; if (openFileDialog.ShowDialog(this) == DialogResult.OK) { m_configurationFileName = openFileDialog.FileName; } else { return; } } else { m_configurationFileName = configurationFileName; } try { Cursor = Cursors.WaitCursor; ProxyConnections = ProxyConnectionCollection.LoadConfiguration(m_configurationFileName); // Establish an editing user control for each proxy connection foreach (ProxyConnection connection in m_proxyConnections) { if (!m_loaded) { SplashScreen.SetStatus("Loading " + connection.Name + "...", true); } // Editing-control creation happens after proxy connection exists and is in the binding list, // so we depend on the PropertyChanged event to attach to needed control events AddProxyConnectionEditorControl(connection); } ConfigurationSaved = true; if (m_loaded) { ThreadPool.QueueUserWorkItem(PostProxyConnectionsLoad); } // Change form title to include working file name UpdateFormTitle(); ShowToolTipHelpForEmptyConfiguration(); } catch (Exception ex) { MessageBox.Show("Failed to load configuration file: " + ex.Message, Tag.ToNonNullString(Text), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } finally { Cursor = Cursors.Default; } }