Example #1
0
        public bool MoveNext()
        {
            lock (this.client)
            {
                if (resultIndex < results.Count)
                {
                    this.current = results[resultIndex++];
                    return(true);
                }
                else
                {
                    ResponsePull response;
                    if (this.context == null)
                    {
                        if (resultIndex > 0)
                        {
                            // case: previous pull returned an invalid context
                            return(false);
                        }
                        RequestEnumeration request = new RequestEnumeration(filter);
                        if (attributes != null)
                        {
                            request.Selection = new List <string>();
                            request.Selection.AddRange(this.attributes);
                        }

                        Message msgRequest  = requestFactory.CreateEnumerationRequest(request);
                        Message msgResponse = client.Enumerate(msgRequest);
                        if (msgResponse.IsFault)
                        {
                            ClientHelper.HandleFault(msgResponse);
                        }

                        response           = responseFactory.CreateEnumerationResponse(msgResponse);
                        this.endOfSequence = response.EndOfSequence != null;
                    }
                    else
                    {
                        if (this.endOfSequence == true)
                        {
                            // case: previous pull returned an end of sequence flag
                            this.current = null;
                            return(false);
                        }

                        RequestPull request = new RequestPull();
                        request.EnumerationContext = this.context;

                        Message msgRequest  = requestFactory.CreatePullRequest(request);
                        Message msgResponse = client.Pull(msgRequest);
                        if (msgResponse.IsFault)
                        {
                            ClientHelper.HandleFault(msgResponse);
                        }

                        response = responseFactory.CreatePullResponse(msgResponse);
                    }

                    if (response == null)
                    {
                        return(false);
                    }

                    resultIndex        = 0;
                    this.results       = resourceFactory.CreateResource(response, false).ConvertAll <RmResource>(x => x as RmResource);
                    this.context       = response.EnumerationContext;
                    this.endOfSequence = response.IsEndOfSequence;

                    if (this.results.Count > 0)
                    {
                        this.current = results[resultIndex++];
                        return(true);
                    }
                    else
                    {
                        this.current = null;
                        return(false);
                    }
                }
            }
        }