Exemple #1
0
 public void LoadRealmDatabase(string _RootPath, WowRealm _Realm, DateTime?_HistoryEarliestTime = null)
 {
     try
     {
         GetRealm(_Realm).LoadDatabase(_RootPath + _Realm.ToString() + "\\", _HistoryEarliestTime);
         m_NeedCleanup = true;
     }
     catch (Exception ex)
     {
         Logger.LogException(ex);
     }
 }
Exemple #2
0
        private uint GetDictionaryItemID(uint _ItemID, WowRealm _Realm)
        {
            if (_ItemID > 0xFFFFFF)
            {
                throw new Exception("(GetDictionaryItemID) ItemID: " + _ItemID.ToString() + " is too large");
            }

            switch (_Realm)
            {
            case WowRealm.Unknown:
                throw new Exception("(GetDictionaryItemID) Could not get dictionary ItemID for Unknown Realm");

            case WowRealm.Emerald_Dream:
                return((1U << 24) + _ItemID);

            case WowRealm.Al_Akir:
                return((1U << 24) + _ItemID);

            case WowRealm.Warsong:
            case WowRealm.Warsong2:
            case WowRealm.Nemesis:
                return((1U << 24) + _ItemID);

            case WowRealm.All:
                return(uint.MaxValue);

            case WowRealm.Archangel:
            case WowRealm.WarsongTBC:
                return((0x10U << 24) + _ItemID);

            case WowRealm.Valkyrie:
            case WowRealm.Elysium:
            case WowRealm.Elysium2:
            case WowRealm.Zeth_Kur:
                return((2U << 24) + _ItemID);

            case WowRealm.Rebirth:
                return((3U << 24) + _ItemID);

            case WowRealm.VanillaGaming:
                return((4U << 24) + _ItemID);

            case WowRealm.Nostalrius:
            case WowRealm.NostalriusPVE:
            case WowRealm.Nostralia:
            case WowRealm.Firemaw:     //Should have own ID
                return((5U << 24) + _ItemID);

            case WowRealm.Kronos:
            case WowRealm.KronosII:
                return((6U << 24) + _ItemID);

            case WowRealm.NostalGeek:
                return((7U << 24) + _ItemID);

            case WowRealm.Nefarian:
                return((8U << 24) + _ItemID);

            case WowRealm.Vengeance_Wildhammer:
            case WowRealm.Vengeance_Stonetalon:
                return((0x11U << 24) + _ItemID);

            case WowRealm.ExcaliburTBC:
                return((0x12U << 24) + _ItemID);

            case WowRealm.L4G_Hellfire:
            case WowRealm.Hellfire2:
            case WowRealm.HellGround: //Should have own ID
            case WowRealm.Felmyst:    //Should have own ID
            case WowRealm.Outland:    //Should have own ID
            case WowRealm.Medivh:     //Should have own ID
            case WowRealm.Ares:       //Should have own ID
                return((0x13U << 24) + _ItemID);

            default:
                if (StaticValues.GetWowVersion(_Realm) == WowVersionEnum.Vanilla)    //Should have own ID
                {
                    return((5U << 24) + _ItemID);
                }
                else if (StaticValues.GetWowVersion(_Realm) == WowVersionEnum.TBC)    //Should have own ID
                {
                    return((0x13U << 24) + _ItemID);
                }

                break;
            }
            throw new Exception("(GetDictionaryItemID) Could not get dictionary ItemID for Realm: " + _Realm.ToString());
        }
Exemple #3
0
        public bool ReloadRealmDB(WowRealm _Realm, string _RootPath, bool _PurgeRealmDB = true, object _SynchronizationLockObject = null, DateTime?_HistoryEarliestTime = null)
        {
            if (_SynchronizationLockObject == null)
            {
                _SynchronizationLockObject = new object();
            }

            try
            {
                if (m_Realms.ContainsKey(_Realm) == true)
                {
                    RealmDatabase oldRealm;
                    lock (_SynchronizationLockObject)
                    {
                        oldRealm = m_Realms[_Realm];
                    }
                    if (oldRealm.IsDBFileUpdated(_RootPath + _Realm.ToString() + "\\") == true)
                    {
                        var reloadedRealm = new RealmDatabase(_Realm);
                        reloadedRealm.LoadDatabase(_RootPath + _Realm.ToString() + "\\", _HistoryEarliestTime);
                        if (_PurgeRealmDB == true)
                        {
                            var purgeTask = new System.Threading.Tasks.Task(() =>
                            {
                                reloadedRealm.RemoveUnknowns();
                                reloadedRealm.RemoveGMs();
                                GC.Collect();
                            });
                            purgeTask.Start();
                            purgeTask.Wait(300 * 1000);//300 sekunder(5 minuter)
                        }
                        reloadedRealm.WaitForLoad(RealmDatabase.LoadStatus.EverythingLoaded);
                        if (reloadedRealm.IsLoadComplete() == false)
                        {
                            Logger.ConsoleWriteLine("Failed to reload database " + _Realm + ", it took too long", ConsoleColor.Red);
                            return(false);
                        }
                        lock (_SynchronizationLockObject)
                        {
                            m_Realms[_Realm] = reloadedRealm;
                        }
                        GC.Collect();
                        return(true);
                    }
                }
                else
                {
                    Logger.ConsoleWriteLine("Realm was not loaded when requesting reload, this is unoptimal solution due to unnecessary locking for a long time!", ConsoleColor.Red);
                    try
                    {
                        lock (_SynchronizationLockObject)
                        {
                            LoadRealmDatabase(_RootPath, _Realm, _HistoryEarliestTime);
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.LogException(ex);
                    }
                    return(true);
                }
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
            }
            return(false);
        }
Exemple #4
0
        private uint GetDictionaryItemID(uint _ItemID, WowRealm _Realm)
        {
            if (_ItemID > 0xFFFFFF)
            {
                throw new Exception("(GetDictionaryItemID) ItemID: " + _ItemID.ToString() + " is too large");
            }

            switch (_Realm)
            {
            case WowRealm.Unknown:
                throw new Exception("(GetDictionaryItemID) Could not get dictionary ItemID for Unknown Realm");

            case WowRealm.Emerald_Dream:
                return((1U << 24) + _ItemID);

            case WowRealm.Al_Akir:
                return((1U << 24) + _ItemID);

            case WowRealm.Warsong:
                return((1U << 24) + _ItemID);

            case WowRealm.All:
                return(uint.MaxValue);

            case WowRealm.Archangel:
                return((0x10U << 24) + _ItemID);

            case WowRealm.Valkyrie:
                return((2U << 24) + _ItemID);

            case WowRealm.Rebirth:
                return((3U << 24) + _ItemID);

            case WowRealm.VanillaGaming:
                return((4U << 24) + _ItemID);

            case WowRealm.Nostalrius:
            case WowRealm.NostalriusPVE:
                return((5U << 24) + _ItemID);

            case WowRealm.Kronos:
                return((6U << 24) + _ItemID);

            case WowRealm.NostalGeek:
                return((7U << 24) + _ItemID);

            case WowRealm.Nefarian:
                return((8U << 24) + _ItemID);

            default:
                break;
            }
            throw new Exception("(GetDictionaryItemID) Could not get dictionary ItemID for Realm: " + _Realm.ToString());
        }
Exemple #5
0
        private void Thread_LoadDatabase(string _RealmPath, DateTime?_HistoryEarliestDateTime = null)
        {
            try
            {
                var timer = System.Diagnostics.Stopwatch.StartNew();
                Logger.ConsoleWriteLine("Started Loading Database " + Realm.ToString(), ConsoleColor.Green);
                if (System.IO.File.Exists(_RealmPath + "\\PlayersData.dat") == true)
                {
                    m_LoadedDBFileDateTime = System.IO.File.GetLastWriteTimeUtc(_RealmPath + "\\PlayersData.dat");
                    Dictionary <string, PlayerData.Player> loadedPlayers = null;
                    Utility.LoadSerialize <Dictionary <string, PlayerData.Player> >(_RealmPath + "\\PlayersData.dat", out loadedPlayers);

                    lock (m_LockObj)
                    {
                        m_Players    = loadedPlayers;
                        m_LoadStatus = LoadStatus.PlayersLoaded;
                    }
                }
                if (System.IO.File.Exists(_RealmPath + "\\PlayersHistoryData_Now.dat") == true)
                {
                    DateTime loadDate = DateTime.UtcNow;// new DateTime(2013, 5, 5, 1, 1, 1);
                    if (_HistoryEarliestDateTime != null)
                    {
                        loadDate = _HistoryEarliestDateTime.Value;
                    }

                    Dictionary <string, PlayerData.PlayerHistory> loadedPlayersHistory = null;
                    loadedPlayersHistory = _LoadPlayersHistoryChunked(_RealmPath, loadDate);

                    lock (m_LockObj)
                    {
                        m_History.m_PlayersHistory = loadedPlayersHistory;
                        m_LoadStatus = LoadStatus.PlayersHistoryLoaded;
                    }
                }
                if (System.IO.File.Exists(_RealmPath + "\\PlayersExtraData.dat") == true)
                {
                    Dictionary <string, PlayerData.ExtraData> loadedPlayersExtraData = null;
                    VF.Utility.LoadSerialize <Dictionary <string, PlayerData.ExtraData> >(_RealmPath + "\\PlayersExtraData.dat", out loadedPlayersExtraData);
                    if (loadedPlayersExtraData == null)
                    {
                        loadedPlayersExtraData = new Dictionary <string, PlayerData.ExtraData>();
                    }

                    lock (m_LockObj)
                    {
                        m_PlayersExtraData = loadedPlayersExtraData;
                        m_LoadStatus       = LoadStatus.PlayersExtraDataLoaded;
                    }
                }

                lock (m_LockObj)
                {
                    m_LoadStatus = LoadStatus.EverythingLoaded;
                }
                m_LoaderThread = null;

                Logger.ConsoleWriteLine("Done with loading Database " + Realm.ToString() + ", it took " + (timer.ElapsedMilliseconds / 1000) + " seconds", ConsoleColor.Green);
            }
            catch (Exception ex)
            {
                m_LoadStatus = LoadStatus.Load_Failed;
                Logger.LogException(ex);
            }
        }
Exemple #6
0
        public static Dictionary <string, PlayerData.PlayerHistory> _LoadPlayersHistoryChunked(string _RealmPath, WowRealm _Realm, DateTime _HistoryEarliestDateTime)
        {
            Dictionary <string, PlayerData.PlayerHistory> loadedPlayersHistory = new Dictionary <string, PlayerData.PlayerHistory>();
            DateTime dateToLoad = DateTime.UtcNow;

            dateToLoad = dateToLoad.AddDays(15 - dateToLoad.Day); //Så att dagen ställs in på ungefär mitten av månaden för säkerhetsskull

            {                                                     ////BORDE BRYTAS UT TILL EN FUNKTION???
                Utility.LoadSerialize <Dictionary <string, PlayerData.PlayerHistory> >
                    (_RealmPath + "\\PlayersHistoryData_Now.dat", out loadedPlayersHistory);
            }////BORDE BRYTAS UT TILL EN FUNKTION???
            while (dateToLoad >= _HistoryEarliestDateTime)
            {
                if (System.IO.File.Exists(_RealmPath + "\\PlayersHistoryData_" + dateToLoad.ToString("yyyy_MM") + ".dat") == true)
                {////BORDE BRYTAS UT TILL EN FUNKTION???
                    GC.Collect();
                    Dictionary <string, PlayerData.PlayerHistory> extraPlayerHistory = null;
                    Utility.LoadSerialize <Dictionary <string, PlayerData.PlayerHistory> >
                        (_RealmPath + "\\PlayersHistoryData_" + dateToLoad.ToString("yyyy_MM") + ".dat", out extraPlayerHistory);

                    foreach (var playerHistory in loadedPlayersHistory)
                    {
                        PlayerData.PlayerHistory oldHistory = null;
                        if (extraPlayerHistory.TryGetValue(playerHistory.Key, out oldHistory))
                        {
                            playerHistory.Value.AddOldHistory(oldHistory);
                            extraPlayerHistory.Remove(playerHistory.Key);
                        }
                    }
                    foreach (var playerHistory in extraPlayerHistory)
                    {
                        loadedPlayersHistory.Add(playerHistory.Key, playerHistory.Value);
                    }
                    Logger.ConsoleWriteLine("Loaded \"PlayersHistoryData_" + dateToLoad.ToString("yyyy_MM") + ".dat\" for Database " + _Realm.ToString(), ConsoleColor.White);
                }////BORDE BRYTAS UT TILL EN FUNKTION???
                dateToLoad = dateToLoad.AddMonths(-1);
            }

            if (_HistoryEarliestDateTime.Year <= 2012 && System.IO.File.Exists(_RealmPath + "\\PlayersHistoryData_ManuallyAdded.dat") == true)
            {////BORDE BRYTAS UT TILL EN FUNKTION???
                Dictionary <string, PlayerData.PlayerHistory> extraPlayerHistory = null;
                Utility.LoadSerialize <Dictionary <string, PlayerData.PlayerHistory> >
                    (_RealmPath + "\\PlayersHistoryData_ManuallyAdded.dat", out extraPlayerHistory);

                foreach (var playerHistory in loadedPlayersHistory)
                {
                    PlayerData.PlayerHistory oldHistory = null;
                    if (extraPlayerHistory.TryGetValue(playerHistory.Key, out oldHistory))
                    {
                        playerHistory.Value.AddOldHistory(oldHistory);
                        extraPlayerHistory.Remove(playerHistory.Key);
                    }
                }
                foreach (var playerHistory in extraPlayerHistory)
                {
                    loadedPlayersHistory.Add(playerHistory.Key, playerHistory.Value);
                }
                Logger.ConsoleWriteLine("Loaded \"PlayersHistoryData_ManuallyAdded.dat\" for Database " + _Realm.ToString(), ConsoleColor.White);
            }////BORDE BRYTAS UT TILL EN FUNKTION???

            return(loadedPlayersHistory);
        }