/// <summary> /// This is called before values are updated. We can use this to compare the thumbnail and write it to the cache if its changed /// </summary> /// <param name="entity"></param> /// <param name="type"></param> /// <param name="path"></param> /// <param name="value"></param> /// <param name="context"></param> public override void DemandMutation(object entity, MutationType type, string path, object value, ISecurityContext context) { if (path == "Lot_Thumbnail") { var lot = (Lot)entity; var newValue = (cTSOGenericData)value; var oldValue = lot.Lot_Thumbnail; var persist = false; if (newValue != null) { if (oldValue == null) { persist = true; } else { persist = !FastBytesCompare(oldValue.Data, newValue.Data); } } if (persist && Shards.CurrentShard.HasValue) { var key = CacheKey.For("shards", Shards.CurrentShard.Value, "lot_thumbs", lot.Id); Cache.Add(key, ((cTSOGenericData)value).Data); } } }
public Texture2D GetLotThumbnail(string shardName, uint lotId) { //might reintroduce the cache at some point, though with the thumbnails behind cloudflare it's likely not an issue for now. var shard = LoginRegulator.Shards.GetByName(shardName); var shardKey = CacheKey.For("shards", shard.Id); var thumbKey = CacheKey.Combine(shardKey, "lot_thumbs", lotId); if (Cache.ContainsKey(thumbKey)) { try { var thumbData = Cache.Get <byte[]>(thumbKey).Result; var thumb = ImageLoader.FromStream(GameFacade.GraphicsDevice, new MemoryStream(thumbData)); return(thumb); }catch (Exception ex) { //Handles cases where the cache file got corrupted var thumb = TextureUtils.TextureFromFile(GameFacade.GraphicsDevice, GameFacade.GameFilePath("userdata/houses/defaulthouse.bmp")); TextureUtils.ManualTextureMask(ref thumb, new uint[] { 0xFF000000 }); return(thumb); } } else { var thumb = TextureUtils.TextureFromFile(GameFacade.GraphicsDevice, GameFacade.GameFilePath("userdata/houses/defaulthouse.bmp")); TextureUtils.ManualTextureMask(ref thumb, new uint[] { 0xFF000000 }); return(thumb); } }