Ejemplo n.º 1
0
        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();
            }
        }
Ejemplo n.º 2
0
        private void btnExport_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;

            SortableBindingList <ProxySetting> exportList = new SortableBindingList <ProxySetting>();

            foreach (ProxySetting proxy in this.lbxProxyNames.SelectedItems)
            {
                exportList.Add(proxy);
            }

            if (File.Exists(this.txtFileName.Text))
            {
                DialogResult result = MessageBox.Show("File Exists.  Overwrite?", "Overwrite File", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    File.Delete(this.txtFileName.Text);
                }
                else
                {
                    return;
                }
            }

            exportList.Save(this.txtFileName.Text);

            MessageBox.Show("Proxy settings successfully Exported", "Export Success", MessageBoxButtons.OK, MessageBoxIcon.Information);

            this.Close();
        }
Ejemplo n.º 3
0
        private void btnImport_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;

            foreach (ProxySetting proxy in this.lbxProxyNames.SelectedItems)
            {
                _proxyListToImport.Add(proxy);
            }

            this.Close();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Handles the Click event of the btnAdd control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btnAdd_Click(object sender, EventArgs e)
        {
            ProxyNamePromptDialog dlgNamePrompt = new ProxyNamePromptDialog(_proxyList);
            DialogResult          result        = dlgNamePrompt.ShowDialog(this);

            if (result == DialogResult.OK)
            {
                ProxySetting newProxy = new ProxySetting();
                newProxy.Name = dlgNamePrompt.txtName.Text;

                LanSettingDialog dlgLanSettings = new LanSettingDialog(newProxy);
                result = dlgLanSettings.ShowDialog(this);
                if (result == DialogResult.OK)
                {
                    //don't add it until they've entered the data for it and saved it.
                    newProxy.SaveInConfigFile();
                    _proxyList.Add(newProxy);
                    _proxyList.Sort();
                }
            }
        }