예제 #1
0
        private void InternalAddRange(IActionItem[] items)
        {
            lock (lockObject)
            {
                // stack pre-cleanup
                UnsafeDisbranchedCleanup();

                // add items
                foreach (var item in items)
                    actionItems.Add(item);

                // post-cleanup
                IActionItem[] discarded = null;
                if (capacity >= 0 && actionItems.Count > capacity)
                {
                    // stack is overloaded
                    discarded = actionItems
                        .Take(actionItems.Count - capacity)
                        .ToArray();
                    int itemsToRemove = actionItems.Count - capacity;
                    for (int i = 0; i < itemsToRemove; ++i)
                    {
                        actionItems[0].Freeze();
                        actionItems.RemoveAt(0);
                    }
                }

                ResetIndexOnTop();

                // raise event to notify of cleaned up items
                if (discarded != null)
                {
                    OnActionItemsDiscarded(new DiscardedActionItemsEventArgs<IActionItem>(
                        ActionItemDiscardType.Swallowed,
                        discarded));
                }

                // raise event to notify of added items
                var added = items;
                if (capacity >= 0 && items.Length > capacity)
                    added = items.Skip(items.Length - capacity).ToArray();

                OnActionItemsAdded(new ActionItemsEventArgs<IActionItem>(added));
            }
        }