コード例 #1
0
ファイル: DatabaseApi.cs プロジェクト: artikh/CouchDude
		/// <constructor />
		public DatabaseApi(CouchApi parent, DbUriConstructor uriConstructor)
		{
			if (parent == null) throw new ArgumentNullException("parent");

			this.parent = parent;
			this.uriConstructor = uriConstructor;
			Synchronously = new SynchronousDatabaseApi(this);
		}
コード例 #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);
        }
コード例 #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);
            }
        }
コード例 #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);
			}
		}
コード例 #5
0
ファイル: CouchDbRequester.cs プロジェクト: artikh/CouchDude
        public static async Task <HttpResponseMessage> RequestCouchDb(this CouchApi self, HttpRequestMessage request)
        {
            try
            {
                return(await self.SendAsync(request));
            }
            catch (Exception e)
            {
                var aggregateException = e as AggregateException;
                if (aggregateException != null)
                {
                    var innerExceptions = aggregateException.InnerExceptions;

                    var newInnerExceptions = new Exception[innerExceptions.Count];
                    for (var i = 0; i < innerExceptions.Count; i++)
                    {
                        newInnerExceptions[i] = WrapIfNeeded(innerExceptions[i]);
                    }
                    throw new AggregateException(aggregateException.Message, newInnerExceptions);
                }

                throw WrapIfNeeded(e);
            }
        }
コード例 #6
0
 public ReplicatorApi(CouchApi parent)
 {
     this.parent = parent;
     synchronousReplicatorApi = new SynchronousReplicatorApi(this);
     replicatorDbApi          = parent.Db(parent.Settings.ReplicatorDatabase);
 }