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); }
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(); } } }
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); } } }
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); }
protected virtual void OnSuccessfulViewQueryResponseContentMaterializer <T>(HttpResponseMessage response, ViewQueryResponse <T> result) where T : class { using (var content = response.Content.ReadAsStream()) ResponseMaterializer.PopulateViewQueryResponse(result, content); }
protected virtual void OnSuccessfulBulkResponseContentMaterializer(HttpResponseMessage response, BulkResponse result) { using (var content = response.Content.ReadAsStream()) ResponseMaterializer.PopulateBulkResponse(result, content); }