/// <summary> /// Adds item to the priority queue /// </summary> /// <param name="item"> /// The item to be added. /// </param> /// <param name="autoSave"> /// The auto Save. /// </param> /// <returns> /// The item added. /// </returns> public QueueItem Add(QueueItem item, bool autoSave = true) { Contract.Requires(item.Processing == false, "Cannot add a non-pending context"); item = this.context.QueueItems.Add(item); if (autoSave) { this.context.SaveChanges(); } return item; }
/// <summary> /// Removes an item from the priority queue /// </summary> /// <param name="item"> /// The item to be removed. /// </param> /// <returns> /// The item removed. /// </returns> public QueueItem Remove(QueueItem item) { Contract.Requires(item.Id != 0); item = this.context.QueueItems.Remove(item); this.context.SaveChanges(); return item; }
/// <summary> /// Queue an item of work to be run in the future /// </summary> /// <param name="workItemBase"> /// The work item. /// </param> /// <param name="timeToRun"> /// The time to run. /// </param> /// <returns> /// The item queued /// </returns> public override QueueItem Queue(WorkItemBase workItemBase, DateTime timeToRun) { Contract.Requires(timeToRun >= DateTime.Now); Contract.Ensures(Contract.Result<QueueItem>().Id != 0); var queueItem = new QueueItem { Processing = false, TimeToRun = timeToRun, Item = workItemBase }; using (var repository = new QueueItemRepository(this.Factory.GetContext())) { return repository.Add(queueItem); } }