Example #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int pageNr    = PageUtility.GetQueryInt(Request, "page", 1);
            int pageIndex = pageNr - 1;//Change range from 0 to * instead of 1 to *
            int count     = PageUtility.GetQueryInt(Request, "count", 100);

            if (count > 500)
            {
                count = 500;
            }

            string searchStr   = PageUtility.GetQueryString(Request, "search", "null");
            string searchRealm = PageUtility.GetQueryString(Request, "realm", "All");
            string searchRace  = PageUtility.GetQueryString(Request, "race", "All");
            string searchClass = PageUtility.GetQueryString(Request, "class", "All");
            string searchLevel = PageUtility.GetQueryString(Request, "level", "All");
            string searchSort  = PageUtility.GetQueryString(Request, "sort", "NameSearch");

            if (searchStr != "")
            {
                this.Title = "Search \"" + searchStr + "\" | RealmPlayers";
            }
            else
            {
                this.Title = "Search | RealmPlayers";
            }
            //List<Tuple<WowRealm, Player>>

            WowRealm realm = StaticValues.ConvertRealm(searchRealm);

            if (realm == WowRealm.Unknown)
            {
                realm = WowRealm.All;
            }

            int nr = 0;

            if (searchStr.Length >= 4 || searchStr.Contains(' '))
            {
                var guildSummaryDB = Hidden.ApplicationInstance.Instance.GetGuildSummaryDatabase();

                var searchStrLower = searchStr.ToLower();
                var guildArray     = guildSummaryDB.GetGuilds(realm).Where((_Value) => _Value.Value.GuildName.ToLower().Contains(searchStrLower));

                if (guildArray.Count() > pageIndex * count)
                {
                    Dictionary <string, Player> realmDB = null;
                    if (realm != WowRealm.All)
                    {
                        realmDB = DatabaseAccess.GetRealmPlayers(this, realm);
                    }
                    var realmDBRealm = realm;

                    System.Text.StringBuilder guildResultTable = new System.Text.StringBuilder(10000);
                    guildResultTable.Append("<h3>Guilds matching &quot;" + searchStr + "&quot;</h3>");
                    guildResultTable.Append("<table id=\"guild-table\" class=\"table\"><thead>");
                    guildResultTable.Append(PageUtility.CreateGuildTableHeaderRow(Table_GuildColumns));
                    guildResultTable.Append("</thead><tbody>");
                    var orderedGuildArray = guildArray.OrderBy((_Value) => _Value.Key);
                    foreach (var guild in orderedGuildArray)
                    {
                        if (realmDBRealm != guild.Value.Realm)
                        {
                            realmDB      = DatabaseAccess.GetRealmPlayers(this, guild.Value.Realm);
                            realmDBRealm = guild.Value.Realm;
                        }
                        guild.Value.GenerateCache(realmDB);
                    }
                    orderedGuildArray = orderedGuildArray.OrderByDescending((_Value) => _Value.Value.GetMembers().Count);
                    foreach (var guild in orderedGuildArray)
                    {
                        if (guild.Value.GetMembers().Count < 2)
                        {
                            continue;
                        }
                        nr++;
                        if (nr > pageIndex * count && nr <= (pageIndex + 1) * count)
                        {
                            guildResultTable.Append(PageUtility.CreateGuildRow(0, guild.Value, Table_GuildColumns));
                        }
                        if (nr >= (pageIndex + 1) * count)
                        {
                            break;
                        }
                    }
                    guildResultTable.Append("</tbody></table>");
                    guildResultTable.Append("<h3>Players matching &quot;" + searchStr + "&quot;</h3>");
                    if (nr > 0)
                    {
                        m_GuildResultTableHTML = new MvcHtmlString(guildResultTable.ToString());
                    }
                }
                else
                {
                    m_GuildResultTableHTML = null;
                    nr += guildArray.Count();
                }
            }

            var playersList = FindPlayersMatching(searchStr, searchRealm, searchRace, searchClass, searchLevel, searchSort);//.OrderBy((_Value) => { return ((int)_Value.Item1).ToString() + _Value.Item2.Name; });

            System.Text.StringBuilder page = new System.Text.StringBuilder(10000);

            IEnumerable <Player> orderedPlayersList = playersList;
            //if (playersList.Count() > 500 || searchStr.Length < 2)
            //    orderedPlayersList = playersList;//.OrderBy(_Player => _Player.Item2.Name);
            //else
            //if (searchStr.Length >= 1)
            //{
            //    string nameFormattedSearchStr = char.ToUpper(searchStr[0]) + searchStr.Substring(1).ToLower();
            //    orderedPlayersList = playersList.OrderByDescending(_Player => _Player.LastSeen.AddYears(_Player.Name.StartsWith(nameFormattedSearchStr) ? 2 : 0));
            //}
            //else
            //{
            //    orderedPlayersList = playersList.OrderBy(_Player => _Player.Name);
            //}
            var playerListCount = playersList.Count();

            foreach (Player player in orderedPlayersList)
            {
                if (playerListCount < count && player.Character.Level < 10 && searchStr.Length <= (double)player.Name.Length * 0.7)
                {
                    continue;
                }

                nr++;
                if (nr > pageIndex * count && nr <= (pageIndex + 1) * count)
                {
                    page.Append(PageUtility.CreatePlayerRow(0, player.Realm, player, Table_Columns));
                }
                if (nr >= (pageIndex + 1) * count)
                {
                    break;
                }
            }
            if (nr != 0 && nr <= pageIndex * count)
            {
                pageIndex = (nr - 1) / count;
                Response.Redirect(PageUtility.CreateUrlWithNewQueryValue(Request, "page", (pageIndex + 1).ToString()));
            }

            m_BreadCrumbHTML   = new MvcHtmlString(PageUtility.BreadCrumb_AddHome() + PageUtility.BreadCrumb_AddFinish("Characters"));
            m_CharListInfoHTML = new MvcHtmlString(CreateCharListInfo(searchStr, playersList.Count()));
            m_TableHeadHTML    = new MvcHtmlString(PageUtility.CreatePlayerTableHeaderRow(Table_Columns, null, Request));
            m_TableBodyHTML    = new MvcHtmlString(page.ToString());

            m_PaginationHTML = new MvcHtmlString(PageUtility.CreatePagination(Request, pageNr, ((playersList.Count() - 1) / count) + 1));
        }
Example #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int pageNr    = PageUtility.GetQueryInt(Request, "page", 1);
            int pageIndex = pageNr - 1;//Change range from 0 to * instead of 1 to *
            int count     = PageUtility.GetQueryInt(Request, "count", 50);

            if (count > 500)
            {
                count = 500;
            }

            var realm = RealmControl.Realm;

            if (realm == WowRealm.Unknown)
            {
                return;
            }

            this.Title = "Guilds @ " + StaticValues.ConvertRealmParam(realm) + " | RealmPlayers";

            var realmDB = DatabaseAccess.GetRealmPlayers(this, realm, NotLoadedDecision.RedirectAndWait);

            var guildSummaryDB = Hidden.ApplicationInstance.Instance.GetGuildSummaryDatabase();
            //;// DatabaseAccess.GetRealmGuilds(this, realm, NotLoadedDecision.RedirectAndWait).Where((guild) => { return guild.Value.GetTotalPlayers() > 0; })
            var    guildArray = guildSummaryDB.GetGuilds(realm);//.OrderByDescending((guild) => { return guild.Value.Players.Count; });
            string page       = "";
            int    nr         = 0;

            string guildProgressData = "";

            List <Tuple <int, Tuple <VF_RPDatabase.GuildSummary, string> > > progressGuilds = new List <Tuple <int, Tuple <VF_RPDatabase.GuildSummary, string> > >();

            foreach (var guild in guildArray)
            {
                guild.Value.GenerateCache(realmDB);
                if (guild.Value.GetMembers().Count > 0)
                {
                    string thisGuildProgressData   = guild.Value.m_GuildProgressData.Item1;
                    int    progressComparisonValue = guild.Value.m_GuildProgressData.Item2;
                    if (thisGuildProgressData == "" && guild.Value.Stats_GetTotalMaxLevels() >= 25)
                    {
                        try
                        {
                            thisGuildProgressData           = CreateProgressStr(this, guild.Value, realm, out progressComparisonValue);
                            guild.Value.m_GuildProgressData = Tuple.Create(thisGuildProgressData, progressComparisonValue);
                        }
                        catch (Exception ex)
                        {
                            Logger.LogException(ex);
                        }
                    }
                    progressGuilds.Add(Tuple.Create(progressComparisonValue, Tuple.Create(guild.Value, thisGuildProgressData)));
                }
            }
            var orderedProgressGuilds = progressGuilds.OrderByDescending(_Value =>
            {
                UInt64 sortValue = (((UInt64)_Value.Item1) << 32);
                if (sortValue != 0)
                {
                    //sortValue |= (((UInt64)(UInt32)_Value.Item2.Item1.Stats_GetAveragePVPRank()) << 16) | ((UInt64)(UInt32)_Value.Item2.Item1.GetMembers().Count);
                    sortValue |= (((UInt64)(UInt32)_Value.Item2.Item1.Stats_GetAverageMemberHKs()) << 16) | ((UInt64)(UInt32)_Value.Item2.Item1.GetMembers().Count);
                }
                else
                {
                    sortValue |= (UInt64)(UInt32)_Value.Item2.Item1.Stats_GetTotalMaxLevels();
                }
                return(sortValue);
            });

            if (orderedProgressGuilds.Count() > 0)
            {
                if (GuildProgress.GetProgressAQ40(orderedProgressGuilds.First().Item1) == 0) //AQ Content not released
                {
                    guildProgressData += "g_AQReleased = false;";
                }
                else
                {
                    guildProgressData += "g_AQReleased = true;";
                }
                if (GuildProgress.GetProgressNaxx(orderedProgressGuilds.First().Item1) == 0) //Naxx Content not released
                {
                    guildProgressData += "g_NaxxReleased = false;";
                }
                else
                {
                    guildProgressData += "g_NaxxReleased = true;";
                }
            }
            foreach (var guild in orderedProgressGuilds)
            {
                nr++;
                if (nr > pageIndex * count && nr <= (pageIndex + 1) * count)
                {
                    page += PageUtility.CreateGuildRow(nr, guild.Item2.Item1, Table_Columns);
                    guildProgressData += guild.Item2.Item2;
                }
                if (nr >= (pageIndex + 1) * count)
                {
                    break;
                }
            }
            if (nr != 0 && nr <= pageIndex * count)
            {
                pageIndex = (nr - 1) / count;
                Response.Redirect(PageUtility.CreateUrlWithNewQueryValue(Request, "page", (pageIndex + 1).ToString()));
            }
            m_BreadCrumbHTML = new MvcHtmlString(PageUtility.BreadCrumb_AddHome()
                                                 + PageUtility.BreadCrumb_AddRealm(RealmControl.Realm)
                                                 + PageUtility.BreadCrumb_AddFinish("Guilds"));
            m_GuildListInfoHTML = new MvcHtmlString(CreateGuildListInfo(StaticValues.GetWowVersion(RealmControl.Realm), progressGuilds.Count));
            m_TableHeadHTML     = new MvcHtmlString(PageUtility.CreateGuildTableHeaderRow(Table_Columns));
            m_TableBodyHTML     = new MvcHtmlString(page);

            m_PaginationHTML  = new MvcHtmlString(PageUtility.CreatePagination(Request, pageNr, ((guildArray.Count() - 1) / count) + 1));
            m_GuildScriptData = new MvcHtmlString("<script>var guildProgress = new Array();"
                                                  + guildProgressData
                                                  + "</script>");
        }