public void RemoveKeys()
        {
            var dictionary = new SynchronizedDictionary <string, string>();

            var collection = new[] {
                new KeyValuePair <string, string>("22", "33"),
                new KeyValuePair <string, string>("44", "55"),
                new KeyValuePair <string, string>("66", "77"),
            };

            dictionary.AddRange(collection);

            Assert.Equal(dictionary.Count, collection.Count());

            dictionary.RemoveKeys(collection.Select(t => t.Key));

            Assert.Equal(0, dictionary.Count());
        }
示例#2
0
        /// <summary>
        /// Loads the cached responses and redirects from files.
        /// </summary>
        /// <param name="fileName">the filename. (will be suffixed with .Responses or .Redirects)</param>
        public void LoadCacheState(string fileName)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException(nameof(fileName));
            }

            if (Responses && Responses.Count() > 0)
            {
                Logger.LogWarning($"Loading cached {nameof(WebRequestFactory)} will override {Responses.Count} responses from the cache. If you want to keep them consider using {nameof(WebRequestFactory)}.{nameof(WebRequestFactory.AppendCacheState)}.");
            }

            if (Redirects && Redirects.Count() > 0)
            {
                Logger.LogWarning($"Loading cached {nameof(WebRequestFactory)} will override {Redirects.Count} redirects from the cache. If you want to keep them consider using {nameof(WebRequestFactory)}.{nameof(WebRequestFactory.AppendCacheState)}.");
            }

            if (File.Exists(fileName + ".ooc.json"))
            {
                Responses = new SynchronizedDictionary <string, string, OutOfCoreHashmap <string, string> >(new OutOfCoreHashmap <string, string>(fileName + ".ooc.json"));
            }
            else if (File.Exists(fileName + "." + nameof(Responses)))
            {
                SynchronizedDictionary <string, string, AVLHashMap <string, string> > old = Serializer.ReadJsonData <SynchronizedDictionary <string, string, AVLHashMap <string, string> > >(fileName + "." + nameof(Responses));

                Responses = new SynchronizedDictionary <string, string, OutOfCoreHashmap <string, string> >(new OutOfCoreHashmap <string, string>(1024, fileName + ".ooc.json"));

                LamestWebserver.Core.Logger.LogInformation($"Importing {old.Count} responses for {nameof(WebRequestFactory)} from '{fileName}.{nameof(Responses)}'...");

                foreach (var kvpair in old)
                {
                    Responses[kvpair.Key] = kvpair.Value;
                }
            }
            else
            {
                Logger.LogExcept(new IOException($"File not found '{fileName}.ooc.json'."));
            }

            Redirects = Serializer.ReadJsonData <SynchronizedDictionary <string, string, AVLHashMap <string, string> > >(fileName + "." + nameof(Redirects));
        }
        public void RemoveKeys()
        {
            var dictionary = new SynchronizedDictionary<string, string>();

            var collection = new[] {
                new KeyValuePair<string, string>("22", "33"),
                new KeyValuePair<string, string>("44", "55"),
                new KeyValuePair<string, string>("66", "77"),
            };

            dictionary.AddRange(collection);

            Assert.Equal(dictionary.Count, collection.Count());

            dictionary.RemoveKeys(collection.Select(t => t.Key));

            Assert.Equal(0, dictionary.Count());
        }