示例#1
0
        public bool AddContribution(RPPContribution _Contribution)
        {
            int loggedExceptions = 0;

            try
            {
                SavedVariablesParser.Document doc = new SavedVariablesParser.Document(_Contribution.GetFilename());
                var xmlDoc = doc.ConvertToXMLDocument();

                WowVersionEnum wowVersion = WowVersionEnum.Unknown;
                try
                {
                    string addonVersion = XMLUtility.GetChildValue(xmlDoc.DocumentElement, "VF_RealmPlayersVersion", "0.0");
                    if (addonVersion.Split('.').Length == 2) //VF_RealmPlayers
                    {
                        if (Utility.ParseDouble(addonVersion) <= 1.58)
                        {
                            return(false);
                        }
                        wowVersion = WowVersionEnum.Vanilla;
                    }
                    else //VF_RealmPlayersTBC
                    {
                        wowVersion = WowVersionEnum.TBC;
                    }
                }
                catch (Exception ex)
                {
                    Logger.LogException(ex);
                }
#if UPDATE_SQL_DB
                List <VF.SQLUploadID> uploadIDs = new List <VF.SQLUploadID>();
#endif
                var dataNode = XMLUtility.GetChild(xmlDoc.DocumentElement, "VF_RealmPlayersData");
                int wowVersionWrongGuessCount = 0;
                foreach (System.Xml.XmlNode playerNode in dataNode.ChildNodes)
                {
                    try
                    {
                        if (PlayerData.DataParser.ParsePlayerName(playerNode) == "OnlineData")
                        {
                            foreach (System.Xml.XmlNode onlineDataNode in playerNode.ChildNodes)
                            {
                                int loggedStrangeDataException = 0;

                                string   onlineData = onlineDataNode.Attributes["value"].Value;
                                var      dataParts  = onlineData.Split(new char[] { ';' }, 5);
                                string   realmStr   = dataParts[1];
                                WowRealm realm      = StaticValues.ConvertRealm(realmStr);
                                if (realm == WowRealm.Unknown)
                                {
                                    realmStr = realmStr.Substring(0, 1) + realmStr.Substring(2);
                                    realm    = StaticValues.ConvertRealm(realmStr);
                                }

                                string   dateTimeStartStr = dataParts[2];
                                string   dateTimeEndStr   = dataParts[3];
                                string[] playersDatas     = dataParts[4].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                                DateTime dateTimeStart;
                                DateTime dateTimeEnd;
                                if (System.DateTime.TryParse(dateTimeStartStr, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AssumeUniversal | System.Globalization.DateTimeStyles.AdjustToUniversal, out dateTimeStart) == true &&
                                    System.DateTime.TryParse(dateTimeEndStr, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AssumeUniversal | System.Globalization.DateTimeStyles.AdjustToUniversal, out dateTimeEnd) == true)
                                {
                                    PlayersOnlineDB playersOnlineDB = m_Realms[realm].PlayersOnlineData;

                                    var onlineEntry = playersOnlineDB.GetOnlineEntry(dateTimeStart, dateTimeEnd);
                                    if (onlineEntry == null && (dateTimeEnd - dateTimeStart).TotalMinutes < 5)
                                    {
                                        //Widen the online-span to approx 5 minutes since we are creating a new entry anyways...
                                        double addMinutes = 5.0 - (dateTimeEnd - dateTimeStart).TotalMinutes;
                                        double halfMins   = addMinutes / 2;
                                        dateTimeStart = dateTimeStart.AddMinutes(-halfMins);
                                        dateTimeEnd   = dateTimeEnd.AddMinutes(halfMins);
                                    }
                                    onlineEntry = playersOnlineDB.CreateOnlineEntry(dateTimeStart, dateTimeEnd);

                                    foreach (var playerData in playersDatas)
                                    {
                                        var data = playerData.Split(':');
                                        if (data.Length == 6)
                                        {
                                            PlayersOnlineDB.OnlinePlayerEntry onlinePlayer = new PlayersOnlineDB.OnlinePlayerEntry();
                                            onlinePlayer.Name  = data[0];
                                            onlinePlayer.Race  = (PlayerRace)int.Parse(data[1]);
                                            onlinePlayer.Class = (PlayerClass)int.Parse(data[2]);
                                            onlinePlayer.Guild = data[3];
                                            onlinePlayer.Level = int.Parse(data[4]);
                                            onlinePlayer.Zone  = (WorldZone)int.Parse(data[5]);
                                            onlineEntry.AddOnlinePlayer(onlinePlayer);
                                        }
                                        else if (loggedStrangeDataException < 5)
                                        {
                                            Logger.ConsoleWriteLine("Strange data in OnlineData segment! \"" + playerData + "\"");
                                            ++loggedStrangeDataException;
                                        }
                                    }
                                    m_Realms[realm].Updated = true;
                                    Logger.ConsoleWriteLine(onlineEntry.OnlinePlayers.Count + " players online " + dateTimeStart.ToDateTimeStr());
                                }
                            }
                        }
                        else if (XMLUtility.GetChild(playerNode, "PlayerData") != null)
                        {
                            string   realmStr = PlayerData.DataParser.ParseRealm(playerNode);
                            WowRealm realm    = StaticValues.ConvertRealm(realmStr);
                            if (realm == WowRealm.Unknown)
                            {
                                realmStr = realmStr.Substring(0, 1) + realmStr.Substring(2);
                                realm    = StaticValues.ConvertRealm(realmStr);
                            }
                            if (StaticValues.DeadRealms.Contains(realm) == true ||
                                StaticValues.Disabled_UploadRealmNames.Contains(realmStr) == true)
                            {
                                Logger.ConsoleWriteLine("RealmStr: \"" + realmStr + "\" was recognized as a dead realm");
                                continue;
                            }
                            if ((StaticValues.GetWowVersion(realm) != wowVersion))
                            {
                                ++wowVersionWrongGuessCount;
                            }

                            if (realm == WowRealm.Unknown || m_Realms.ContainsKey(realm) == false)
                            {
                                Logger.ConsoleWriteLine("RealmStr: \"" + realmStr + "\" was not recognized as a realm");
                            }
                            else
                            {
#if UPDATE_SQL_DB
                                Func <int, VF.SQLUploadID> getUploadID = (int _Index) =>
                                {
                                    while (uploadIDs.Count <= _Index)
                                    {
                                        using (VF.SQLComm comm = new VF.SQLComm())
                                        {
                                            var uploadID = comm.GenerateNewUploadEntry(_Contribution.GetContributor(), DateTime.UtcNow);
                                            uploadIDs.Add(uploadID);
                                        }
                                    }
                                    return(uploadIDs[_Index]);
                                };
                                RealmDatabase realmDB = m_Realms[realm];
                                realmDB.UpdatePlayer(playerNode, _Contribution.GetContributor(), getUploadID);
#else
                                RealmDatabase realmDB = m_Realms[realm];
                                realmDB.UpdatePlayer(playerNode, _Contribution.GetContributor(), null);
#endif
                            }
                        }
                    }
                    catch (Npgsql.NpgsqlException ex)
                    {
                        throw ex;
                    }
                    catch (Exception ex)
                    {
                        if (loggedExceptions < 5)
                        {
                            Logger.LogException(ex);
                        }
                        ++loggedExceptions;
                    }
                }
                if (wowVersionWrongGuessCount > 0)
                {
                    Logger.ConsoleWriteLine("RealmPlayers WoWversion guess was wrong " + wowVersionWrongGuessCount + " times!!!", ConsoleColor.Red);
                }
                Logger.ConsoleWriteLine(_Contribution.GetContributor().GetFilename() + " just updated database successfully!");
                return(true);
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
            }
            return(false);
        }
示例#2
0
        public void AddContribution(RPPContribution _Contribution)
        {
            int loggedExceptions = 0;

            try
            {
                SavedVariablesParser.Document doc = new SavedVariablesParser.Document(_Contribution.GetFilename());
                var xmlDoc = doc.ConvertToXMLDocument();

                WowVersionEnum wowVersion = WowVersionEnum.Unknown;
                try
                {
                    string addonVersion = XMLUtility.GetChildValue(xmlDoc.DocumentElement, "VF_RealmPlayersVersion", "0.0");
                    if (addonVersion.Split('.').Length == 2) //VF_RealmPlayers
                    {
                        if (Utility.ParseDouble(addonVersion) <= 1.58)
                        {
                            return;
                        }
                        wowVersion = WowVersionEnum.Vanilla;
                    }
                    else //VF_RealmPlayersTBC
                    {
                        wowVersion = WowVersionEnum.TBC;
                    }
                }
                catch (Exception ex)
                {
                    Logger.LogException(ex);
                }
                var dataNode = XMLUtility.GetChild(xmlDoc.DocumentElement, "VF_RealmPlayersData");
                foreach (System.Xml.XmlNode playerNode in dataNode.ChildNodes)
                {
                    try
                    {
                        if (XMLUtility.GetChild(playerNode, "PlayerData") != null)
                        {
                            string   realmStr = PlayerData.DataParser.ParseRealm(playerNode);
                            WowRealm realm    = StaticValues.ConvertRealm(realmStr);
                            if (realm == WowRealm.Archangel || wowVersion == WowVersionEnum.TBC)
                            {
                                if (realm != WowRealm.Archangel || wowVersion != WowVersionEnum.TBC)
                                {
                                    Logger.ConsoleWriteLine("RealmPlayers WoWversion guess was wrong!!!", ConsoleColor.Red);
                                }
                            }

                            if (realm == WowRealm.Unknown || m_Realms.ContainsKey(realm) == false)
                            {
                                Logger.ConsoleWriteLine("RealmStr: \"" + realmStr + "\" was not recognized as a realm");
                            }
                            else
                            {
                                RealmDatabase realmDB = m_Realms[realm];
                                realmDB.UpdatePlayer(playerNode, _Contribution.GetContributor());
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        if (loggedExceptions < 5)
                        {
                            Logger.LogException(ex);
                        }
                        ++loggedExceptions;
                    }
                }
                Logger.ConsoleWriteLine(_Contribution.GetContributor().GetFilename() + " just updated database successfully!");
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
            }
        }
示例#3
0
        public bool AddContribution(RPPContribution _Contribution)
        {
            int loggedExceptions = 0;

            try
            {
                SavedVariablesParser.Document doc = new SavedVariablesParser.Document(_Contribution.GetFilename());
                var xmlDoc = doc.ConvertToXMLDocument();

                WowVersionEnum wowVersion = WowVersionEnum.Unknown;
                try
                {
                    string addonVersion = XMLUtility.GetChildValue(xmlDoc.DocumentElement, "VF_RealmPlayersVersion", "0.0");
                    if (addonVersion.Split('.').Length == 2) //VF_RealmPlayers
                    {
                        if (Utility.ParseDouble(addonVersion) <= 1.58)
                        {
                            return(false);
                        }
                        wowVersion = WowVersionEnum.Vanilla;
                    }
                    else //VF_RealmPlayersTBC
                    {
                        wowVersion = WowVersionEnum.TBC;
                    }
                }
                catch (Exception ex)
                {
                    Logger.LogException(ex);
                }
                List <VF.SQLUploadID> uploadIDs = new List <VF.SQLUploadID>();
                var dataNode = XMLUtility.GetChild(xmlDoc.DocumentElement, "VF_RealmPlayersData");
                int wowVersionWrongGuessCount = 0;
                foreach (System.Xml.XmlNode playerNode in dataNode.ChildNodes)
                {
                    try
                    {
                        if (XMLUtility.GetChild(playerNode, "PlayerData") != null)
                        {
                            string   realmStr = PlayerData.DataParser.ParseRealm(playerNode);
                            WowRealm realm    = StaticValues.ConvertRealm(realmStr);
                            if ((StaticValues.GetWowVersion(realm) != wowVersion))
                            {
                                ++wowVersionWrongGuessCount;
                            }

                            if (realm == WowRealm.Unknown || m_Realms.ContainsKey(realm) == false)
                            {
                                Logger.ConsoleWriteLine("RealmStr: \"" + realmStr + "\" was not recognized as a realm");
                            }
                            else
                            {
                                Func <int, VF.SQLUploadID> getUploadID = (int _Index) =>
                                {
                                    while (uploadIDs.Count <= _Index)
                                    {
                                        using (VF.SQLComm comm = new VF.SQLComm())
                                        {
                                            var uploadID = comm.GenerateNewUploadEntry(_Contribution.GetContributor(), DateTime.UtcNow);
                                            uploadIDs.Add(uploadID);
                                        }
                                    }
                                    return(uploadIDs[_Index]);
                                };
                                RealmDatabase realmDB = m_Realms[realm];
                                realmDB.UpdatePlayer(playerNode, _Contribution.GetContributor(), getUploadID);
                            }
                        }
                    }
                    catch (Npgsql.NpgsqlException ex)
                    {
                        throw ex;
                    }
                    catch (Exception ex)
                    {
                        if (loggedExceptions < 5)
                        {
                            Logger.LogException(ex);
                        }
                        ++loggedExceptions;
                    }
                }
                if (wowVersionWrongGuessCount > 0)
                {
                    Logger.ConsoleWriteLine("RealmPlayers WoWversion guess was wrong " + wowVersionWrongGuessCount + " times!!!", ConsoleColor.Red);
                }
                Logger.ConsoleWriteLine(_Contribution.GetContributor().GetFilename() + " just updated database successfully!");
                return(true);
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
            }
            return(false);
        }