public static DrawingBrush Get(CardViewModel card) { try { if (card?.Id == null || card.Name == null || Cache == null) { return(new DrawingBrush()); } var cardImageObj = new CardImageObject(card); var key = $"{card.Id}_{cardImageObj.GetHashCode()}"; if (!Refresh.Contains(card.Id) && Cache.TryGet(key, out var cached)) { return(cached.Image); } Refresh.Remove(card.Id); DrawingBrush image = null; Application.Current.Dispatcher.Invoke(() => image = ThemeManager.GetBarImageBuilder(card).Build()); if (image.CanFreeze) { image.Freeze(); } cardImageObj = new CardImageObject(image, card); Cache.Cache(key, cardImageObj); return(cardImageObj.Image); } catch (Exception ex) { Log.Error($"Image builder failed: {ex.Message}"); return(new DrawingBrush()); } }
public static IList <DocObj> GetDocuments(String author, String book, String sort, String mode) { #if TRACE Trace.WriteLine(String.Format("GetDocuments({0}, {1})", author, book)); #endif String key = String.Format("GetDocuments(\"{0}\", \"{1}\")", author, book); Object obj = MemCache.Cache(key); if (!(obj is IList <DocObj>)) { obj = _DbProvider.GetDocuments(author, book, sort, mode); MemCache.Cache( key, obj); } if (!(String.Equals(sort, "Title", StringComparison.InvariantCultureIgnoreCase) || String.Equals(sort, "Chapter", StringComparison.InvariantCultureIgnoreCase))) { sort = "Chapter"; } if (!(String.Equals(mode, "Asc", StringComparison.InvariantCultureIgnoreCase) || String.Equals(mode, "Desc", StringComparison.InvariantCultureIgnoreCase))) { mode = "ASC"; } if (String.Equals(sort, "Title", StringComparison.InvariantCultureIgnoreCase)) { if (String.Equals(mode, "ASC", StringComparison.InvariantCultureIgnoreCase)) { return(((IList <DocObj>)obj).OrderBy(k => k.Title).ToList()); } else { return(((IList <DocObj>)obj).OrderByDescending(k => k.Title).ToList()); } } else { if (String.Equals(mode, "ASC", StringComparison.InvariantCultureIgnoreCase)) { return(((IList <DocObj>)obj).OrderBy(k => k.Chapter).ToList()); } else { return(((IList <DocObj>)obj).OrderByDescending(k => k.Chapter).ToList()); } } }
public static void SaveDocument(DocObj doc) { String key = String.Format("GetDocuments(\"{0}\")", doc.Id); _DbProvider.SaveDocument(doc); MemCache.Cache( key, doc); MemCache.Cache( String.Format("GetDocuments(\"{0}\", \"{1}\")", doc.Author, doc.Book), null); }
public static DocObj InsertDocument(DocObj doc) { DocObj inserted = _DbProvider.InsertDocument(doc); String key = String.Format("GetDocuments(\"{0}\")", inserted.Id); MemCache.Cache( key, inserted); MemCache.Cache( String.Format("GetDocuments(\"{0}\", \"{1}\")", doc.Author, doc.Book), null); return(inserted); }
public static DocObj GetDocument(Guid id) { #if TRACE Trace.WriteLine(String.Format("GetDocuments({0})", id)); #endif String key = String.Format("GetDocuments(\"{0}\")", id); Object obj = MemCache.Cache(key); if (obj is DocObj) { return((DocObj)obj); } obj = _DbProvider.GetDocument(id); MemCache.Cache( key, obj); return((DocObj)obj); }
public static IList <Book> GetBooks(String author) { #if TRACE Trace.WriteLine(String.Format("GetBooks({0})", author)); #endif String key = String.Format("GetBooks(\"{0}\")", author); Object obj = MemCache.Cache(key); if (obj is IList <Book> ) { return((IList <Book>)obj); } obj = _DbProvider.GetBooks(author); MemCache.Cache( key, obj); return((IList <Book>)obj); }