private void SaveData() { _connection.RunInTransaction(() => { var oldLength = _entry.Length; var oldModificationTime = _entry.LastWriteTimeUtc; var oldETag = _entry.ETag; try { var data = new FileData() { Id = _entry.Id, Data = _baseStream.ToArray(), }; _entry.Length = data.Data.Length; _entry.LastWriteTimeUtc = DateTime.UtcNow; _entry.ETag = EntityTag.Parse(_entry.ETag).Single().Update().ToString(); _connection.InsertOrReplace(data); _connection.Update(_entry); } catch (Exception) { _entry.Length = oldLength; _entry.LastWriteTimeUtc = oldModificationTime; _entry.ETag = oldETag; throw; } }); }
/// <summary> /// Initializes a new instance of the <see cref="SQLiteEntry"/> class. /// </summary> /// <param name="fileSystem">The file system this entry belongs to</param> /// <param name="parent">The parent collection</param> /// <param name="info">The file system information</param> /// <param name="path">The root-relative path of this entry</param> /// <param name="name">The entry name (<see langword="null"/> when <see cref="FileEntry.Name"/> of <see cref="SQLiteEntry.Info"/> should be used)</param> protected SQLiteEntry(SQLiteFileSystem fileSystem, ICollection parent, FileEntry info, Uri path, [CanBeNull] string name) { Parent = parent; Info = info; SQLiteFileSystem = fileSystem; Path = path; ETag = EntityTag.Parse(Info.ETag).Single(); Name = name ?? info.Name; }
/// <inheritdoc /> public Task SetCreationTimeUtcAsync(DateTime creationTime, CancellationToken cancellationToken) { if (Info.CreationTimeUtc != creationTime) { Info.CreationTimeUtc = creationTime; Info.ETag = EntityTag.Parse(Info.ETag).Single().Update().ToString(); Connection.Update(Info); } return(Task.FromResult(0)); }