Пример #1
0
        public void CreateBucket()
        {
            ServerNode.ActivateDatabase();
            var hostUrl = ConfigurationManager.AppSettings["ApiHostUrl"];

            var createBucket = new CreateBucketRequest
                                   {BucketName = "TestBucket", MaxRecordSize = 1024, MaxRecordsPerBin = 250000};

            var requstJson = JsonConvert.SerializeObject(createBucket);
            var request = HttpWebRequest.Create(hostUrl + "/buckets/") as HttpWebRequest;
            request.Method = "PUT";
            request.ContentLength = requstJson.Length;
            request.GetRequestStream().Write(Encoding.ASCII.GetBytes(requstJson),0,requstJson.Length);
            var response = request.GetResponse();
            var reader = new StreamReader(response.GetResponseStream());
            var message = reader.ReadToEnd();
        }
Пример #2
0
        /// <summary>
        /// Creates the bucket.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>System.String.</returns>
        private HttpStatusCode CreateBucket(CreateBucketRequest request)
        {
            try
            {
                request.BucketName = request.BucketName.ToLower();
                if (string.IsNullOrEmpty(request.BucketName))
                    return HttpStatusCode.BadRequest;

                if (Buckets.ContainsKey(request.BucketName))
                    return HttpStatusCode.BadRequest;

                Buckets.Add(request.BucketName,DataBucket.CreateNewBucket(request.BucketName,DbLocation,request.MaxRecordSize,request.MaxRecordsPerBin));
                return HttpStatusCode.OK;
            }
            catch (Exception ex)
            {
                return HttpStatusCode.InternalServerError;
            }
        }