public async Task<Metadata> SaveData(StoreLocation location, Metadata metadata, UpdateAuditInfo audit, Func<IWriteAsyncStream, Task<long?>> savingFunc, CancellationToken token) { var current = await GetMetadata(location).ConfigureAwait(false); var info = current == null ? new AuditInfo() : current.Audit; info.UpdatedBy = audit == null ? "0" : audit.UpdatedBy; info.UpdatedByName = audit == null ? string.Empty : audit.UpdatedByName; info.UpdatedOn = DateTime.UtcNow; info.CreatedBy = info.CreatedBy ?? info.UpdatedBy; info.CreatedByName = info.CreatedByName ?? info.UpdatedByName; info.CreatedOn = info.CreatedOn ?? info.UpdatedOn; metadata = metadata ?? new Metadata(); metadata.Audit = info; var key = GetObjectKey(location); long? length = null; using(var stream = new AmazonMultiUploadStream(_client, _bucket, key, metadata)) { length = await savingFunc(stream).ConfigureAwait(false); await stream.Complete(token).ConfigureAwait(false); metadata.Snapshot = stream.VersionId; } if (length.HasValue && (metadata == null || !metadata.ContentLength.HasValue)) { metadata[MetadataConstants.ContentLengthMetadataKey] = length.Value.ToString(CultureInfo.InvariantCulture); // Save the length straight away before the snapshot... metadata = await SaveMetadata(location, metadata).ConfigureAwait(false); } return metadata; }
public async Task <Metadata> SaveData(StoreLocation location, Metadata metadata, UpdateAuditInfo audit, Func <IWriteAsyncStream, Task <long?> > savingFunc, CancellationToken token) { var current = await GetMetadata(location).ConfigureAwait(false); var info = current == null ? new AuditInfo() : current.Audit; info.UpdatedBy = audit == null ? "0" : audit.UpdatedBy; info.UpdatedByName = audit == null ? string.Empty : audit.UpdatedByName; info.UpdatedOn = DateTime.UtcNow; info.CreatedBy = info.CreatedBy ?? info.UpdatedBy; info.CreatedByName = info.CreatedByName ?? info.UpdatedByName; info.CreatedOn = info.CreatedOn ?? info.UpdatedOn; metadata = metadata ?? new Metadata(); metadata.Audit = info; var key = GetObjectKey(location); long?length = null; using (var stream = new AmazonMultiUploadStream(_client, _bucket, key, metadata)) { length = await savingFunc(stream).ConfigureAwait(false); await stream.Complete(token).ConfigureAwait(false); metadata.Snapshot = stream.VersionId; } if (length.HasValue && (metadata == null || !metadata.ContentLength.HasValue)) { metadata[MetadataConstants.ContentLengthMetadataKey] = length.Value.ToString(CultureInfo.InvariantCulture); // Save the length straight away before the snapshot... metadata = await SaveMetadata(location, metadata).ConfigureAwait(false); } return(metadata); }