예제 #1
0
        internal BinaryLogFile(string filename)
        {
            _filename = filename;

            _headerStream = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
            _headerReader = new StreamBinaryReader(_headerStream);
            _headerWriter = new StreamBinaryWriter(_headerStream);

            _contentStream = new FileStream(filename, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
            _contentReader = new StreamBinaryReader(_contentStream);
            _contentWriter = new StreamBinaryWriter(_contentStream);

            _recCount        = 1;
            _creationTime    = new DateTime(_headerReader.ReadInt64());
            _contentPosition = _headerReader.ReadInt64();
        }
예제 #2
0
        public static IBinaryLog CreateFile(string filename, long headerSize)
        {
            if (headerSize % 16 != 0)
            {
                throw new ArgumentException();
            }

            using (var stream = new FileStream(filename, FileMode.CreateNew))
                using (var writer = new StreamBinaryWriter(stream))
                {
                    writer.WriteInt64(DateTime.UtcNow.Ticks);
                    writer.WriteInt64(headerSize);
                    stream.SetLength(headerSize);
                }

            return(OpenFile(filename));
        }