Пример #1
0
        private OutgoingMessage HandleCountEnumerate(IncomingMessage requestMessage, EnumerationContextKey contextKey, EnumerateRequest request, EnumerationContext context)
        {
            var responseMessage = CreateEnumerateResponse();
            int count           = GetHandler(request.Filter)
                                  .EstimateRemainingItemsCount(context, requestMessage, responseMessage);

            responseMessage.AddHeader(new TotalItemsCountEstimateHeader(count), false);
            responseMessage.SetBody(new SerializerBodyWriter(new EnumerateResponse
            {
                EnumerationContext = contextKey
            }));
            return(responseMessage);
        }
        public static PullResponse PullNextBatch(this IMessageBuilder messageBuilder, EnumerationContextKey context, int maxElements, out IMessageBuilder nextMessageBuilder)
        {
            var responseMessage = messageBuilder
                .WithAction(Constants.PullAction)               
                .AddBody(new PullRequest
                             {
                                 EnumerationContext = context,
                                 MaxElements = new MaxElements(maxElements)
                             })
                .SendAndGetResponse(out nextMessageBuilder);

            return responseMessage.GetPayload<PullResponse>();
        }
Пример #3
0
        private OutgoingMessage HandleNormalEnumerate(IncomingMessage requestMessage, EnumerationContextKey contextKey, EnumerateRequest request, EnumerationContext context)
        {
            var responseMessage = CreateEnumerateResponse();
            var enumerator = GetEnumerator(request, requestMessage, context, responseMessage);

            OnEnumerationStarted(context.Context, enumerator, request.EnumerationMode);

            responseMessage.SetBody(
                new SerializerBodyWriter(new EnumerateResponse
                                             {
                                                 EnumerationContext = contextKey,
                                                 Expires = request.Expires
                                             }));
            return responseMessage;
        }
Пример #4
0
        private OutgoingMessage Enumerate(IncomingMessage requestMessage)
        {
            var request    = requestMessage.GetPayload <EnumerateRequest>();
            var contextKey = EnumerationContextKey.Unique();
            var filter     = CreateFilterInstance(request.Filter);
            var context    = new EnumerationContext(contextKey.Text, filter);

            if (IsCountRequest(requestMessage))
            {
                return(HandleCountEnumerate(requestMessage, contextKey, request, context));
            }
            if (request.OptimizeEnumeration != null)
            {
                return(HandleOptimizedEnumerate(requestMessage, contextKey, request, context));
            }
            return(HandleNormalEnumerate(requestMessage, contextKey, request, context));
        }
Пример #5
0
        private OutgoingMessage HandleNormalEnumerate(IncomingMessage requestMessage, EnumerationContextKey contextKey, EnumerateRequest request, EnumerationContext context)
        {
            var responseMessage = CreateEnumerateResponse();
            var enumerator      = GetEnumerator(request, requestMessage, context, responseMessage);

            OnEnumerationStarted(context.Context, enumerator, request.EnumerationMode);

            responseMessage.SetBody(
                new SerializerBodyWriter(new EnumerateResponse
            {
                EnumerationContext = contextKey,
                Expires            = request.Expires
            }));
            return(responseMessage);
        }
Пример #6
0
        private OutgoingMessage HandleOptimizedEnumerate(IncomingMessage requestMessage, EnumerationContextKey contextKey, EnumerateRequest request, EnumerationContext context)
        {
            var responseMessage = CreateEnumerateResponse();
            var maxElements     = CalculateMaxElements(request.MaxElements);

            if (request.EnumerationMode == EnumerationMode.EnumerateEPR)
            {
                var  enumerator = GetEnumerator(request, requestMessage, context, responseMessage);
                bool endOfSequence;
                var  items = enumerator.Take(maxElements, out endOfSequence);
                if (!endOfSequence)
                {
                    OnEnumerationStarted(context.Context, enumerator, request.EnumerationMode);
                }
                responseMessage.SetBody(new SerializerBodyWriter(
                                            new EnumerateResponse
                {
                    Items              = new EnumerationItemList(items, request.EnumerationMode),
                    EndOfSequence      = endOfSequence ? new EndOfSequence() : null,
                    EnumerationContext = endOfSequence ? null : contextKey
                }));
                return(responseMessage);
            }
            throw new NotSupportedException();
        }
Пример #7
0
 private OutgoingMessage HandleOptimizedEnumerate(IncomingMessage requestMessage, EnumerationContextKey contextKey, EnumerateRequest request, EnumerationContext context)
 {
     var responseMessage = CreateEnumerateResponse();
     var maxElements = CalculateMaxElements(request.MaxElements);
     if (request.EnumerationMode == EnumerationMode.EnumerateEPR)
     {
         var enumerator = GetEnumerator(request, requestMessage, context, responseMessage);
         bool endOfSequence;
         var items = enumerator.Take(maxElements, out endOfSequence);
         if (!endOfSequence)
         {
             OnEnumerationStarted(context.Context, enumerator, request.EnumerationMode);
         }
         responseMessage.SetBody(new SerializerBodyWriter(
                              new EnumerateResponse
                                  {
                                      Items = new EnumerationItemList(items, request.EnumerationMode),
                                      EndOfSequence = endOfSequence ? new EndOfSequence() : null,
                                      EnumerationContext = endOfSequence ? null : contextKey
                                  }));
         return responseMessage;
     }
     throw new NotSupportedException();
 }                     
Пример #8
0
        private OutgoingMessage HandleCountEnumerate(IncomingMessage requestMessage, EnumerationContextKey contextKey, EnumerateRequest request, EnumerationContext context)
        {
            var responseMessage = CreateEnumerateResponse();
            int count = GetHandler(request.Filter)
                .EstimateRemainingItemsCount(context, requestMessage, responseMessage);

            responseMessage.AddHeader(new TotalItemsCountEstimateHeader(count), false);
            responseMessage.SetBody(new SerializerBodyWriter(new EnumerateResponse
                                                          {
                                                              EnumerationContext = contextKey
                                                          }));
            return responseMessage;
        }
        public static PullResponse PullNextBatch(this IMessageBuilder messageBuilder, EnumerationContextKey context, int maxElements, out IMessageBuilder nextMessageBuilder)
        {
            var responseMessage = messageBuilder
                                  .WithAction(Constants.PullAction)
                                  .AddBody(new PullRequest
            {
                EnumerationContext = context,
                MaxElements        = new MaxElements(maxElements)
            })
                                  .SendAndGetResponse(out nextMessageBuilder);

            return(responseMessage.GetPayload <PullResponse>());
        }