public void TestClear1()
        {
            PriorityLinkedList <JobTimeoutModel> pq = this.CreateSimpleQueue();

            pq.Clear();
            Assert.Equal(0, pq.Count);
            Assert.False(pq.Contains(this.j1));
            Assert.False(pq.Contains(this.j2));
            Assert.False(pq.Contains(this.j3));
        }
        public void TestContains()
        {
            PriorityLinkedList <JobTimeoutModel> pq = this.CreateSimpleQueue();

            Assert.True(pq.Contains(this.j1));
            Assert.True(pq.Contains(this.j2));
            Assert.True(pq.Contains(this.j3));
            JobTimeoutModel j4 = new JobTimeoutModel("abc", DateTime.Now + TimeSpan.FromMinutes(15), new JobRequest());

            Assert.False(pq.Contains(j4));
        }
    public bool DispatchEvent <T>(T evt) where T : struct
    {
        Type typeFromHandle = typeof(T);

        if (!m_handlerTable.ContainsKey(typeFromHandle))
        {
            return(false);
        }
        PriorityLinkedList <EventHandlerDelegate <T> > handlerList = GetHandlerList <T>();
        bool copyOnWrite = handlerList.CopyOnWrite;

        handlerList.CopyOnWrite = true;
        LinkedListNode <ElementPriorityPair <EventHandlerDelegate <T> > > linkedListNode = handlerList.First();

        while (linkedListNode != null)
        {
            LinkedListNode <ElementPriorityPair <EventHandlerDelegate <T> > > next = linkedListNode.Next;
            EventHandlerDelegate <T> element = linkedListNode.Value.Element;
            if (element.Target != null && element.Target.Equals(null))
            {
                handlerList.Remove(linkedListNode.Value.Element);
                linkedListNode = next;
            }
            else
            {
                try
                {
                    if (handlerList.Contains(element) && element(evt))
                    {
                        handlerList.CopyOnWrite = copyOnWrite;
                        return(true);
                    }
                }
                catch (Exception ex)
                {
                    Log.LogErrorFormatted(this, "The event handler for event '{0}' threw an exception. Execution will continue but the game may be in a broken state.", typeof(T).FullName);
                    Log.LogException(this, ex);
                }
                linkedListNode = next;
            }
        }
        handlerList.CopyOnWrite = copyOnWrite;
        return(false);
    }
Esempio n. 4
0
 /// <summary>
 ///     Returns ture if this job exists in the timeout system, else false.
 /// </summary>
 /// <param name="j"></param>
 /// <returns></returns>
 public static bool JobExists(JobTimeoutModel j)
 {
     lock (Queue) {
         return(Queue.Contains(j));
     }
 }