コード例 #1
0
ファイル: DiskCache.cs プロジェクト: ninlilizi/Socks5
        /// <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);
        }
コード例 #2
0
        public void RemoveAt(int index)
        {
            var item = entries[index];

            entries.RemoveAt(index);
            EntryRemoved?.Invoke(this, new UI.GenericEventArgs <UI.DataEntry>(item));
        }
コード例 #3
0
ファイル: RemoteFileSystem.cs プロジェクト: 5l1v3r1/Maze-1
        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 _);
                }
            }
        }
コード例 #4
0
 public bool Remove(DataEntry item)
 {
     if (entries.Remove(item))
     {
         EntryRemoved?.Invoke(this, new UI.GenericEventArgs <UI.DataEntry>(item));
         return(true);
     }
     return(false);
 }
コード例 #5
0
        public void RemoveEntry(int index)
        {
            CheckBounds(index);

            IComponent oldValue = storage[index];

            storage[index] = null;
            EntryRemoved?.Invoke(this, new StorageEntryEventArgs(index, oldValue));
        }
コード例 #6
0
        public void Clear()
        {
            var items = entries.ToArray();

            entries.Clear();
            foreach (var item in items)
            {
                EntryRemoved?.Invoke(this, new UI.GenericEventArgs <UI.DataEntry>(item));
            }
        }
コード例 #7
0
        /// <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);
        }
コード例 #8
0
        /// <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));
            }
        }
コード例 #9
0
        /// <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);
        }
コード例 #10
0
ファイル: DiskCache.cs プロジェクト: ninlilizi/Socks5
        /// <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();
        }
コード例 #11
0
 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));
         }
     }
 }
コード例 #12
0
ファイル: DiskCache.cs プロジェクト: sjp/DiskCache
        /// <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);
            }
        }
コード例 #13
0
ファイル: DiskCache.cs プロジェクト: ninlilizi/Socks5
        /// <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);
                }
            }
        }
コード例 #14
0
ファイル: DiskCache.cs プロジェクト: ninlilizi/Socks5
        /// <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();
        }
コード例 #15
0
ファイル: DiskCache.cs プロジェクト: sjp/DiskCache
        /// <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();
        }
コード例 #16
0
 protected virtual void OnEntryRemoved(bool evicted, string key, TValue value)
 {
     EntryRemoved?.Invoke(this, new EntryRemovedEventArgs <TValue>(key, value, evicted));
 }