public void UnregisterTicked(ITicked ticked) { lock (_tickLock) { _tickedItems.Remove(ticked); } }
public void RegisterTicked(ITicked ticked) { lock (_tickLock) { _tickedItems.AddLast(ticked); } }
public void TestExceptionHandler() { Exception raised = null; ITicked itemException = null; var queue = new TickedQueue { MaxProcessedPerUpdate = 1 }; queue.TickExceptionHandler += delegate(Exception e, ITicked t) { raised = e; itemException = t; }; var aVal = 0; var a = new TickedObject((x => aVal++), 0); var b = new TickedObject((x => { throw new NotImplementedException("HELLO WORLD!"); }), 0); queue.Add(a, true); queue.Add(b, DateTime.UtcNow.AddMilliseconds(1), true); // Verify the queue works as expected queue.Update(DateTime.UtcNow.AddSeconds(0.5f)); Assert.AreEqual(1, aVal, "Invalid aVal after the first update"); TestDelegate testDelegate = (() => queue.Update(DateTime.UtcNow.AddSeconds(1f))); Assert.DoesNotThrow(testDelegate, "Did not expect any exceptions to be thrown"); Assert.AreEqual(1, aVal, "Invalid aVal after the third update"); Assert.AreEqual("HELLO WORLD!", raised.Message); Assert.IsInstanceOf <NotImplementedException>(raised); Assert.AreSame(itemException, b); }
/// <summary> /// Add the specified ticked object to the queue, using currentTime as the time to use for the tick check. /// </summary> /// <param name='ticked'> /// The ITicked object. /// </param> /// <param name='currentTime'> /// Current time. Doesn't have to be the real time. /// </param> /// <param name='looped'> /// Sets whether the ticked item will be called once, or looped. /// </param> public void Add(ITicked ticked, DateTime currentTime, bool looped) { TickedQueueItem item = new TickedQueueItem(ticked, currentTime); item.Loop = looped; Add(item, currentTime); }
/// <summary> /// Initializes a new instance of the <see cref="TickedPriorityQueue.TickedQueueItem"/> class. /// </summary> /// <param name='ticked'> /// Object to be ticked. /// </param> /// <param name='currentTime'> /// Current time. /// </param> /// <exception cref='ArgumentNullException'> /// Is thrown when an argument passed to the constructor is invalid because it is <see langword="null" /> . /// </exception> public TickedQueueItem(ITicked ticked, DateTime currentTime) { _ticked = ticked; if (_ticked == null) throw new ArgumentNullException("Missing a valid ITicked reference"); ResetTickFromTime(currentTime); Priority = _ticked.Priority; Loop = true; }
/// <summary> /// Initializes a new instance of the <see cref="TickedPriorityQueue.TickedQueueItem"/> class. /// </summary> /// <param name='ticked'> /// Object to be ticked. /// </param> /// <param name='currentTime'> /// Current time. /// </param> /// <param name="isLooped">Indicates if this item should be looped</param> /// <exception cref='ArgumentNullException'> /// Is thrown when an argument passed to the constructor is invalid because it is <see langword="null" /> . /// </exception> public TickedQueueItem(ITicked ticked, DateTime currentTime, bool isLooped = true) { if (ticked == null) throw new ArgumentNullException("Missing a valid ITicked reference"); _ticked = ticked; ResetTickFromTime(currentTime); Priority = _ticked.Priority; Loop = isLooped; IsActive = true; }
/// <summary> /// Remove the specified ticked object from the queue. /// Will only remove the same object once, even if multiple instances exist. /// </summary> /// <param name='ticked'> /// The ITicked object to remove. /// </param> public void Remove(ITicked ticked) { foreach (var item in _queue) { if (item.ContainsTicked(ticked)) { _queue.Remove(item); break; } } }
/// <summary> /// Initializes a new instance of the <see cref="TickedPriorityQueue.TickedQueueItem"/> class. /// </summary> /// <param name='ticked'> /// Object to be ticked. /// </param> /// <param name='currentTime'> /// Current time. /// </param> /// <param name="isLooped">Indicates if this item should be looped</param> /// <exception cref='ArgumentNullException'> /// Is thrown when an argument passed to the constructor is invalid because it is <see langword="null" /> . /// </exception> public TickedQueueItem(ITicked ticked, DateTime currentTime, bool isLooped = true) { if (ticked == null) { throw new ArgumentNullException("Missing a valid ITicked reference"); } _ticked = ticked; ResetTickFromTime(currentTime); Priority = _ticked.Priority; Loop = isLooped; IsActive = true; }
/// <summary> /// Remove the specified ticked object from the queue. /// Will only remove the same object once, even if multiple instances exist. /// </summary> /// <param name='ticked'> /// The ITicked object to remove. /// </param> /// <returns>True if the item was successfully removed, false otherwise</returns> public bool Remove(ITicked ticked) { bool found = false; foreach (var item in _queue) { if (item.ContainsTicked(ticked)) { // In case the item is added to a work queue item.IsActive = false; found = _queue.Remove(item); break; } } return(found); }
void LogException(Exception e, ITicked ticked) { Debug.LogException(e, this); }
/// <summary> /// Removes an ITicked reference from the queue. /// </summary> /// <param name="ticked"> /// A <see cref="ITicked"/> reference, which will be ticked periodically based on its properties. /// </param> /// <returns>True if the item was successfully removed, false if otherwise</returns> public bool Remove(ITicked ticked) { return _queue.Remove(ticked); }
/// <summary> /// Adds an ITicked reference to the queue. /// </summary> /// <param name="ticked"> /// A <see cref="ITicked"/> reference, which will be ticked periodically based on its properties. /// </param> public void Add(ITicked ticked) { _queue.Add(ticked); }
/// <summary> /// Checks if this instance wraps the specified <see cref="TickedPriorityQueue.ITicked"/> object. /// </summary> /// <returns> /// <c>true</c> if the wrapped object is ticked, else <c>false</c>. /// </returns> /// <param name='ticked'> /// The <see cref="TickedPriorityQueue.ITicked"/> object to check. /// </param> public bool ContainsTicked(ITicked ticked) { return ticked == _ticked; }
/// <summary> /// Removes an ITicked reference from the queue. /// </summary> /// <param name="ticked"> /// A <see cref="ITicked"/> reference, which will be ticked periodically based on its properties. /// </param> /// <returns>True if the item was successfully removed, false if otherwise</returns> public bool Remove(ITicked ticked) { return(_queue.Remove(ticked)); }
/// <summary> /// Add the specified ticked object to the queue, using currentTime as the time to use for the tick check. /// </summary> /// <param name='ticked'> /// The ITicked object. /// </param> /// <param name='currentTime'> /// Current time. Doesn't have to be the real time. /// </param> public void Add(ITicked ticked, DateTime currentTime) { Add(ticked, currentTime, LoopByDefault); }
/// <summary> /// Removes an ITicked reference from the queue. /// </summary> /// <param name="ticked"> /// A <see cref="ITicked"/> reference, which will be ticked periodically based on its properties. /// </param> public void Remove(ITicked ticked) { _queue.Remove(ticked); }
/// <summary> /// Add the specified ticked object to the queue. /// </summary> /// <param name='ticked'> /// The ITicked object. /// </param> /// <param name='looped'> /// Sets whether the ticked item will be called once, or looped. /// </param> public void Add(ITicked ticked, bool looped) { Add(ticked, DateTime.UtcNow, looped); }
/// <summary> /// Initializes a new instance of the <see cref="TickedPriorityQueue.TickedQueueItem"/> class. /// </summary> /// <param name='ticked'> /// Object to be ticked. /// </param> /// <exception cref='ArgumentNullException'> /// Is thrown when an argument passed to a method is invalid because it is <see langword="null" /> . /// </exception> public TickedQueueItem(ITicked ticked) : this(ticked, DateTime.UtcNow) { }
/// <summary> /// Add the specified ticked object to the queue. /// </summary> /// <param name='ticked'> /// The ITicked object. /// </param> public void Add(ITicked ticked) { Add(ticked, DateTime.UtcNow, LoopByDefault); }
/// <summary> /// Remove the specified ticked object from the queue. /// Will only remove the same object once, even if multiple instances exist. /// </summary> /// <param name='ticked'> /// The ITicked object to remove. /// </param> /// <returns>True if the item was successfully removed, false otherwise</returns> public bool Remove(ITicked ticked) { bool found = false; foreach(var item in _queue) { if (item.ContainsTicked(ticked)) { // In case the item is added to a work queue item.IsActive = false; found = _queue.Remove(item); break; } } return found; }
/// <summary> /// Add the specified ticked object to the queue, using currentTime as the time to use for the tick check. /// </summary> /// <param name='ticked'> /// The ITicked object. /// </param> /// <param name='currentTime'> /// Current time. Doesn't have to be the real time. /// </param> /// <param name='looped'> /// Sets whether the ticked item will be called once, or looped. /// </param> public void Add(ITicked ticked, DateTime currentTime, bool looped) { var item = new TickedQueueItem(ticked, currentTime, looped); Add(item, currentTime); }
/// <summary> /// Adds an ITicked reference to the queue. /// </summary> /// <param name="ticked"> /// A <see cref="ITicked"/> reference, which will be ticked periodically based on its properties. /// </param> public void Add(ITicked ticked) { // Debug.Log (ticked.ToString()); _queue.Add(ticked); }