Exemplo n.º 1
0
 private void InvokeChanged(OptionsItemChangedEventArgs <TKey, TOptionsItem> args)
 {
     if (OnItemChange != null)
     {
         OnItemChange?.Invoke(args);
     }
 }
Exemplo n.º 2
0
        private void OnChanged(TOptions newInstance)
        {
            _logger.LogInformation("Change detected for options, diffing items.");

            // calculate which items are new, modified, or removed since last time.

            // We should lock in case this fires concurrently on differetn threads and a key gets added?
            foreach (var itemsEnumerable in _itemAccessors)
            {
                var changes = _differ.GetChanges(_instance, newInstance, itemsEnumerable.GetItems).ToList();
                if (!changes.Any())
                {
                    continue;
                }

                var changeDictionary = new Dictionary <ItemChangeType, List <TOptionsItem> >();
                var adds             = new List <TOptionsItem>();
                var updates          = new List <TOptionsItem>();
                var deletes          = new List <TOptionsItem>();

                changeDictionary.Add(ItemChangeType.Added, adds);
                changeDictionary.Add(ItemChangeType.Modified, updates);
                changeDictionary.Add(ItemChangeType.Removed, deletes);

                foreach (var item in changes)
                {
                    switch (item.Item2)
                    {
                    case ItemChangeType.Added:
                        adds.Add(item.Item1);
                        continue;

                    case ItemChangeType.Modified:
                        updates.Add(item.Item1);
                        continue;

                    case ItemChangeType.Removed:
                        deletes.Add(item.Item1);
                        continue;
                    }
                }

                var args = new OptionsItemChangedEventArgs <TKey, TOptionsItem>()
                {
                    MemberName = itemsEnumerable.MemberName,
                    Changes    = changeDictionary
                };

                InvokeChanged(args);
            }
            _instance = newInstance;
        }
Exemplo n.º 3
0
 public void OnItemChange(OptionsItemChangedEventArgs <TKey, TOptionsItem> args) => _listener.Invoke(args);