コード例 #1
0
        public async Task <ScoreSnapshotDetail> GetAsync(Guid ownerId, Guid scoreId, Guid snapshotId)
        {
            var key = ScoreSnapshotStorageUtils.CreateSnapshotKey(ownerId, scoreId, snapshotId);

            var request = new GetObjectRequest()
            {
                BucketName = ScoreSnapshotBucketName,
                Key        = key,
            };

            try
            {
                var response = await _s3Client.GetObjectAsync(request);

                if (response.HttpStatusCode == HttpStatusCode.OK)
                {
                    byte[] buffer = new byte[response.ResponseStream.Length];
                    await response.ResponseStream.ReadAsync(buffer);

                    return(ScoreSnapshotStorageUtils.MapFromJson(buffer));
                }
            }
            catch (Exception ex)
            {
                throw new NotFoundSnapshotException(ex);
            }
            throw new NotFoundSnapshotException("Not found snapshot.");
        }
コード例 #2
0
        public async Task CreateSnapshotItemAsync(Guid ownerId, Guid scoreId, ScoreSnapshotDetail snapshotDetail,
                                                  ScoreObjectAccessControls accessControl)
        {
            var key = ScoreSnapshotStorageUtils.CreateSnapshotKey(ownerId, scoreId, snapshotDetail.Id);

            var json = ScoreSnapshotStorageUtils.ConvertToJson(snapshotDetail);

            await using var jsonStream = new MemoryStream(json);

            var acl = accessControl switch
            {
                ScoreObjectAccessControls.Private => S3CannedACL.Private,
                ScoreObjectAccessControls.Public => S3CannedACL.PublicRead,
                _ => throw new NotSupportedException(),
            };

            var request = new PutObjectRequest()
            {
                BucketName  = ScoreDataSnapshotS3Bucket,
                Key         = key,
                CannedACL   = acl,
                InputStream = jsonStream,
            };
            await _s3Client.PutObjectAsync(request);
        }