public static void LoadServerRanking()
        {
            try
            {
                var          ranking      = RankingFactory.Get <UserRank>(LevelRanking.RankingKey);
                LevelRanking levelranking = ranking as LevelRanking;
                levelranking.rankingData.RankTime = DateTime.Now;
                levelranking.rankingData.RankList.Clear();


                foreach (var v in ServerSet.Set)
                {
                    string   url   = v.ServerUrl;
                    string[] split = url.Split(':');
                    url = "http://" + split[0] + ":8091/GlobalCommon.aspx?";
                    url = url + HttpUtility.UrlEncode("ID=LevelRankingData");

                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                    request.Timeout = 5000;
                    request.Method  = "GET";
                    WebResponse     webresponse  = request.GetResponse();
                    HttpWebResponse httpResponse = (HttpWebResponse)webresponse;
                    Stream          stream       = httpResponse.GetResponseStream(); //获取响应的字符串流  
                    StreamReader    sr           = new StreamReader(stream);         //创建一个stream读取流  
                    string          data         = sr.ReadToEnd();                   //从头读到尾,放到字符串html  

                    if (data != null && data.Length > 0)
                    {
                        byte[]           bytes = Convert.FromBase64String(data);
                        MessageStructure ms    = new MessageStructure(bytes);

                        int listsize = ms.ReadInt();
                        for (int i = 0; i < listsize; ++i)
                        {
                            UserRank rank = new UserRank();
                            rank.UserID     = ms.ReadInt();
                            rank.NickName   = ms.ReadString();
                            rank.Profession = ms.ReadInt();
                            rank.RankId     = ms.ReadInt();
                            rank.UserLv     = ms.ReadInt();
                            rank.AvatarUrl  = ms.ReadString();
                            rank.FightValue = ms.ReadInt();
                            rank.VipLv      = ms.ReadInt();
                            levelranking.rankingData.RankList.Add(rank);
                        }
                    }
                }


                Ranking <UserRank> levelRanking = RankingFactory.Get <UserRank>(LevelRanking.RankingKey);
                levelRanking.ForceRefresh();
            }
            catch (Exception ex)
            {
                new BaseLog().SaveLog(ex);
                return;
            }
        }
Пример #2
0
 public UserRank(UserRank ur)
 {
     UserID     = ur.UserID;
     NickName   = ur.NickName;
     Profession = ur.Profession;
     RankId     = ur.RankId;
     UserLv     = ur.UserLv;
     AvatarUrl  = ur.AvatarUrl;
     FightValue = ur.FightValue;
     //RankDate = ur.RankDate;
     //HaveRankNum = ur.HaveRankNum;
     //IsFighting = ur.IsFighting;
     //FightDestUid = ur.FightDestUid;
     VipLv = ur.VipLv;
 }
        public static void LoadServerRanking()
        {
            try
            {
                new BaseLog().SaveLog("全服排名开始...");
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();

                var          ranking      = RankingFactory.Get <UserRank>(LevelRanking.RankingKey);
                LevelRanking levelranking = ranking as LevelRanking;
                levelranking.rankingData.RankTime = DateTime.Now;
                levelranking.rankingData.RankList.Clear();


                int count = 0;
                for (int i = 0; i < ServerSet.Set.Count; ++i)
                {
                    if (ServerSet.Set[i].ServerUrl.Contains("168.254") ||
                        ServerSet.Set[i].ServerUrl.Contains("192.168"))
                    {
                        continue;
                    }
                    string serverName = ServerSet.Set[i].ServerName;
                    string connectKey = "ServerDB_" + (count++ + 1).ToString();
                    var    dbProvider = DbConnectionProvider.CreateDbProvider(connectKey);
                    string sql        = "SELECT UserID,NickName,ServerID,Profession,UserLv,AvatarUrl,VipLv,LevelRankID FROM UserBasisCache";
                    using (IDataReader reader = dbProvider.ExecuteReader(CommandType.Text, sql))
                    {
                        while (reader.Read())
                        {
                            UserRank rankInfo = new UserRank();
                            rankInfo.UserID     = reader["UserID"].ToInt();
                            rankInfo.NickName   = reader["NickName"].ToString();
                            rankInfo.Profession = reader["Profession"].ToInt();
                            rankInfo.UserLv     = Convert.ToInt16(reader["UserLv"]);
                            rankInfo.VipLv      = reader["VipLv"].ToInt();
                            rankInfo.AvatarUrl  = reader["AvatarUrl"].ToString();
                            rankInfo.RankId     = reader["LevelRankID"].ToInt();
                            rankInfo.ServerID   = reader["ServerID"].ToInt();
                            rankInfo.ServerName = serverName;
                            levelranking.rankingData.RankList.Add(rankInfo);
                        }
                    }

                    sql = "SELECT UserID, FightValue FROM UserAttributeCache";
                    using (IDataReader reader = dbProvider.ExecuteReader(CommandType.Text, sql))
                    {
                        while (reader.Read())
                        {
                            int userId = reader["UserID"].ToInt();
                            var rank   = levelranking.rankingData.RankList.Find(t => t.UserID == userId);
                            if (rank != null)
                            {
                                rank.FightValue = reader["FightValue"].ToInt();
                            }
                        }
                    }
                }


                Ranking <UserRank> levelRanking = RankingFactory.Get <UserRank>(LevelRanking.RankingKey);
                levelRanking.ForceRefresh();

                stopwatch.Stop();
                new BaseLog().SaveLog("全服排名消耗时间:" + stopwatch.Elapsed.TotalMilliseconds + "ms");
            }
            catch (Exception ex)
            {
                new BaseLog().SaveLog(ex);
                return;
            }
        }