/// <summary>
 /// Removes an item from the queue provided the lock has not timed out
 /// </summary>
 /// <param name="queueName"></param>
 /// <param name="queueModel"></param>
 /// <returns></returns>
 public bool DeleteItem(string queueName, Model.Queue.QueueModel queueModel)
 {
     if (queueModel.LockExpirationInUTC < DateTime.UtcNow)
     {
         AzureQueueHelper azureQueueHelper = new AzureQueueHelper();
         azureQueueHelper.DeleteQueueItem(queueName, queueModel.Id, queueModel.PopReceipt);
         return(true);
     }
     else
     {
         return(false);
     }
 }
Esempio n. 2
0
        public void CustomerQueue()
        {
            Model.Customer.CustomerModel customerModel = this.CreateCustomerModel();
            Common.JSON.JSONService      jsonService   = new Common.JSON.JSONService();
            string json = jsonService.Serialize <Model.Customer.CustomerModel>(customerModel);

            Interface.Repository.IQueueRepository queueRepository = DI.Container.Resolve <Interface.Repository.IQueueRepository>();
            queueRepository.Enqueue("customer", json); // Typically you would just put an id in the queue since they have size limits on their payload

            Model.Queue.QueueModel queueModel = new Model.Queue.QueueModel();
            queueModel = queueRepository.Dequeue("customer", TimeSpan.FromMinutes(1));
            Model.Customer.CustomerModel loadedModel = jsonService.Deserialize <Model.Customer.CustomerModel>(queueModel.Item);
            Assert.AreEqual(loadedModel.CustomerName, customerModel.CustomerName);
            queueRepository.DeleteItem("customer", queueModel);
        } // CustomerEntityFramework
        /// <summary>
        /// Grabs an item from the queue locking it for a specified timespan (you need to call DeleteItem to remove
        /// it from the queue)
        /// </summary>
        /// <param name="queueName"></param>
        /// <param name="timeSpan"></param>
        /// <returns></returns>
        public Model.Queue.QueueModel Dequeue(string queueName, TimeSpan timeSpan)
        {
            AzureQueueHelper azureQueueHelper = new AzureQueueHelper();
            DateTime         expirationDate   = DateTime.UtcNow.Add(timeSpan);

            Microsoft.WindowsAzure.Storage.Queue.CloudQueueMessage item = azureQueueHelper.GetQueueItem(queueName.ToLower());
            if (item == null)
            {
                return(null);
            }
            else
            {
                Model.Queue.QueueModel queueModel = new Model.Queue.QueueModel();
                queueModel.Id                  = item.Id;
                queueModel.PopReceipt          = item.PopReceipt;
                queueModel.Item                = item.AsString;
                queueModel.LockExpirationInUTC = expirationDate;

                return(queueModel);
            }
        }