Example #1
0
 private void ShowServerInformation(ProxyServer.ProxyServer server)
 {
     // 显示服务器信息
     serverNameTextBox.Text        = server.Name;
     serverPasswordTextBox.Text    = server.LoginPassword;
     serverDescriptionTextBox.Text = server.Description;
     serverUserNameTextBox.Text    = server.LoginName;
     portTextBox.Text     = server.LoginPort.ToString();
     serverIPTextBox.Text = server.Hostname;
 }
Example #2
0
        private void confirmButton_Click(object sender, EventArgs e)
        {
            // 转换成ProxyServer对象类型 方便返回到主窗口
            int index = GetServerIndex(serverList,
                                       serverComboBox.SelectedItem.ToString().Split(new char[] { '(' },
                                                                                    StringSplitOptions.RemoveEmptyEntries)[0]);

            if (index != -1)
            {
                this.server         = serverList[index];
                SelectedServerIndex = index;
            }
        }
Example #3
0
        private void AddServer()
        {
            // 创建一个新的新的ProxyServer对象
            ProxyServer.ProxyServer server = new ProxyServer.ProxyServer();
            server.Name = "新建服务器";

            serverList.Add(server);

            // 修改后记得刷新列表显示
            UpdateServerListBox(serverList);

            //
            serversListBox.SelectedIndex = serversListBox.Items.Count - 1;
        }
Example #4
0
        /// <summary>
        /// 更换代理服务器
        /// </summary>
        private void ChangeServer()
        {
            ChangeServerForm form = new ChangeServerForm();

            if (form.ShowDialog() == DialogResult.Yes)
            {
                var obj = form.SelectedServer;
                if (obj != null)
                {
                    proxyServer = obj;
                    ShowProxyServerInfo(proxyServer);
                    // 更新配置信息
                    programConfig.SelectedServerIndex = form.SelectedServerIndex;
                }
            }
        }
Example #5
0
        /// <summary>
        /// 编辑代理服务器
        /// </summary>
        private void EditServer()
        {
            EditServerForm dialogForm = new EditServerForm();

            dialogForm.ShowDialog();

            // 关闭服务器编辑窗口后,需要从新从磁盘加载最新服务器配置,防止因为没有及时更新导致错误。
            var list = FileOperation.ReadServerList();

            if (list.Count > 0)
            {
                // 加载同名服务器最新信息
                for (var i = 0; i < list.Count; i++)
                {
                    if (list[i].Name == proxyServer.Name)
                    {
                        proxyServer = list[i];
                        ShowProxyServerInfo(proxyServer);

                        // 同时更新配置
                        programConfig.SelectedServerIndex = i;
                        return;
                    }
                }

                // 不存在的话,那么就尝试使用第一个
                proxyServer = list[0];
                ShowProxyServerInfo(proxyServer);
                // 同时更新配置
                programConfig.SelectedServerIndex = 0;
            }
            else
            {
                proxyServer = new ProxyServer.ProxyServer();
                ShowProxyServerInfo(proxyServer);
                programConfig.SelectedServerIndex = -1;
            }
        }
Example #6
0
 /// <summary>
 /// 显示代理服务器信息
 /// </summary>
 /// <param name="server"></param>
 private void ShowProxyServerInfo(ProxyServer.ProxyServer server)
 {
     // 显示代理服务器信息
     serverNameTextBox.Text = server.Name;
     serverIPTextBox.Text   = string.Format("{0}:{1}", server.Hostname, server.LoginPort);
 }
Example #7
0
        private void LoadConfig()
        {
            // 读取默认的配置信息
            programConfig = FileOperation.ReadConfig();

            if (programConfig != null)
            {
                if (programConfig.Client != null)
                {
                    client = programConfig.Client;
                }
                else
                {
                    client = new Client.Client();
                    programConfig.Client = client;
                }
            }
            else
            {
                // 做一些初始化的工作
                client        = new Client.Client();
                proxyServer   = new ProxyServer.ProxyServer();
                programConfig = new Config.Config(autoStartCheckBox.Checked,
                                                  closeWithoutQuitCheckBox.Checked, client, -1, 9000);
            }
            // 显示本机的有关信息
            ShowClientInfo(programConfig.Client);

            // checkbox状态
            autoStartCheckBox.Checked            = programConfig.AutoStartup;
            closeWithoutQuitCheckBox.Checked     = programConfig.EnableBackgroundMode;
            acceptControlRequestCheckBox.Checked = programConfig.AcceptControlRequest;

            // 显示代理服务器信息
            if (programConfig.SelectedServerIndex != -1)
            {
                var serverList = FileOperation.ReadServerList();
                if (serverList.Count > 0)
                {
                    if (programConfig.SelectedServerIndex < serverList.Count)
                    {
                        proxyServer = serverList[programConfig.SelectedServerIndex];
                    }
                    else
                    {
                        proxyServer = serverList[0];
                    }
                    ShowProxyServerInfo(proxyServer);
                }

                // 检查是否需要自动启动
                if (autoStartCheckBox.Checked)
                {
                    AutoStartService();
                }
            }
            else
            {
                // 打开编辑窗口,提示用户添加服务器
                MessageBox.Show("没有可以选择的代理服务器,请自行添加代理服务器后更换。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                EditServer();
                ChangeServer();
            }
        }