public void TestTickTimeReset() { TickedObject obj = new TickedObject(null); obj.Priority = 6; obj.TickLength = 7; var now = DateTime.UtcNow; TickedQueueItem item = new TickedQueueItem(obj, now); Assert.AreEqual(item.NextTickTime, now.AddSeconds(obj.TickLength), "Initial next tick time did not match"); var future = now.AddSeconds(3); item.ResetTickFromTime(future); Assert.AreEqual(item.NextTickTime, future.AddSeconds(obj.TickLength), "Next tick time did not match after reset"); }
/// <summary> /// Add the specified item and currentTime. /// </summary> /// <param name='item'> /// The TickedQueueItem element to add to the list. /// </param> /// <param name='currentTime'> /// Current time. Doesn't have to be the real time. /// </param> /// <remarks> /// Notice that unlike the two public methods that receive an ITicked, /// this one expects a TickedQueueItem. It was done to avoid having to /// discard a TickedQueueItem instance every time that a looped item is /// ticked and re-added to the queue. As such, it expects to already /// have been configured for if to loop or not. /// </remarks> private void Add(TickedQueueItem item, DateTime currentTime) { item.ResetTickFromTime(currentTime); int index = _queue.BinarySearch(item, new TickedQueueItemComparer()); //if the binary search doesn't find something identical, it'll return a //negative value signifying where the new item should reside, so bitflipping //that gives the new index if (index < 0) { index = ~index; } _queue.Insert(index, item); }
/// <summary> /// Add the specified item and currentTime. /// </summary> /// <param name='item'> /// The TickedQueueItem element to add to the list. /// </param> /// <param name='currentTime'> /// Current time. Doesn't have to be the real time. /// </param> /// <remarks> /// Notice that unlike the two public methods that receive an ITicked, /// this one expects a TickedQueueItem. It was done to avoid having to /// discard a TickedQueueItem instance every time that a looped item is /// ticked and re-added to the queue. As such, it expects to already /// have been configured for if to loop or not. /// </remarks> private void Add(TickedQueueItem item, DateTime currentTime) { item.ResetTickFromTime(currentTime); int index = _queue.BinarySearch(item, new TickedQueueItemComparer()); //if the binary search doesn't find something identical, it'll return a //negative value signifying where the new item should reside, so bitflipping //that gives the new index if (index < 0) index = ~index; _queue.Insert(index, item); }
/// <summary> /// Add the specified item and currentTime. /// </summary> /// <param name='item'> /// The TickedQueueItem element to add to the list. /// </param> /// <param name='currentTime'> /// Current time. Doesn't have to be the real time. /// </param> /// <remarks> /// Notice that unlike the two public methods that receive an ITicked, /// this one expects a TickedQueueItem. It was done to avoid having to /// discard a TickedQueueItem instance every time that a looped item is /// ticked and re-added to the queue. As such, it expects to already /// have been configured for if to loop or not. /// </remarks> private void Add(TickedQueueItem item, DateTime currentTime) { item.ResetTickFromTime(currentTime); _queue.Add(item); }