Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="height"></param>
        /// <param name="block"></param>
        /// <returns>false if we have more than UnprocessedBlockBuffer.Capacity blocks in memory already</returns>
        public bool TryAddOrReplace(Height height, Block block)
        {
            if (_blocks.Count > Capacity)
            {
                return(false);
            }

            _blocks.AddOrReplace(height, block);

            if (_blocks.Count == 1)
            {
                OnHaveBlocks();
            }
            return(true);
        }
Exemplo n.º 2
0
        public void ConcurrentObservableDictionaryTest()
        {
            ConcurrentObservableDictionary <int, string> dict = new ConcurrentObservableDictionary <int, string>();
            var times = 0;

            dict.CollectionChanged += delegate
            {
                times++;
            };

            dict.Add(1, "foo");
            dict.Add(2, "moo");
            dict.Add(3, "boo");

            dict.AddOrReplace(1, "boo");
            dict.Remove(dict.First(x => x.Value == "moo"));

            Assert.True(dict.Values.All(x => x == "boo"));
            Assert.Equal(5, times);
        }
Exemplo n.º 3
0
        public void ConcurrentObservableDictionaryTest()
        {
            ConcurrentObservableDictionary <int, string> dict = new ConcurrentObservableDictionary <int, string>();

            _times = 0;
            dict.CollectionChanged += Dict_CollectionChanged;

            try
            {
                dict.Add(1, "foo");
                dict.Add(2, "moo");
                dict.Add(3, "boo");

                dict.AddOrReplace(1, "boo");
                dict.Remove(dict.First(x => x.Value == "moo"));

                Assert.DoesNotContain(dict.Values, x => x != "boo");
                Assert.Equal(5, _times);
            }
            finally
            {
                dict.CollectionChanged -= Dict_CollectionChanged;
            }
        }