/// <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)); }
private void OnEntryRemoved(IDbTransaction tx, ICommit commit, EntryRemoved @event) { var sqlParams = @event.ToDynamic(); sqlParams.Id = commit.AggregateId(); // Get the original where entry. const string sql1 = @" SELECT [Where] ,[UserId] FROM [dbo].[WhereProjector.Entry] WHERE [EntryId] = @Id;" ; var row = tx.Connection.QuerySingle <dynamic>(sql1, (object)sqlParams, tx); var where = row.Where; var userId = row.UserId; const string sql2 = @" DELETE FROM [dbo].[WhereProjector.Entry] WHERE [EntryId] = @Id;" ; tx.Connection.Execute(sql2, (object)sqlParams, tx); DeleteWhereProjection(tx, userId, where); }
private void OnEntryRemoved(IDbTransaction tx, ICommit commit, EntryRemoved @event) { var sqlParams = @event.ToDynamic(); sqlParams.Id = commit.AggregateId(); // Get the original where entry. const string sql1 = @" SELECT [UserId] FROM [dbo].[ActivityProjector.Entry] WHERE [EntryId] = @Id;" ; var userId = tx.Connection.QuerySingle <int>(sql1, (object)sqlParams, tx); const string sql2 = @" DELETE FROM [dbo].[ActivityProjector.Entry] WHERE [EntryId] = @Id;" ; tx.Connection.Execute(sql2, (object)sqlParams, tx); RecordActivity(tx, new Models.Activity { UserId = userId, Type = (int)ActivityType.EntryRemoved, When = commit.CommitStamp, Link = commit.AggregateId().ToString() }); }
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)); }
/// <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)); } }
public void Clear() { var items = entries.ToArray(); entries.Clear(); foreach (var item in items) { EntryRemoved?.Invoke(this, new UI.GenericEventArgs <UI.DataEntry>(item)); } }
private void OnEntryRemoved(IDbTransaction tx, ICommit commit, EntryRemoved @event) { var sqlParams = @event.ToDynamic(); sqlParams.Id = commit.AggregateId(); const string sql = @" DELETE FROM [dbo].[PlacementProjector.Entry] WHERE [Id] = @Id;" ; tx.Connection.Execute(sql, (object)sqlParams, tx); }
/// <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); } }
public override void Deactivation() { base.Deactivation(); foreach (RouteEntry Entry in EntryAdded.Values) { Entry.Remove(); } foreach (RouteEntry Entry in EntryRemoved.Values) { Entry.Add(); Engine.Instance.Logs.Log(LogType.Verbose, MessagesFormatter.Format(Messages.NetworkLockRouteRestored, Entry.ToString())); } DefaultGateway = ""; DefaultInterface = ""; EntryAdded.Clear(); EntryRemoved.Clear(); }
/// <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)); }
public override void Activation() { base.Activation(); List <RouteEntry> EntryList = Platform.Instance.RouteList(); DefaultGateway = ""; DefaultInterface = ""; EntryRemoved.Clear(); EntryAdded.Clear(); foreach (RouteEntry Entry in EntryList) { if (IsIP(Entry.Gateway)) { if (DefaultGateway.Valid == false) { DefaultGateway = Entry.Gateway; DefaultInterface = Entry.Interface; } else if (DefaultGateway != Entry.Gateway) { Failed = true; break; } } } if (DefaultGateway.Valid == false) { Failed = true; } if (Failed) { DefaultGateway = ""; DefaultInterface = ""; foreach (RouteEntry Entry in EntryList) { Engine.Instance.Logs.Log(LogType.Verbose, Entry.ToString()); } throw new Exception("error"); } /* * foreach (RouteEntry Entry in EntryList) * { * if (IsIP(Entry.Gateway)) * { * EntryRemoved[Entry.Key] = Entry; * Engine.Instance.Logs.Log(LogType.Verbose, Messages.Format(Messages.NetworkLockRouteRemoved, Entry.ToString())); * Entry.Remove(); * } * } */ IpAddress destinationHole = DefaultGateway; string interfaceHole = "1"; int routesHoleN = 4; for (int i = 0; i < routesHoleN; i++) { string maskHole = "192.0.0.0"; string ipHole = Conversions.ToString((256 / routesHoleN * i)) + ".0.0.0"; RouteAdd(ipHole, maskHole, destinationHole, interfaceHole); } }
void Apply(EntryRemoved @event) { _isRemoved = true; }