Ejemplo n.º 1
0
        private static IEnumerable <EnumerationItem> PullItems(int maximum, EnumerationMode mode, IEnumerator <object> enumerator, out bool endOfSequence)
        {
            int i = 0;
            List <EnumerationItem> result = new List <EnumerationItem>();
            bool moveNext = false;

            while (i < maximum && (moveNext = enumerator.MoveNext()))
            {
                if (mode == EnumerationMode.EnumerateEPR)
                {
                    if (i == 0)
                    {
                        EnumerationModeExtension.Activate(EnumerationMode.EnumerateEPR, null);
                    }
                    result.Add(new EnumerationItem((EndpointAddress)enumerator.Current));
                }
                else
                {
                    if (i == 0)
                    {
                        EnumerationModeExtension.Activate(EnumerationMode.EnumerateObjectAndEPR,
                                                          enumerator.Current.GetType());
                    }
                    result.Add(new EnumerationItem(
                                   new EndpointAddress("http://tempuri.org"),
                                   enumerator.Current));
                }
                i++;
            }
            endOfSequence = !moveNext || i < maximum;
            return(result);
        }
Ejemplo n.º 2
0
        public int EstimateCount(Uri resourceUri, Filter filter, IEnumerable <Selector> selectors)
        {
            using (ClientContext <IWSEnumerationContract> ctx =
                       new ClientContext <IWSEnumerationContract>(_endpointUri, _binding.MessageVersion.Addressing, _proxyFactory,
                                                                  mx =>
            {
                mx.Add(new ResourceUriHeader(resourceUri.ToString()));
                mx.Add(new SelectorSetHeader(selectors));
            }))
            {
                OperationContextProxy.Current.AddHeader(new RequestTotalItemsCountEstimate());
                FilterMapExtension.Activate(_filterMap);
                EnumerationModeExtension.Activate(EnumerationMode.EnumerateEPR, null);

                ctx.Channel.Enumerate(new EnumerateRequest
                {
                    EnumerationMode     = EnumerationMode.EnumerateEPR,
                    OptimizeEnumeration = _optimize ? new OptimizeEnumeration() : null,
                    Filter = filter,
                });

                TotalItemsCountEstimate totalItemsCountEstimate =
                    OperationContextProxy.Current.FindHeader <TotalItemsCountEstimate>();
                return(totalItemsCountEstimate.Value);
            }
        }
Ejemplo n.º 3
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)
         }));
     }
 }
Ejemplo n.º 4
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;
            }
        }