예제 #1
0
        // Get Replication configuration assigned to the bucket
        public async static Task Run(MinioClient minio,
                                     string bucketName = "my-bucket-name")
        {
            try
            {
                Console.WriteLine("Running example for API: GetBucketReplicationConfiguration");
                var repl = await minio.GetBucketReplicationAsync(
                    new GetBucketReplicationArgs()
                    .WithBucket(bucketName)
                    );

                if (repl != null && repl.Rules != null && repl.Rules.Count > 0)
                {
                    Console.WriteLine($"Got Bucket Replication Configuration set for bucket {bucketName}.");
                    foreach (var rule in repl.Rules)
                    {
                        Console.WriteLine("ID: " + rule.ID + ", Status: " + rule.Status);
                    }
                    Console.WriteLine();
                    return;
                }
                Console.WriteLine($"Bucket Replication Configuration not set for bucket {bucketName}.");
                Console.WriteLine();
            }
            catch (Exception e)
            {
                Console.WriteLine($"[Bucket]  Exception: {e}");
            }
        }
    // Get Replication configuration assigned to the bucket
    public static async Task Run(MinioClient minio,
                                 string bucketName        = "my-bucket-name",
                                 string replicationRuleID = "my-replication-rule-ID")
    {
        try
        {
            Console.WriteLine("Running example for API: GetBucketReplicationConfiguration");
            var repl = await minio.GetBucketReplicationAsync(
                new GetBucketReplicationArgs()
                .WithBucket(bucketName)
                );

            if (repl != null && repl.Rules != null && repl.Rules.Count > 0)
            {
                Console.WriteLine($"Got Bucket Replication Configuration set for bucket {bucketName}.");
                foreach (var rule in repl.Rules)
                {
                    if (rule.ID != replicationRuleID)
                    {
                        // failed test due to replication rule id mismatch
                        var errMessage = "Unexpected replication rule ID: " +
                                         $"expected: {replicationRuleID}, got: {rule.ID}";
                        throw new UnexpectedMinioException(errMessage);
                    }

                    Console.WriteLine("ID: " + rule.ID + ", Status: " + rule.Status);
                }

                Console.WriteLine();
                return;
            }

            Console.WriteLine();
        }
        catch (MissingBucketReplicationConfigurationException)
        {
            Console.WriteLine($"[Bucket] Exception: Replication Configuration not set for bucket {bucketName}.");
        }
        catch (Exception e)
        {
            Console.WriteLine($"[Bucket]  Exception: {e}");
        }
    }