Exemple #1
0
        public Task <DocumentInfo> DeleteDocument(string documentId, string revision)
        {
            if (string.IsNullOrEmpty(documentId))
            {
                throw new ArgumentNullException("documentId");
            }
            if (string.IsNullOrEmpty(revision))
            {
                throw new ArgumentNullException("revision");
            }

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

            using (SyncContext.SwitchToDefault())
                return(DeleteDocumentInternal(documentId, revision, request));
        }
        public static async Task <Document> Start(
            DbUriConstructor uriConstructor,
            DatabaseApi databaseApi,
            CouchApi couchApi,
            string documentId,
            string revision,
            AdditionalDocumentProperty additionalProperties)
        {
            var documentUri = uriConstructor.GetFullDocumentUri(documentId, revision, additionalProperties);
            var request     = new HttpRequestMessage(HttpMethod.Get, documentUri);

            var response = await couchApi.RequestCouchDb(request);

            if (!response.IsSuccessStatusCode)
            {
                var error = new CouchError(couchApi.Settings.Serializer, response);
                error.ThrowDatabaseMissingExceptionIfNedded(uriConstructor);
                if (response.StatusCode == HttpStatusCode.NotFound)
                {
                    return(null);
                }
                error.ThrowCouchCommunicationException();
            }

            var content   = response.Content;
            var mediaType = content.Headers.ContentType != null? content.Headers.ContentType.MediaType: "<unknown>";

            switch (mediaType)
            {
            case MediaType.Json:
                return(ReadDocument(
                           databaseApi,
                           await content.ReadAsUtf8TextReaderAsync()
                           ));

            case MediaType.Multipart:
                return(await ReadMultipart(databaseApi, content));

            default:
                throw new CouchCommunicationException(
                          "Unexpected media type response recived requesting CouchDB document: {0}", mediaType);
            }
        }
		public static async Task<Document> Start(
			DbUriConstructor uriConstructor,
			DatabaseApi databaseApi,
			CouchApi couchApi,
			string documentId, 
			string revision, 
			AdditionalDocumentProperty additionalProperties)
		{
			var documentUri = uriConstructor.GetFullDocumentUri(documentId, revision, additionalProperties);
			var request = new HttpRequestMessage(HttpMethod.Get, documentUri);

			var response = await couchApi.RequestCouchDb(request);
			if (!response.IsSuccessStatusCode)
			{
				var error = new CouchError(couchApi.Settings.Serializer, response);
				error.ThrowDatabaseMissingExceptionIfNedded(uriConstructor);
				if (response.StatusCode == HttpStatusCode.NotFound)
					return null;
				error.ThrowCouchCommunicationException();
			}

			var content = response.Content;
			var mediaType = content.Headers.ContentType != null? content.Headers.ContentType.MediaType: "<unknown>";
			switch (mediaType)
			{
				case MediaType.Json:
					return ReadDocument(
						databaseApi, 
						await content.ReadAsUtf8TextReaderAsync()
					);
				case MediaType.Multipart:
					return await ReadMultipart(databaseApi, content);
				default:
					throw new CouchCommunicationException(
						"Unexpected media type response recived requesting CouchDB document: {0}", mediaType);
			}
		}