Exemplo n.º 1
0
        private IEnumerator <IAsyncResult> ListMessagesImpl(string queueNameStart, DateTime?visibilityStart, Guid messageIdStart, int?subQueueId, bool includeInvisibleMessages, int numberOfMessages, AsyncIteratorContext <ListMessagesResult> context)
        {
            IAsyncResult asyncResult = this.StorageManager.AsyncProcessor.BeginExecute <ListMessagesResult>((TimeSpan remaining) => {
                ListMessagesResult listMessagesResults;
                using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext())
                {
                    Microsoft.WindowsAzure.DevelopmentStorage.Store.QueueContainer queueContainer = this.LoadQueueContainer(dbContext);
                    this._queue       = queueContainer;
                    queueNameStart    = (string.IsNullOrEmpty(queueNameStart) ? this._queue.QueueName : queueNameStart);
                    DateTime?nullable = visibilityStart;
                    visibilityStart   = new DateTime?((nullable.HasValue ? nullable.GetValueOrDefault() : DateTime.UtcNow));
                    IQueryable <QueueMessage> queueMessages =
                        from m in dbContext.QueueMessages
                        select m;
                    queueMessages =
                        from m in queueMessages
                        where (m.AccountName == this._queue.AccountName) && (m.QueueName == queueNameStart) && (m.ExpiryTime >= DateTime.UtcNow)
                        select m;
                    if (messageIdStart != Guid.Empty)
                    {
                        queueMessages = (!includeInvisibleMessages ?
                                         from m in queueMessages
                                         where ((DateTime?)m.VisibilityStartTime > visibilityStart) && (m.VisibilityStartTime <= DateTime.UtcNow) || ((DateTime?)m.VisibilityStartTime == visibilityStart) && (m.VisibilityStartTime <= DateTime.UtcNow) && string.Compare(m.MessageId.ToString(), messageIdStart.ToString(), true) >= 0
                                         select m :
                                         from m in queueMessages
                                         where ((DateTime?)m.VisibilityStartTime > visibilityStart) || ((DateTime?)m.VisibilityStartTime == visibilityStart) && string.Compare(m.MessageId.ToString(), messageIdStart.ToString(), true) >= 0
                                         select m);
                    }
                    else if (!includeInvisibleMessages)
                    {
                        queueMessages =
                            from m in queueMessages
                            where (DateTime?)m.VisibilityStartTime <= visibilityStart
                            select m;
                    }
                    queueMessages = (
                        from m in queueMessages
                        orderby m.VisibilityStartTime
                        select m).Take <QueueMessage>(numberOfMessages);
                    ListMessagesResult listMessagesResults1 = new ListMessagesResult();
                    List <IMessageData> messageDatas        = new List <IMessageData>();
                    int num = 1;
                    QueueMessage queueMessage = null;
                    foreach (QueueMessage queueMessage1 in queueMessages)
                    {
                        queueMessage = queueMessage1;
                        messageDatas.Add(new DbMessageData(queueMessage1, true));
                        num++;
                    }
                    if (num > numberOfMessages && queueMessage != null)
                    {
                        IQueryable <QueueMessage> queueMessages1 = (
                            from msg in dbContext.QueueMessages
                            where (msg.AccountName == queueMessage.AccountName) && (msg.QueueName == queueMessage.QueueName) && ((msg.VisibilityStartTime > queueMessage.VisibilityStartTime) || (msg.VisibilityStartTime == queueMessage.VisibilityStartTime) && string.Compare(msg.MessageId.ToString(), queueMessage.MessageId.ToString(), true) > 0)
                            orderby msg.VisibilityStartTime, msg.MessageId
                            select msg).Take <QueueMessage>(1);
                        if (queueMessages1 != null && queueMessages1.Count <QueueMessage>() > 0)
                        {
                            QueueMessage queueMessage2      = queueMessages1.First <QueueMessage>();
                            listMessagesResults1.NextMarker = SummaryResult.EncodeMarker <ListMessagesMarker>(new ListMessagesMarker(queueMessage2.QueueName, 0, new DateTime?(queueMessage2.VisibilityStartTime), queueMessage2.MessageId));
                        }
                    }
                    listMessagesResults1.Messages = messageDatas;
                    listMessagesResults           = listMessagesResults1;
                }
                return(listMessagesResults);
            }, this.Timeout, context.GetResumeCallback(), context.GetResumeState("DbQueueContainer.PeekMessage"));

            yield return(asyncResult);

            context.ResultData = this.StorageManager.AsyncProcessor.EndExecute <ListMessagesResult>(asyncResult);
        }
Exemplo n.º 2
0
        protected override IEnumerator <IAsyncResult> ListMessagesImpl(IAccountIdentifier identity, string account, string queue, string messageMarker, bool includeInvisibleMessages, bool incldueMessageTextProperty, int maxMessages, TimeSpan?timeout, RequestContext requestContext, AsyncIteratorContext <ListMessagesResult> context)
        {
            string   nextQueueStart;
            DateTime?nextVisibilityStart;
            Guid     guid;
            int?     subQueueId;
            object   obj;

            this.ValidateNumMessages(maxMessages, this.config.MaxMessagesToReturnForListMessages);
            RemainingTime remainingTime = new RemainingTime(timeout);
            SASAuthorizationParameters sASAuthorizationParameter = new SASAuthorizationParameters()
            {
                SupportedSasTypes  = SasType.ResourceSas | SasType.AccountSas,
                SignedResourceType = SasResourceType.Object,
                SignedPermission   = SASPermission.Read
            };
            SASAuthorizationParameters sASAuthorizationParameter1 = sASAuthorizationParameter;
            IAsyncResult asyncResult = this.BeginGetQueue(identity, account, queue, PermissionLevel.Read, sASAuthorizationParameter1, remainingTime, requestContext, context.GetResumeCallback(), context.GetResumeState("QueueManager.PeekMessagesImpl"));

            yield return(asyncResult);

            IQueueContainer operationStatus = this.EndGetQueue(asyncResult);

            if (requestContext != null)
            {
                operationStatus.OperationStatus = requestContext.OperationStatus;
            }
            operationStatus.Timeout = remainingTime;
            ListMessagesMarker listMessagesMarker = SummaryResult.DecodeMarker <ListMessagesMarker>(messageMarker);

            if (listMessagesMarker == null)
            {
                Logger <IRestProtocolHeadLogger> .Instance.VerboseDebug.Log("ListMessageImpl marker is null");
            }
            else
            {
                IStringDataEventStream verboseDebug = Logger <IRestProtocolHeadLogger> .Instance.VerboseDebug;
                verboseDebug.Log("ListMessageImpl marker.NextQueueStart: {0}", new object[] { listMessagesMarker.NextQueueStart });
                IStringDataEventStream stringDataEventStream = Logger <IRestProtocolHeadLogger> .Instance.VerboseDebug;
                object[] objArray = new object[] { listMessagesMarker.SubQueueId };
                stringDataEventStream.Log("ListMessageImpl marker.SubQueueId: {0}", objArray);
                IStringDataEventStream verboseDebug1 = Logger <IRestProtocolHeadLogger> .Instance.VerboseDebug;
                object[] nextMessageIdStart          = new object[] { listMessagesMarker.NextMessageIdStart };
                verboseDebug1.Log("ListMessageImpl marker.NextMessageIdStart: {0}", nextMessageIdStart);
                IStringDataEventStream stringDataEventStream1 = Logger <IRestProtocolHeadLogger> .Instance.VerboseDebug;
                object[] objArray1 = new object[1];
                object[] objArray2 = objArray1;
                obj          = (listMessagesMarker.NextVisibilityStart.HasValue ? listMessagesMarker.NextVisibilityStart.Value.ToString("mm/dd/yy hh:mm:ss.fff") : "null");
                objArray2[0] = obj;
                stringDataEventStream1.Log("ListMessageImpl marker.NextVisibilityStart: {0}", objArray1);
            }
            IQueueContainer queueContainer = operationStatus;

            if (listMessagesMarker == null)
            {
                nextQueueStart = null;
            }
            else
            {
                nextQueueStart = listMessagesMarker.NextQueueStart;
            }
            if (listMessagesMarker == null)
            {
                nextVisibilityStart = null;
            }
            else
            {
                nextVisibilityStart = listMessagesMarker.NextVisibilityStart;
            }
            guid = (listMessagesMarker == null ? Guid.Empty : listMessagesMarker.NextMessageIdStart);
            if (listMessagesMarker == null)
            {
                subQueueId = null;
            }
            else
            {
                subQueueId = listMessagesMarker.SubQueueId;
            }
            asyncResult = queueContainer.BeginListMessages(nextQueueStart, nextVisibilityStart, guid, subQueueId, includeInvisibleMessages, maxMessages, context.GetResumeCallback(), context.GetResumeState("QueueManager.PeekMessagesImpl"));
            yield return(asyncResult);

            ListMessagesResult listMessagesResults = operationStatus.EndListMessages(asyncResult);

            listMessagesResults.PoppedMessages = this.WrapGetMessageResults(listMessagesResults.Messages);
            context.ResultData = listMessagesResults;
            StringBuilder stringBuilder = new StringBuilder();
            int           num           = 0;

            foreach (PoppedMessage poppedMessage in context.ResultData.PoppedMessages)
            {
                stringBuilder.Append(string.Format("[{0}],", poppedMessage.ToString()));
                num++;
            }
            IStringDataEventStream verboseDebug2 = Logger <IRestProtocolHeadLogger> .Instance.VerboseDebug;

            object[] str = new object[] { num, stringBuilder.ToString() };
            verboseDebug2.Log("ListMessages response: Count={0} Messages={1}", str);
        }