Exemplo n.º 1
0
        /// <summary>
        /// Enqueues an association between the entity and the provided event and invokes the
        /// operation of the event. Removes the same association from the queue if an
        /// exception is thrown by the event.
        /// </summary>
        /// <param name="ev"></param>
        private void EventPerform(Event ev)
        {
            EntityEventInvokeQueueItem item = new EntityEventInvokeQueueItem(this, ev);

            evQueue.Enqueue(item);
            try
            {
                ev.PerformOperation();
            }
            catch (Exception e)
            {
                Queue <EntityEventInvokeQueueItem> tmpQueue = new Queue <EntityEventInvokeQueueItem>();
                while (evQueue.Count > 0)
                {
                    if (evQueue.Peek() != item)
                    {
                        tmpQueue.Enqueue(evQueue.Dequeue());
                    }
                }
                while (tmpQueue.Count > 0)
                {
                    evQueue.Enqueue(tmpQueue.Dequeue());
                }
                throw e;
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Causes an event to perform its operation and invokes all specific handlers.
 /// </summary>
 /// <param name="ev"></param>
 protected void InvokeEvent(Event ev)
 {
     if (evQueue.Count == 0)
     {
         EventPerform(ev);
         while (evQueue.Count > 0)
         {
             EntityEventInvokeQueueItem item = evQueue.Peek();
             item.Entity.NotifyEvent(item.Event);
             evQueue.Dequeue();
         }
     }
     else
     {
         EventPerform(ev);
     }
 }