Пример #1
0
        private EnumerateResponse HandleOptimizedEnumerate(EnumerationContextKey contextKey, EnumerateRequest request, EnumerationContext context)
        {
            int maxElements = request.MaxElements != null
                              ? request.MaxElements.Value
                              : 1;

            if (request.EnumerationMode == EnumerationMode.EnumerateEPR)
            {
                IEnumerator <object> enumerator = GetHandler(request.Filter).Enumerate(context).GetEnumerator();

                bool endOfSequence;
                EnumerationItemList items = new EnumerationItemList(PullItems(maxElements, request.EnumerationMode, enumerator, out endOfSequence));
                if (!endOfSequence)
                {
                    _activeEnumerations[contextKey] = new EnumerationState(enumerator, request.EnumerationMode);
                }
                return(new EnumerateResponse
                {
                    Items = items,
                    EndOfSequence = endOfSequence ? new EndOfSequence() : null,
                    EnumerationContext = endOfSequence ? null : contextKey
                });
            }
            throw new NotSupportedException();
        }
Пример #2
0
      private EnumerateResponse HandleOptimizedEnumerate(EnumerationContextKey contextKey, EnumerateRequest request, EnumerationContext context)
      {
         int maxElements = request.MaxElements != null 
                              ? request.MaxElements.Value 
                              : 1;

         if (request.EnumerationMode == EnumerationMode.EnumerateEPR)
         {
            IEnumerator<object> enumerator = GetHandler(request.Filter).Enumerate(context).GetEnumerator();

            bool endOfSequence;
            EnumerationItemList items = new EnumerationItemList(PullItems(maxElements, request.EnumerationMode,enumerator, out endOfSequence));
            if (!endOfSequence)
            {
               _activeEnumerations[contextKey] = new EnumerationState(enumerator, request.EnumerationMode);
            }
            return new EnumerateResponse
                      {
                         Items = items,
                         EndOfSequence = endOfSequence ? new EndOfSequence() : null,
                         EnumerationContext = endOfSequence ? null : contextKey
                      };
         }
         throw new NotSupportedException();
      }
Пример #3
0
        public EnumerateResponse Enumerate(EnumerateRequest request)
        {
            EnumerationContextKey contextKey = EnumerationContextKey.Unique();
            EnumerationContext    context    = new EnumerationContext(contextKey.Text, request.Filter, SelectorSetHeader.GetCurrent());

            if (RequestTotalItemsCountEstimate.IsPresent)
            {
                HandleCountEnumerate(contextKey.Text, request.Filter);
                return(new EnumerateResponse
                {
                    EnumerationContext = contextKey
                });
            }
            if (request.OptimizeEnumeration != null)
            {
                return(HandleOptimizedEnumerate(contextKey, request, context));
            }

            IEnumerator <object> enumerator = GetHandler(request.Filter).Enumerate(context).GetEnumerator();

            _activeEnumerations[contextKey] = new EnumerationState(enumerator, request.EnumerationMode);
            return(new EnumerateResponse
            {
                EnumerationContext = contextKey,
                Expires = request.Expires
            });
        }
Пример #4
0
 private PullResponse PullNextEPRBatch(EnumerationContextKey context, string resourceUri, int maxElements, IEnumerable <Selector> selectors)
 {
     using (ClientContext <IWSEnumerationContract> ctx =
                new ClientContext <IWSEnumerationContract>(_endpointUri, _binding.MessageVersion.Addressing, _proxyFactory,
                                                           mx =>
     {
         mx.Add(new ResourceUriHeader(resourceUri));
         mx.Add(new SelectorSetHeader(selectors));
     }))
     {
         FilterMapExtension.Activate(_filterMap);
         EnumerationModeExtension.Activate(EnumerationMode.EnumerateEPR, null);
         return(ctx.Channel.Pull(new PullRequest
         {
             EnumerationContext = context,
             MaxElements = new MaxElements(maxElements)
         }));
     }
 }
Пример #5
0
        public IEnumerable <EndpointAddress> EnumerateEPR(Uri resourceUri, Filter filter, int maxElements, IEnumerable <Selector> selectors)
        {
            EnumerateResponse response;

            using (ClientContext <IWSEnumerationContract> ctx =
                       new ClientContext <IWSEnumerationContract>(_endpointUri, _binding.MessageVersion.Addressing, _proxyFactory,
                                                                  mx =>
            {
                mx.Add(new ResourceUriHeader(resourceUri.ToString()));
                mx.Add(new SelectorSetHeader(selectors));
            }))
            {
                FilterMapExtension.Activate(_filterMap);
                EnumerationModeExtension.Activate(EnumerationMode.EnumerateEPR, null);
                response = ctx.Channel.Enumerate(new EnumerateRequest
                {
                    EnumerationMode     = EnumerationMode.EnumerateEPR,
                    OptimizeEnumeration = _optimize ? new OptimizeEnumeration() : null,
                    Filter      = filter,
                    MaxElements = new MaxElements(maxElements)
                });
            }
            if (response.Items != null)
            {
                foreach (EnumerationItem item in response.Items.Items)
                {
                    yield return(item.EprValue);
                }
            }
            EnumerationContextKey context = response.EnumerationContext;
            bool endOfSequence            = response.EndOfSequence != null;

            while (!endOfSequence)
            {
                PullResponse pullResponse = PullNextEPRBatch(context, resourceUri.ToString(), maxElements, selectors);
                foreach (EnumerationItem item in pullResponse.Items.Items)
                {
                    yield return(item.EprValue);
                }
                endOfSequence = pullResponse.EndOfSequence != null;
                context       = pullResponse.EnumerationContext;
            }
        }
Пример #6
0
        public override bool Equals(object obj)
        {
            EnumerationContextKey other = obj as EnumerationContextKey;

            return(other != null && Text.Equals(other.Text));
        }
Пример #7
0
 private PullResponse PullNextEPRBatch(EnumerationContextKey context, string resourceUri, int maxElements, IEnumerable<Selector> selectors)
 {
    using (ClientContext<IWSEnumerationContract> ctx =
       new ClientContext<IWSEnumerationContract>(_endpointUri, _binding.MessageVersion.Addressing, _proxyFactory,
          mx =>
             {
                mx.Add(new ResourceUriHeader(resourceUri));
                mx.Add(new SelectorSetHeader(selectors));
             }))
    {
       FilterMapExtension.Activate(_filterMap);
       EnumerationModeExtension.Activate(EnumerationMode.EnumerateEPR, null);
       return ctx.Channel.Pull(new PullRequest
       {
          EnumerationContext = context,               
          MaxElements = new MaxElements(maxElements)
       });
    }
 }