Exemplo n.º 1
0
        private void Folders_DictionaryChanged(object sender, DictionaryChangedEventArgs <int, ApiSubscriptionFolder> e)
        {
            if (e.Action == NotifyCollectionChangedAction.Reset || e.Action == NotifyCollectionChangedAction.Replace)
            {
                RebuildTree();
            }
            else
            {
                foreach (var oldItem in e.OldItems)
                {
                    RemoveFolder(oldItem.Value);
                }

                // Add all the folders first
                foreach (var newItem in e.NewItems)
                {
                    var vmFolder = new SubscriptionFolderViewModel(newItem.Value);
                    var tvFolder = new SortedTreeViewNode <SubscriptionItemViewModelBase, string>(vmFolder);
                    treeFolders.Add(newItem.Key, tvFolder);
                }

                // And then parent them
                foreach (var newItem in e.NewItems)
                {
                    var tvFolder = treeFolders[newItem.Key];
                    GetParentFolder(tvFolder.Data.ParentId).Children.Add(tvFolder);
                }
            }

            StateHasChanged();
        }
        public void ReplaceTest()
        {
            var initialItems = MakeTestPairs(Enumerable.Range(0, 50));
            var dictionary   = new ObservableDictionary <int, string>(initialItems);

            DictionaryChangedEventArgs <int, string> args = null;

            dictionary.DictionaryChanged += (sender, e) => args = e;

            Random random = new Random();

            for (int i = 0; i < 20; i++)
            {
                int index = random.Next(dictionary.Count);
                if (dictionary[index] == "aaaa")
                {
                    continue;
                }

                args = null;
                dictionary[index] = "aaaa";

                Assert.IsNotNull(args);
                Assert.AreEqual(NotifyCollectionChangedAction.Replace, args.Action);
                Assert.AreEqual(1, args.NewItems.Count);
                Assert.AreEqual(index, args.NewItems[0].Key);
                Assert.AreEqual("aaaa", args.NewItems[0].Value);
                Assert.AreEqual(1, args.OldItems.Count);
                Assert.AreEqual(index, args.OldItems[0].Key);
                Assert.AreEqual(index.ToString(), args.OldItems[0].Value);
                Assert.AreEqual(50, dictionary.Count);
            }
        }
        public void BeginEndBulkOperationTest()
        {
            DictionaryChangedEventArgs <int, string> args = null;

            var dictionary = new ObservableDictionary <int, string>();

            dictionary.DictionaryChanged += (sender, e) => args = e;

            dictionary.BeginBatch();
            dictionary.Add(1, "1");
            Assert.IsNull(args);
            dictionary.Add(2, "2");
            Assert.IsNull(args);
            dictionary.EndBatch();
            Assert.IsNotNull(args);

            args = null;
            dictionary.BeginBatch();
            dictionary.AddRange(MakeTestPairs(4, 5, 6));
            Assert.IsNull(args);
            dictionary.Add(10, "10");
            Assert.IsNull(args);
            dictionary.Remove(4);
            Assert.IsNull(args);
            dictionary[4] = "44";
            Assert.IsNull(args);
            dictionary[44] = "44";
            Assert.IsNull(args);
            dictionary.Clear();
            Assert.IsNull(args);
            dictionary.EndBatch();
            Assert.IsNotNull(args);
        }
        public void AddTest()
        {
            var dictionary = new ObservableDictionary <int, string>();

            DictionaryChangedEventArgs <int, string> args = null;

            dictionary.DictionaryChanged += (sender, e) => args = e;

            for (int i = 0; i < 50; i++)
            {
                args = null;
                dictionary.Add(i, i.ToString());
                Assert.IsNotNull(args);
                Assert.AreEqual(NotifyCollectionChangedAction.Add, args.Action);
                Assert.AreEqual(1, args.NewItems.Count);
                Assert.AreEqual(i, args.NewItems[0].Key);
                Assert.AreEqual(i.ToString(), args.NewItems[0].Value);
                Assert.AreEqual(0, args.OldItems.Count);
                Assert.AreEqual(i + 1, dictionary.Count);
            }

            for (int i = 50; i < 100; i++)
            {
                args          = null;
                dictionary[i] = i.ToString();
                Assert.IsNotNull(args);
                Assert.AreEqual(NotifyCollectionChangedAction.Add, args.Action);
                Assert.AreEqual(1, args.NewItems.Count);
                Assert.AreEqual(i, args.NewItems[0].Key);
                Assert.AreEqual(i.ToString(), args.NewItems[0].Value);
                Assert.AreEqual(0, args.OldItems.Count);
                Assert.AreEqual(i + 1, dictionary.Count);
            }
        }
        public void Add(object key, object value)
        {
            DictionaryChangedEventArgs changedEventArgs = new DictionaryChangedEventArgs(Change.Edit);

            Keys.Add((T1)key);
            Values.Add((T2)value);
            DictionaryChange?.Invoke(this, changedEventArgs);
        }
        public object this[object key] {
            get  {
                int index = Keys.IndexOf((T1)key);
                return(Values[index]);
            }

            set {
                DictionaryChangedEventArgs changedEventArgs = new DictionaryChangedEventArgs(Change.Edit);

                DictionaryChange?.Invoke(this, changedEventArgs);
                int index = Keys.IndexOf((T1)key);
                Values[index] = (T2)value;
            }
        }
        public void ResetTest()
        {
            var initialItems = MakeTestPairs(Enumerable.Range(0, 50));
            var dictionary   = new ObservableDictionary <int, string>(initialItems);

            DictionaryChangedEventArgs <int, string> args = null;

            dictionary.DictionaryChanged += (sender, e) => args = e;

            dictionary.Clear();
            Assert.IsNotNull(args);
            Assert.AreEqual(NotifyCollectionChangedAction.Reset, args.Action);
            Assert.AreEqual(0, args.NewItems.Count);
            Assert.AreEqual(0, args.OldItems.Count);
            Assert.AreEqual(0, dictionary.Count);
        }
        // TODO: apply armor
        private void Armor_OnDictionaryChanged(object sender, DictionaryChangedEventArgs <ArmorFactory.ArmorSlot, ItemState> e)
        {
            switch (e.EventType)
            {
            case DictionaryEventType.AddItem:

                break;

            case DictionaryEventType.ChangeItem:

                break;

            case DictionaryEventType.RemoveItem:

                break;
            }
        }
Exemplo n.º 9
0
        void _resultsDict_DictionaryChanged(object sender, DictionaryChangedEventArgs <ICollectionChangedList <Result>, string> e)
        {
            switch (e.ChangedType)
            {
            case DictionaryChangedType.Added:
                bindResultsList(e.Key, e.NewValue);
                break;

            case DictionaryChangedType.Removed:
                unBindResultsList(e.Key);
                break;

            case DictionaryChangedType.Setted:
                unBindResultsList(e.Key);
                bindResultsList(e.Key, e.NewValue);
                break;
            }
        }
Exemplo n.º 10
0
        private void Subscriptions_DictionaryChanged(object sender, DictionaryChangedEventArgs <int, ApiSubscription> e)
        {
            if (e.Action == NotifyCollectionChangedAction.Reset)
            {
                RebuildTree();
            }
            else
            {
                foreach (var oldItem in e.OldItems)
                {
                    RemoveSubscription(oldItem.Value);
                }

                foreach (var newItem in e.NewItems)
                {
                    AddSubscription(newItem.Value);
                }
            }
        }
Exemplo n.º 11
0
        private void Folders_DictionaryChanged(object sender, DictionaryChangedEventArgs <int, ApiSubscriptionFolder> e)
        {
            if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Reset)
            {
                folders.Clear();
            }

            foreach (var oldItem in e.OldItems)
            {
                var item = folders.FirstOrDefault(x => x.Id == oldItem.Key);
                if (item != null)
                {
                    folders.Remove(item);
                }
            }

            InsertFolders(e.NewItems.Select(x => x.Value));
            StateHasChanged();
        }
Exemplo n.º 12
0
        public void RemoveTest()
        {
            var initialItems = MakeTestPairs(Enumerable.Range(0, 50));
            var dictionary   = new ObservableDictionary <int, string>(initialItems);

            DictionaryChangedEventArgs <int, string> args = null;

            dictionary.DictionaryChanged += (sender, e) => args = e;

            for (int i = 0; i < 50; i++)
            {
                args = null;
                dictionary.Remove(i);
                Assert.IsNotNull(args);
                Assert.AreEqual(NotifyCollectionChangedAction.Remove, args.Action);
                Assert.AreEqual(0, args.NewItems.Count);
                Assert.AreEqual(1, args.OldItems.Count);
                Assert.AreEqual(i, args.OldItems[0].Key);
                Assert.AreEqual(i.ToString(), args.OldItems[0].Value);
                Assert.AreEqual(50 - i - 1, dictionary.Count);
            }
        }
Exemplo n.º 13
0
        public void AddRangeTest()
        {
            DictionaryChangedEventArgs <int, string> args = null;

            var dictionary = new ObservableDictionary <int, string>();

            dictionary.DictionaryChanged += (sender, e) => args = e;

            dictionary.Add(1, "1");
            Assert.IsNotNull(args);
            Assert.AreEqual(NotifyCollectionChangedAction.Add, args.Action);
            Assert.AreEqual(1, args.NewItems.Count);
            Assert.AreEqual(1, args.NewItems[0].Key);
            Assert.AreEqual("1", args.NewItems[0].Value);

            args = null;
            dictionary.AddRange(MakeTestPairs(2, 3, 4, 5));
            Assert.IsNotNull(args);
            Assert.AreEqual(NotifyCollectionChangedAction.Add, args.Action);
            Assert.AreEqual(4, args.NewItems.Count);
            Assert.AreEqual(2, args.NewItems[0].Key);
            Assert.AreEqual("2", args.NewItems[0].Value);
            Assert.AreEqual(5, args.NewItems[3].Key);
            Assert.AreEqual("5", args.NewItems[3].Value);
            Assert.AreEqual(5, dictionary.Count);

            args = null;
            dictionary.AddRange(MakeTestPairs(6, 7, 8, 9, 10, 11, 12, 13, 14, 15));
            Assert.IsNotNull(args);
            Assert.AreEqual(NotifyCollectionChangedAction.Add, args.Action);
            Assert.AreEqual(10, args.NewItems.Count);
            Assert.AreEqual(6, args.NewItems[0].Key);
            Assert.AreEqual("6", args.NewItems[0].Value);
            Assert.AreEqual(15, args.NewItems[9].Key);
            Assert.AreEqual("15", args.NewItems[9].Value);
            Assert.AreEqual(15, dictionary.Count);
        }
Exemplo n.º 14
0
 private void Armor_OnDictionaryChanged(object sender, DictionaryChangedEventArgs <ArmorFactory.ArmorSlot, ItemState> e)
 {
     RecaclculateMagicItems();
 }
Exemplo n.º 15
0
 /// <summary>
 /// Serialize User Holdings Dictionary on each change.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void _serializationOnDictionaryChanged(object sender, DictionaryChangedEventArgs <Holding, int> e)
 {
     _userHoldings.Serialize();
 }
 public void OnEventOccur(DictionaryChangedEventArgs <string, RedisValue> args)
 {
     Console.WriteLine($"Manual observer [{args.Action}] {args.Key}: {args.OldValue} -> {args.NewValue}");
 }
Exemplo n.º 17
0
        public virtual void EquipmentRemoved(object sender, DictionaryChangedEventArgs<EquipmentSlot, Armor> e)
        {
            Armor equipment = e.Value;

            if (equipment == null)
                return;

            equipment.Effects.ListAdded -= EffectAdded;
            equipment.Effects.ListRemoved -= EffectRemoved;

            foreach (Effect effect in equipment.Effects)
                Effects.Remove(effect);

            equipment.Modifiers.ListAdded -= ModifierAdded;
            equipment.Modifiers.ListRemoved -= ModifierRemoved;

            foreach (Modifier modifier in equipment.Modifiers)
                Modifiers.Remove(modifier);
        }
Exemplo n.º 18
0
 void OnTagsChanged(object sender, DictionaryChangedEventArgs <string, Tag> eventArgs)
 {
     _threadContext.InvalidateScope(this);
 }
Exemplo n.º 19
0
 public void OnEventOccur(DictionaryChangedEventArgs <string, RedisValue> args)
 {
     Occured = Key == args.Key && Value == args.NewValue;
 }
 public void OnEventOccur(DictionaryChangedEventArgs <string, double> args)
 {
     LastValue = args.NewValue;
 }