public void SetPosition(FileId fileId, long pos) { var position = new FilePosition(fileId, pos); _positions[fileId.BaseFileName] = position; using (var stream = FileUtils.OpenFileStreamForWritingNoTruncate(GetTargetFileName(fileId.BaseFileName))) using (var writer = new StreamWriter(stream)) { FilePositionSerialiser.Write(position, writer); } }
public FilePosition GetPosition(string baseFileName) { FilePosition item; if (_positions.TryGetValue(baseFileName, out item)) { return(item); } else { string fileName = GetTargetFileName(baseFileName); if (File.Exists(fileName)) { using (var stream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read)) using (var reader = new StreamReader(stream, Encoding.UTF8, false, 200)) { return(FilePositionSerialiser.Read(baseFileName, reader)); } } return(null); } }