コード例 #1
0
        /// <summary>
        /// 此流程为从服务器更新cookie
        /// </summary>
        /// <returns></returns>
        bool SyncCookie()
        {
            bool syncStatus = false;

            try
            {
                String result = GetServerCookie();
                if (!String.IsNullOrEmpty(result))
                {
                    LoginInfoSyncResponse infoSyncResponse = JsonConvert.DeserializeObject <LoginInfoSyncResponse>(result);
                    if (infoSyncResponse.data != null && !String.IsNullOrEmpty(infoSyncResponse.data))
                    {
                        CookieModel = new FiddlerCacheInfo(infoSyncResponse.data);
                        InitProxyUrl(infoSyncResponse.proxyUrl);
                        SaveCookieSign = true;
                        syncStatus     = true;
                    }
                }
            }
            catch (Exception)
            {
            }
            return(syncStatus);
        }
コード例 #2
0
 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;
     }
 }