Esempio n. 1
0
        private void CreateDB(CreateMode create)
        {
            if (File.Exists(_dbPath) || File.Exists(_dbPkIdxPath))
            {
                switch (create)
                {
                case CreateMode.Create:
                    throw new Exception("Cannot create DB, DB already exists at " + _path);

                case CreateMode.OpenOrCreate:
                    return;

                case CreateMode.Overwrite:
                    File.Delete(_dbPath);
                    File.Delete(_dbPkIdxPath);
                    break;
                }
            }


            if (!Directory.Exists(_path))
            {
                Directory.CreateDirectory(_path);
            }

            File.Create(_dbPath, 10000, FileOptions.Asynchronous | FileOptions.RandomAccess | FileOptions.WriteThrough).Close();
            _dbfile = new FileStream(_dbPath, FileMode.Open, FileAccess.ReadWrite, FileShare.None, 10000, false);

            File.Create(_dbPkIdxPath, 10000, FileOptions.Asynchronous | FileOptions.RandomAccess | FileOptions.WriteThrough).Close();
            _dbpkidxfile = new FileStream(_dbPkIdxPath, FileMode.Open, FileAccess.ReadWrite, FileShare.None, 10000, false);

            _identity = new PkIndex <K>();
            Close();
        }
Esempio n. 2
0
        private void InitDB()
        {
            _dbfile      = new FileStream(_dbPath, FileMode.Open, FileAccess.ReadWrite, FileShare.None, 10000, false);
            _dbpkidxfile = new FileStream(_dbPkIdxPath, FileMode.Open, FileAccess.ReadWrite, FileShare.None, 10000, false);
            _identity    = ProtoBuf.Serializer.DeserializeWithLengthPrefix <PkIndex <K> >(_dbpkidxfile, _prefix);


            foreach (long l in _identity)
            {
                if (l > _newPos)
                {
                    _newPos = l;
                }

                if (_newPos != 0)
                {
                    int objLen = 0;
                    _dbfile.Position = _newPos;
                    ProtoBuf.Serializer.TryReadLengthPrefix(_dbfile, _prefix, out objLen);
                    _newPos += objLen;
                }
            }
        }