예제 #1
0
        public RollingFileReader(string baseFileName, IFilePositionStore store, ReadBehaviour readBehaviour)
        {
            //TODO UNCs are not allowed

            _store       = store;
            BaseFileName = baseFileName;
            switch (readBehaviour)
            {
            case ReadBehaviour.FromBeginning:
                _position = new FilePosition(new FileId(baseFileName, DateTime.MinValue), 0);
                break;

            case ReadBehaviour.FromWhereLeft:
                _position = _store.GetPosition(baseFileName);
                if (_position == null)
                {
                    _position = new FilePosition(new FileId(baseFileName, DateTime.MinValue), 0);
                }
                break;

            case ReadBehaviour.FromCurrentPos:
                var  fileInfo = new FileInfo(baseFileName);    //TODO what if not there??
                var  fileId   = new FileId(baseFileName, fileInfo.LastWriteTimeUtc);
                long pos      = fileInfo.Length;
                _position = new FilePosition(fileId, pos);
                break;

            default:
                throw new NotSupportedException("Unsupported ReadBehaviour");
            }

            FileStream = OpenFileStream(_position);
        }
예제 #2
0
        public void RollBack()
        {
            _position = _store.GetPosition(_position.FileId.BaseFileName);
//TODO reopen stream  - we could have moved to a new file.
        }