Exemplo n.º 1
0
		/// <constructor />
		public DatabaseApi(CouchApi parent, DbUriConstructor uriConstructor)
		{
			if (parent == null) throw new ArgumentNullException("parent");

			this.parent = parent;
			this.uriConstructor = uriConstructor;
			Synchronously = new SynchronousDatabaseApi(this);
		}
Exemplo n.º 2
0
        /// <constructor />
        public DatabaseApi(CouchApi parent, DbUriConstructor uriConstructor)
        {
            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }

            this.parent         = parent;
            this.uriConstructor = uriConstructor;
            Synchronously       = new SynchronousDatabaseApi(this);
        }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
		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);
			}
		}
Exemplo n.º 5
0
 /// <constructor />
 public BulkUpdateBatch(DbUriConstructor uriConstructor, ISerializer serializer)
 {
     this.uriConstructor = uriConstructor;
     this.serializer     = serializer;
 }
Exemplo n.º 6
0
 public void ThrowDatabaseMissingExceptionIfNedded(DbUriConstructor uriConstructor)
 {
     ThrowDatabaseMissingExceptionIfNedded(uriConstructor.DatabaseName);
 }
Exemplo n.º 7
0
 /// <constructor />
 public BulkUpdateBatch(DbUriConstructor uriConstructor, ISerializer serializer)
 {
     this.uriConstructor = uriConstructor;
     this.serializer = serializer;
 }
Exemplo n.º 8
0
 public void ThrowDatabaseMissingExceptionIfNedded(DbUriConstructor uriConstructor)
 {
     ThrowDatabaseMissingExceptionIfNedded(uriConstructor.DatabaseName);
 }