예제 #1
0
        public IEnumerable <T> GetPaginatedResultBlocking <T>(TrueShipGetRequestBase request, string logPrefix) where T : class
        {
            var objectAccumulator = new List <T>();
            var fistPage          = this._webRequestServices.SubmitGetBlocking <TrueShipBaseResponse <T> >(request, logPrefix);

            if (string.IsNullOrEmpty(fistPage.Next))
            {
                return(fistPage.Results);
            }

            var nextPageUri = new Uri(fistPage.Next);

            while (true)
            {
                var nextPage = this._webRequestServices.SubmitGetBlocking <TrueShipBaseResponse <T> >(nextPageUri, logPrefix);
                objectAccumulator.AddRange(nextPage.Results);
                if (HasFinishedIteratingPages(nextPage))
                {
                    break;
                }
                nextPageUri = new Uri(nextPage.Next);
            }

            return(objectAccumulator);
        }
예제 #2
0
        public async Task <IEnumerable <T> > GetPaginatedResult <T>(TrueShipGetRequestBase request, string logPrefix, CancellationToken ct) where T : class
        {
            var objectAccumulator = new List <T>();
            var firstPage         = await this._webRequestServices.SubmitGet <TrueShipBaseResponse <T> >(request, logPrefix, ct).ConfigureAwait(false);

            if (string.IsNullOrEmpty(firstPage.Next))
            {
                return(firstPage.Results);
            }
            objectAccumulator.AddRange(firstPage.Results);

            var nextPageUri = new Uri(firstPage.Next);

            while (true)
            {
                var nextPage = await this._webRequestServices.SubmitGet <TrueShipBaseResponse <T> >(nextPageUri, logPrefix, ct).ConfigureAwait(false);

                objectAccumulator.AddRange(nextPage.Results);
                if (HasFinishedIteratingPages(nextPage))
                {
                    break;
                }
                nextPageUri = new Uri(nextPage.Next);
            }

            return(objectAccumulator);
        }
예제 #3
0
        public T SubmitGetBlocking <T>(TrueShipGetRequestBase trueShipRequest, string logPrefix) where T : class
        {
            var request = trueShipRequest.ToHttpRequest();

            this._logservice.LogTrace(logPrefix, "Submitting GET request: {0}".FormatWith(request.RequestUri));

            HttpWebResponse response = null;

            ActionPolicies.Get.Do(() =>
            {
                response = ( HttpWebResponse )request.GetResponse();
            });
            var stream = response.GetResponseStream();

            this._logservice.LogTrace(logPrefix, "Got response with status {0}. {1}".FormatWith(response.StatusCode, "N/A"));
            return(JsonSerializer.DeserializeFromStream <T>(stream));
        }
예제 #4
0
        public async Task <T> SubmitGet <T>(TrueShipGetRequestBase requestModel, string logPrefix, CancellationToken ct) where T : class
        {
            var request = requestModel.ToHttpRequest();

            return(await this.ExecuteGetRequest <T>(request, logPrefix, ct));
        }