예제 #1
0
        /// <summary>
        /// Creates the new map.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="location">The location.</param>
        /// <param name="maxBlockSize">Size of the max block.</param>
        /// <param name="maxBlocksPerFile">The max blocks per file.</param>
        /// <returns>MappedFile.</returns>
        public static MappedFile CreateNewMap(string fileName, string location, int maxBlockSize, int maxBlocksPerFile)
        {
            lock (MapLock)
            {
                var map = new MappedFile
                {
                    FileName     = fileName,
                    Location     = location,
                    MaxBlockSize = maxBlockSize,
                    MapFile      =
                        MemoryMappedFile.CreateFromFile(Path.Combine(location, fileName),
                                                        FileMode.CreateNew,
                                                        fileName, maxBlockSize * maxBlocksPerFile)
                };

                for (var i = 0; i < maxBlocksPerFile; i++)
                {
                    map.FreeBlocks.Add(i);
                }

                map.BlocksFree = maxBlocksPerFile;
                var configPath = Path.Combine(location, fileName + ".config");
                File.WriteAllText(configPath, map.ToString());

                return(map);
            }
        }
예제 #2
0
 /// <summary>
 /// Creates the new map file.
 /// </summary>
 private void CreateNewMapFile()
 {
     lock (_mapLock)
     {
         var count = (MappedFiles.Count() + 1);
         var hash  = (Name + "-" + count).GetHashCode();
         MappedFiles.Add(hash,
                         MappedFile.CreateNewMap(hash + ".bin", Location, MaxDocumentSize,
                                                 MaxDocumentCountPerFile));
     }
 }
예제 #3
0
        /// <summary>
        /// Loads the data bucket.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="location">The location.</param>
        /// <returns>DataBucket.</returns>
        public static DataBucket LoadDataBucket(string name, string location)
        {
            var bucket =
                JsonConvert.DeserializeObject <DataBucket>(File.ReadAllText(Path.Combine(location, name + ".bucket")));

            var files    = Directory.GetFiles(bucket.Location);
            var fileInfo = files.Select(fi => new FileInfo(fi)).Where(fi => fi.Extension.Equals(".bin", StringComparison.OrdinalIgnoreCase));

            bucket.MappedFiles =
                fileInfo.Select(fi => new KeyValuePair <long, MappedFile>(long.Parse(fi.Name.Replace(".bin", string.Empty)), MappedFile.LoadMap(fi.Name, bucket.Location)))
                .ToDictionary(k => k.Key, v => v.Value);
            bucket.KeyTree = KeyTree.Load(Path.Combine(bucket.Location, bucket.Name + "-KeyTree.key"));
            return(bucket);
        }
예제 #4
0
        /// <summary>
        /// Creates the new map.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="location">The location.</param>
        /// <param name="maxBlockSize">Size of the max block.</param>
        /// <param name="maxBlocksPerFile">The max blocks per file.</param>
        /// <returns>MappedFile.</returns>
        public static MappedFile CreateNewMap(string fileName, string location, int maxBlockSize, int maxBlocksPerFile)
        {
            lock (MapLock)
            {
                var map = new MappedFile
                              {
                                  FileName = fileName,
                                  Location = location,
                                  MaxBlockSize = maxBlockSize,
                                  MapFile =
                                      MemoryMappedFile.CreateFromFile(Path.Combine(location, fileName),
                                                                      FileMode.CreateNew,
                                                                      fileName, maxBlockSize*maxBlocksPerFile)
                              };

                for (var i = 0; i < maxBlocksPerFile; i++)
                {
                    map.FreeBlocks.Add(i);
                }

                map.BlocksFree = maxBlocksPerFile;
                var configPath = Path.Combine(location, fileName + ".config");
                File.WriteAllText(configPath, map.ToString());

                return map;
            }
        }