Ejemplo n.º 1
0
        void AddEventimpl(IReadOnlyCollection <VoidTrader> newItems)
        {
            var traderVMs = newItems.Select(trader => new VoidTradeViewModel(trader, FiltersEvent));
            var itemVMs   = newItems.Where(trader => trader.Manifest != null)
                            .SelectMany(trader => trader.Manifest.Select(m => new VoidItemViewModel(m, FiltersEvent)));

            items.AddRange(itemVMs);
            traders.AddRange(traderVMs);
        }
Ejemplo n.º 2
0
 protected virtual void AddEventImpl(IReadOnlyCollection <ItemModel> newItems)
 {
     LogAdded(newItems);
     items.AddRange(newItems.Select(item => CreateItem(item, FiltersEvent)));
 }
Ejemplo n.º 3
0
        void OnCollectionChanged <ItemVM>(
            NotifyCollectionChangedEventArgs e,
            ObservableCollection <ItemVM> allItems,
            Func <ItemVM, bool> filter,
            Func <ItemVM, UserNotification> createNotification)
        {
            if (e.Action == NotifyCollectionChangedAction.Move)
            {
                return;
            }

            IEnumerable <ItemVM> removedItems;

            if (e.Action == NotifyCollectionChangedAction.Reset)
            {
                removedItems = sourceToNotificationMapping.Keys.OfType <ItemVM>();
            }
            else
            {
                removedItems = e.OldItems?.Cast <ItemVM>();
            }

            if (removedItems != null)
            {
                RemoveAllItems(removedItems);
            }

            IEnumerable <ItemVM> addedItems;

            if (e.Action == NotifyCollectionChangedAction.Reset)
            {
                addedItems = allItems;
            }
            else
            {
                addedItems = e.NewItems?.Cast <ItemVM>();
            }

            var actuallyAdded = new List <ItemVM>();

            if (addedItems != null)
            {
                Tools.Logging.Send(LogLevel.Info, $"Управление нотификациями: добавляю группу");
                var notificationsToAdd = new List <UserNotification>();
                foreach (var i in addedItems)
                {
                    if (!filter(i))
                    {
                        continue;
                    }
                    if (sourceToNotificationMapping.ContainsKey(i))
                    {
                        continue;
                    }
                    actuallyAdded.Add(i);
                    var notification = createNotification(i);
                    sourceToNotificationMapping.Add(i, notification);
                    Tools.Logging.Send(LogLevel.Info, $"Управление нотификациями: добавляю нотификацию \"{notification}\"!");
                    notificationsToAdd.Add(notification);
                }
                Tools.Logging.Send(LogLevel.Info, $"Управление нотификациями: группа добавлена");
                if (notificationsToAdd.Count > 0)
                {
                    notifications.AddRange(notificationsToAdd);
                }
            }

            if (actuallyAdded.Count > 0)
            {
                RemoveLater(actuallyAdded);
            }
        }