protected virtual void OnSuccessfulDocumentHeaderResponseContentMaterializer(HttpResponseMessage response, DocumentHeaderResponse result)
        {
            if (response.RequestMessage.Method == HttpMethod.Head)
            {
                AssignMissingIdFromRequestUri(response, result);
                AssignMissingRevFromRequestHeaders(response, result);

                return;
            }

            using (var content = response.Content.ReadAsStream())
                ResponseMaterializer.PopulateDocumentHeaderResponse(result, content);
        }
Example #2
0
        protected virtual void OnSuccessfulDocumentResponseContentMaterializer(HttpResponseMessage response, DocumentResponse result)
        {
            using (var content = response.Content.ReadAsStream())
            {
                if (ContentShouldHaveIdAndRev(response.RequestMessage))
                {
                    ResponseMaterializer.PopulateDocumentHeaderResponse(result, content);
                }
                else
                {
                    AssignMissingIdFromRequestUri(response, result);
                    AssignMissingRevFromRequestHeaders(response, result);
                }

                content.Position = 0;
                using (var reader = new StreamReader(content, MyCouchRuntime.DefaultEncoding))
                {
                    result.Content = reader.ReadToEnd();
                }
            }
        }
Example #3
0
        protected virtual void OnSuccessfulEntityResponseContentMaterializer <T>(HttpResponseMessage response, EntityResponse <T> result) where T : class
        {
            using (var content = response.Content.ReadAsStream())
            {
                if (ContentShouldHaveIdAndRev(response.RequestMessage))
                {
                    ResponseMaterializer.PopulateDocumentHeaderResponse(result, content);
                }
                else
                {
                    AssignMissingIdFromRequestUri(response, result);
                    AssignMissingRevFromRequestHeaders(response, result);
                }

                if (result.RequestMethod == HttpMethod.Get)
                {
                    content.Position = 0;
                    result.Entity    = Serializer.Deserialize <T>(content);
                }
            }
        }
Example #4
0
        protected virtual async Task <TResponse> MaterializeAsync <TResponse>(
            HttpResponseMessage httpResponse,
            ResponseMaterializer <TResponse> sucessfulResponseMaterializer = null,
            ResponseMaterializer <TResponse> failedResponseMaterializer    = null) where TResponse : Response, new()
        {
            var response = new TResponse();

            await BasicResponseMaterializer.MaterializeAsync(response, httpResponse).ForAwait();

            if (response.IsSuccess && sucessfulResponseMaterializer != null)
            {
                await sucessfulResponseMaterializer(response, httpResponse).ForAwait();

                return(response);
            }

            if (!response.IsSuccess && failedResponseMaterializer != null)
            {
                await failedResponseMaterializer(response, httpResponse).ForAwait();
            }

            return(response);
        }
Example #5
0
 protected virtual void OnSuccessfulViewQueryResponseContentMaterializer <T>(HttpResponseMessage response, ViewQueryResponse <T> result) where T : class
 {
     using (var content = response.Content.ReadAsStream())
         ResponseMaterializer.PopulateViewQueryResponse(result, content);
 }
Example #6
0
 protected virtual void OnSuccessfulBulkResponseContentMaterializer(HttpResponseMessage response, BulkResponse result)
 {
     using (var content = response.Content.ReadAsStream())
         ResponseMaterializer.PopulateBulkResponse(result, content);
 }