public bool DeleteFromConfig() { //Remove this config element Configuration myConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); ProxyDefinitionSection mySection = (ProxyDefinitionSection)myConfig.GetSection("ProxyDefinition"); mySection.ProxyDefinitions.Remove(this.Name); myConfig.Save(); return(true); }
public static void Main() { Process ThisProcess = Process.GetCurrentProcess(); Process[] appProcesses = Process.GetProcessesByName(ThisProcess.ProcessName); //only proceed if not already running (counting this instance). if (appProcesses.Length == 1) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); SortableBindingList <ProxySetting> proxyList = new SortableBindingList <ProxySetting>(); //Get all proxies defined in the config file. ProxyDefinitionSection section = (ProxyDefinitionSection)ConfigurationManager.GetSection("ProxyDefinition"); if (section.ProxyDefinitions != null) { foreach (ProxyElement proxyElement in section.ProxyDefinitions) { ProxySetting newSetting = new ProxySetting(proxyElement); proxyList.Add(newSetting); } } if (proxyList.Count == 0) { DialogResult result = MessageBox.Show("You currently have no Proxy Settings defined. \n\n Would you like to create an initial configuration based on your current proxy settings in Internet Explorer?", "Create Initial Proxy Set", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (result == DialogResult.Yes) { ProxySetting currentRegistryProxy = ProxySetting.GetCurrentProxyFromInternetExplorer(); ProxyNamePromptDialog dlgNamePrompt = new ProxyNamePromptDialog(proxyList); dlgNamePrompt.txtName.Text = currentRegistryProxy.Name; result = dlgNamePrompt.ShowDialog(); if (result == DialogResult.OK) { currentRegistryProxy.Name = dlgNamePrompt.txtName.Text; currentRegistryProxy.SaveInConfigFile(); proxyList.Add(currentRegistryProxy); } } } new MainForm(proxyList); Application.Run(); } }
public bool SaveInConfigFile() { //Update config element values to the values on this class. Configuration myConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); ProxyDefinitionSection mySection = (ProxyDefinitionSection)myConfig.GetSection("ProxyDefinition"); ProxyElement configElement = mySection.ProxyDefinitions[this.Name]; //If this name isn't found add one. if (configElement == null) { configElement = new ProxyElement(); configElement.Name = this.Name; mySection.ProxyDefinitions.Add(configElement); } configElement.Name = this.Name; configElement.AutoDetect = this.AutoDetectSettings; configElement.UseAutoConfigScript = this.UseAutoConfigureScript; configElement.AutoConfigScriptAddress = this.UseAutoConfigureScriptAddress; configElement.UseProxyServer = this.UseProxyServer; configElement.UseProxyServerAddress = this.UseProxyServerAddress; configElement.BypassProxyForLocalAddress = this.BypassProxyForLocalAddress; configElement.UseProxyServerPort = this.UseProxyServerPort; configElement.ExcludeAddressesFromProxy = this.ExcludeAddressesFromProxy; configElement.UseSameProxyServerForAll = this.UseSameProxyServerForAllProtocols; UpdateProxyAddressAndPort(this.HTTPProxyAddress, this.HTTPProxyPort, "HTTP", configElement); UpdateProxyAddressAndPort(this.SecureProxyAddress, this.SecureProxyPort, "HTTPS", configElement); UpdateProxyAddressAndPort(this.FTPProxyAddress, this.FTPProxyPort, "FTP", configElement); UpdateProxyAddressAndPort(this.GopherProxyAddress, this.GopherProxyPort, "Gopher", configElement); UpdateProxyAddressAndPort(this.SocksProxyAddress, this.SocksProxyPort, "Socks", configElement); myConfig.Save(); return(true); }