示例#1
0
        async Task <DocumentInfo> DeleteAttachmentInternal(string attachmentId, string documentId, string documentRevision)
        {
            var attachmentUri  = uriConstructor.GetFullAttachmentUri(attachmentId, documentId, documentRevision);
            var requestMessage = new HttpRequestMessage(HttpMethod.Delete, attachmentUri);
            var response       = await parent.RequestCouchDb(requestMessage);

            if (!response.IsSuccessStatusCode)
            {
                var error = new CouchError(parent.Settings.Serializer, response);
                error.ThrowDatabaseMissingExceptionIfNedded(uriConstructor.DatabaseName);
                error.ThrowAttachmentMissingException(attachmentId, documentId, documentRevision);
                error.ThrowDocumentNotFoundIfNedded(documentId, documentRevision);
                error.ThrowStaleStateExceptionIfNedded(
                    string.Format("deleting attachment ID '{0}'", attachmentId), documentId, documentRevision);
                error.ThrowCouchCommunicationException();
            }
            return(await ReadDocumentInfo(response));
        }
示例#2
0
        public Task <Attachment> RequestAttachment(string attachmentId, string documentId, string documentRevision = null)
        {
            if (attachmentId.HasNoValue())
            {
                throw new ArgumentNullException("attachmentId");
            }
            if (documentId.HasNoValue())
            {
                throw new ArgumentNullException("documentId");
            }

            var attachmentUri  = uriConstructor.GetFullAttachmentUri(attachmentId, documentId, documentRevision);
            var requestMessage = new HttpRequestMessage(HttpMethod.Get, attachmentUri);

            requestMessage.Headers.Accept.Clear();

            using (SyncContext.SwitchToDefault())
                return(parent
                       .RequestCouchDb(requestMessage)
                       .ContinueWith <Attachment>(
                           rt => {
                    var response = rt.Result;
                    if (!response.IsSuccessStatusCode)
                    {
                        var error = new CouchError(parent.Settings.Serializer, response);
                        error.ThrowDatabaseMissingExceptionIfNedded(uriConstructor.DatabaseName);
                        if (error.IsAttachmentMissingFromDocument)
                        {
                            return null;
                        }
                        error.ThrowDocumentNotFoundIfNedded(documentId, documentRevision);
                        error.ThrowStaleStateExceptionIfNedded(
                            string.Format("request attachment ID '{0}'", attachmentId), documentId, documentRevision);
                        error.ThrowCouchCommunicationException();
                    }
                    return new HttpResponseMessageAttachment(attachmentId, response);
                }));
        }
示例#3
0
		public Task<Attachment> RequestAttachment(string attachmentId, string documentId, string documentRevision = null)
		{
			if (attachmentId.HasNoValue()) throw new ArgumentNullException("attachmentId");
			if (documentId.HasNoValue()) throw new ArgumentNullException("documentId");

			var attachmentUri = uriConstructor.GetFullAttachmentUri(attachmentId, documentId, documentRevision);
			var requestMessage = new HttpRequestMessage(HttpMethod.Get, attachmentUri);
			requestMessage.Headers.Accept.Clear();

			using (SyncContext.SwitchToDefault())
				return parent
					.RequestCouchDb(requestMessage)
					.ContinueWith<Attachment>(
						rt => {
							var response = rt.Result;
							if (!response.IsSuccessStatusCode)
							{
								var error = new CouchError(parent.Settings.Serializer, response);
								error.ThrowDatabaseMissingExceptionIfNedded(uriConstructor.DatabaseName);
								if (error.IsAttachmentMissingFromDocument)
									return null;
								error.ThrowDocumentNotFoundIfNedded(documentId, documentRevision);
								error.ThrowStaleStateExceptionIfNedded(
									string.Format("request attachment ID '{0}'", attachmentId), documentId, documentRevision);
								error.ThrowCouchCommunicationException();
							}
							return new HttpResponseMessageAttachment(attachmentId, response);
						});
		}
示例#4
0
		async Task<DocumentInfo> DeleteAttachmentInternal(string attachmentId, string documentId, string documentRevision)
		{
			var attachmentUri = uriConstructor.GetFullAttachmentUri(attachmentId, documentId, documentRevision);
			var requestMessage = new HttpRequestMessage(HttpMethod.Delete, attachmentUri);
			var response = await parent.RequestCouchDb(requestMessage);
			if (!response.IsSuccessStatusCode)
			{
				var error = new CouchError(parent.Settings.Serializer, response);
				error.ThrowDatabaseMissingExceptionIfNedded(uriConstructor.DatabaseName);
				error.ThrowAttachmentMissingException(attachmentId, documentId, documentRevision);
				error.ThrowDocumentNotFoundIfNedded(documentId, documentRevision);
				error.ThrowStaleStateExceptionIfNedded(
					string.Format("deleting attachment ID '{0}'", attachmentId), documentId, documentRevision);
				error.ThrowCouchCommunicationException();
			}
			return await ReadDocumentInfo(response);
		}