private void ChinaLifeForm_Load(object sender, EventArgs e) { try { //系统初始化,关闭代理 FiddlerUtils.CloseProxy(); Task.Factory.StartNew(() => { UpdateVersion(); }); CloseSameProcess(); MessageBox.Show("请注意!!! 使用代理工具期间,尽量关闭安全软件哦!(如360安全卫士,防火墙等)", "提醒"); this.usernameTxt.Text = Config.UserName; if (String.IsNullOrEmpty(Config.UserName)) { try { String filePath = GetUserCodeFilePath(); if (File.Exists(filePath)) { this.usernameTxt.Text = File.ReadAllText(filePath); } } catch (Exception ex) { } } StartSyncCookieTimer(); StartUpdateVersionTimer(); StartUpdateProcessAndStartSocketConnect(); } catch (Exception ex) { } }
private void closeProxyButton_Click(object sender, EventArgs e) { FiddlerUtils.CloseProxy(); MessageBox.Show("代理已关闭!\r\n\r\n如代理仍未关闭,请手动取消系统代理即可!", "提醒"); CloseUpdateProcess(); System.Environment.Exit(0); }
private static void SetRegProxyClose(Microsoft.Win32.RegistryKey rsrch_rk) { rsrch_rk.SetValue("ProxyEnable", 0); rsrch_rk.Flush(); rsrch_rk.Close(); InternetSetOption(IntPtr.Zero, INTERNET_OPTION_SETTINGS_CHANGED, IntPtr.Zero, 0); InternetSetOption(IntPtr.Zero, INTERNET_OPTION_REFRESH, IntPtr.Zero, 0); FiddlerUtils.ChangeReg(); }
private void ChinaLifeForm_FormClosing(object sender, FormClosingEventArgs e) { CloseUpdateProcess(); FiddlerUtils.CloseProxy(); }
private void startProxyButton_Click(object sender, EventArgs e) { try { this.startProxyButton.Enabled = false; Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", true); if (rk.GetValue("ProxyEnable").ToString() == "1") { /** * 1.如果系统代理已经是勾选状态,且判定为代理工具设置的代理,则直接从服务器获取最新cookie,提示已更新即可 * 此场景应该较多 * 2.否则提醒用户关闭后在开启 */ String proxyServer = rk.GetValue("ProxyServer").ToString(); if (!String.IsNullOrEmpty(proxyServer) && proxyServer.Contains(":8899")) { Config.UserName = this.usernameTxt.Text.Trim(); bool syncCookieStatus = SyncCookie(); if (syncCookieStatus) { MessageBox.Show("代理已更新,请执行 CTRL+F5 刷新页面哦!", "提醒"); } else { MessageBox.Show("代理更新失败,请关闭代理后重试,或联系管理员处理!", "提醒"); } } else { MessageBox.Show("代理已经是启动状态哦!,如需重新启动代理,请先点击关闭代理按钮!", "提醒"); } } else { try { Config.UserName = this.usernameTxt.Text.Trim(); if (!String.IsNullOrEmpty(Config.UserName)) { string result = GetServerCookie(); if (!String.IsNullOrEmpty(result)) { LoginInfoSyncResponse infoSyncResponse = JsonConvert.DeserializeObject <LoginInfoSyncResponse>(result); if (infoSyncResponse.data != null && !String.IsNullOrEmpty(infoSyncResponse.data)) { try { CookieModel = new FiddlerCacheInfo(infoSyncResponse.data); InitProxyUrl(infoSyncResponse.proxyUrl); SaveCookieSign = true; FiddlerUtils.SetSSLCer(); Fiddler.FiddlerApplication.BeforeRequest += FiddlerApplication_BeforeRequest; Fiddler.FiddlerApplication.BeforeResponse += FiddlerApplication_BeforeResponse; BiHu.BaoXian.ClassCommon.WebProxy.Start(8899); MessageBox.Show("代理已启动!!! \r\n\r\n\r\n请执行以下步骤 ( 建议使用Chrome浏览器 ^_^ ) :\r\n\r\n\r\n1.打开浏览器。\r\n\r\n2.执行 Ctrl + Shift + Delete 清空缓存。\r\n\r\n3.重启浏览器,直接进入核心系统首页即可。", "提醒"); } catch (Exception ex) { throw new Exception(String.Format("启动代理发生异常,请与管理员联系!\r\n\r\n({0})\r\n\r\n注:可点击【关闭代理】按钮,再试一次哦!", ex.Message)); } } else { MessageBox.Show("工号信息失效,请与管理员联系!", "提醒"); } } else { MessageBox.Show("工号信息为空,请与管理员联系!", "提醒"); } } else { MessageBox.Show("请输入核心系统工号哦!", "提醒"); this.usernameTxt.Focus(); } } catch (Exception ex) { MessageBox.Show(String.Format("启动代理发生异常:{0}\r\n\r\n注:可点击【关闭代理】按钮,再试一次哦!", ex.Message), "提醒"); } } } catch (Exception) { } finally { this.startProxyButton.Enabled = true; } }