Пример #1
0
        public Task <string> RequestLastestDocumentRevision(string documentId)
        {
            if (string.IsNullOrEmpty(documentId))
            {
                throw new ArgumentNullException("documentId");
            }

            var documentUri = uriConstructor.GetFullDocumentUri(documentId);
            var request     = new HttpRequestMessage(HttpMethod.Head, documentUri);

            using (SyncContext.SwitchToDefault())
                return(parent.RequestCouchDb(request).ContinueWith(
                           rt => {
                    var response = rt.Result;
                    if (!response.IsSuccessStatusCode)
                    {
                        var couchApiError = new CouchError(parent.Settings.Serializer, response);
                        couchApiError.ThrowDatabaseMissingExceptionIfNedded(uriConstructor);
                        couchApiError.ThrowStaleStateExceptionIfNedded("update", documentId);
                        couchApiError.ThrowInvalidDocumentExceptionIfNedded(documentId);
                        if (response.StatusCode == HttpStatusCode.NotFound)
                        {
                            return null;
                        }
                        couchApiError.ThrowCouchCommunicationException();
                    }

                    var etag = response.Headers.ETag;
                    if (etag == null || etag.Tag == null)
                    {
                        throw new ParseException("Etag header expected but was not found.");
                    }
                    return etag.Tag.Trim('"');
                }));
        }
Пример #2
0
			private async Task<DocumentInfo> Save()
			{
				var request = new HttpRequestMessage(HttpMethod.Put, parent.uriConstructor.GetFullDocumentUri(document.Id)) {
					Content = new JsonContent(document.RawJsonObject)
				};

				var response = await parent.parent.RequestCouchDb(request);
				var documentId = document.Id;
				if (!response.IsSuccessStatusCode)
				{
					var error = new CouchError(parent.parent.Settings.Serializer, response);
					error.ThrowDatabaseMissingExceptionIfNedded(parent.uriConstructor);
					if (error.IsConflict)
						return conflictAction(error);
					error.ThrowInvalidDocumentExceptionIfNedded(documentId);
					error.ThrowCouchCommunicationException();
				}
				return await ReadDocumentInfo(response);
			}
Пример #3
0
            private async Task <DocumentInfo> Save()
            {
                var request = new HttpRequestMessage(HttpMethod.Put, parent.uriConstructor.GetFullDocumentUri(document.Id))
                {
                    Content = new JsonContent(document.RawJsonObject)
                };

                var response = await parent.parent.RequestCouchDb(request);

                var documentId = document.Id;

                if (!response.IsSuccessStatusCode)
                {
                    var error = new CouchError(parent.parent.Settings.Serializer, response);
                    error.ThrowDatabaseMissingExceptionIfNedded(parent.uriConstructor);
                    if (error.IsConflict)
                    {
                        return(conflictAction(error));
                    }
                    error.ThrowInvalidDocumentExceptionIfNedded(documentId);
                    error.ThrowCouchCommunicationException();
                }
                return(await ReadDocumentInfo(response));
            }
Пример #4
0
		public Task<string> RequestLastestDocumentRevision(string documentId)
		{
			if (string.IsNullOrEmpty(documentId)) throw new ArgumentNullException("documentId");

			var documentUri = uriConstructor.GetFullDocumentUri(documentId);
			var request = new HttpRequestMessage(HttpMethod.Head, documentUri);

			using (SyncContext.SwitchToDefault())
				return parent.RequestCouchDb(request).ContinueWith(
					rt => {
						var response = rt.Result;
						if (!response.IsSuccessStatusCode)
						{
							var couchApiError = new CouchError(parent.Settings.Serializer, response);
							couchApiError.ThrowDatabaseMissingExceptionIfNedded(uriConstructor);
							couchApiError.ThrowStaleStateExceptionIfNedded("update", documentId);
							couchApiError.ThrowInvalidDocumentExceptionIfNedded(documentId);
							if (response.StatusCode == HttpStatusCode.NotFound)
								return null;
							couchApiError.ThrowCouchCommunicationException();
						}

						var etag = response.Headers.ETag;
						if (etag == null || etag.Tag == null)
							throw new ParseException("Etag header expected but was not found.");
						return etag.Tag.Trim('"');
					});
		}