Exemplo n.º 1
0
        public TreasureDeath GetCachedDeathTreasure(uint dataId)
        {
            if (cachedDeathTreasure.TryGetValue(dataId, out var value))
                return value;

            using (var context = new WorldDbContext())
            {
                var result = context.TreasureDeath
                    .AsNoTracking()
                    .FirstOrDefault(r => r.TreasureType == dataId);

                cachedDeathTreasure[dataId] = result;
                return result;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Imports an SQL file into the database
        /// </summary>
        public static void ImportSQL(string sqlFile)
        {
            var sqlCommands = File.ReadAllText(sqlFile);

            // not sure why ExecuteSqlCommand doesn't parse this correctly..
            var idx = sqlCommands.IndexOf($"/* Lifestoned Changelog:");

            if (idx != -1)
            {
                sqlCommands = sqlCommands.Substring(0, idx);
            }

            using (var ctx = new WorldDbContext())
                ctx.Database.ExecuteSqlCommand(sqlCommands);
        }
Exemplo n.º 3
0
         /// <summary>
        /// This will populate all sub collections except the following: LandblockInstances, PointsOfInterest<para />
        /// This will also update the weenie cache.
        /// </summary>
        public override Weenie GetWeenie(WorldDbContext context, uint weenieClassId)
        {
            var weenie = base.GetWeenie(context, weenieClassId);

            // If the weenie doesn't exist in the cache, we'll add it.
            if (weenie != null)
            {
                weenieCache[weenieClassId] = WeenieConverter.ConvertToEntityWeenie(weenie);
                weenieClassNameToClassIdCache[weenie.ClassName.ToLower()] = weenie.ClassId;
            }
            else
                weenieCache[weenieClassId] = null;

            return weenie;
        }
Exemplo n.º 4
0
        /// <summary>
        /// This takes under ? second to complete.
        /// </summary>
        public void CacheAllHousePortals()
        {
            using (var context = new WorldDbContext())
            {
                var results = context.HousePortal
                              .AsNoTracking()
                              .GroupBy(r => r.HouseId)
                              .ToList();

                foreach (var result in results)
                {
                    cachedHousePortals[result.Key] = result.ToList();
                }
            }
        }
Exemplo n.º 5
0
        public Quest GetCachedQuest(string questName)
        {
            if (cachedQuest.TryGetValue(questName, out var quest))
            {
                return(quest);
            }

            using (var context = new WorldDbContext())
            {
                quest = context.Quest.FirstOrDefault(q => q.Name.Equals(questName));
                cachedQuest[questName] = quest;

                return(quest);
            }
        }
Exemplo n.º 6
0
        public void CacheAllTreasuresMaterialGroupsInParallel()
        {
            using (var context = new WorldDbContext())
            {
                var results = context.TreasureMaterialGroups
                              .AsNoTracking()
                              .GroupBy(r => r.MaterialGroup)
                              .ToList();

                foreach (var result in results)
                {
                    cachedTreasureMaterialGroups[(int)result.Key] = result.ToList();
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// This takes under 1 second to complete.
        /// </summary>
        public void CacheAllWieldedTreasuresInParallel()
        {
            using (var context = new WorldDbContext())
            {
                var results = context.TreasureWielded
                              .AsNoTracking()
                              .GroupBy(r => r.TreasureType)
                              .ToList();

                foreach (var result in results)
                {
                    cachedWieldedTreasure[result.Key] = result.ToList();
                }
            }
        }
Exemplo n.º 8
0
        public List<LandblockInstance> GetCachedInstancesByLandblock(WorldDbContext context, ushort landblock)
        {
            if (cachedLandblockInstances.TryGetValue(landblock, out var value))
                return value;

            var results = context.LandblockInstance
                .Include(r => r.LandblockInstanceLink)
                .AsNoTracking()
                .Where(r => r.Landblock == landblock)
                .ToList();

            cachedLandblockInstances.TryAdd(landblock, results.ToList());

            return cachedLandblockInstances[landblock];
        }
Exemplo n.º 9
0
        public Spell GetCachedSpell(uint spellId)
        {
            if (spellCache.TryGetValue(spellId, out var spell))
                return spell;

            using (var context = new WorldDbContext())
            {
                var result = context.Spell
                    .AsNoTracking()
                    .FirstOrDefault(r => r.Id == spellId);

                spellCache[spellId] = result;
                return result;
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// This takes under 1 second to complete.
        /// </summary>
        public List <Event> GetAllEvents()
        {
            using (var context = new WorldDbContext())
            {
                var results = context.Event
                              .AsNoTracking()
                              .ToList();

                foreach (var result in results)
                {
                    cachedEvents[result.Name.ToLower()] = result;
                }

                return(results);
            }
        }
Exemplo n.º 11
0
        public uint GetWeenieClassId(string weenieClassName)
        {
            using (var context = new WorldDbContext())
            {
                var result = context.Weenie
                             .AsNoTracking()
                             .FirstOrDefault(r => r.ClassName == weenieClassName);

                if (result != null)
                {
                    return(result.ClassId);
                }

                return(0);
            }
        }
Exemplo n.º 12
0
        public List<TreasureWielded> GetCachedWieldedTreasure(uint dataId)
        {
            if (cachedWieldedTreasure.TryGetValue(dataId, out var value))
                return value;

            using (var context = new WorldDbContext())
            {
                var results = context.TreasureWielded
                    .AsNoTracking()
                    .Where(r => r.TreasureType == dataId)
                    .ToList();

                cachedWieldedTreasure[dataId] = results;
                return results;
            }
        }
Exemplo n.º 13
0
        public List<Encounter> GetCachedEncountersByLandblock(ushort landblock)
        {
            if (cachedEncounters.TryGetValue(landblock, out var value))
                return value;

            using (var context = new WorldDbContext())
            {
                var results = context.Encounter
                    .AsNoTracking()
                    .Where(r => r.Landblock == landblock)
                    .ToList();

                cachedEncounters.TryAdd(landblock, results);
                return results;
            }
        }
Exemplo n.º 14
0
        public PointsOfInterest GetCachedPointOfInterest(string name)
        {
            var nameToLower = name.ToLower();

            if (cachedPointsOfInterest.TryGetValue(nameToLower, out var value))
                return value;

            using (var context = new WorldDbContext())
            {
                var result = context.PointsOfInterest
                    .AsNoTracking()
                    .FirstOrDefault(r => r.Name.ToLower() == nameToLower);

                cachedPointsOfInterest[nameToLower] = result;
                return result;
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// This will make sure every weenie in the database has been read and cached.<para />
        /// This function may take 2+ minutes to complete.
        /// </summary>
        public void CacheAllWeeniesInParallel()
        {
            using (var context = new WorldDbContext())
            {
                var results = context.Weenie
                    .AsNoTracking()
                    .ToList();

                Parallel.ForEach(results, ConfigManager.Config.Server.Threading.DatabaseParallelOptions, result =>
                {
                    if (!weenieCache.ContainsKey(result.ClassId))
                        GetWeenie(result.ClassId); // This will add the result into the caches
                });
            }

            PopulateWeenieSpecificCaches();
        }
Exemplo n.º 16
0
        public List<HousePortal> GetCachedHousePortalsByLandblock(uint landblockId)
        {
            if (cachedHousePortalsByLandblock.TryGetValue(landblockId, out var value))
                return value;

            using (var context = new WorldDbContext())
            {
                var results = context.HousePortal
                    .AsNoTracking()
                    .Where(p => landblockId == p.ObjCellId >> 16)
                    .ToList();

                cachedHousePortalsByLandblock[landblockId] = results;

                return results;
            }
        }
Exemplo n.º 17
0
        public List<HousePortal> GetCachedHousePortals(uint houseId)
        {
            if (cachedHousePortals.TryGetValue(houseId, out var value))
                return value;

            using (var context = new WorldDbContext())
            {
                var results = context.HousePortal
                    .AsNoTracking()
                    .Where(p => p.HouseId == houseId)
                    .ToList();

                cachedHousePortals[houseId] = results;

                return results;
            }
        }
Exemplo n.º 18
0
        private static Dictionary <uint, Dictionary <int, HashSet <uint> > > BuildWeenieEmoteCache()
        {
            /// wcid => emote hash => list of order ids with delay 0
            var emoteCache = new Dictionary <uint, Dictionary <int, HashSet <uint> > >();

            using (var ctx = new WorldDbContext())
            {
                var query = from emote in ctx.WeeniePropertiesEmote
                            join action in ctx.WeeniePropertiesEmoteAction on emote.Id equals action.EmoteId
                            where action.Delay == 0.0f
                            select new
                {
                    Emote  = emote,
                    Action = action
                };

                var emoteActions = query.ToList();

                foreach (var emoteAction in emoteActions)
                {
                    var emote  = emoteAction.Emote;
                    var action = emoteAction.Action;

                    var wcid = emote.ObjectId;

                    if (!emoteCache.TryGetValue(wcid, out var hashTable))
                    {
                        hashTable = new Dictionary <int, HashSet <uint> >();
                        emoteCache.Add(wcid, hashTable);
                    }

                    var emoteHash = CalculateEmoteHash(emote);

                    if (!hashTable.TryGetValue(emoteHash, out var actionIdx))
                    {
                        actionIdx = new HashSet <uint>();
                        hashTable.Add(emoteHash, actionIdx);
                    }

                    actionIdx.Add(action.Order);
                }
            }

            return(emoteCache);
        }
Exemplo n.º 19
0
        // =====================================
        // TreasureMaterial
        // =====================================


        // =====================================
        // TreasureWielded
        // =====================================

        public Dictionary <uint, List <TreasureWielded> > GetAllTreasureWielded(WorldDbContext context)
        {
            var results = context.TreasureWielded;

            var treasure = new Dictionary <uint, List <TreasureWielded> >();

            foreach (var record in results)
            {
                if (!treasure.ContainsKey(record.TreasureType))
                {
                    treasure.Add(record.TreasureType, new List <TreasureWielded>());
                }

                treasure[record.TreasureType].Add(record);
            }

            return(treasure);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Weenies will have all their collections populated except the followign: LandblockInstances, PointsOfInterest, WeeniePropertiesEmoteAction
        /// </summary>
        public List <LandblockInstances> GetCachedInstancesByLandblock(ushort landblock)
        {
            if (cachedLandblockInstances.TryGetValue(landblock, out var value))
            {
                return(value);
            }

            using (var context = new WorldDbContext())
            {
                var results = context.LandblockInstances
                              .AsNoTracking()
                              .Where(r => r.Landblock == landblock);

                cachedLandblockInstances.TryAdd(landblock, results.OrderBy(x => x.LinkController).ThenBy(x => x.LinkSlot).ToList());
            }

            return(cachedLandblockInstances[landblock]);
        }
Exemplo n.º 21
0
        public override CookBook GetCookbook(WorldDbContext context, uint sourceWeenieClassId, uint targetWeenieClassId)
        {
            var cookbook = base.GetCookbook(context, sourceWeenieClassId, targetWeenieClassId);

            lock (cookbookCache)
            {
                // We double check before commiting the recipe.
                // We could be in this lock, and queued up behind us is an attempt to add a result for the same source:target pair.
                if (cookbookCache.TryGetValue(sourceWeenieClassId, out var sourceRecipes))
                {
                    if (!sourceRecipes.ContainsKey(targetWeenieClassId))
                        sourceRecipes.Add(targetWeenieClassId, cookbook);
                }
                else
                    cookbookCache.Add(sourceWeenieClassId, new Dictionary<uint, CookBook>() { { targetWeenieClassId, cookbook } });
            }

            return cookbook;
        }
Exemplo n.º 22
0
        public Event GetCachedEvent(string name)
        {
            var nameToLower = name.ToLower();

            if (cachedEvents.TryGetValue(nameToLower, out var value))
            {
                return(value);
            }

            using (var context = new WorldDbContext())
            {
                var result = context.Event
                             .AsNoTracking()
                             .FirstOrDefault(r => r.Name.ToLower() == nameToLower);

                cachedEvents[nameToLower] = result;
                return(result);
            }
        }
Exemplo n.º 23
0
        /// <summary>
        /// This will make sure every weenie in the database has been read and cached.<para />
        /// This function may take 2+ minutes to complete.
        /// </summary>
        public void CacheAllWeeniesInParallel()
        {
            using (var context = new WorldDbContext())
            {
                var results = context.Weenie
                              .AsNoTracking()
                              .ToList();

                Parallel.ForEach(results, result =>
                {
                    if (!weenieCache.ContainsKey(result.ClassId))
                    {
                        GetWeenie(result.ClassId);
                    }
                });
            }

            PopulateWeenieSpecificCaches();
        }
Exemplo n.º 24
0
        /// <summary>
        /// This will make sure every weenie in the database has been read and cached.<para />
        /// This function may take 10+ minutes to complete.
        /// </summary>
        public void CacheAllWeenies()
        {
            using (var context = new WorldDbContext())
            {
                var results = context.Weenie
                              .AsNoTracking()
                              .ToList();

                foreach (var result in results)
                {
                    if (weenieCache.ContainsKey(result.ClassId))
                    {
                        continue;
                    }

                    GetWeenie(context, result.ClassId);
                }
            }
        }
Exemplo n.º 25
0
        public AceRecipe GetCachedRecipe(uint sourceWeenieClassid, uint targetWeenieClassId)
        {
            lock (recipeCache)
            {
                if (recipeCache.TryGetValue(sourceWeenieClassid, out var recipiesForSource))
                {
                    if (recipiesForSource.TryGetValue(targetWeenieClassId, out var value))
                    {
                        return(value);
                    }
                }
            }

            using (var context = new WorldDbContext())
            {
                var result = context.AceRecipe
                             .AsNoTracking()
                             .FirstOrDefault(r => r.SourceWcid == sourceWeenieClassid && r.TargetWcid == targetWeenieClassId);

                lock (recipeCache)
                {
                    // We double check before commiting the recipe.
                    // We could be in this lock, and queued up behind us is an attempt to add a result for the same source:target pair.
                    if (recipeCache.TryGetValue(sourceWeenieClassid, out var sourceRecipies))
                    {
                        if (!sourceRecipies.ContainsKey(targetWeenieClassId))
                        {
                            sourceRecipies.Add(targetWeenieClassId, result);
                        }
                    }
                    else
                    {
                        recipeCache.Add(sourceWeenieClassid, new Dictionary <uint, AceRecipe>()
                        {
                            { targetWeenieClassId, result }
                        });
                    }
                }

                return(result);
            }
        }
Exemplo n.º 26
0
        /// <summary>
        /// Weenies will have all their collections populated except the following: LandblockInstances, PointsOfInterest
        /// </summary>
        public List <LandblockInstance> GetCachedInstancesByLandblock(ushort landblock)
        {
            if (cachedLandblockInstances.TryGetValue(landblock, out var value))
            {
                return(value);
            }

            using (var context = new WorldDbContext())
            {
                var results = context.LandblockInstance
                              .Include(r => r.LandblockInstanceLink)
                              .AsNoTracking()
                              .Where(r => r.Landblock == landblock)
                              .ToList();

                cachedLandblockInstances.TryAdd(landblock, results.ToList());
            }

            return(cachedLandblockInstances[landblock]);
        }
Exemplo n.º 27
0
        private Realm GetRealm(WorldDbContext context, uint id)
        {
            var realm = context.Realm
                        .FirstOrDefault(r => r.Id == id);

            if (realm == null)
            {
                return(null);
            }

            realm.RealmPropertiesBool   = context.RealmPropertiesBool.Where(r => r.RealmId == realm.Id).ToList();
            realm.RealmPropertiesFloat  = context.RealmPropertiesFloat.Where(r => r.RealmId == realm.Id).ToList();
            realm.RealmPropertiesInt    = context.RealmPropertiesInt.Where(r => r.RealmId == realm.Id).ToList();
            realm.RealmPropertiesInt64  = context.RealmPropertiesInt64.Where(r => r.RealmId == realm.Id).ToList();
            realm.RealmPropertiesString = context.RealmPropertiesString.Where(r => r.RealmId == realm.Id).ToList();

            realm.RealmRulesetLinksRealm       = context.RealmRulesetLinks.Where(r => r.RealmId == realm.Id).ToList();
            realm.RealmRulesetLinksLinkedRealm = context.RealmRulesetLinks.Where(r => r.LinkedRealmId == realm.Id).ToList();
            return(realm);
        }
Exemplo n.º 28
0
        public List <CookBook> GetCookbooksByRecipeId(uint recipeId)
        {
            var results = new List <CookBook>();

            using (var context = new WorldDbContext())
            {
                context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;

                var baseRecords = context.CookBook.Where(i => i.RecipeId == recipeId).ToList();

                foreach (var baseRecord in baseRecords)
                {
                    var cookbook = GetCookbook(context, baseRecord.SourceWCID, baseRecord.TargetWCID);

                    results.Add(cookbook);
                }
            }

            return(results);
        }
Exemplo n.º 29
0
        public static void TryPrimeDatabase()
        {
            SetDatabaseConfig();

            var worker = new BackgroundWorker();

            worker.DoWork += (sender, doWorkEventArgs) =>
            {
                try
                {
                    using (var ctx = new WorldDbContext())
                    {
                        var weenie = ctx.Weenie.FirstOrDefault();
                    }
                }
                catch (Exception)
                {
                }
            };
            worker.RunWorkerAsync();
        }
Exemplo n.º 30
0
        public Weenie GetScrollWeenie(uint spellID)
        {
            if (!scrollsBySpellID.TryGetValue(spellID, out var weenie))
            {
                if (!weenieSpecificCachesPopulated)
                {
                    using (var context = new WorldDbContext())
                    {
                        var query = from weenieRecord in context.Weenie
                                    join did in context.WeeniePropertiesDID on weenieRecord.ClassId equals did.ObjectId
                                    where weenieRecord.Type == (int)WeenieType.Scroll && did.Type == (ushort)PropertyDataId.Spell && did.Value == spellID
                                    select weenieRecord;

                        weenie = query.FirstOrDefault();

                        scrollsBySpellID[spellID] = weenie;
                    }
                }
            }

            return(weenie);
        }
Exemplo n.º 31
0
 public static void Main()
 {
     WorldDbContext data = new WorldDbContext();
     data.Continents.Count();
     Console.WriteLine("World database created, now you can use database first aproach");
 }