Beispiel #1
0
        public static VF_RealmPlayersDatabase.PlayersOnlineDB GetRealmOnlinePlayers(System.Web.UI.Page _Page, WowRealm _Realm, NotLoadedDecision _Decision = NotLoadedDecision.SpinWait)
        {
            var realm = _FindRealmDB(_Page, _Realm, _Decision);

            if (realm == null || (realm.IsPlayersOnlineLoadComplete() == false && _Decision != NotLoadedDecision.SpinWait))
            {
                if (_Decision == NotLoadedDecision.RedirectAndWait)
                {
                    PageUtility.RedirectErrorLoading(_Page, StaticValues.ConvertRealmParam(_Realm));
                }
                return(null);
            }
            return(realm.PlayersOnlineData);
        }
Beispiel #2
0
        //public static RealmDatabase GetRealmDB(System.Web.UI.Page _Page, WowRealm _Realm, string _RedirectSubRealmSection = "")
        //{
        //    var rppDatabase = ApplicationInstance.Instance.GetRPPDatabase(false);
        //    if (rppDatabase == null)
        //    {
        //        PageUtility.RedirectErrorLoading(_Page, StaticValues.ConvertRealmParam(_Realm) + _RedirectSubRealmSection);
        //        return null;
        //    }
        //    return rppDatabase.GetRealm(_Realm);
        //}
        //public static PlayerData.PlayerHistory GetRealmPlayerHistory(System.Web.UI.Page _Page, WowRealm _Realm, string _Player)
        //{
        //    var realm = GetRealmDB(_Page, _Realm, "-history");
        //    if (realm.IsPlayersHistoryLoadComplete() == false)
        //    {
        //        PageUtility.RedirectErrorLoading(_Page, StaticValues.ConvertRealmParam(_Realm) + "-history");
        //        return null;
        //    }
        //    PlayerData.PlayerHistory playerHistory;
        //    if (realm.PlayersHistory.TryGetValue(_Player, out playerHistory) == false)
        //        return null;
        //    return playerHistory;
        //}
        //public static PlayerData.Player GetRealmPlayer(System.Web.UI.Page _Page, WowRealm _Realm, string _Player)
        //{
        //    var realm = GetRealmDB(_Page, _Realm, "-latest");
        //    if (realm.IsPlayersLoadComplete() == false)
        //    {
        //        PageUtility.RedirectErrorLoading(_Page, StaticValues.ConvertRealmParam(_Realm) + "-latest");
        //        return null;
        //    }
        //    PlayerData.Player player;
        //    if (realm.Players.TryGetValue(_Player, out player) == false)
        //        return null;
        //    return player;
        //}
        //public static Dictionary<int, List<Tuple<DateTime, string>>> GetRealmCacheDB_ItemsUsed(System.Web.UI.Page _Page, WowRealm _Realm)
        //{
        //    var realm = GetRealmDB(_Page, _Realm, "-itemsused");
        //    if (realm.IsLoadComplete() == false)
        //    {
        //        PageUtility.RedirectErrorLoading(_Page, StaticValues.ConvertRealmParam(_Realm) + "-itemsused");
        //        return null;
        //    }
        //}
        public static RealmDatabase _FindRealmDB(System.Web.UI.Page _Page, WowRealm _Realm, NotLoadedDecision _Decision = NotLoadedDecision.SpinWait)
        {
            var rppDatabase = Hidden.ApplicationInstance.Instance._GetRPPDatabase(_Decision == NotLoadedDecision.SpinWait);

            if (rppDatabase == null)
            {
                if (_Decision == NotLoadedDecision.RedirectAndWait)
                {
                    PageUtility.RedirectErrorLoading(_Page, StaticValues.ConvertRealmParam(_Realm));
                }
                return(null);
            }
            return(rppDatabase.GetRealm(_Realm));
        }
Beispiel #3
0
        public static Dictionary <string, PlayerData.PlayerHistory> _GetRealmPlayersHistory(System.Web.UI.Page _Page, WowRealm _Realm, NotLoadedDecision _Decision = NotLoadedDecision.RedirectAndWait)
        {
            var realm = _FindRealmDB(_Page, _Realm);

            if (realm == null || (realm.IsPlayersHistoryLoadComplete() == false && _Decision != NotLoadedDecision.SpinWait))
            {
                if (_Decision == NotLoadedDecision.RedirectAndWait)
                {
                    PageUtility.RedirectErrorLoading(_Page, StaticValues.ConvertRealmParam(_Realm) + "-history");
                }
                return(null);
            }
            return(realm.PlayersHistory);
        }
Beispiel #4
0
 public string GetRealmParam()
 {
     return(StaticValues.ConvertRealmParam(m_Realm));
 }
Beispiel #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var realm = PageUtility.GetQueryRealm(Request);

            if (realm == WowRealm.Unknown)
            {
                return;
            }
            var wowVersion = StaticValues.GetWowVersion(realm);

            var onlinePlayersDB = DatabaseAccess.GetRealmOnlinePlayers(this, realm);

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

            m_BreadCrumbHTML = new MvcHtmlString(PageUtility.BreadCrumb_AddHome()
                                                 + PageUtility.BreadCrumb_AddRealm(realm)
                                                 + PageUtility.BreadCrumb_AddFinish("OnlineStats"));

            m_PageInfoHTML = new MvcHtmlString("<h1>OnlineStats"
                                               + "</h1><p>OnlineStats for realm " + StaticValues.ConvertRealmViewing(realm) + "</p>"
                                               + "<p>" + onlinePlayersDB.OnlineEntries.Count + " nr of onlinestats entries!</p>");

            string graphSection = "";

            {
                List <int>    dataX  = new List <int>();
                List <int>    dataY1 = new List <int>();
                List <int>    dataY2 = new List <int>();
                List <int>    dataY3 = new List <int>();
                List <int>    dataY4 = new List <int>();
                List <int>    dataY5 = new List <int>();
                List <string> labels = new List <string>();

                DateTime currOnlineDateTime = DateTime.UtcNow.AddDays(-14);
                currOnlineDateTime = currOnlineDateTime.AddMinutes(-currOnlineDateTime.Minute).AddSeconds(-currOnlineDateTime.Second).AddHours(1);
                //Remove minute and second significants

                int day = 0;

                HashSet <string> onlinePlayers            = new HashSet <string>();
                HashSet <string> playersInRaidAndDungeons = new HashSet <string>();
                HashSet <string> playersInBattlegrounds   = new HashSet <string>();
                HashSet <string> playersAtLvl60           = new HashSet <string>();

                Action addGraphEntry = () =>
                {
                    labels.Add(currOnlineDateTime.ToDateStr() + "<br />Players online: " + PageUtility.CreateColorString(onlinePlayers.Count.ToString(), System.Drawing.Color.Green)
                               + "<br />Players in Raids/Dungeons: " + PageUtility.CreateColorString(playersInRaidAndDungeons.Count.ToString()
                                                                                                     + (onlinePlayers.Count != 0 ? " ( " + (((double)playersInRaidAndDungeons.Count / (double)onlinePlayers.Count) * 100).ToStringDot("0.0") + "% )" : ""), System.Drawing.Color.Yellow)
                               + "<br />Players in Battlegrounds: " + PageUtility.CreateColorString(playersInBattlegrounds.Count.ToString()
                                                                                                    + (onlinePlayers.Count != 0 ? " ( " + (((double)playersInBattlegrounds.Count / (double)onlinePlayers.Count) * 100).ToStringDot("0.0") + "% )" : ""), System.Drawing.Color.Red)
                               + "<br />Players below lvl 60: " + PageUtility.CreateColorString((onlinePlayers.Count - playersAtLvl60.Count).ToString()
                                                                                                + (onlinePlayers.Count != 0 ? " ( " + (((double)(onlinePlayers.Count - playersAtLvl60.Count) / (double)onlinePlayers.Count) * 100).ToStringDot("0.0") + "% )" : ""), System.Drawing.Color.Cyan)
                               + "<br />Players at lvl 60: " + PageUtility.CreateColorString(playersAtLvl60.Count.ToString()
                                                                                             + (onlinePlayers.Count != 0 ? " ( " + (((double)playersAtLvl60.Count / (double)onlinePlayers.Count) * 100).ToStringDot("0.0") + "% )" : ""), System.Drawing.Color.Purple));
                    dataX.Add(++day);
                    dataY1.Add(onlinePlayers.Count);
                    dataY2.Add(playersInRaidAndDungeons.Count);
                    dataY3.Add(playersInBattlegrounds.Count);
                    dataY4.Add(playersAtLvl60.Count);
                    dataY5.Add(onlinePlayers.Count - playersAtLvl60.Count);
                    onlinePlayers.Clear();
                    playersInRaidAndDungeons.Clear();
                    playersInBattlegrounds.Clear();
                    playersAtLvl60.Clear();
                };
                foreach (var onlineEntry in onlinePlayersDB.OnlineEntries)
                {
                    if (onlineEntry.DateTime_EndSpan < currOnlineDateTime)
                    {
                        continue;
                    }

                    while (currOnlineDateTime <= onlineEntry.DateTime_StartSpan.AddHours(-8))
                    {
                        addGraphEntry();
                        currOnlineDateTime = currOnlineDateTime.AddHours(8);
                    }

                    foreach (var entry in onlineEntry.OnlinePlayers)
                    {
                        onlinePlayers.Add(entry.Key);
                        if (StaticValues.IsZoneRaid(entry.Value.Zone) || StaticValues.IsZoneDungeon(entry.Value.Zone))
                        {
                            playersInRaidAndDungeons.Add(entry.Key);
                        }
                        if (StaticValues.IsZoneBattleground(entry.Value.Zone))
                        {
                            playersInBattlegrounds.Add(entry.Key);
                        }
                        if (entry.Value.Level == 60)
                        {
                            playersAtLvl60.Add(entry.Key);
                        }
                    }
                    foreach (var entry in onlineEntry.OnlinePlayers_Duplicates)
                    {
                        if (StaticValues.IsZoneRaid(entry.Zone) || StaticValues.IsZoneDungeon(entry.Zone))
                        {
                            playersInRaidAndDungeons.Add(entry.Name);
                        }
                        if (StaticValues.IsZoneBattleground(entry.Zone))
                        {
                            playersInBattlegrounds.Add(entry.Name);
                        }
                        if (entry.Level == 60)
                        {
                            playersAtLvl60.Add(entry.Name);
                        }
                    }
                }

                addGraphEntry();

                graphSection += "<div class='fame' style='min-width: 1100px; max-width: 1100px'>" + PageUtility.CreateGraph(dataX,
                                                                                                                            new List <Tuple <List <int>, System.Drawing.Color> >
                {
                    new Tuple <List <int>, System.Drawing.Color>(dataY5, System.Drawing.Color.Cyan),
                    new Tuple <List <int>, System.Drawing.Color>(dataY4, System.Drawing.Color.Purple),
                    new Tuple <List <int>, System.Drawing.Color>(dataY3, System.Drawing.Color.Red),
                    new Tuple <List <int>, System.Drawing.Color>(dataY2, System.Drawing.Color.Yellow),
                    new Tuple <List <int>, System.Drawing.Color>(dataY1, System.Drawing.Color.Green)
                },
                                                                                                                            labels
                                                                                                                            , 1100, 400) + "</div>";
            }
            m_BodyHTML = new MvcHtmlString(graphSection);
        }
Beispiel #6
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;
            }

            var realm = RealmControl.Realm;

            if (realm == VF_RealmPlayersDatabase.WowRealm.Unknown)
            {
                return;
            }
            var wowVersion = StaticValues.GetWowVersion(realm);
            int itemID     = PageUtility.GetQueryInt(Request, "item", 19364);
            int suffixID   = PageUtility.GetQueryInt(Request, "suffix", 0);

            this.Title = "\"" + itemID + "\" ItemUsage @ " + StaticValues.ConvertRealmParam(realm) + " | RealmPlayers";

            m_BreadCrumbHTML = new MvcHtmlString(PageUtility.BreadCrumb_AddHome()
                                                 + PageUtility.BreadCrumb_AddFinish("ItemUsage"));

            var itemSummaryDB = Hidden.ApplicationInstance.Instance.GetItemSummaryDatabase();

            using (VF.SQLComm comm = new VF.SQLComm())
            {
                List <Tuple <DateTime, string> > players = null;
                players = itemSummaryDB.GetItemUsage(realm, itemID, suffixID);//, out players) == true)
                {
                    string currentItemDatabase = DatabaseAccess.GetCurrentItemDatabaseAddress();

                    var itemInfo = DatabaseAccess.GetItemInfo(itemID, wowVersion);
                    m_ItemUsageInfoHTML = new MvcHtmlString("<div style='overflow: hidden; display: table;'><div style='display: table-cell;'><h1>Players with&nbsp;<h1></div>"
                                                            + "<div class='inventory' style='background: none; width: 58px; height: 58px; display: table-cell;'><div>"
                                                            + "<img class='itempic' src='" + "http://realmplayers.com/" + itemInfo.GetIconImageAddress() + "'/>"
                                                            + "<div class='quality' id='" + CharacterViewer.ItemQualityConversion[itemInfo.ItemQuality] + "'></div>"
                                                            + "<img class='itemframe' src='assets/img/icons/ItemNormalFrame.png'/>"
                                                            + CharacterViewer.GenerateItemLink(currentItemDatabase, itemID, suffixID, wowVersion)
                                                            + "</div></div>"
                                                            + "<span class='badge badge-inverse'>" + players.Count + " Players</span></div>" + "<p>Sorted by date \"aquired\"</p>");

                    Dictionary <PlayerColumn, string[]> extraColumns = new Dictionary <PlayerColumn, string[]>();
                    PlayerColumn ItemAndAquiredDateAfterColumn       = PlayerColumn.Number;
                    extraColumns.Add(ItemAndAquiredDateAfterColumn, new string[] { "Item", "Date Aquired" });
                    m_TableHeadHTML = new MvcHtmlString(PageUtility.CreatePlayerTableHeaderRow(Table_Columns, extraColumns));

                    string tableBody = "";
                    int    nr        = 0;
                    Func <Tuple <DateTime, string>, DateTime> lambdaComparison = (_Tuple) => { return(_Tuple.Item1); };
                    players = players.OrderBy(lambdaComparison).ToList();
                    foreach (var playerDateAndName in players)
                    {
                        Player player = DatabaseAccess.FindRealmPlayer(this, realm, playerDateAndName.Item2);
                        if (player != null)
                        {
                            ++nr;
                            // style='position: absolute; margin: auto; width:58px; height:58px;'
                            if (nr > pageIndex * count && nr <= (pageIndex + 1) * count)
                            {
                                //string itemLink = "";
                                VF_RealmPlayersDatabase.PlayerData.ItemInfo playerItemData = null;
                                try
                                {
                                    playerItemData = player.Gear.Items.First((_Item) => { return(_Item.Value.ItemID == itemID); }).Value;
                                }
                                catch (Exception)
                                {
                                    playerItemData = null;
                                }
                                if (playerItemData != null)
                                {
                                    //Data fanns i gearen som playern använder för tillfället!
                                    //itemLink = currentItemDatabase + "?item=" + playerItemData.ItemID + "' rel='rand=" + playerItemData.SuffixID + ";ench=" + playerItemData.EnchantID;
                                }
                                else
                                {
                                    //Måste titta igenom history!
#if NO_SQL
                                    PlayerHistory playerHistory = DatabaseAccess.FindRealmPlayerHistory(this, realm, playerDateAndName.Item2);
                                    if (playerHistory != null)
                                    {
                                        for (int i = playerHistory.GearHistory.Count - 1; i >= 0; --i)
                                        {
                                            try
                                            {
                                                playerItemData = playerHistory.GearHistory[i].Data.Items.First((_Item) => { return(_Item.Value.ItemID == itemID); }).Value;
                                            }
                                            catch (Exception)
                                            {
                                                playerItemData = null;
                                            }
                                            if (playerItemData != null)
                                            {
                                                //Data fanns i gearen som playern använder för tillfället!
                                                //itemLink = currentItemDatabase + "?item=" + playerItemData.ItemID + "' rel='rand=" + playerItemData.SuffixID + ";ench=" + playerItemData.EnchantID;
                                                break;
                                            }
                                        }
                                    }
#else
                                    /*Disable this for now. it is too slow...*/
                                    //playerItemData = comm.GetLatestItemInfoForPlayer(playerDateAndName.Item2, realm, itemID);
#endif
                                }
                                if (playerItemData == null)
                                {
                                    playerItemData = new VF_RealmPlayersDatabase.PlayerData.ItemInfo {
                                        Slot = VF_RealmPlayersDatabase.ItemSlot.Unknown, ItemID = itemID, SuffixID = 0, EnchantID = 0, UniqueID = 0, GemIDs = null
                                    };
                                }
                                extraColumns[ItemAndAquiredDateAfterColumn] = new string[] {
                                    "<div class='inventory' style='background: none; width: 58px; height: 58px;'><div>"
                                    + "<img class='itempic' src='" + "http://realmplayers.com/" + itemInfo.GetIconImageAddress() + "'/>"
                                    + "<div class='quality' id='" + CharacterViewer.ItemQualityConversion[itemInfo.ItemQuality] + "'></div>"
                                    + "<img class='itemframe' src='assets/img/icons/ItemNormalFrame.png'/>"
                                    + CharacterViewer.GenerateItemLink(currentItemDatabase, playerItemData, wowVersion)
                                    + "</div></div>"
                                    , playerDateAndName.Item1.ToString("yyyy-MM-dd")
                                };
                                tableBody += PageUtility.CreatePlayerRow(nr, realm, player, Table_Columns, null, extraColumns);
                            }
                            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_TableBodyHTML = new MvcHtmlString(tableBody);

                    int maxPageNr = 1000000 / count;
                    m_PaginationHTML = new MvcHtmlString(PageUtility.CreatePagination(Request, pageNr, ((players.Count - 1) / count) + 1));
                }
            }
        }
Beispiel #7
0
        public string CreateInventoryInfo(List <PlayerItemInfo> _Items, PlayerRace _Race, PlayerClass _Class, PlayerSex _Sex, WowRealm _Realm = WowRealm.All, WowVersionEnum _WowVersion = WowVersionEnum.Vanilla)
        {
            string invInfo = "";

            string currentItemDatabase = DatabaseAccess.GetCurrentItemDatabaseAddress();

            var itemSummaryDB = Hidden.ApplicationInstance.Instance.GetItemSummaryDatabase();

            string modelEqString = "";
            var    itemIDs       = _Items.Select((_Value) => _Value.ItemID);

            foreach (var item in _Items)
            {
                var itemInfo = DatabaseAccess.GetItemInfo(item.ItemID, _WowVersion);
                if (itemInfo == null)
                {
                    invInfo += "<div class='equipment-slot' id='" + CharacterViewer.ItemSlotToIDConversion[item.Slot] + "'><div class='quality' id='epic'></div><img src='assets/img/icons/inv_misc_questionmark.png'/></div>";
                }
                else
                {
                    string currInvInfo = "<div class='equipment-slot' id='" + CharacterViewer.ItemSlotToIDConversion[item.Slot] + "'>"
                                         + "<img class='itempic' src='" + "http://realmplayers.com/" + itemInfo.GetIconImageAddress() + "'/>"
                                         + "<div class='quality' id='" + CharacterViewer.ItemQualityConversion[itemInfo.ItemQuality] + "'></div>"
                                         + "<img class='itemframe' src='assets/img/icons/ItemNormalFrame.png'/>"
                                         + CharacterViewer.GenerateItemLink(currentItemDatabase, item, _WowVersion, itemInfo.GenerateSetPcsStr(itemIDs));

                    if (item.Slot == ItemSlot.Head && ModelViewerOptions.HideHead == true)
                    {
                    }
                    else
                    {
                        if ((_Class == VF_RealmPlayersDatabase.PlayerClass.Hunter && (item.Slot == ItemSlot.Main_Hand || item.Slot == ItemSlot.Off_Hand)) ||
                            (_Class != VF_RealmPlayersDatabase.PlayerClass.Hunter && item.Slot == ItemSlot.Ranged))
                        {
                        }
                        else
                        {
                            int modelViewerID   = 0;
                            int modelViewerSlot = 0;
                            if (itemInfo.GetModelViewerIDAndSlot(item.Slot, out modelViewerID, out modelViewerSlot, true) == true)
                            {
                                if (item.Slot == ItemSlot.Off_Hand)
                                {
                                    if (itemInfo.AjaxTooltip.Contains("Shield") == false)
                                    {
                                        modelViewerSlot = 22;
                                    }
                                }
                                if (modelViewerID != 0)
                                {
                                    modelEqString = modelEqString + "," + modelViewerSlot + "," + modelViewerID;
                                }
                            }
                        }
                    }
                    //List<Tuple<DateTime, string>> players = null;
                    if (_Realm != WowRealm.All)
                    {
                        int usageCount = itemSummaryDB.GetItemUsageCount(_Realm, item);
                        currInvInfo += "<a class='itemplayersframe' href='ItemUsageInfo.aspx?realm=" + StaticValues.ConvertRealmParam(_Realm) + "&item=" + item.ItemID + (item.SuffixID != 0 ? "&suffix=" + item.SuffixID : "") + "'>" + usageCount + "</a>";
                    }
                    currInvInfo += "</div>";
                    invInfo     += currInvInfo;
                }
            }
            invInfo += "<img style='position: absolute;z-index: 1; pointer-events: none;' src='assets/img/bg/CharacterBackgroundTransparent.png'></img>";

            string modelViewerQuery = PageUtility.GetQueryString(Request, "modelviewer", "unknown").ToLower();

            if (modelViewerQuery != "false" && modelEqString != "" && ModelViewerOptions.View3DModel == true)
            {
                if (modelEqString[0] == ',')//För att bli av med det första ","
                {
                    modelEqString = modelEqString.Substring(1);
                }
                //modelEqString = "1,33743,3,33653,5,33650,6,31110,7,31115,8,31111,9,31127,10,33651,13,25629";
                string modelCharString = ((_Race == VF_RealmPlayersDatabase.PlayerRace.Undead) ? "Scourge" : _Race.ToString().Replace("_", "")) + _Sex.ToString();// "orcmale";

                invInfo += "<div style='z-index: 0; position: absolute; margin: 33px 77px; width:385px; height:512px;'><object type='application/x-shockwave-flash' data='http://wow.zamimg.com/modelviewer/ZAMviewerfp11.swf' width='385' height='512' id='dsjkgbdsg2346' style='visibility: visible;'>"
                           + "<param name='quality' value='low'>"
                           + "<param name='allowscriptaccess' value='always'>"
                           + "<param name='allowfullscreen' value='false'>"
                           + "<param name='menu' value='false'>"
                           + "<param name='bgcolor' value='#181818'>"
                           + "<param name='wmode' value='direct'>"
                           + "<param name='flashvars' value='hd=false&amp;model="
                           + modelCharString
                           + "&amp;modelType=16&amp;contentPath=http://wow.zamimg.com/modelviewer/&amp;equipList="
                           + modelEqString
                           + "'>"
                           + "</object></div>";
            }
            else
            {
                invInfo += "<img class='characterimage' src='" + StaticValues.GetRaceCrestImageUrl(_Race) + "'></img>";
            }

            Hidden.ApplicationInstance.Instance.BackupItemInfos();
            return(invInfo);
        }
Beispiel #8
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>");
        }
Beispiel #9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string sectionStr = PageUtility.GetQueryString(Request, "section", "ranks");
            int    count      = PageUtility.GetQueryInt(Request, "count", 100);

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

            var realm = RealmControl.Realm;

            if (realm == WowRealm.Unknown)
            {
                return;
            }
            var wowVersion = StaticValues.GetWowVersion(realm);

            PlayerColumn[] lifetimeKillsColumns = Table_Lifetime_Kills_Columns;
            PlayerColumn[] rankColumns          = Table_Ranks_Columns;
            Func <KeyValuePair <string, Player>, double> rankSorterLambda = (KeyValuePair <string, Player> _Player) => { return(_Player.Value.GetRankTotal()); };
            Func <Player, bool> rankShowLambda = (Player _Player) => { return(_Player.ReceivedStandingLastWeek() == true && ((DateTime.UtcNow - _Player.LastSeen).TotalDays <= 7.0)); };

            if (wowVersion == VF_RealmPlayersDatabase.WowVersionEnum.TBC)
            {
                lifetimeKillsColumns = Table_Lifetime_Kills_Columns_TBC;
                rankColumns          = Table_Ranks_Columns_TBC;
                rankSorterLambda     = (KeyValuePair <string, Player> _Player) => {
                    return(_Player.Value.GetArenaRatingTotal());
                };
                rankShowLambda = (Player _Player) => {
                    return(_Player.Arena != null);
                };
            }
            if (sectionStr == "standings")
            {
                this.Title = "Standings @ " + StaticValues.ConvertRealmParam(realm) + " | RealmPlayers";

                m_PageHTML = new MvcHtmlString(CreateStandingsTable(realm, count, (player) => { return(player.ReceivedStandingLastWeek()); }));

                if (wowVersion == VF_RealmPlayersDatabase.WowVersionEnum.TBC)
                {
                    GeneratePageDetails("Standings", count * 2, "TBC works with a different PVP system so there are no standings.");
                }
                else
                {
                    var rankUpdateDay = StaticValues.GetRankUpdadeDayType(realm);
                    switch (rankUpdateDay)
                    {
                    case VF_RealmPlayersDatabase.StaticValues.RankUpdateDayType.Wednesday_Morning:
                        GeneratePageDetails("Standings", count * 2, "Last weeks standings for players. Only shows players who received a standing last week. This list resets when the realm calculates new standings for players every wednesday morning.");
                        break;

                    case VF_RealmPlayersDatabase.StaticValues.RankUpdateDayType.Wednesday_Midday:
                        GeneratePageDetails("Standings", count * 2, "Last weeks standings for players. Only shows players who received a standing last week. This list resets when the realm calculates new standings for players every wednesday.");
                        break;

                    case VF_RealmPlayersDatabase.StaticValues.RankUpdateDayType.Sunday_Midnight:
                        GeneratePageDetails("Standings", count * 2, "Last weeks standings for players. Only shows players who received a standing last week. This list resets when the realm calculates new standings for players every sunday midnight.");
                        break;

                    default:
                        break;
                    }
                }
            }
            else if (sectionStr == "twink_ranks")
            {
                this.Title = "Twinks @ " + StaticValues.ConvertRealmParam(realm) + " | RealmPlayers";

                m_PageHTML = new MvcHtmlString(CreatePVPTable(realm, count, Table_Twink_Ranks_Columns
                                                              , (KeyValuePair <string, Player> _Player) => { return(_Player.Value.GetRankTotal()); }
                                                              , (Player _Player) => { return(_Player.Character.Level > 10 && _Player.Character.Level < 60 && _Player.Honor.CurrentRank > 0 && (DateTime.UtcNow - _Player.LastSeen).TotalDays <= 30); }));
                GeneratePageDetails("Twinks", count, "PVP Ranks for players that are below lvl 60. This is meant to show active twinks on the realm. Only shows players that was seen less than 30 days ago");
            }
            else if (sectionStr == "lifetime_kills")
            {
                this.Title = "Lifetime Kills @ " + StaticValues.ConvertRealmParam(realm) + " | RealmPlayers";

                m_PageHTML = new MvcHtmlString(CreatePVPTable(realm, count, lifetimeKillsColumns
                                                              , (KeyValuePair <string, Player> _Player) => { return(_Player.Value.Honor.LifetimeHK); }
                                                              , (Player _Player) => { return(true); }));

                GeneratePageDetails("Lifetime Kills", count, "List sorted by the amount of total honorable kills received. This is to show the players who have pvped the most overall.");
            }
            else if (sectionStr == "highest_ranks")
            {
                this.Title = "Highest Ranks @ " + StaticValues.ConvertRealmParam(realm) + " | RealmPlayers";

                if (wowVersion == VF_RealmPlayersDatabase.WowVersionEnum.TBC)
                {
                    m_PageHTML = new MvcHtmlString("");
                    GeneratePageDetails("Highest Ranks", count, "TBC works with a different PVP system so there are no lifetime highest ranks.");
                }
                else
                {
                    var      playerSummaryDB     = Hidden.ApplicationInstance.Instance.GetPlayerSummaryDatabase();
                    var      pvpSummaries        = playerSummaryDB.GetPVPSummaries(realm);
                    DateTime referenceDateTime   = new DateTime(2010, 1, 1);
                    var      orderedPVPSummaries = pvpSummaries.OrderByDescending((_Value) => ((int)_Value.Value.m_HighestRank.Key) * 100000 - (_Value.Value.m_HighestRank.Value != DateTime.MinValue ? (int)((_Value.Value.m_HighestRank.Value - referenceDateTime).TotalDays) : 0));
                    //////////////////////////////////
                    int pageIndex = PageUtility.GetQueryInt(Request, "page", 1) - 1;//Change range from 0 to * instead of 1 to *

                    PlayerColumn[] playerColumns = new PlayerColumn[] {
                        PlayerColumn.Number,
                        PlayerColumn.Character_And_Guild,
                        PlayerColumn.Race_And_Class,
                        PlayerColumn.Total_HKs,
                        PlayerColumn.LastSeen,
                    };
                    Dictionary <PlayerColumn, string[]> extraColumns = new Dictionary <PlayerColumn, string[]>();

                    extraColumns[PlayerColumn.Number] = new string[] { "Rank", "Date Achieved" };
                    //extraColumns[PlayerColumn.Total_HKs] = new string[] { "Weeks with standing" };

                    string table = "<table class='table'>";
                    table += "<thead>" + PageUtility.CreatePlayerTableHeaderRow(playerColumns, extraColumns) + "</thead>";
                    table += "<tbody>";
                    var playerArray = DatabaseAccess.GetRealmPlayers(this, realm, NotLoadedDecision.RedirectAndWait);
                    int nr          = 0;
                    foreach (var pvpSummary in orderedPVPSummaries)
                    {
                        nr++;
                        if (nr > pageIndex * count && nr <= (pageIndex + 1) * count)
                        {
                            Player playerData = null;
                            if (playerArray.TryGetValue(playerSummaryDB.GetPlayer(pvpSummary), out playerData) == true)
                            {
                                VF_RealmPlayersDatabase.PlayerFaction playerFaction = StaticValues.GetFaction(playerData.Character.Race);
                                int   rank         = (int)pvpSummary.Value.m_HighestRank.Key;
                                float rankProgress = pvpSummary.Value.m_HighestRank.Key - (float)rank;
                                extraColumns[PlayerColumn.Number] = new string[] { PageUtility.CreatePlayerRankDiv(rank, rankProgress, playerFaction), pvpSummary.Value.m_HighestRank.Value.ToString("yyyy-MM-dd") };
                                //extraColumns[PlayerColumn.Total_HKs] = new string[] { pvpSummary.Value.m_ActivePVPWeeks.ToString() };
                                table += PageUtility.CreatePlayerRow(nr, realm, playerData, playerColumns, null, extraColumns);
                            }
                        }
                        if (nr >= (pageIndex + 1) * count)
                        {
                            break;
                        }
                    }
                    table += "</tbody></table>";

                    if (nr != 0 && nr <= pageIndex * count)
                    {
                        pageIndex = (nr - 1) / count;
                        Response.Redirect(PageUtility.CreateUrlWithNewQueryValue(Request, "page", (pageIndex + 1).ToString()));
                    }
                    m_PageHTML = new MvcHtmlString(table);
                    //////////////////////////////////

                    GeneratePageDetails("Highest Ranks", count, "Highest lifetime achieved PVP Ranks for players, sorted by date of achievment");
                }
            }
            else// if (sectionStr == "ranks")
            {
                this.Title = "Ranks @ " + StaticValues.ConvertRealmParam(realm) + " | RealmPlayers";

                if (realm == WowRealm.Nostalrius || realm == WowRealm.NostalriusPVE)
                {
                    rankShowLambda = (Player _Player) =>
                    {
                        return((DateTime.UtcNow - _Player.LastSeen).TotalDays < 14);
                    };
                    GeneratePageDetails("Ranks", count, "Highest PVP Ranks for active players.");
                }
                else if (wowVersion == VF_RealmPlayersDatabase.WowVersionEnum.TBC)
                {
                    GeneratePageDetails("Arena Ranking", count, "Shows the highest rated arena teams, sorted by a sum of the total rating for 5v5, 3v3 and 2v2.");
                }
                else
                {
                    GeneratePageDetails("Ranks", count, "Highest PVP Ranks for players. Only lists players who received standing last week. This is because no rank decay would make the list extremely boring(filled with players that dont even pvp).");
                }
                m_PageHTML = new MvcHtmlString(CreatePVPTable(realm, count, rankColumns
                                                              , rankSorterLambda, rankShowLambda));
            }
            //href='javascript:navigateWithNewQuery(\"page\",\"1\")'
            int pageNr    = PageUtility.GetQueryInt(Request, "page", 1);
            int maxPageNr = 1000000 / count;

            m_PaginationHTML = new MvcHtmlString(PageUtility.CreatePagination(Request, pageNr, maxPageNr));
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string pageView = RealmPlayersServer.PageUtility.GetQueryString(Request, "view", "players");
            var    realm    = PageUtility.GetQueryRealm(Request);

            if (realm == WowRealm.Unknown)
            {
                return;
            }
            var wowVersion = StaticValues.GetWowVersion(realm);

            string guildStr = PageUtility.GetQueryString(Request, "guild");

            var realmDB        = DatabaseAccess.GetRealmPlayers(this, realm);
            var guildSummaryDB = Hidden.ApplicationInstance.Instance.GetGuildSummaryDatabase();
            var guild          = guildSummaryDB.GetGuildSummary(realm, guildStr);// DatabaseAccess.GetRealmGuild(this, realm, guildStr, NotLoadedDecision.RedirectAndWait);

            if (guild == null)
            {
                return;
            }
            guild.GenerateCache(realmDB);

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

            m_ProgressInfoHTML = new MvcHtmlString("<div id='" + guild.GuildName.Replace(' ', '_') + "-Progress'></div>");

            var    membersArray            = guild.GetMembers();
            var    orderedPlayersArray     = membersArray.OrderBy((player) => { return(player.Item2.History.Last().GuildRankNr); });
            int    progressComparisonValue = 0;
            string guildProgressData       = GuildList.CreateProgressStr(this, guild, realm, out progressComparisonValue);

            m_GuildScriptData = new MvcHtmlString("<script>var guildProgress = new Array();" + guildProgressData + "</script>");

            if (pageView == "players")
            {
                m_BreadCrumbHTML = new MvcHtmlString(PageUtility.BreadCrumb_AddHome()
                                                     + PageUtility.BreadCrumb_AddRealm(realm)
                                                     + PageUtility.BreadCrumb_AddGuilds(realm)
                                                     + PageUtility.BreadCrumb_AddFinish(guild.GuildName));

                m_GuildInfoHTML = new MvcHtmlString("<h1><img src='assets/img/icons/ui-pvp-"
                                                    + StaticValues.GetFactionCSSName(guild.Faction) + ".png'/><span class='"
                                                    + StaticValues.GetFactionCSSName(guild.Faction) + "-color'>" + guild.GuildName
                                                    + "</span><span class='badge badge-inverse'>" + membersArray.Count + " Members</span></h1>"
                                                    + "<p>Guild on the server " + StaticValues.ConvertRealmViewing(realm) + "</p>"
                                                    + "<p><a href='/GuildViewer.aspx?realm=" + StaticValues.ConvertRealmParam(realm) + "&guild=" + guildStr + "&view=latestevents'>View Latest Events</a></p>"
                                                    + "<p><a href='/RaidStats/RaidList.aspx?realm=" + StaticValues.ConvertRealmParam(realm) + "&guild=" + guildStr + "'>View recorded raids on RaidStats</a></p>");

                string page = "";
                foreach (var player in orderedPlayersArray)
                {
                    page += PageUtility.CreatePlayerRow(0, realm, player.Item1, Table_Columns);
                }
                m_CharactersTableHeadHTML = new MvcHtmlString(PageUtility.CreatePlayerTableHeaderRow(Table_Columns));
                m_CharactersTableBodyHTML = new MvcHtmlString(page);
            }
            else if (pageView == "latestmembers")
            {
                m_BreadCrumbHTML = new MvcHtmlString(PageUtility.BreadCrumb_AddHome()
                                                     + PageUtility.BreadCrumb_AddRealm(realm)
                                                     + PageUtility.BreadCrumb_AddGuilds(realm)
                                                     + PageUtility.BreadCrumb_AddGuild(realm, guild.GuildName)
                                                     + PageUtility.BreadCrumb_AddFinish("Latest Members"));

                m_GuildInfoHTML = new MvcHtmlString("<h1><img src='assets/img/icons/ui-pvp-"
                                                    + StaticValues.GetFactionCSSName(guild.Faction) + ".png'/><span class='"
                                                    + StaticValues.GetFactionCSSName(guild.Faction) + "-color'>" + guild.GuildName
                                                    + "</span><span class='badge badge-inverse'>" + membersArray.Count + " Members</span></h1>"
                                                    + "<p>Guild on the server " + StaticValues.ConvertRealmViewing(realm) + "</p>"
                                                    + "<p><a href='/GuildViewer.aspx?realm=" + StaticValues.ConvertRealmParam(realm) + "&guild=" + guildStr + "'>View Members</a></p>"
                                                    + "<p><a href='/RaidStats/RaidList.aspx?realm=" + StaticValues.ConvertRealmParam(realm) + "&guild=" + guildStr + "'>View recorded raids on RaidStats</a></p>");
            }
            else if (pageView == "latestitems")
            {
                m_BreadCrumbHTML = new MvcHtmlString(PageUtility.BreadCrumb_AddHome()
                                                     + PageUtility.BreadCrumb_AddRealm(realm)
                                                     + PageUtility.BreadCrumb_AddGuilds(realm)
                                                     + PageUtility.BreadCrumb_AddGuild(realm, guild.GuildName)
                                                     + PageUtility.BreadCrumb_AddFinish("Latest Items"));

                m_GuildInfoHTML = new MvcHtmlString("<h1><img src='assets/img/icons/ui-pvp-"
                                                    + StaticValues.GetFactionCSSName(guild.Faction) + ".png'/><span class='"
                                                    + StaticValues.GetFactionCSSName(guild.Faction) + "-color'>" + guild.GuildName
                                                    + "</span><span class='badge badge-inverse'>" + membersArray.Count + " Members</span></h1>"
                                                    + "<p>Guild on the server " + StaticValues.ConvertRealmViewing(realm) + "</p>"
                                                    + "<p><a href='/GuildViewer.aspx?realm=" + StaticValues.ConvertRealmParam(realm) + "&guild=" + guildStr + "'>View Members</a></p>"
                                                    + "<p><a href='/RaidStats/RaidList.aspx?realm=" + StaticValues.ConvertRealmParam(realm) + "&guild=" + guildStr + "'>View recorded raids on RaidStats</a></p>");
            }
            else if (pageView == "latestevents")
            {
                m_BreadCrumbHTML = new MvcHtmlString(PageUtility.BreadCrumb_AddHome()
                                                     + PageUtility.BreadCrumb_AddRealm(realm)
                                                     + PageUtility.BreadCrumb_AddGuilds(realm)
                                                     + PageUtility.BreadCrumb_AddGuild(realm, guild.GuildName)
                                                     + PageUtility.BreadCrumb_AddFinish("Latest Events"));

                m_GuildInfoHTML = new MvcHtmlString("<h1><img src='assets/img/icons/ui-pvp-"
                                                    + StaticValues.GetFactionCSSName(guild.Faction) + ".png'/><span class='"
                                                    + StaticValues.GetFactionCSSName(guild.Faction) + "-color'>" + guild.GuildName
                                                    + "</span><span class='badge badge-inverse'>" + membersArray.Count + " Members</span></h1>"
                                                    + "<p>Guild on the server " + StaticValues.ConvertRealmViewing(realm) + "</p>"
                                                    + "<p><a href='/GuildViewer.aspx?realm=" + StaticValues.ConvertRealmParam(realm) + "&guild=" + guildStr + "'>View Members</a></p>"
                                                    + "<p><a href='/RaidStats/RaidList.aspx?realm=" + StaticValues.ConvertRealmParam(realm) + "&guild=" + guildStr + "'>View recorded raids on RaidStats</a></p>");
            }

            if (pageView == "latestmembers" || pageView == "latestevents")
            {
                var guildSummary = Hidden.ApplicationInstance.Instance.GetGuildSummary(realm, guildStr);
                if (guildSummary == null)
                {
                    return;
                }

                var statusChanges = guildSummary.GenerateLatestStatusChanges(DateTime.UtcNow.AddDays(-14));

                string latestmembersStr = "";
                statusChanges.Reverse();
                foreach (var sChange in statusChanges)
                {
                    if (realmDB.ContainsKey(sChange.Player))
                    {
                        var playerData = realmDB[sChange.Player];

                        string statusChangeDescription = "";
                        if (sChange.FromStatus == null || sChange.FromStatus.IsInGuild == false)
                        {
                            if (sChange.ToStatus.IsInGuild == true)
                            {
                                statusChangeDescription = "Added to the Guild as Rank \"" + sChange.ToStatus.GuildRank + "\"";
                            }
                            else
                            {
                                continue;
                            }
                        }
                        else if (sChange.ToStatus.IsInGuild == false)
                        {
                            statusChangeDescription = "Removed from the Guild";
                        }
                        else
                        {
                            statusChangeDescription = "Changed Rank From \"" + sChange.FromStatus.GuildRank + "\" to \"" + sChange.ToStatus.GuildRank + "\"";
                        }

                        latestmembersStr += PageUtility.CreateTableRow(""
                                                                       , PageUtility.CreateTableColumn(PageUtility.CreateColorCodedPlayerLink(realm, playerData))
                                                                       + PageUtility.CreateTableColumn("<div style='overflow: hidden;white-space: nowrap;'>" + statusChangeDescription + "</div>")
                                                                       + PageUtility.CreateTableColumn("<div style='overflow: hidden;white-space: nowrap;'>" + sChange.ToStatus.DateTime.ToLocalTime().ToString("yyyy-MM-dd") + "</div>"));
                    }
                }
                m_LatestMembersHTML = new MvcHtmlString(latestmembersStr);
            }

            if (pageView == "latestitems" || pageView == "latestevents")
            {
                List <Tuple <DateTime, Player, List <Tuple <PlayerItemInfo, ItemInfo> > > > latestItems = new List <Tuple <DateTime, Player, List <Tuple <PlayerItemInfo, ItemInfo> > > >();

                var realmHistory = DatabaseAccess._GetRealmPlayersHistory(this, realm, NotLoadedDecision.SpinWait);
                foreach (var data in orderedPlayersArray)
                {
                    Player        player        = data.Item1;
                    PlayerHistory playerHistory = null;
                    if (realmHistory.TryGetValue(player.Name, out playerHistory) == true)
                    {
                        var recvItems = HistoryGenerator.GenerateLatestReceivedItems(playerHistory, DateTime.MinValue);

                        var orderedRecvItems = recvItems.OrderByDescending(_Value => _Value.Key);
                        int i = 0;
                        foreach (var recvItem in orderedRecvItems)
                        {
                            if (i++ > 10)
                            {
                                break;
                            }

                            List <Tuple <PlayerItemInfo, ItemInfo> > newestItems = new List <Tuple <PlayerItemInfo, ItemInfo> >();
                            foreach (var item in recvItem.Value)
                            {
                                var itemInfo = DatabaseAccess.GetItemInfo(item.ItemID, wowVersion);
                                if (itemInfo.ItemQuality >= 4) //Atleast epic(4)
                                {
                                    newestItems.Add(Tuple.Create(item, itemInfo));
                                }
                            }
                            if (newestItems.Count > 0)
                            {
                                latestItems.Add(Tuple.Create(recvItem.Key, player, newestItems));
                            }
                        }
                    }
                }

                string latestItemsStr = "";
                {
                    var itemSummaryDB = Hidden.ApplicationInstance.Instance.GetItemSummaryDatabase();

                    string currentItemDatabase = DatabaseAccess.GetCurrentItemDatabaseAddress();

                    var orderedLatestItems = latestItems.OrderByDescending((_Value) => _Value.Item1);

                    int i = 0;
                    foreach (var recvItem in orderedLatestItems)
                    {
                        if (i++ > 100)
                        {
                            break;
                        }

                        int recvItemIndex = 0;
                        int xMax          = 58 * 3;
                        int yMax          = (int)((recvItem.Item3.Count - 1) / 3) * 58;

                        yMax += 58;
                        string itemLinks = "<div class='inventory' style='background: none; width: " + xMax + "px; height: " + yMax + "px;'>";
                        foreach (var item in recvItem.Item3)
                        {
                            int xPos = (recvItemIndex % 3) * 58;
                            int yPos = (int)(recvItemIndex / 3) * 58;
                            //string itemLink = currentItemDatabase + "?item=" + item.Item1.ItemID + "' rel='rand=" + item.Item1.SuffixID + ";ench=0";

                            var itemInfo = item.Item2;
                            itemLinks += "<div style='background: none; width: 58px; height: 58px;margin: " + yPos + "px " + xPos + "px;'>"
                                         + "<img class='itempic' src='" + "http://realmplayers.com/" + itemInfo.GetIconImageAddress() + "'/>"
                                         + "<div class='quality' id='" + CharacterViewer.ItemQualityConversion[itemInfo.ItemQuality] + "'></div>"
                                         + "<img class='itemframe' src='assets/img/icons/ItemNormalFrame.png'/>"
                                         + CharacterViewer.GenerateItemLink(currentItemDatabase, item.Item1, wowVersion);

                            var itemUsageCount = itemSummaryDB.GetItemUsageCount(realm, item.Item1);
                            itemLinks += "<a class='itemplayersframe' href='ItemUsageInfo.aspx?realm=" + StaticValues.ConvertRealmParam(realm) + "&item=" + item.Item1.ItemID + (item.Item1.SuffixID != 0 ? "&suffix=" + item.Item1.SuffixID : "") + "'>" + itemUsageCount + "</a>";
                            itemLinks += "</div>";
                            ++recvItemIndex;
                        }

                        itemLinks      += "</div>";
                        latestItemsStr += PageUtility.CreateTableRow(""
                                                                     , PageUtility.CreateTableColumn(itemLinks)
                                                                     + PageUtility.CreateTableColumn(PageUtility.CreateColorCodedPlayerLink(realm, recvItem.Item2))
                                                                     + PageUtility.CreateTableColumn("<div style='overflow: hidden;white-space: nowrap;'>" + recvItem.Item1.ToString("yyyy-MM-dd") + "</div>"));
                    }
                }
                m_LatestItemsHTML = new MvcHtmlString(latestItemsStr);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            m_BreadCrumbHTML = new MvcHtmlString(PageUtility.BreadCrumb_AddHome()
                                                 + PageUtility.BreadCrumb_AddFinish("RareItemsList"));

            var realm = RealmControl.Realm;

            if (realm == WowRealm.Unknown)
            {
                return;
            }
            var wowVersion = StaticValues.GetWowVersion(realm);

            int count = PageUtility.GetQueryInt(Request, "count", 100);

            var itemSummaryDB = Hidden.ApplicationInstance.Instance.GetItemSummaryDatabase();

            m_ItemUsageInfoHTML = new MvcHtmlString("<h1>Rarest items<span class='badge badge-inverse'>" + count + " Items</span></h1>"
                                                    + "<p>List contains the most rarest items on the realm.</p>");

            Dictionary <PlayerColumn, string[]> extraColumns = new Dictionary <PlayerColumn, string[]>();
            PlayerColumn ItemAndAquiredDateAfterColumn       = PlayerColumn.Number;

            extraColumns.Add(ItemAndAquiredDateAfterColumn, new string[] { "Item", "Count", "First Aquired", "First Player(s)" });
            m_TableHeadHTML = new MvcHtmlString(PageUtility.CreatePlayerTableHeaderRow(Table_Columns, extraColumns));

            string currentItemDatabase = DatabaseAccess.GetCurrentItemDatabaseAddress();

            string tableBody = "";
            int    nr        = 1;
            Func <KeyValuePair <ulong, VF_RPDatabase.ItemSummary>, int> lambdaComparison = (_Tuple) => { return(_Tuple.Value.m_ItemOwners.Count((_Value) => (itemSummaryDB.GetPlayerRealm(_Value.Item1) == realm))); };
            Func <Tuple <ulong, DateTime>, DateTime> lambdaDateTimeComparison            = (_Tuple) => { return(_Tuple.Item2); };
            var rareItemsList = itemSummaryDB.m_Items.OrderBy(lambdaComparison);

            foreach (var rareItem in rareItemsList)
            {
                if (nr >= count)
                {
                    break;
                }
                int rareItemCount = rareItem.Value.m_ItemOwners.Count((_Value) => (itemSummaryDB.GetPlayerRealm(_Value.Item1) == realm));
                if (rareItemCount > 0 && Code.Resources.ItemAnalyzer.IsRareItem(rareItem.Value.m_ItemID) == true)
                {
                    var itemInfo = DatabaseAccess.GetItemInfo(rareItem.Value.m_ItemID, wowVersion);
                    if (itemInfo.ItemQuality < 4)
                    {
                        continue;
                    }
                    //rareItem.
                    Player   player         = null;
                    var      orderedAquires = rareItem.Value.m_ItemOwners.OrderBy(lambdaDateTimeComparison);
                    DateTime dateTimeCutoff = orderedAquires.First((_Value) => (itemSummaryDB.GetPlayerRealm(_Value.Item1) == realm)).Item2;
                    if (dateTimeCutoff < new DateTime(2013, 8, 1, 0, 0, 0))
                    {
                        dateTimeCutoff = new DateTime(2013, 8, 1, 0, 0, 0);
                    }
                    else
                    {
                        dateTimeCutoff = dateTimeCutoff.AddDays(3);
                    }

                    string firstPlayers     = "<div style='overflow: hidden; display: table; height: 58px;'>";
                    var    interestingItems = orderedAquires.Where((_Tuple) => { return(_Tuple.Item2 < dateTimeCutoff && (itemSummaryDB.GetPlayerRealm(_Tuple.Item1) == realm)); });
                    if (interestingItems.Count() < 5)
                    {
                        foreach (var playerAquire in interestingItems)
                        {
                            if (playerAquire.Item2 < dateTimeCutoff)
                            {
                                player = DatabaseAccess.FindRealmPlayer(this, realm, itemSummaryDB.GetPlayerName(playerAquire.Item1));
                                if (player != null)
                                {
                                    var playerFaction = StaticValues.GetFaction(player.Character.Race);
                                    firstPlayers += "<div class='" + StaticValues.GetFactionCSSName(playerFaction) + "_col' style='display: table-cell; width:160px;" /*"background-color: " + (playerFaction == PlayerFaction.Horde ? "#372727" : "#272f37")*/ + "'>";
                                    firstPlayers += "<p style='text-align:center;'><a href='CharacterViewer.aspx?realm=" + StaticValues.ConvertRealmParam(realm) + "&player=" + System.Web.HttpUtility.HtmlEncode(player.Name) + "'>" + PageUtility.CreateColorCodedName(player.Name, player.Character.Class) + "</a>";
                                    if (player.Guild.GuildName != "nil")
                                    {
                                        string visualGuildName = PageUtility.BreakLongStr(player.Guild.GuildName, 16, 8);
                                        firstPlayers += "<br>" + PageUtility.CreateLink("GuildViewer.aspx?realm=" + StaticValues.ConvertRealmParam(realm) + "&guild=" + System.Web.HttpUtility.HtmlEncode(player.Guild.GuildName), "&lt;" + visualGuildName + "&gt;") + "</p>";
                                    }
                                    firstPlayers += "</div>";
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        firstPlayers += "Data not detailed enough<br>(more than 5 players within aquire timespan)";
                    }
                    firstPlayers += "</div>";
                    extraColumns[ItemAndAquiredDateAfterColumn] = new string[] {
                        "<div class='inventory' style='background: none; width: 58px; height: 58px;'><div>"
                        + "<img class='itempic' src='" + "http://realmplayers.com/" + itemInfo.GetIconImageAddress() + "'/>"
                        + "<div class='quality' id='" + CharacterViewer.ItemQualityConversion[itemInfo.ItemQuality] + "'></div>"
                        + "<img class='itemframe' src='assets/img/icons/ItemNormalFrame.png'/>"
                        + CharacterViewer.GenerateItemLink(currentItemDatabase, rareItem.Value.m_ItemID, rareItem.Value.m_SuffixID, wowVersion)
                        + "<a class='itemplayersframe' href='ItemUsageInfo.aspx?realm=" + StaticValues.ConvertRealmParam(realm) + "&item=" + rareItem.Value.m_ItemID + (rareItem.Value.m_SuffixID != 0 ? "&suffix=" + rareItem.Value.m_SuffixID : "") + "'>" + rareItemCount.ToString() + "</a>"
                        + "</div></div>"
                        , rareItemCount.ToString()
                        , " &gt; " + interestingItems.First().Item2.ToString("yyyy-MM-dd") + "<br> &lt; " + dateTimeCutoff.ToString("yyyy-MM-dd")
                        , firstPlayers
                    };
                    tableBody += PageUtility.CreateTableRow("",
                                                            PageUtility.CreateTableColumn("#" + (nr++))
                                                            + PageUtility.CreateTableColumn(extraColumns[ItemAndAquiredDateAfterColumn][0])
                                                            + PageUtility.CreateTableColumn(extraColumns[ItemAndAquiredDateAfterColumn][1])
                                                            + PageUtility.CreateTableColumn(extraColumns[ItemAndAquiredDateAfterColumn][2])
                                                            + PageUtility.CreateTableColumn(extraColumns[ItemAndAquiredDateAfterColumn][3]));
                }
            }
            m_TableBodyHTML = new MvcHtmlString(tableBody);
        }