protected virtual void SetMissingIdFromRequestUri(DocumentHeaderResponse response, HttpResponseMessage httpResponse)
 {
     if (string.IsNullOrWhiteSpace(response.Id) && httpResponse.RequestMessage.Method != HttpMethod.Post)
     {
         response.Id = httpResponse.RequestMessage.ExtractIdFromUri(false);
     }
 }
예제 #2
0
 protected override void PopulateMissingIdFromRequestUri(DocumentHeaderResponse response, HttpResponseMessage httpResponse)
 {
     if (string.IsNullOrWhiteSpace(response.Id))
     {
         response.Id = httpResponse.RequestMessage.GetUriSegmentByRightOffset(1);
     }
 }
        public void CreateViews()
        {
            BookOrderViews bookOrderViews = new BookOrderViews();

            using (var client = new MyCouchClient(_databaseUri, _databaseName))
            {
                var getResponse = client.Documents.GetAsync(bookOrderViews.Id).Result;

                if (getResponse.IsEmpty)
                {
                    DocumentHeaderResponse postResponse = client.Documents.PostAsync(
                        bookOrderViews.Json()).Result;

                    if (postResponse.StatusCode != HttpStatusCode.Created)
                    {
                        throw new Exception("Error creating query view");
                    }
                }
                else
                {
                    DocumentHeaderResponse putResponse = client.Documents.PutAsync(
                        bookOrderViews.Id,
                        getResponse.Rev,
                        bookOrderViews.Json()).Result;

                    if (putResponse.StatusCode != HttpStatusCode.Created)
                    {
                        throw new Exception("Error updating query");
                    }
                }
            }
        }
예제 #4
0
        public async Task <DocumentHeaderResponse> TryPut(CouchConveyEntry <T> entry, string revision)
        {
            try
            {
                DocumentHeaderResponse header = null;
                if (entry.Json == null && entry.Entity == null)
                {
                    header = await this.Client.Documents.DeleteAsync(entry.Id, revision);
                }
                else if (revision != null)
                {
                    header = await this.Client.Documents.PutAsync(entry.Id, revision, entry.Json);
                }
                else
                {
                    header = await this.Client.Documents.PutAsync(entry.Id, entry.Json);
                }

                if (header.StatusCode == System.Net.HttpStatusCode.Conflict && entry.Overwrite)
                {
                    return(null);                     // In this case, we will retry this outside so it's expected exception.
                }
                return(header);
            }
            catch (MyCouchResponseException ex)
            {
                Logger.DebugFormat("Error during put document {0}:{1} by {2}", entry.Id, revision, ex);
                if (ex.HttpStatus == System.Net.HttpStatusCode.Conflict && entry.Overwrite)
                {
                    return(null);                     // In this case, we will retry this outside so it's expected exception.
                }
                throw ex;
            }
        }
예제 #5
0
 protected virtual void PopulateMissingIdFromRequestUri(DocumentHeaderResponse response, HttpResponseMessage httpResponse)
 {
     if (string.IsNullOrWhiteSpace(response.Id) && httpResponse.RequestMessage.Method != HttpMethod.Post)
     {
         response.Id = httpResponse.RequestMessage.GetUriSegmentByRightOffset();
     }
 }
 protected virtual void SetMissingRevFromRequestHeaders(DocumentHeaderResponse response, HttpResponseMessage httpResponse)
 {
     if (string.IsNullOrWhiteSpace(response.Rev))
     {
         response.Rev = httpResponse.Headers.GetETag();
     }
 }
예제 #7
0
        public virtual void PopulateDocumentHeaderResponse(DocumentHeaderResponse response, Stream data)
        {
            var mappings = new Dictionary <string, Action <JsonTextReader> >
            {
                { "id", jr => response.Id = jr.Value.ToString() },
                { "rev", jr => response.Rev = jr.Value.ToString() }
            };

            Map(data, mappings);
        }
        public virtual async Task MaterializeAsync(DocumentHeaderResponse response, HttpResponseMessage httpResponse)
        {
            if (httpResponse.RequestMessage.Method != HttpMethod.Head)
            {
                using (var content = await httpResponse.Content.ReadAsStreamAsync().ForAwait())
                    SetDocumentHeaderFromResponseStream(response, content);
            }

            SetMissingIdFromRequestUri(response, httpResponse);
            SetMissingRevFromRequestHeaders(response, httpResponse);
        }
        public virtual async void Materialize(DocumentHeaderResponse response, HttpResponseMessage httpResponse)
        {
            if (httpResponse.RequestMessage.Method != HttpMethod.Head)
            {
                using (var content = await httpResponse.Content.ReadAsStreamAsync().ForAwait())
                    SetDocumentHeaderFromResponseStream(response, content);
            }

            SetMissingIdFromRequestUri(response, httpResponse);
            SetMissingRevFromRequestHeaders(response, httpResponse);
        }
        protected async virtual void OnSuccessfulResponse(DocumentHeaderResponse response, HttpResponseMessage httpResponse)
        {
            if (httpResponse.RequestMessage.Method == HttpMethod.Head)
            {
                PopulateMissingIdFromRequestUri(response, httpResponse);
                PopulateMissingRevFromRequestHeaders(response, httpResponse);

                return;
            }

            using (var content = await httpResponse.Content.ReadAsStreamAsync().ForAwait())
                PopulateDocumentHeaderFromResponseStream(response, content);
        }
        protected virtual void OnSuccessfulResponse(DocumentHeaderResponse response, HttpResponseMessage httpResponse)
        {
            if (httpResponse.RequestMessage.Method == HttpMethod.Head)
            {
                PopulateMissingIdFromRequestUri(response, httpResponse);
                PopulateMissingRevFromRequestHeaders(response, httpResponse);

                return;
            }

            using (var content = httpResponse.Content.ReadAsStream())
                PopulateDocumentHeaderFromResponseStream(response, content);
        }
        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 OnFailedResponse(DocumentHeaderResponse response, HttpResponseMessage httpResponse)
        {
            base.OnFailedResponse(response, httpResponse);

            PopulateMissingIdFromRequestUri(response, httpResponse);
        }
 protected override void PopulateMissingIdFromRequestUri(DocumentHeaderResponse response, HttpResponseMessage httpResponse)
 {
     if (string.IsNullOrWhiteSpace(response.Id))
         response.Id = httpResponse.RequestMessage.GetUriSegmentByRightOffset(1);
 }
        public virtual async Task MaterializeAsync(DocumentHeaderResponse response, HttpResponseMessage httpResponse)
        {
            await _failedResponseMaterializer.MaterializeAsync(response, httpResponse).ForAwait();

            SetMissingIdFromRequestUri(response, httpResponse);
        }
예제 #16
0
 protected virtual void AssignMissingIdFromRequestUri(HttpResponseMessage response, DocumentHeaderResponse result)
 {
     if (string.IsNullOrWhiteSpace(result.Id))
     {
         result.Id = response.RequestMessage.GetUriSegmentByRightOffset();
     }
 }
예제 #17
0
 public DocumentHeaderResponseAssertions(DocumentHeaderResponse response)
 {
     Response = response;
 }
예제 #18
0
 public static DocumentHeaderResponseAssertions Should(this DocumentHeaderResponse response)
 {
     return(new DocumentHeaderResponseAssertions(response));
 }
        protected virtual void OnFailedDocumentHeaderResponseContentMaterializer(HttpResponseMessage response, DocumentHeaderResponse result)
        {
            OnFailedResponseContentMaterializer(response, result);

            AssignMissingIdFromRequestUri(response, result);
        }
        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);
        }
예제 #21
0
 protected virtual void AssignMissingRevFromRequestHeaders(HttpResponseMessage response, DocumentHeaderResponse result)
 {
     if (string.IsNullOrWhiteSpace(result.Rev))
     {
         result.Rev = response.Headers.GetETag();
     }
 }
 protected virtual void SetMissingRevFromRequestHeaders(DocumentHeaderResponse response, HttpResponseMessage httpResponse)
 {
     if (string.IsNullOrWhiteSpace(response.Rev))
         response.Rev = httpResponse.Headers.GetETag();
 }
        protected virtual void OnFailedResponse(DocumentHeaderResponse response, HttpResponseMessage httpResponse)
        {
            base.OnFailedResponse(response, httpResponse);

            PopulateMissingIdFromRequestUri(response, httpResponse);
        }
 protected virtual void SetDocumentHeaderFromResponseStream(DocumentHeaderResponse response, Stream content)
 {
     Serializer.Populate(response, content);
 }
        protected virtual void OnFailedDocumentHeaderResponseContentMaterializer(HttpResponseMessage response, DocumentHeaderResponse result)
        {
            OnFailedResponseContentMaterializer(response, result);

            AssignMissingIdFromRequestUri(response, result);
        }
 protected virtual void SetMissingIdFromRequestUri(DocumentHeaderResponse response, HttpResponseMessage httpResponse)
 {
     if (string.IsNullOrWhiteSpace(response.Id) && httpResponse.RequestMessage.Method != HttpMethod.Post)
         response.Id = httpResponse.RequestMessage.ExtractIdFromUri(false);
 }
예제 #27
0
        public virtual void Materialize(DocumentHeaderResponse response, HttpResponseMessage httpResponse)
        {
            _failedResponseMaterializer.Materialize(response, httpResponse);

            SetMissingIdFromRequestUri(response, httpResponse);
        }
 protected virtual void SetDocumentHeaderFromResponseStream(DocumentHeaderResponse response, Stream content)
 {
     Serializer.Populate(response, content);
 }
        public virtual void Materialize(DocumentHeaderResponse response, HttpResponseMessage httpResponse)
        {
            _failedResponseMaterializer.Materialize(response, httpResponse);

            SetMissingIdFromRequestUri(response, httpResponse);
        }