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); }
public async Task <(ScoreSnapshotDetail snapshot, ScoreAccesses access)> CreateSnapshotAsync(Guid ownerId, Guid scoreId, string snapshotName) { // TODO ここで作成されたデータを使い JSON ファイルを作成し S3 に保存する var snapshotId = Guid.NewGuid(); var response = await CreateSnapshotAsync(ownerId, scoreId, snapshotId, snapshotName); var snapshot = ScoreSnapshotDetail.Create(snapshotId, snapshotName, response.dynamoDbScore, response.hashSet); var access = ScoreDatabaseUtils.ConvertToScoreAccess(response.dynamoDbScore.Access); return(snapshot, access); }
public async Task CreateAsyncTest() { var accessKey = "minio_test"; var secretKey = "minio_test_pass"; var s3ClientFactory = new S3ClientFactory() .SetEndpointUrl(new Uri("http://localhost:19000")) .SetCredentials(new BasicAWSCredentials(accessKey, secretKey)); var dynamoDbClientFactory = new DynamoDbClientFactory().SetEndpointUrl(new Uri("http://localhost:18000")); var configuration = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary <string, string>() { [EnvironmentNames.ScoreDynamoDbTableName] = ScoreTableName, [EnvironmentNames.ScoreLargeDataDynamoDbTableName] = ScoreTableName, [EnvironmentNames.ScoreItemDynamoDbTableName] = ScoreTableName, [EnvironmentNames.ScoreItemRelationDynamoDbTableName] = ScoreTableName, [EnvironmentNames.ScoreItemS3Bucket] = ScoreBucket, [EnvironmentNames.ScoreDataSnapshotS3Bucket] = ScoreBucket, }) .Build(); var serviceCollection = new ServiceCollection(); serviceCollection.AddSingleton(dynamoDbClientFactory.Create()); serviceCollection.AddSingleton(s3ClientFactory.Create()); serviceCollection.AddSingleton <ScoreQuota>(); serviceCollection.AddSingleton <IConfiguration>(configuration); serviceCollection.AddScoped <Initializer>(); serviceCollection.AddScoped <ScoreSnapshotCreator>(); serviceCollection.AddScoped <ScoreSnapshotRemover>(); await using var provider = serviceCollection.BuildServiceProvider(); var initializer = provider.GetRequiredService <Initializer>(); var creator = provider.GetRequiredService <ScoreSnapshotCreator>(); var deleter = provider.GetRequiredService <ScoreSnapshotRemover>(); var ownerId = Guid.Parse("80b16bc7-5258-441f-9a2a-d6d95fc16c4a"); var scoreId = Guid.Parse("fc4ac609-0914-4cd6-9caa-cada12c7b03d"); var snapshotId = Guid.Parse("3dd43d78-ff83-46f5-8ed3-fddbc06ec943"); var data = new ScoreSnapshotDetail() { Id = snapshotId, Name = "スナップショット名", Data = new ScoreData() { Title = "楽譜", DescriptionHash = "楽譜の説明", Annotations = new [] { new ScoreAnnotation() { Id = 0, ContentHash = "hash00", }, new ScoreAnnotation() { Id = 1, ContentHash = "hash01", }, }, Pages = new [] { new ScorePage() { Id = 0, Page = "page1", ItemId = new Guid("3b74ca20-0e47-49b4-941f-45176766ae7d"), }, new ScorePage() { Id = 1, Page = "page2", ItemId = new Guid("e3c0a4a6-344d-4247-9932-070ae822186b"), }, }, }, HashSet = new Dictionary <string, string>() { ["hash00"] = "アノテーション1", ["hash01"] = "アノテーション2", }, }; await creator.CreateSnapshotItemAsync(ownerId, scoreId, data, ScoreObjectAccessControls.Public); }
public async Task DeleteAllAsyncTest() { var accessKey = "minio_test"; var secretKey = "minio_test_pass"; var s3ClientFactory = new S3ClientFactory() .SetEndpointUrl(new Uri("http://localhost:19000")) .SetCredentials(new BasicAWSCredentials(accessKey, secretKey)); var dynamoDbClientFactory = new DynamoDbClientFactory().SetEndpointUrl(new Uri("http://localhost:18000")); var configuration = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary <string, string>() { [EnvironmentNames.ScoreDynamoDbTableName] = ScoreTableName, [EnvironmentNames.ScoreLargeDataDynamoDbTableName] = ScoreTableName, [EnvironmentNames.ScoreItemDynamoDbTableName] = ScoreTableName, [EnvironmentNames.ScoreItemRelationDynamoDbTableName] = ScoreTableName, [EnvironmentNames.ScoreItemS3Bucket] = ScoreBucket, [EnvironmentNames.ScoreDataSnapshotS3Bucket] = ScoreBucket, }) .Build(); var serviceCollection = new ServiceCollection(); serviceCollection.AddSingleton(dynamoDbClientFactory.Create()); serviceCollection.AddSingleton(s3ClientFactory.Create()); serviceCollection.AddSingleton <ScoreQuota>(); serviceCollection.AddSingleton <IConfiguration>(configuration); serviceCollection.AddScoped <Initializer>(); serviceCollection.AddScoped <ScoreSnapshotCreator>(); serviceCollection.AddScoped <ScoreDeleter>(); await using var provider = serviceCollection.BuildServiceProvider(); var initializer = provider.GetRequiredService <Initializer>(); var creator = provider.GetRequiredService <ScoreSnapshotCreator>(); var deleter = provider.GetRequiredService <ScoreDeleter>(); var ownerId = Guid.Parse("e9ca7322-9dd6-4429-b1d8-d3c9244a68ed"); var scoreId = Guid.Parse("eea7e8c1-15ec-4f69-a675-364f24099267"); var snapshotIds = new[] { Guid.Parse("0ea2f185-8355-439c-a427-d5734c17f886"), Guid.Parse("18be42eb-de3c-4899-bdc3-7ed512ce07ae"), Guid.Parse("7569ad9a-1bb4-4c33-9cb8-11e5c680a404"), }; var data = new ScoreSnapshotDetail() { Name = "スナップショット名(delete all)", Data = new ScoreData() { Title = "楽譜", DescriptionHash = "楽譜の説明", Annotations = new [] { new ScoreAnnotation() { Id = 0, ContentHash = "hash00", }, new ScoreAnnotation() { Id = 1, ContentHash = "hash01", }, }, Pages = new [] { new ScorePage() { Id = 0, Page = "page1", ItemId = new Guid("3b74ca20-0e47-49b4-941f-45176766ae7d"), }, new ScorePage() { Id = 1, Page = "page2", ItemId = new Guid("e3c0a4a6-344d-4247-9932-070ae822186b"), }, }, }, HashSet = new Dictionary <string, string>() { ["hash00"] = "アノテーション1", ["hash01"] = "アノテーション2", }, }; try { foreach (var snapshotId in snapshotIds) { data.Id = snapshotId; await creator.CreateSnapshotItemAsync(ownerId, scoreId, data, ScoreObjectAccessControls.Public); } } catch { // 握りつぶす } await deleter.DeleteAllSnapshotAsync(ownerId, scoreId); }
public async Task DeleteAsyncTest() { var accessKey = "minio_test"; var secretKey = "minio_test_pass"; var s3ClientFactory = new S3ClientFactory() .SetEndpointUrl(new Uri("http://localhost:19000")) .SetCredentials(new BasicAWSCredentials(accessKey, secretKey)); var dynamoDbClientFactory = new DynamoDbClientFactory().SetEndpointUrl(new Uri("http://localhost:18000")); var configuration = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary <string, string>() { [EnvironmentNames.ScoreDynamoDbTableName] = ScoreTableName, [EnvironmentNames.ScoreLargeDataDynamoDbTableName] = ScoreTableName, [EnvironmentNames.ScoreItemDynamoDbTableName] = ScoreTableName, [EnvironmentNames.ScoreItemRelationDynamoDbTableName] = ScoreTableName, [EnvironmentNames.ScoreItemS3Bucket] = ScoreBucket, [EnvironmentNames.ScoreDataSnapshotS3Bucket] = ScoreBucket, }) .Build(); var serviceCollection = new ServiceCollection(); serviceCollection.AddSingleton(dynamoDbClientFactory.Create()); serviceCollection.AddSingleton(s3ClientFactory.Create()); serviceCollection.AddSingleton <ScoreQuota>(); serviceCollection.AddSingleton <IConfiguration>(configuration); serviceCollection.AddScoped <Initializer>(); serviceCollection.AddScoped <ScoreSnapshotCreator>(); serviceCollection.AddScoped <ScoreSnapshotRemover>(); await using var provider = serviceCollection.BuildServiceProvider(); var initializer = provider.GetRequiredService <Initializer>(); var creator = provider.GetRequiredService <ScoreSnapshotCreator>(); var deleter = provider.GetRequiredService <ScoreSnapshotRemover>(); var ownerId = Guid.Parse("31937be9-d1df-4076-b2b6-9cb5e2d94a17"); var scoreId = Guid.Parse("8a9aaa16-2ca2-4b22-9cf5-21e7b681dbc9"); var snapshotId = Guid.Parse("f30cd5f5-b807-4273-9299-f95d0baf85b9"); var data = new ScoreSnapshotDetail() { Id = snapshotId, Name = "スナップショット名(delete)", Data = new ScoreData() { Title = "楽譜", DescriptionHash = "楽譜の説明", Annotations = new [] { new ScoreAnnotation() { Id = 0, ContentHash = "hash00", }, new ScoreAnnotation() { Id = 1, ContentHash = "hash01", }, }, Pages = new [] { new ScorePage() { Id = 0, Page = "page1", ItemId = new Guid("3b74ca20-0e47-49b4-941f-45176766ae7d"), }, new ScorePage() { Id = 1, Page = "page2", ItemId = new Guid("e3c0a4a6-344d-4247-9932-070ae822186b"), }, }, }, HashSet = new Dictionary <string, string>() { ["hash00"] = "アノテーション1", ["hash01"] = "アノテーション2", }, }; try { await creator.CreateSnapshotItemAsync(ownerId, scoreId, data, ScoreObjectAccessControls.Public); } catch { // 握りつぶす } await deleter.DeleteSnapshotAsync(ownerId, scoreId, snapshotId); }
public static byte[] ConvertToJson(ScoreSnapshotDetail snapshotDetail) { var option = new JsonSerializerOptions() { AllowTrailingCommas = false, DictionaryKeyPolicy = default,