예제 #1
0
        public HttpStatusCode StoreDocument(WriteDocRequest documents)
        {
            var hostUrl = ConfigurationManager.AppSettings["ApiHostUrl"];

            var requstJson = JsonConvert.SerializeObject(documents);
            var request    = HttpWebRequest.Create(hostUrl + "/documents/") as HttpWebRequest;

            request.Timeout       = 400000;
            request.Method        = "PUT";
            request.ContentLength = requstJson.Length;
            request.GetRequestStream().Write(Encoding.ASCII.GetBytes(requstJson), 0, requstJson.Length);
            var response = request.GetResponse() as HttpWebResponse;

            return(response.StatusCode);
        }
예제 #2
0
        /// <summary>
        /// Stores the specified request.
        /// </summary>
        /// <param name="requests">The requests.</param>
        /// <returns>System.String.</returns>
        private HttpStatusCode Store(WriteDocRequest request)
        {
            try
            {
                if (string.IsNullOrEmpty(request.BucketName))
                {
                    return(HttpStatusCode.BadRequest);
                }

                if (string.IsNullOrEmpty(request.Key))
                {
                    return(HttpStatusCode.BadRequest);
                }

                if (!request.Update)
                {
                    Buckets[request.BucketName.ToLower()].Add(request.Key,
                                                              request.Value);

                    return(HttpStatusCode.OK);
                }

                if (request.Update)
                {
                    Buckets[request.BucketName.ToLower()].Update(request.Key,
                                                                 request.Value);

                    return(HttpStatusCode.OK);
                }

                return(HttpStatusCode.BadRequest);
            }
            catch (DuplicateKeyException keyError)
            {
                return(HttpStatusCode.Forbidden);
            }
            catch (KeyNotFoundException keyError)
            {
                return(HttpStatusCode.NotFound);
            }
            catch (Exception ex)
            {
                return(HttpStatusCode.InternalServerError);
            }
        }