public long TryAppend(byte[] buffer, TapeAppendCondition condition) { if (buffer == null) { throw new ArgumentNullException("buffer"); } if (buffer.Length == 0) { throw new ArgumentException("Buffer must contain at least one byte."); } using (var file = OpenForWrite()) { // we need to know version first. file.Seek(0, SeekOrigin.End); var version = TapeStreamSerializer.ReadVersionFromTheEnd(file); if (!condition.Satisfy(version)) { return(0); } var versionToWrite = version + 1; TapeStreamSerializer.WriteRecord(file, buffer, versionToWrite); return(versionToWrite); } }
public long GetCurrentVersion() { try { using (var s = OpenForRead()) { // seek end s.Seek(0, SeekOrigin.End); return(TapeStreamSerializer.ReadVersionFromTheEnd(s)); } } catch (FileNotFoundException) { return(0); } catch (DirectoryNotFoundException) { return(0); } }