Example #1
0
        /// <summary>
        /// Activates the database.
        /// </summary>
        public static void ActivateDatabase()
        {
            Buckets    = new Dictionary <string, DataBucket>();
            DbLocation = ConfigurationManager.AppSettings["DatabaseLocation"];
            var buckets = Directory.GetFiles(DbLocation, "*.bucket").Select(fi => new FileInfo(fi));

            foreach (var bucket in buckets)
            {
                var bk = DataBucket.LoadDataBucket(bucket.Name.Replace(".bucket", string.Empty), DbLocation);
                Buckets.Add(bk.Name, bk);
            }

            var hostUrl = ConfigurationManager.AppSettings["ApiHostUrl"];

            ServiceHost = new NancyHost(new Uri(hostUrl));
            ServiceHost.Start();
        }
Example #2
0
        /// <summary>
        /// Creates the new bucket.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="location">The location.</param>
        /// <param name="maxDocumentSize">Size of the max document.</param>
        /// <param name="maxDocumentCountPerFile">The max document count per file.</param>
        /// <returns>DataBucket.</returns>
        public static DataBucket CreateNewBucket(string name, string location, int maxDocumentSize, int maxDocumentCountPerFile)
        {
            var bucket = new DataBucket
            {
                Name                    = name,
                Location                = Path.Combine(location, name),
                MaxDocumentSize         = maxDocumentSize,
                MaxDocumentCountPerFile = maxDocumentCountPerFile
            };

            if (!Directory.Exists(bucket.Location))
            {
                Directory.CreateDirectory(bucket.Location);
            }

            bucket.CreateNewMapFile();
            bucket.KeyTree = KeyTree.CreateNew(Path.Combine(bucket.Location, bucket.Name + "-KeyTree.key"));
            File.WriteAllText(Path.Combine(location, name + ".bucket"), bucket.ToString());

            return(bucket);
        }
Example #3
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);
            }
        }
Example #4
0
        /// <summary>
        /// Creates the new bucket.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="location">The location.</param>
        /// <param name="maxDocumentSize">Size of the max document.</param>
        /// <param name="maxDocumentCountPerFile">The max document count per file.</param>
        /// <returns>DataBucket.</returns>
        public static DataBucket CreateNewBucket(string name, string location, int maxDocumentSize, int maxDocumentCountPerFile)
        {
            var bucket = new DataBucket
                             {
                                 Name = name,
                                 Location = Path.Combine(location,name),
                                 MaxDocumentSize = maxDocumentSize,
                                 MaxDocumentCountPerFile = maxDocumentCountPerFile
                             };

            if (!Directory.Exists(bucket.Location))
                Directory.CreateDirectory(bucket.Location);

            bucket.CreateNewMapFile();
            bucket.KeyTree = KeyTree.CreateNew(Path.Combine(bucket.Location, bucket.Name + "-KeyTree.key"));
            File.WriteAllText(Path.Combine(location,name + ".bucket"),bucket.ToString());

            return bucket;
        }