/// <summary> /// Attempts to remove a single entry from the cache /// </summary> /// /// <param name="key">The key used to locate the value in the cache.</param> public bool TryRemove(TKey key) { var fileInfo = new FileInfo(_fileLookup[key].Name); if (fileInfo.Exists) { try { if (IsFileLockedWait(fileInfo, 500)) { Console.WriteLine("Attempt to delete locked file: " + fileInfo); } else { File.Delete(_fileLookup[key].Name); _fileLookup.TryRemove(key, out var tmpFilePath); _entryLookup.TryRemove(key, out var lookupEntry); EntryRemoved?.Invoke(this, lookupEntry); return(true); } } catch (Exception e) { //Console.WriteLine("EXCEPTION Testing for file lock: " + fileInfo); Console.WriteLine("EXCEPTION filename: " + fileInfo); Console.WriteLine("EXCEPTION : " + e); } } return(false); }
public void RemoveAt(int index) { var item = entries[index]; entries.RemoveAt(index); EntryRemoved?.Invoke(this, new UI.GenericEventArgs <UI.DataEntry>(item)); }
public async Task Remove(FileExplorerEntry entry) { if (entry.Type == FileExplorerEntryType.File) { await FileSystemResource.DeleteFile(entry.Path, _restClient); } else { await FileSystemResource.DeleteDirectory(entry.Path, _restClient); } EntryRemoved?.Invoke(this, entry); var parentFolder = Path.GetDirectoryName(entry.Path); if (parentFolder != null && TryGetCachedDirectory(parentFolder, out var cachedDirectory)) { lock (cachedDirectory.EntriesLock) { cachedDirectory.Entries = cachedDirectory.Entries.Remove(entry); } } if (entry.Type != FileExplorerEntryType.File) { var normalizedPath = NormalizePath(entry.Path); foreach (var keyValuePair in _localCache.Where(x => x.Key.StartsWith(normalizedPath, PathStringComparison))) { _localCache.TryRemove(keyValuePair.Key, out _); } } }
public bool Remove(DataEntry item) { if (entries.Remove(item)) { EntryRemoved?.Invoke(this, new UI.GenericEventArgs <UI.DataEntry>(item)); return(true); } return(false); }
public void RemoveEntry(int index) { CheckBounds(index); IComponent oldValue = storage[index]; storage[index] = null; EntryRemoved?.Invoke(this, new StorageEntryEventArgs(index, oldValue)); }
public void Clear() { var items = entries.ToArray(); entries.Clear(); foreach (var item in items) { EntryRemoved?.Invoke(this, new UI.GenericEventArgs <UI.DataEntry>(item)); } }
/// <summary> /// Removes the element with the specified key from the dictionary. /// </summary> public bool Remove(KeyValuePair <K, V> entry) { var removed = ((IDictionary <K, V>)dictionary).Remove(entry); if (removed) { EntryRemoved?.Invoke(this, new EntryRemovedEventArgs <K, V>(entry.Key, entry.Value)); } return(removed); }
/// <summary> /// Removes all entries from the dictionary. /// </summary> public void Clear() { var oldKvps = dictionary.ToList(); dictionary.Clear(); foreach (var entry in oldKvps) { EntryRemoved?.Invoke(this, new EntryRemovedEventArgs <K, V>(entry.Key, entry.Value)); } }
/// <summary> /// Removes the first occurrence of a specific object from the dictionary. /// </summary> public bool Remove(K key) { V oldValue; TryGetValue(key, out oldValue); var removed = ((IDictionary <K, V>)dictionary).Remove(key); if (removed) { EntryRemoved?.Invoke(this, new EntryRemovedEventArgs <K, V>(key, oldValue)); } return(removed); }
/// <summary> /// Empties the cache of all values that it is currently tracking. /// </summary> public void Clear() { while (!_entryLookup.IsEmpty) { foreach (var entry in _entryLookup.ToList()) { var fileInfo = new FileInfo(_fileLookup[entry.Key].Name); if (fileInfo.Exists) { try { if (IsFileLockedWait(fileInfo, 500)) { Console.WriteLine("Attempt to delete locked file: " + fileInfo); } else { File.Delete(_fileLookup[entry.Key].Name); } } catch (Exception e) { //Console.WriteLine("EXCEPTION Testing for file lock: " + fileInfo); Console.WriteLine("EXCEPTION filename: " + fileInfo); Console.WriteLine("EXCEPTION : " + e); } } _entryLookup.TryRemove(entry.Key, out var lookupEntry); EntryRemoved?.Invoke(this, lookupEntry); } if (!_entryLookup.IsEmpty) { Task.Delay(100).Wait(); } } foreach (var dir in CachePath.EnumerateDirectories()) { dir.Delete(true); } foreach (var file in CachePath.EnumerateFiles()) { file.Delete(); } _entryLookup.Clear(); _fileLookup.Clear(); }
public V this[K key] { get { return(dictionary[key]); } set { V oldValue; var removed = TryGetValue(key, out oldValue); if (removed) { EntryRemoved?.Invoke(this, new EntryRemovedEventArgs <K, V>(key, oldValue)); } dictionary[key] = value; EntryAdded?.Invoke(this, new EntryAddedEventArgs <K, V>(key, value)); if (removed) { EntryChanged?.Invoke(this, new EntryChangedEventArgs <K, V>(key, value, oldValue)); } } }
/// <summary> /// Applies the cache policy to all values held in the cache. /// </summary> protected void ApplyCachePolicy() { var expiredEntries = Policy.GetExpiredEntries(_entryLookup.Values, MaximumStorageCapacity); foreach (var expiredEntry in expiredEntries) { var key = expiredEntry.Key; var filePath = _fileLookup[key]; var fileInfo = new FileInfo(filePath); if (fileInfo.IsFileLocked()) { continue; } fileInfo.Delete(); _fileLookup.TryRemove(key, out var tmpFilePath); _entryLookup.TryRemove(key, out var lookupEntry); EntryRemoved?.Invoke(this, lookupEntry); } }
/// <summary> /// Applies the cache policy to all values held in the cache. /// </summary> protected void ApplyCachePolicy() { var expiredEntries = Policy.GetExpiredEntries(_entryLookup.Values, MaximumStorageCapacity); foreach (var expiredEntry in expiredEntries) { var key = expiredEntry.Key; var filePath = _fileLookup[key].Name; var fileInfo = new FileInfo(filePath); if (IsFileLocked(fileInfo)) { Console.WriteLine("Attempt to delete locked file: " + fileInfo); } { fileInfo.Delete(); _fileLookup.TryRemove(key, out var tmpFilePath); _entryLookup.TryRemove(key, out var lookupEntry); EntryRemoved?.Invoke(this, lookupEntry); } } }
/// <summary> /// Empties the cache of all values that it is currently tracking. /// </summary> public async Task ClearAsync() { while (!_entryLookup.IsEmpty) { foreach (var entry in _entryLookup) { var fileInfo = new FileInfo(_fileLookup[entry.Key].Name); if (IsFileLocked(fileInfo)) { Console.WriteLine("Attempt to delete locked file: " + fileInfo); } { File.Delete(_fileLookup[entry.Key].Name); _entryLookup.TryRemove(entry.Key, out var lookupEntry); EntryRemoved?.Invoke(this, lookupEntry); } } if (!_entryLookup.IsEmpty) { await Task.Delay(100).ConfigureAwait(false); } } foreach (var dir in CachePath.EnumerateDirectories()) { dir.Delete(true); } foreach (var file in CachePath.EnumerateFiles()) { file.Delete(); } _entryLookup.Clear(); _fileLookup.Clear(); }
/// <summary> /// Empties the cache of all values that it is currently tracking. /// </summary> public async Task ClearAsync() { while (!_entryLookup.IsEmpty) { foreach (var entry in _entryLookup) { var fileInfo = new FileInfo(_fileLookup[entry.Key]); if (fileInfo.IsFileLocked()) { continue; } File.Delete(_fileLookup[entry.Key]); _entryLookup.TryRemove(entry.Key, out var lookupEntry); EntryRemoved?.Invoke(this, lookupEntry); } if (!_entryLookup.IsEmpty) { await Task.Delay(100).ConfigureAwait(false); } } foreach (var dir in CachePath.EnumerateDirectories()) { dir.Delete(true); } foreach (var file in CachePath.EnumerateFiles()) { file.Delete(); } _entryLookup.Clear(); _fileLookup.Clear(); }
protected virtual void OnEntryRemoved(bool evicted, string key, TValue value) { EntryRemoved?.Invoke(this, new EntryRemovedEventArgs <TValue>(key, value, evicted)); }