Esempio n. 1
0
        public async Task <HttpClientResponse> GetDocumentAsync(string id)
        {
            HttpClientResponse response = new HttpClientResponse();
            var _httpClient             = _clientFactory.CreateClient("Couchdb");
            var dbResult = await _httpClient.GetAsync(_couchDbName + "/" + id);

            if (dbResult.IsSuccessStatusCode)
            {
                response.IsSuccess            = true;
                response.SuccessContentObject = await dbResult.Content.ReadAsStringAsync();
            }
            else
            {
                response.IsSuccess    = false;
                response.FailedReason = dbResult.ReasonPhrase;
            }
            return(response);
        }
Esempio n. 2
0
        public async Task <HttpClientResponse> GetDocumentAsync(string id)
        {
            HttpClientResponse response = new HttpClientResponse();
            var dbClient = DbHttpClient();

            //CouchDB URL : GET http://{hostname_or_IP}:{Port}/{couchDbName}/{_id}
            var dbResult = await dbClient.GetAsync(_couchDbName + "/" + id);

            if (dbResult.IsSuccessStatusCode)
            {
                response.IsSuccess            = true;
                response.SuccessContentObject = await dbResult.Content.ReadAsStringAsync();
            }
            else
            {
                response.IsSuccess    = false;
                response.FailedReason = dbResult.ReasonPhrase;
            }
            return(response);
        }
Esempio n. 3
0
        public async Task <HttpClientResponse> DeleteDocumentAsync(string id, string rev)
        {
            HttpClientResponse response = new HttpClientResponse();
            var _httpClient             = _clientFactory.CreateClient("Couchdb");

            //CouchDB URL : DELETE http://{hostname_or_IP}:{Port}/{couchDbName}/{_id}/?rev={_rev}
            var dbResult = await _httpClient.DeleteAsync(_couchDbName + "/" + id + "?rev=" + rev);

            if (dbResult.IsSuccessStatusCode)
            {
                response.IsSuccess            = true;
                response.SuccessContentObject = await dbResult.Content.ReadAsStringAsync();
            }
            else
            {
                response.IsSuccess    = false;
                response.FailedReason = dbResult.ReasonPhrase;
            }
            return(response);
        }
Esempio n. 4
0
        public async Task <HttpClientResponse> PostDocumentAsync(PharmaDetails pharmaDetails)
        {
            HttpClientResponse response = null;

            try
            {
                response = new HttpClientResponse();
                var dbClient    = DbHttpClient();
                var jsonData    = JsonConvert.SerializeObject(pharmaDetails);
                var httpContent = new StringContent(jsonData, Encoding.UTF8, "application/json");

                //CouchDB URL : POST http://{hostname_or_IP}:{Port}/{couchDbName}
                var postResult = await dbClient.PostAsync(_couchDbName, httpContent).ConfigureAwait(true);

                if (postResult.IsSuccessStatusCode)
                {
                    response.IsSuccess            = true;
                    response.SuccessContentObject = await postResult.Content.ReadAsStringAsync();
                }
                else
                {
                    response.IsSuccess    = false;
                    response.FailedReason = postResult.ReasonPhrase;
                }
            }
            catch (WebException exception)
            {
                using (var reader = new StreamReader(exception.Response.GetResponseStream()))
                {
                    response.FailedReason = reader.ReadToEnd();
                    response.IsSuccess    = false;
                }
            }


            return(response);
        }