private IndexItem BuildIndexItem(Item item, CharacterFile character) { if (string.IsNullOrEmpty(item.baseName)) { return(null); } var itemDef = _itemCache.GetItem(item.baseName); if (itemDef == null) { return(null); } //itemStatDef is the item definition that is used for stats (relevant in case of blueprints, where the item itself doesn't have stats, but the crafted item does) var itemStatDefIdentifier = ItemHelper.GetItemStatSource(itemDef); ItemRaw itemStatDef = itemDef; if (itemStatDefIdentifier != null) { itemStatDef = _itemCache.GetItem(itemStatDefIdentifier); // Some items are defined slightly differently - where the target item actually refers to a loot table instead of the item itself. if (itemStatDef != null && itemStatDef.StringParametersRaw.ContainsKey("Class") && itemStatDef.StringParametersRaw["Class"] == "LootItemTable_DynWeight") { var lootName1 = itemStatDef.StringParametersRaw.ContainsKey("lootName1") ? itemStatDef.StringParametersRaw["lootName1"] : null; if (lootName1 == null) { itemStatDef = null; } else { itemStatDef = _itemCache.GetItem(lootName1); } } } if (itemStatDef == null) { itemStatDef = itemDef; } var indexItem = new IndexItem(); indexItem.ItemName = ItemHelper.GetFullItemName(item, itemDef); indexItem.Owner = character.Header.Name; if (itemStatDef.NumericalParametersRaw.ContainsKey("levelRequirement")) { indexItem.LevelRequirement = (int)itemStatDef.NumericalParametersRaw["levelRequirement"]; } indexItem.Rarity = ItemHelper.GetItemRarity(itemDef); indexItem.ItemType = ItemHelper.GetItemType(itemStatDef); indexItem.Source = itemDef; indexItem.SourceInstance = item; indexItem.ItemStats = ItemHelper.GetStats(item, itemStatDef).Select(x => x.Replace("{^E}", "").Replace("{%+.0f0}", "").Replace("{%t0}", "").Trim()).ToList(); indexItem.Searchable = BuildSearchableString(character, item, itemDef, indexItem.ItemStats); return(indexItem); }
public void Add_Datetime_TTLAbsSli() { DateTime dt_1 = DateTime.Now; ItemCache <DateTime> ic_1 = new ItemCache <DateTime>(); ic_1.Key = "Add_Datetime_TTLAbsSli"; ic_1.Value = dt_1; ic_1.SlidingExpiration = new TimeSpan(0, 0, 10); ic_1.AbsoluteExpiration = new TimeSpan(0, 0, 25); ic_1.Save(true); System.Threading.Thread.Sleep(5000); ItemCache <DateTime> ic_2 = ItemCache <DateTime> .GetItem("Add_Datetime_TTLAbsSli"); Assert.AreEqual <DateTime>(dt_1, ic_2.Value); System.Threading.Thread.Sleep(5000); ItemCache <DateTime> ic_3 = ItemCache <DateTime> .GetItem("Add_Datetime_TTLAbsSli"); Assert.AreEqual <DateTime>(dt_1, ic_3.Value); System.Threading.Thread.Sleep(10000); ItemCache <DateTime> ic_4 = ItemCache <DateTime> .GetItem("Add_Datetime_TTLAbsSli"); Assert.AreEqual(ic_4, null); }
public static void TestSubKeyCaching() { CacheKey cacheKey = new CacheKey("a key").Subkey("a subkey").Subkey("another subkey"); int count = 0; ItemCache cache = new ItemCache(); object o = new object(); object item = cache.GetItem(cacheKey, () => { ++count; return(o); }); Assert.That(count, Is.EqualTo(1)); Assert.That(item, Is.EqualTo(o)); item = cache.GetItem(cacheKey, () => { ++count; return(o); }); Assert.That(count, Is.EqualTo(1)); Assert.That(item, Is.EqualTo(o)); }
public void Add_String() { string obj_1 = Properties.Settings.Default.Value_Text_long; ItemCache <string> ic_1 = new ItemCache <string>(); ic_1.Key = "Add_String"; ic_1.Value = obj_1; ic_1.Save(true); ItemCache <string> ic_2 = ItemCache <string> .GetItem("Add_String"); Assert.AreEqual <string>(obj_1, ic_2.Value); }
public void Add_Datetime() { DateTime dt_1 = DateTime.Now; ItemCache <DateTime> ic_1 = new ItemCache <DateTime>(); ic_1.Key = "Add_Datetime"; ic_1.Value = dt_1; ic_1.Save(true); ItemCache <DateTime> ic_2 = ItemCache <DateTime> .GetItem("Add_Datetime"); Assert.AreEqual <DateTime>(dt_1, ic_2.Value); }
public static void TestFlushCache() { CacheKey cacheKey = new CacheKey("a key").Subkey("a subkey"); int count = 0; ItemCache cache = new ItemCache(); int item1 = cache.GetItem(cacheKey.Subkey("1"), () => { return(++count); }); Assert.That(item1, Is.EqualTo(1)); Assert.That(count, Is.EqualTo(1)); int item2 = cache.GetItem(cacheKey.Subkey("2"), () => { return(++count); }); Assert.That(item2, Is.EqualTo(2)); Assert.That(count, Is.EqualTo(2)); item1 = cache.GetItem(cacheKey.Subkey("1"), () => { return(++count); }); Assert.That(item1, Is.EqualTo(1)); Assert.That(count, Is.EqualTo(2)); item2 = cache.GetItem(cacheKey.Subkey("2"), () => { return(++count); }); Assert.That(item2, Is.EqualTo(2)); Assert.That(count, Is.EqualTo(2)); cache.RemoveItem(CacheKey.RootKey); item1 = cache.GetItem(cacheKey.Subkey("1"), () => { return(++count); }); Assert.That(item1, Is.EqualTo(3)); Assert.That(count, Is.EqualTo(3)); item2 = cache.GetItem(cacheKey.Subkey("2"), () => { return(++count); }); Assert.That(item2, Is.EqualTo(4)); Assert.That(count, Is.EqualTo(4)); item1 = cache.GetItem(cacheKey.Subkey("1"), () => { return(++count); }); Assert.That(item1, Is.EqualTo(3)); Assert.That(count, Is.EqualTo(4)); item2 = cache.GetItem(cacheKey.Subkey("2"), () => { return(++count); }); Assert.That(item2, Is.EqualTo(4)); Assert.That(count, Is.EqualTo(4)); }
public Item GetItem(Func <Item, bool> filter) { return(ItemCache.GetItem(filter)); }