Exemplo n.º 1
0
 /// <summary>
 /// Gets the Count of pending items
 /// </summary>
 /// <returns>
 /// How many items are pending
 /// </returns>
 /// <exception cref="NotImplementedException">
 /// Thrown for now
 /// </exception>
 public override int CountOfPendingItems()
 {
     using (var repository = new QueueItemRepository(this.Factory.GetContext()))
     {
         return repository.Find(x => x.Processing == false).ToList().Count();
     }
 }
Exemplo n.º 2
0
        /// <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>
        /// <param name="numberOfTimes">
        /// How many times should this item be queued
        /// </param>
        public override void MassQueue(WorkItemBase workItemBase, DateTime timeToRun, int numberOfTimes)
        {
            Contract.Requires(timeToRun >= DateTime.Now);
            Contract.Requires(numberOfTimes > 0);

            using (var repository = new QueueItemRepository(this.Factory.GetContext()))
            {
                for (int i = 0; i < numberOfTimes; i++)
                {
                    repository.Add(new QueueItem { Processing = false, TimeToRun = timeToRun, Item = workItemBase }, numberOfTimes == (i + 1));
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Runs a task if one is avilable
        /// </summary>
        /// <returns>
        /// true on success false on no task available
        /// </returns>
        public override bool RunTask()
        {
            using (var repository = new QueueItemRepository(this.Factory.GetContext()))
            {
                var queueItem = repository.DequeueItem();
                if (queueItem.Id == 0)
                {
                    return false;
                }

                queueItem.Run();

                repository.Remove(queueItem);
                return true;
            }
        }
Exemplo n.º 4
0
        /// <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);
            }
        }