Пример #1
0
        public async Task <List <Bucket> > ListBucketsAsync()
        {
            ListAllMyBucketsResult list = await _client.ListBucketsAsync();

            if (list == null)
            {
                throw new Exception("List buckets failed, result obj is null");
            }
            List <Bucket> result = new List <Bucket>();

            foreach (var item in list.Buckets)
            {
                result.Add(new Bucket()
                {
                    Name         = item.Name,
                    Location     = Options.Region,
                    CreationDate = item.CreationDate,
                    Owner        = new Owner()
                    {
                        Id   = Options.AccessKey,
                        Name = Options.AccessKey,
                    }
                });
            }
            return(result);
        }
Пример #2
0
        public async Task <String> ListAllBuckets()
        {
            var endpoint  = "127.0.0.1:9000";
            var accessKey = "VDX5QGGFWH9HFGCQXY42";
            var secretKey = "FSDxipLeNUX7E8Y6ttsXVhaTyGe6mnlCHsP1xWKW";
            var minio     = new MinioClient(endpoint, accessKey, secretKey);

            List <String> rez = new List <String>();

            try
            {
                var getListBucketsTask = await minio.ListBucketsAsync();

                //   List<Bucket> b = getListBucketsTask.Result.Buckets;

                foreach (Bucket bucket in getListBucketsTask.Buckets)
                {
                    rez.Add(bucket.Name.ToString());
                    //  await minio.MakeBucketAsync(bucket.Name.ToString()+"/testBucket");
                }
            }
            catch (MinioException e)
            {
                Console.WriteLine("File Upload Error: {0}", e.Message);
            }
            String json = new JavaScriptSerializer().Serialize(rez);

            return(json);
        }
Пример #3
0
        public async Task <List <BucketInfo> > ListBucketAsync(ListBucketParam param)
        {
            try
            {
                ListAllMyBucketsResult allMyBuckets = await _minio.ListBucketsAsync();

                List <BucketInfo> bucketInfos = new List <BucketInfo>();
                foreach (var bucket in allMyBuckets.Buckets)
                {
                    if (!string.IsNullOrEmpty(param.Keyword) && !bucket.Name.Contains(param.Keyword))
                    {
                        continue;
                    }

                    bucketInfos.Add(new BucketInfo()
                    {
                        BucketName       = bucket.Name,
                        CreationDateTime = bucket.CreationDateDateTime
                    });
                }

                return(bucketInfos);
            }
            catch (Exception exception)
            {
                //SentrySdk.CaptureException(exception);
                throw;
            }
        }
Пример #4
0
 /// <summary>
 /// 获取所有Bucket桶
 /// </summary>
 /// <returns></returns>
 public async Task <ListAllMyBucketsResult> ListBucketsAsync()
 {
     try
     {
         return(await _minioClient.ListBucketsAsync());
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Пример #5
0
        public MinioServiceController()
        {
            minio = new MinioClient(endpoint, accessKey, secretKey);

            var getListBucketsTask = minio.ListBucketsAsync();

            // Iterate over the list of buckets.
            foreach (Bucket bucket in getListBucketsTask.Result.Buckets)
            {
                Console.Out.WriteLine(bucket.Name + " " + bucket.CreationDateDateTime);
            }
        }
Пример #6
0
        static void Main(string[] args)
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
                                                   | SecurityProtocolType.Tls11
                                                   | SecurityProtocolType.Tls12;

            /// Note: s3 AccessKey and SecretKey needs to be added in App.config file
            /// See instructions in README.md on running examples for more information.
            var minio = new MinioClient()
                        .WithEndpoint("play.min.io")
                        .WithCredentials("Q3AM3UQ867SPQQA43P2F",
                                         "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
                        .WithSSL()
                        .Build();
            var getListBucketsTask = minio.ListBucketsAsync();

            try
            {
                Task.WaitAll(getListBucketsTask); // block while the task completes
            }
            catch (AggregateException aggEx)
            {
                aggEx.Handle(HandleBatchExceptions);
            }

            var list = getListBucketsTask.Result;

            foreach (Bucket bucket in list.Buckets)
            {
                Console.WriteLine(bucket.Name + " " + bucket.CreationDateDateTime);
            }

            //Supply a new bucket name
            string bucketName = "mynewbucket";

            if (isBucketExists(minio, bucketName))
            {
                RemoveBucketArgs remBuckArgs = new Minio.RemoveBucketArgs()
                                               .WithBucket(bucketName);
                var removeBucketTask = minio.RemoveBucketAsync(remBuckArgs);
                Task.WaitAll(removeBucketTask);
            }

            MakeBucketArgs mkBktArgs = new MakeBucketArgs()
                                       .WithBucket(bucketName);

            Task.WaitAll(minio.MakeBucketAsync(mkBktArgs));

            bool found = isBucketExists(minio, bucketName);

            Console.WriteLine("Bucket exists? = " + found);
            Console.ReadLine();
        }
Пример #7
0
        public async Task <List <string> > TestMinio()
        {
            try
            {
                var minio = new MinioClient("http://52.187.28.154:9001",
                                            "W9J5XIE4M3T0YVSR52V7",
                                            "xmrPyNhU2VolKQTrxYAKk+te4peBJZzSW1M7WxjU"
                                            );

                try
                {
                    // Create bucket if it doesn't exist.
                    bool found = await minio.BucketExistsAsync("mybucket");

                    if (found)
                    {
                        Console.Out.WriteLine("mybucket already exists");
                    }
                    else
                    {
                        // Create bucket 'my-bucketname'.
                        await minio.MakeBucketAsync("mybucket");

                        Console.Out.WriteLine("mybucket is created successfully");
                    }
                }
                catch (MinioException e)
                {
                    Console.Out.WriteLine("Error occurred: " + e);
                }

                var getListBucketsTask = minio.ListBucketsAsync();
                var list = new List <string>();

                foreach (Bucket bucket in getListBucketsTask.Result.Buckets)
                {
                    list.Add(bucket.Name + " " + bucket.CreationDate);
                }

                return(list);
            }
            catch (Exception e1)
            {
                return(new List <string>()
                {
                    e1.Message + "<br>" + e1.StackTrace
                });
            }
        }
        // Check if a bucket exists
        public async static Task Run(MinioClient minio)
        {
            try
            {
                Console.WriteLine("Running example for: set custom request logger");
                minio.SetTraceOn(new MyRequestLogger());
                await minio.ListBucketsAsync();

                minio.SetTraceOff();
                Console.WriteLine();
            }
            catch (Exception e)
            {
                Console.WriteLine($"[Bucket]  Exception: {e}");
            }
        }
Пример #9
0
        static void Main(string[] args)
        {
            /// Note: s3 AccessKey and SecretKey needs to be added in App.config file
            /// See instructions in README.md on running examples for more information.
            //var minio = new MinioClient(ConfigurationManager.AppSettings["Endpoint"],
            //                                 ConfigurationManager.AppSettings["AccessKey"],
            //                                 ConfigurationManager.AppSettings["SecretKey"]).WithSSL();
            //ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
            //                                      | SecurityProtocolType.Tls11
            //                                      | SecurityProtocolType.Tls12;
            var minio = new MinioClient(ConfigurationManager.AppSettings["Endpoint"],
                                        ConfigurationManager.AppSettings["AccessKey"],
                                        ConfigurationManager.AppSettings["SecretKey"]);


            var getListBucketsTask = minio.ListBucketsAsync();

            try
            {
                Task.WaitAll(getListBucketsTask); // block while the task completes
            }
            catch (AggregateException aggEx)
            {
                aggEx.Handle(HandleBatchExceptions);
            }
            var list = getListBucketsTask.Result;

            foreach (Bucket bucket in list.Buckets)
            {
                Console.Out.WriteLine(bucket.Name + " " + bucket.CreationDateDateTime);
            }

            var bucketExistTask = minio.BucketExistsAsync("mynewbucket");

            Task.WaitAll(bucketExistTask);
            var found = bucketExistTask.Result;

            if (!found)
            {
                // Supply a new bucket name
                Task.WaitAll(minio.MakeBucketAsync("mynewbucket"));
            }
            Console.Out.WriteLine("bucket was " + found);
            Console.ReadLine();
        }
Пример #10
0
        // List all buckets on host
        public async static Task Run(MinioClient minio)
        {
            try
            {
                Console.WriteLine("Running example for API: ListBucketsAsync");
                var list = await minio.ListBucketsAsync();

                foreach (var bucket in list.Buckets)
                {
                    Console.WriteLine($"{bucket.Name} {bucket.CreationDateDateTime}");
                }
                Console.WriteLine();
            }
            catch (Exception e)
            {
                Console.WriteLine($"[Bucket]  Exception: {e}");
            }
        }
Пример #11
0
        private async static Task ListBuckets_Test(MinioClient minio)
        {
            try
            {
                Console.Out.WriteLine("Test: ListBucketsAsync");
                var list = await minio.ListBucketsAsync();

                foreach (Bucket bucket in list.Buckets)
                {
                    // Ignore
                    continue;
                }
            }
            catch (Exception)
            {
                Assert.Fail();
            }
        }
Пример #12
0
        public void Show_All_Bucket()
        {
            try
            {
                Minio_connten_class minio_connten = new Minio_connten_class();
                MinioClient         minio_client  = minio_connten.Minio_connten();

                var getListBucketsTask = minio_client.ListBucketsAsync();

                foreach (Bucket bucket in getListBucketsTask.Result.Buckets)
                {
                    Console.WriteLine("BuckerName: {0}, Create Time: {1} \r\n", bucket.Name, bucket.CreationDateDateTime);
                }
            }
            catch (Exception Error)
            {
                Console.WriteLine(Error.Message);
            }
        }
Пример #13
0
        static void Main(string[] args)
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
                                                   | SecurityProtocolType.Tls11
                                                   | SecurityProtocolType.Tls12;


            /// Note: s3 AccessKey and SecretKey needs to be added in App.config file
            /// See instructions in README.md on running examples for more information.
            var minio = new MinioClient("play.min.io:9000",
                                        "Q3AM3UQ867SPQQA43P2F",
                                        "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG").WithSSL();

            var getListBucketsTask = minio.ListBucketsAsync();

            try
            {
                Task.WaitAll(getListBucketsTask); // block while the task completes
            }
            catch (AggregateException aggEx)
            {
                aggEx.Handle(HandleBatchExceptions);
            }
            var list = getListBucketsTask.Result;

            foreach (Bucket bucket in list.Buckets)
            {
                Console.Out.WriteLine(bucket.Name + " " + bucket.CreationDateDateTime);
            }

            //Supply a new bucket name
            Task.WaitAll(minio.MakeBucketAsync("mynewbucket"));

            var bucketExistTask = minio.BucketExistsAsync("mynewbucket");

            Task.WaitAll(bucketExistTask);
            var found = bucketExistTask.Result;

            Console.Out.WriteLine("bucket was " + found);
            Console.ReadLine();
        }
Пример #14
0
        public async Task CreateAndListBuckets()
        {
            var minio = new MinioClient(Endpoint, AccessKey, SecretKey) /*.WithSSL()*/;

            var listBucketsResult = await minio.ListBucketsAsync();

            for (var i = 0; i < 10; i++)
            {
                var bucketName = "bucket" + i;

                if (await minio.BucketExistsAsync(bucketName) == false)
                {
                    await minio.MakeBucketAsync(bucketName);
                }
            }

            foreach (var bucket in listBucketsResult.Buckets)
            {
                Console.WriteLine(bucket.Name + " " + bucket.CreationDateDateTime);
            }
        }
Пример #15
0
        static void Main(string[] args)
        {
            try
            {
                var bucketList = minio.ListBucketsAsync().Result;
                //获取分类列表
                foreach (Bucket bucket in bucketList.Buckets)
                {
                    Console.WriteLine("-" + bucket.Name + " " + bucket.CreationDateDateTime);
                    //获取文件列表
                    minio.ListObjectsAsync(bucket.Name).Subscribe(new MyObserver());
                }

                Console.Read();

                //上传文件
                var bucketName = bucketList.Buckets.FirstOrDefault().Name;

                /*
                 *
                 * var fileName = "test.txt";
                 * var filePath = @"D:\MinIO\test\test.txt";
                 * var contentType = "";
                 * minio.PutObjectAsync(bucketName, fileName, filePath).GetAwaiter().GetResult();
                 * Console.WriteLine("Successfully uploaded " + fileName);
                 */

                //bucket policy
                var policy = minio.GetPolicyAsync(bucketName).Result;


                Console.WriteLine(policy);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            Console.Read();
        }
Пример #16
0
        // Returns ObservableCollection of "Buckets"(MinioTApp2.Models.Models.Buckets) which stored on remote server
        public ObservableCollection <MinioBucketModel> getListBuckets()
        {
            ObservableCollection <MinioBucketModel> buckets = new ObservableCollection <MinioBucketModel>();

            // Start function in other thread
            var getListBucketsTask = minio.ListBucketsAsync();

            // Create an async task for listing buckets.
            try
            {
                Task.WaitAll(getListBucketsTask); // block while the task completes
            }
            catch (AggregateException aggEx)
            {
                aggEx.Handle(HandleBatchExceptions);
            }
            //Iterate over the list of buckets.
            foreach (Bucket bucketObj in getListBucketsTask.Result.Buckets)
            {
                buckets.Add(new MinioBucketModel(bucketObj.Name, bucketObj.CreationDate));
            }
            return(buckets);
        }
Пример #17
0
        public async Task <IEnumerable <string> > ListBuckets()
        {
            var buckets = await _client.ListBucketsAsync();

            return(buckets.Buckets.Select(b => b.Name));
        }
Пример #18
0
 /// <summary>
 /// Cria um balde de forma assincrona no servidor.
 /// </summary>
 /// <param name="bucketName">Nome da carteira a ser criada.</param>
 public Task <ListAllMyBucketsResult> ListAllAsync()
 {
     ValidateInstance();
     return(_minioClient.ListBucketsAsync());
 }
Пример #19
0
        public List <Bucket> GetBucketList()
        {
            var list = _minioClient.ListBucketsAsync().Result;

            return(list.Buckets);
        }
Пример #20
0
 /// <summary>
 /// Cria um balde de forma assincrona no servidor.
 /// </summary>
 /// <param name="bucketName">Nome da carteira a ser criada.</param>
 public async Task <ListAllMyBucketsResult> ListAllAsync()
 {
     ValidateInstance();
     return(await _minioClient.ListBucketsAsync().ConfigureAwait(false));
 }