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

            IComponent oldValue = storage[index];

            storage[index] = null;
            EntryRemoved?.Invoke(this, new StorageEntryEventArgs(index, oldValue));
        }
コード例 #8
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);
        }
コード例 #9
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));
            }
        }
コード例 #10
0
        public void Clear()
        {
            var items = entries.ToArray();

            entries.Clear();
            foreach (var item in items)
            {
                EntryRemoved?.Invoke(this, new UI.GenericEventArgs <UI.DataEntry>(item));
            }
        }
コード例 #11
0
        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);
        }
コード例 #12
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);
        }
コード例 #13
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();
        }
コード例 #14
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));
         }
     }
 }
コード例 #15
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);
            }
        }
コード例 #16
0
        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();
        }
コード例 #17
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);
                }
            }
        }
コード例 #18
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();
        }
コード例 #19
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();
        }
コード例 #20
0
 protected virtual void OnEntryRemoved(bool evicted, string key, TValue value)
 {
     EntryRemoved?.Invoke(this, new EntryRemovedEventArgs <TValue>(key, value, evicted));
 }
コード例 #21
0
        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);
            }
        }
コード例 #22
0
ファイル: EntryAggregate.cs プロジェクト: peternunn/Folium
 void Apply(EntryRemoved @event)
 {
     _isRemoved = true;
 }