Beispiel #1
0
 public override void WriteLine()
 {
     if (!IsCapturing)
     {
         return;
     }
     _capturedContent.AppendLine();
     OnContentUpdated?.Invoke(null, new EventArgs());
 }
Beispiel #2
0
 public static void Clear()
 {
     if (_capturedContent.Length == 0)
     {
         return;
     }
     _capturedContent.Clear();
     OnContentUpdated?.Invoke(null, new EventArgs());
 }
Beispiel #3
0
        public bool AddContent(IItem item, byte index)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            // Validate that the item being added is not a parent of this item.
            if (IsChildOf(item))
            {
                return(false);
            }

            try
            {
                var existingItem = Content[Content.Count - index - 1];

                if (existingItem != null)
                {
                    var joinResult = existingItem.Join(item);

                    OnContentUpdated?.Invoke(this, index, existingItem);

                    if (joinResult)
                    {
                        return(true);
                    }

                    // attempt to add to the parent of this item.
                    if (existingItem.Parent != null && existingItem.Parent.Join(item))
                    {
                        return(true);
                    }
                }
            }
            catch
            {
                // ignored
            }

            return(Join(item));
        }
Beispiel #4
0
        public bool RemoveContent(ushort itemId, byte index, byte count, out IItem splitItem)
        {
            splitItem = null;

            // see if item at index is cummulative, and if it is the same type we're adding.
            IItem existingItem = null;

            try
            {
                existingItem = Content[Content.Count - index - 1];
            }
            catch
            {
                // ignored
            }

            if (existingItem == null || existingItem.Type.TypeId != itemId || existingItem.Count < count)
            {
                return(false);
            }

            var separateResult = existingItem.Separate(count, out splitItem);

            if (separateResult)
            {
                if (existingItem.Amount == 0)
                {
                    existingItem.SetAmount(count); // restore the "removed" count, since we removed "all" of the item.

                    existingItem.SetParent(null);
                    Content.RemoveAt(Content.Count - index - 1);
                    OnContentRemoved?.Invoke(this, index);
                }
                else
                {
                    OnContentUpdated?.Invoke(this, index, existingItem);
                }
            }

            return(separateResult);
        }