Exemple #1
0
        private static MappedFileAttribute GetMappedFileAttribute(this MappedFiles value)
        {
            FieldInfo fieldInfo = value.GetType().GetField(value.ToString());

            MappedFileAttribute[] attributes =
                fieldInfo.GetCustomAttributes(typeof(MappedFileAttribute), false) as MappedFileAttribute[];

            return((attributes.Length != 0) ? attributes[0] : null);
        }
Exemple #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));
     }
 }
Exemple #3
0
        /// <summary>
        /// Stores the specified key.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="document">The document.</param>
        /// <exception cref="System.Exception">Document with this key already exists.</exception>
        public void Add(string key, string document)
        {
            //get a map with a free space
            var keyHash = key.GetHashCode();
            var freeMap = MappedFiles.FirstOrDefault(mf => mf.Value.BlocksFree > 0);

            if (freeMap.Value == null)
            {
                CreateNewMapFile();
                freeMap = MappedFiles.FirstOrDefault(mf => mf.Value.BlocksFree > 0);
            }

            var index = freeMap.Value.Write(document);

            if (index < 0)
            {
                Add(key, document);
                return;
            }

            KeyTree.Insert(keyHash, new DataPointer {
                FileId = freeMap.Key, Pointer = index, Size = document.Length
            });
        }
Exemple #4
0
 public static string GetFileNameWithoutExtension(this MappedFiles value)
 {
     return(Path.ChangeExtension(value.GetFileName(), null));
 }
Exemple #5
0
 public static string GetFileName(this MappedFiles value)
 {
     return(mappings[value].Filename);
 }