private void RemoveItem(MediaItemToken item) { if (item == null) { return; } if (--item.Count > 0) { _db.Update(item); return; } _tokens.Remove(item); _db.Delete(item); StorageApplicationPermissions.FutureAccessList.Remove(item.Token); }
/// <summary> /// Request Token from system. If it returns null, there is no more space for saving this item. /// </summary> /// <param name="accessibleItem"></param> /// <returns></returns> public string RequestToken(IStorageItem accessibleItem) { if (accessibleItem == null) { return(null); } var item = _tokens.SingleOrDefault(i => i.Path.Equals(accessibleItem.Path, StringComparison.OrdinalIgnoreCase)); if (item != null) { item.Count++; _db.Update(item); return(item.Token); } if (_tokens.Count == 1000) { return(null); } var file = accessibleItem as IStorageFile; // For saving tokens, just optimizing for IStorageFile if (file != null) { var fileFolder = Path.GetDirectoryName(file.Path); var reusableToken = _tokens.FirstOrDefault(t => t.Path.Equals(fileFolder, StringComparison.OrdinalIgnoreCase)); if (reusableToken != null) { reusableToken.Count++; _db.Update(reusableToken); return(reusableToken.Token); } } var token = StorageApplicationPermissions.FutureAccessList.Add(accessibleItem); var newItem = new MediaItemToken { Path = accessibleItem.Path, Token = token, Count = 1 }; _tokens.Add(newItem); _db.Insert(newItem); return(token); }