Esempio n. 1
0
        internal AbstractBufferedWriter StartPureValuesFile(out uint fileId)
        {
            var fId = FileCollection.AddFile("pvl");

            fileId = fId.Index;
            var pureValues = new FilePureValues(FileCollection.NextGeneration(), FileCollection.Guid);
            var writer     = fId.GetAppenderWriter();

            FileCollection.SetInfo(fId.Index, pureValues);
            pureValues.WriteHeader(writer);
            return(writer);
        }
 void LoadInfoAboutFiles()
 {
     foreach (var file in _fileCollection.Enumerate())
     {
         try
         {
             var reader = file.GetExclusiveReader();
             if (reader.CheckMagic(MagicStartOfFile))
             {
                 var fileType = (KVFileType)reader.ReadUInt8();
                 IFileInfo fileInfo;
                 switch (fileType)
                 {
                     case KVFileType.TransactionLog:
                         fileInfo = new FileTransactionLog(reader);
                         break;
                     case KVFileType.KeyIndex:
                         fileInfo = new FileKeyIndex(reader);
                         break;
                     case KVFileType.PureValues:
                         fileInfo = new FilePureValues(reader);
                         break;
                     case KVFileType.PureValuesWithId:
                         fileInfo = new FilePureValuesWithId(reader);
                         break;
                     case KVFileType.HashKeyIndex:
                         fileInfo = new HashKeyIndex(reader);
                         break;
                     default:
                         fileInfo = UnknownFile.Instance;
                         break;
                 }
                 if (_fileGeneration < fileInfo.Generation) _fileGeneration = fileInfo.Generation;
                 _fileInfos.TryAdd(file.Index, fileInfo);
             }
             else
             {
                 _fileInfos.TryAdd(file.Index, UnknownFile.Instance);
             }
         }
         catch (Exception)
         {
             _fileInfos.TryAdd(file.Index, UnknownFile.Instance);
         }
     }
 }
Esempio n. 3
0
        void LoadInfoAboutFiles()
        {
            foreach (var file in _fileCollection.Enumerate())
            {
                try
                {
                    var  reader = file.GetExclusiveReader();
                    var  magic  = reader.ReadByteArrayRaw(MagicStartOfFile.Length);
                    Guid?guid   = null;
                    if (
                        BitArrayManipulation.CompareByteArray(magic, magic.Length, MagicStartOfFileWithGuid,
                                                              MagicStartOfFileWithGuid.Length) == 0)
                    {
                        guid = reader.ReadGuid();
                        if (Guid.HasValue && Guid.Value != guid)
                        {
                            _fileInfos.TryAdd(file.Index, UnknownFile.Instance);
                            continue;
                        }
                        Guid = guid;
                    }
                    else if (
                        BitArrayManipulation.CompareByteArray(magic, magic.Length, MagicStartOfFile,
                                                              MagicStartOfFile.Length) != 0)
                    {
                        _fileInfos.TryAdd(file.Index, UnknownFile.Instance);
                        continue;
                    }
                    var       fileType = (KVFileType)reader.ReadUInt8();
                    IFileInfo fileInfo;
                    switch (fileType)
                    {
                    case KVFileType.TransactionLog:
                        fileInfo = new FileTransactionLog(reader, guid);
                        break;

                    case KVFileType.KeyIndex:
                        fileInfo = new FileKeyIndex(reader, guid, false, false, false);
                        break;

                    case KVFileType.KeyIndexWithCommitUlong:
                        fileInfo = new FileKeyIndex(reader, guid, true, false, false);
                        break;

                    case KVFileType.ModernKeyIndex:
                        fileInfo = new FileKeyIndex(reader, guid, true, true, false);
                        break;

                    case KVFileType.ModernKeyIndexWithUlongs:
                        fileInfo = new FileKeyIndex(reader, guid, true, true, true);
                        break;

                    case KVFileType.PureValues:
                        fileInfo = new FilePureValues(reader, guid);
                        break;

                    case KVFileType.PureValuesWithId:
                        fileInfo = new FilePureValuesWithId(reader, guid);
                        break;

                    case KVFileType.HashKeyIndex:
                        fileInfo = new HashKeyIndex(reader, guid);
                        break;

                    default:
                        fileInfo = UnknownFile.Instance;
                        break;
                    }
                    if (_fileGeneration < fileInfo.Generation)
                    {
                        _fileGeneration = fileInfo.Generation;
                    }
                    _fileInfos.TryAdd(file.Index, fileInfo);
                }
                catch (Exception)
                {
                    _fileInfos.TryAdd(file.Index, UnknownFile.Instance);
                }
            }
            if (!Guid.HasValue)
            {
                Guid = System.Guid.NewGuid();
            }
        }
 void LoadInfoAboutFiles()
 {
     foreach (var file in _fileCollection.Enumerate())
     {
         try
         {
             var reader = file.GetExclusiveReader();
             var magic = reader.ReadByteArrayRaw(MagicStartOfFile.Length);
             Guid? guid = null;
             if (
                 BitArrayManipulation.CompareByteArray(magic, magic.Length, MagicStartOfFileWithGuid,
                     MagicStartOfFileWithGuid.Length) == 0)
             {
                 guid = reader.ReadGuid();
                 if (Guid.HasValue && Guid.Value != guid)
                 {
                     _fileInfos.TryAdd(file.Index, UnknownFile.Instance);
                     continue;
                 }
                 Guid = guid;
             }
             else if (
                 BitArrayManipulation.CompareByteArray(magic, magic.Length, MagicStartOfFile,
                     MagicStartOfFile.Length) != 0)
             {
                 _fileInfos.TryAdd(file.Index, UnknownFile.Instance);
                 continue;
             }
             var fileType = (KVFileType)reader.ReadUInt8();
             IFileInfo fileInfo;
             switch (fileType)
             {
                 case KVFileType.TransactionLog:
                     fileInfo = new FileTransactionLog(reader, guid);
                     break;
                 case KVFileType.KeyIndex:
                     fileInfo = new FileKeyIndex(reader, guid, false);
                     break;
                 case KVFileType.KeyIndexWithCommitUlong:
                     fileInfo = new FileKeyIndex(reader, guid, true);
                     break;
                 case KVFileType.PureValues:
                     fileInfo = new FilePureValues(reader, guid);
                     break;
                 case KVFileType.PureValuesWithId:
                     fileInfo = new FilePureValuesWithId(reader, guid);
                     break;
                 case KVFileType.HashKeyIndex:
                     fileInfo = new HashKeyIndex(reader, guid);
                     break;
                 default:
                     fileInfo = UnknownFile.Instance;
                     break;
             }
             if (_fileGeneration < fileInfo.Generation) _fileGeneration = fileInfo.Generation;
             _fileInfos.TryAdd(file.Index, fileInfo);
         }
         catch (Exception)
         {
             _fileInfos.TryAdd(file.Index, UnknownFile.Instance);
         }
     }
     if (!Guid.HasValue)
     {
         Guid = System.Guid.NewGuid();
     }
 }