Exemplo n.º 1
0
        /// <summary>
        /// 创建新的存储文件
        /// </summary>
        private void CreateNewStorageFile()
        {
            _log.Debug("Split limit reached = " + _datawrite.Length);
            int i = _files.Count;

            // close files
            FlushClose(_datawrite);
            FlushClose(_dataread);
            long start = 0;

            if (i > 0)
            {
                start = _lastsplitfile.uptolength; // last file offset
            }
            // rename mgdat to mgdat0000n
            File.Move(_filename, _filename + i.ToString(_splitfileExtension));
            FileStream file = new FileStream(_filename + i.ToString(_splitfileExtension), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            SplitFile  sf   = new SplitFile();

            sf.start      = start;
            sf.uptolength = _lastWriteOffset;
            sf.file       = file;
            _files.Add(sf);

            _uptoindexes.Add(sf.uptolength);

            _lastsplitfile = sf;
            // new mgdat file
            _datawrite = new FileStream(_filename, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.ReadWrite);
            _dataread  = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            _log.Debug("New storage file created, count = " + _files.Count);
        }
Exemplo n.º 2
0
 /// <summary>
 /// 加载拆分的文件
 /// </summary>
 /// <param name="filename"></param>
 private void LoadSplitFiles(string filename)
 {
     _log.Debug("Loading split files...");
     _lastWriteOffset = 0;
     for (int i = 0; ; i++)
     {
         string _filename = filename + i.ToString(_splitfileExtension);
         if (File.Exists(_filename) == false)
         {
             break;
         }
         FileStream file = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
         SplitFile  sf   = new SplitFile();
         sf.start          = _lastWriteOffset;
         _lastWriteOffset += file.Length;
         sf.file           = file;
         sf.uptolength     = _lastWriteOffset;
         _files.Add(sf);
         _uptoindexes.Add(sf.uptolength);
     }
     _lastsplitfile = _files[_files.Count - 1];
     _log.Debug("Number of split files = " + _files.Count);
 }