public override bool CheckFavorite(PictureData data) { try { bool res = _cache.Exists(d => d.PageUrl == data.PageUrl); return res; } catch (Exception ex) { ExManager.Ex(ex); return false; } }
/// <summary> /// path to database's location /// </summary> /// <summary> /// uses default path (App data) /// </summary> public FavoritesSaver() { _currentPath = GetDefaultPath(); try { // Get collection _db = new LiteDatabase(_currentPath); _collection = _db.GetCollection<FavoritePOCO>(CollectionName); FillData(); } catch (Exception ex) { ExManager.Ex(ex); } }
public override bool Delete(PictureData data) { try { _cache.RemoveAt(_cache.FindIndex(d => d.PageUrl == data.PageUrl)); int count = _Delete(data); RaiseRemovedFromFavorite(data); return count > 0; } catch (Exception ex) { ExManager.Ex(ex); return false; } }
//public void Dispose() //{ // db.Dispose(); //} public override bool Save(PictureData data) { try { // Create new entry _cache.Add(data); var fav = new FavoritePOCO { ScraperName = Fussy.EncryptString(data.Scraper.SiteName), ThumbUrl = Fussy.EncryptString(data.ThumbUrl), PageUrl = Fussy.EncryptString(data.PageUrl) }; _collection.Insert(fav); _collection.EnsureIndex(x => x.PageUrl); RaiseAddedToFavorite(data); } catch (Exception ex) { ExManager.Ex(ex); return false; } return true; }
private void FillData() { try { foreach (var data in _collection.FindAll()) { //remove invalid data if (!CheckValid(data)) { DeleteById(data.Id); continue; } _cache.Add(new PictureData(Scraper.GetScraperByName(Fussy.DecryptString(data.ScraperName))) { ThumbUrl = Fussy.DecryptString(data.ThumbUrl), PageUrl = Fussy.DecryptString(data.PageUrl) }); } } catch (Exception ex) { ExManager.Ex(ex); } }