Example #1
0
 private void InternalEnqueue(ExecutionThread task)
 {
     _empty.Reset();
     Empty?.Invoke(false);
     _queuedTasks.Enqueue(task);
     PromoteTasks();
 }
Example #2
0
 /// <summary>
 /// Draws a card, removing it from the talon. The trump will be drawn when there are no cards remaining in the deck.
 /// </summary>
 /// <returns>The drawn card.</returns>
 /// <exception cref="InvalidOperationException">The talon is empty.</exception>
 public Card Draw()
 {
     // If there are any cards in the deck, draw one.
     if (deck.Size > 0)
     {
         return(deck.Draw());
     }
     // If the deck is empty...
     else
     {
         // ...but the trump card remains, "draw" that.
         if (!IsEmpty)
         {
             IsEmpty = true;
             // Fire an event signaling that the final card was drawn.
             Empty?.Invoke(this, new GameLogEventArgs("The last card has been drawn from the talon. The talon is now empty."));
             return(Trump);
         }
         // If the trump card is gone too, this deck shouldn't be drawn from.
         else
         {
             throw new InvalidOperationException("Cannot draw from empty talon.");
         }
     }
 }
        public void RemoveLast()
        {
            Node <T> current  = head;
            Node <T> previous = null;

            if (IsEmpty)
            {
                throw new NullReferenceException();
            }

            do
            {
                if (current == tail)
                {
                    previous.Next = current.Next;
                    tail          = previous;
                    count--;
                    if (tail == null)
                    {
                        Empty?.Invoke();
                    }
                }
                previous = current;
                current  = current.Next;
            } while (current != head);
            DeleteEvent?.Invoke(this, current.Data);
        }
 public void Clear()
 {
     head  = null;
     tail  = null;
     count = 0;
     Empty?.Invoke();
 }
Example #5
0
        public bool CheckIfCanShoot()
        {
            bool b = CurrentBulletCount.Value < AmmoPerShot.Value;

            if (b)
            {
                Empty?.Invoke();
            }
            return(b);
        }
Example #6
0
        public bool TryRemove(TKey key, out TValue value)
        {
            if (!Dictionary.TryRemove(key, out value))
            {
                return(false);
            }
            if (Dictionary.IsEmpty)
            {
                Empty?.Invoke(this, _emptyEventArgs);
            }

            return(true);
        }
Example #7
0
        /// <summary>
        /// Clear the undo history.
        /// WARNING: does not drop the current batch, XXX which seems like an error.
        /// </summary>
        public void ClearUndoHistory()
        {
            // remember if we actually had entries before
            bool nonEmptyBefore = _undoEvents.Any();

            // clear the stack
            _undoEvents.Clear();

            // fire event if this was a change
            if (nonEmptyBefore)
            {
                Empty?.Invoke(this, EventArgs.Empty);
            }
        }
Example #8
0
        private void InternalUnregister(ExecutionThread task)
        {
            _activeTasks.Remove(task);

            if (null != task.Error)
            {
                _errors.Add(task.Error);
            }

            PromoteTasks();

            if (!_queuedTasks.Concat(_activeTasks).Any())
            {
                _empty.Set();
                Empty?.Invoke(true);
            }
        }
Example #9
0
        /// <summary>
        /// Rollback the last command.
        /// </summary>
        public void Undo()
        {
            if (!CanUndo)
            {
                return;
            }

            Working = true;
            IUndoItem undo     = _undoEvents.Pop();
            bool      nowEmpty = !_undoEvents.Any();

            undo.Undo();
            _redoEvents.Push(undo);
            Working = false;

            if (nowEmpty)
            {
                Empty?.Invoke(this, EventArgs.Empty);
            }
        }
Example #10
0
        /// <summary>
        /// roll back everything in the currently open batch, not redoable
        /// </summary>
        public void UndoBatch()
        {
            Working = true;
            bool nonEmptyBefore = (_batch?.Count ?? 0) > 0 || _undoEvents.Any();

            try
            {
                _batch?.Undo();
            }
            finally
            {
                bool nowEmpty = !_undoEvents.Any();
                Working = false;
                _batch  = null;
                if (nonEmptyBefore && nowEmpty)
                {
                    Empty?.Invoke(this, EventArgs.Empty);
                }
            }
        }
Example #11
0
 //[STAThread]
 private void Run()
 {
     while (isRun)
     {
         try
         {
             int count = recycle.Items().Count;
             if (count != 0)
             {
                 NotEmpty?.Invoke();
             }
             else
             {
                 Empty?.Invoke();
             }
         }
         catch (Exception ex)
         {
             //MessageBox.Show(ex.Message);
         }
         Thread.Sleep(10);
     }
 }
        public void RemoveFirst()
        {
            Node <T> current = head;

            if (IsEmpty)
            {
                throw new NullReferenceException();
            }

            if (count == 1)
            {
                head = tail = null;
                Empty?.Invoke();
                count = 0;
            }
            else
            {
                head      = current.Next;
                tail.Next = current.Next;
                count--;
            }
            DeleteEvent?.Invoke(this, current.Data);
        }
Example #13
0
 protected virtual void OnEmpty()
 {
     Empty?.Invoke(this, EventArgs.Empty);
 }
Example #14
0
 private void OnEmpty() => Empty?.Invoke(this, new MachineEventArg {
     Message = $"Out of {Content}"
 });