Exemplo n.º 1
0
 /// <summary>
 /// 数据下载完成后回调
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected virtual void _webClient_DownloadStringCompleted(object sender, HttpCompletedEventArgs e)
 {
     try
     {
         var content = AnalysisContent(e.Result);
         if (content != null)
         {
             if (HttpSucessHandler != null)
             {
                 if (!IsBackThreadCallBack)
                 {
                     _dispatcher.BeginInvoke(() =>
                     {
                         HttpSucessHandler(this, new HttpFactoryArgs <M>(string.Empty, content));
                     });
                 }
                 else
                 {
                     HttpSucessHandler(this, new HttpFactoryArgs <M>(string.Empty, content));
                 }
             }
         }
         else
         {
             if (HttpFailHandler != null)
             {
                 _dispatcher.BeginInvoke(() =>
                 {
                     HttpFailHandler(this, new HttpFactoryArgs <M>("数据解析错误", null));
                 });
             }
             if (HttpFailorTimeOut != null)
             {
                 _dispatcher.BeginInvoke(HttpFailorTimeOut);
             }
         }
     }
     catch (Exception ex)
     {
         if (HttpFailHandler != null)
         {
             _dispatcher.BeginInvoke(() =>
             {
                 HttpFailHandler(this, new HttpFactoryArgs <M>(ex.Message, null));
             });
         }
         if (HttpFailorTimeOut != null)
         {
             _dispatcher.BeginInvoke(HttpFailorTimeOut);
         }
     }
     finally
     {
         Cancel();
     }
 }
Exemplo n.º 2
0
        protected override void _webClient_DownloadStringCompleted(object sender, HttpCompletedEventArgs e)
        {
            try
            {
                var result = string.Empty;
                using (var reader = new StreamReader(e.Result))
                {
                    result = reader.ReadToEnd();
                }

                string   responseStr   = ParseLoginResponse(result, _keyIndex);
                string[] temp          = responseStr.Split('&');
                var      userStateInfo = new UserStateInfo();
                //(用户名&VIP标识&头像地址&等级&积分&经验值&用户状态&时间戳&过期时间&VIP会员到期时间&VIP会员类型& MD5&用户Token)
                for (int i = 0; i < temp.Length; i++)
                {
                    if (i == 0)
                    {
                        //会员名
                        userStateInfo.UserName = temp[i];
                    }
                    else if (i == 1)
                    {
                        //VIP标识
                        try
                        {
                            userStateInfo.VIP = Convert.ToInt32(temp[i]);
                        }
                        catch (Exception)
                        {
                            userStateInfo.VIP = -1;
                        }
                    }
                    else if (i == 2)
                    {
                        //头像地址
                        userStateInfo.FaceUrl = temp[i];
                    }
                    else if (i == 3)
                    {
                        //等级
                        try
                        {
                            userStateInfo.Degree = Convert.ToInt32(temp[i]);
                        }
                        catch (Exception)
                        {
                            userStateInfo.Degree = -1;
                        }
                    }
                    else if (i == 4)
                    {
                        //积分
                        try
                        {
                            userStateInfo.Mark = Convert.ToDouble(temp[i]);
                        }
                        catch (Exception)
                        {
                            userStateInfo.Mark = -1.0;
                        }
                    }
                    else if (i == 5)
                    {
                        //经验值
                        try
                        {
                            userStateInfo.Expence = Convert.ToDouble(temp[i]) * 100.0;  //经验值*100
                        }
                        catch (Exception)
                        {
                            userStateInfo.Expence = -1;
                        }
                    }
                    else if (i == 6)
                    {
                        //用户状态
                        try
                        {
                            userStateInfo.UserState = Convert.ToInt32(temp[i]);
                        }
                        catch (Exception)
                        {
                            userStateInfo.UserState = -1;
                        }
                    }
                    else if (i == 7)
                    {
                        //时间
                        try
                        {
                            userStateInfo.Date = Convert.ToInt64(temp[i]);
                        }
                        catch (Exception)
                        {
                            userStateInfo.Date = -1;
                        }
                    }
                    else if (i == 8)
                    {
                        //过期时间
                        try
                        {
                            userStateInfo.OutDate = Convert.ToInt64(temp[i]);
                        }
                        catch (Exception)
                        {
                            userStateInfo.OutDate = 0;
                        }
                    }
                    else if (i == 9)
                    {
                        //VIP到期时间
                        try
                        {
                            userStateInfo.VIPDate = Convert.ToInt64(temp[i]);
                        }
                        catch (Exception)
                        {
                            userStateInfo.VIPDate = 0;
                        }
                    }
                    else if (i == 10)
                    {
                        //VIP会员的类型
                        try
                        {
                            if (userStateInfo.VIP == 1)
                            {
                                userStateInfo.VIPType = Convert.ToInt32(temp[i]);
                            }
                            else
                            {
                                userStateInfo.VIPType = -1;//普通会员-1
                            }
                        }
                        catch (Exception)
                        {
                            userStateInfo.VIPType = -1;
                        }
                    }
                    else if (i == 11)
                    {
                        //MD5
                        userStateInfo.MD5 = temp[i];
                    }
                    else if (i == 12)
                    {
                        //Token
                        userStateInfo.Token = temp[i];
                    }
                    else if (i == 13)
                    {
                        userStateInfo.P13 = temp[i];
                    }
                    else if (i == 14)
                    {
                        userStateInfo.P14 = temp[i];
                    }
                    else if (i == 15)
                    {
                        userStateInfo.P15 = temp[i];
                    }
                }
                if (HttpSucessHandler != null)
                {
                    _dispatcher.BeginInvoke(() =>
                    {
                        HttpSucessHandler(this, new HttpFactoryArgs <UserStateInfo>(string.Empty, userStateInfo));
                    });
                }
            }
            catch (Exception ex)
            {
                if (HttpFailHandler != null)
                {
                    _dispatcher.BeginInvoke(() =>
                    {
                        HttpFailHandler(this, new HttpFactoryArgs <UserStateInfo>(ex.Message, null));
                    });
                }
            }
            finally
            {
                Cancel();
            }
        }