Ejemplo n.º 1
0
        public override async Task <IEnumerable <T> > GetAllPages <T>(string url, int limit = 50, QueryString query = null)
        {
            var result = new IteratorBasedPage <T>()
            {
                Values = new List <T>()
            };
            IRestResponse <IteratorBasedPage <T> > response = null;

            var request = new BitbucketRestRequest(url, Method.GET);
            var page    = response?.Data?.Next;

            request.AddQueryParameter("pagelen", limit.ToString());

            if (page != null)
            {
                request.AddQueryParameter("page", page);
            }

            if (query != null)
            {
                foreach (var par in query)
                {
                    request.AddQueryParameter(par.Key, par.Value);
                }
            }

            response = await this.ExecuteTaskAsync <IteratorBasedPage <T> >(request);

            if (response.Data?.Values != null)
            {
                result.Values.AddRange(response.Data.Values);
            }


            while (response.Data?.Next != null)
            {
                request  = new BitbucketRestRequest(response.Data.Next, Method.GET);
                response = await this.ExecuteTaskAsync <IteratorBasedPage <T> >(request);

                if (response.Data?.Values != null)
                {
                    result.Values.AddRange(response.Data.Values);
                }
            }

            return(result.Values);
        }
        public override async Task <IEnumerable <T> > GetAllPages <T>(string url, int limit = 50, QueryString query = null)
        {
            var result = new EnterpriseIteratorBasedPage <T>()
            {
                Values = new List <T>()
            };
            IRestResponse <EnterpriseIteratorBasedPage <T> > response;
            ulong pageNumber = 0;

            do
            {
                var request = new BitbucketRestRequest(url, Method.GET);
                request.AddQueryParameter("limit", limit.ToString()).AddQueryParameter("start", pageNumber.ToString());

                if (query != null)
                {
                    foreach (var par in query)
                    {
                        request.AddQueryParameter(par.Key, par.Value);
                    }
                }

                response = await this.ExecuteTaskAsync <EnterpriseIteratorBasedPage <T> >(request);

                if (response.Data?.Values == null)
                {
                    break;
                }

                result.Values.AddRange(response.Data.Values);

                pageNumber = response.Data.NextPageStart;
            } while (response.Data?.IsLastPage == false);

            return(result.Values);
        }
        public override async Task <IEnumerable <T> > GetAllPages <T>(string url, int limit = 50, QueryString query = null)
        {
            var result = new IteratorBasedPage <T>()
            {
                Values = new List <T>()
            };
            IRestResponse <IteratorBasedPage <T> > response;
            var pageNumber = 1;

            do
            {
                var request = new BitbucketRestRequest(url, Method.GET);
                request.AddQueryParameter("pagelen", limit.ToString()).AddQueryParameter("page", pageNumber.ToString());

                if (query != null)
                {
                    foreach (var par in query)
                    {
                        request.AddQueryParameter(par.Key, par.Value);
                    }
                }

                response = await this.ExecuteTaskAsync <IteratorBasedPage <T> >(request);

                if (response.Data?.Values == null)
                {
                    break;
                }

                result.Values.AddRange(response.Data.Values);

                pageNumber++;
            } while (response.Data?.Next != null);//todo 99% this value should be used instead of pagenumber

            return(result.Values);
        }