Dispose() 보호된 메소드

Disposes the service client.
protected Dispose ( bool disposing ) : void
disposing bool
리턴 void
예제 #1
6
        public void RefreshAssetList()
        {
            string SecretKey = null;
            string PublicKey = null;
            AmazonS3Client Client = new AmazonS3Client(PublicKey, SecretKey);

            ListObjectsRequest Request = new ListObjectsRequest
            {
                BucketName = "assets.minecraft.net",
            };

            ListObjectsResponse Result;

            List<Release> releases = new List<Release>();
            do
            {
                Result = Client.ListObjects(Request);
                foreach (S3Object o in Result.S3Objects)
                {
                    string IsSnapshot = "Release";
                    if(!o.Key.Contains("minecraft.jar")) continue;
                    if (Regex.IsMatch(o.Key, "[0-9][0-9]w[0-9][0-9]")) IsSnapshot = "Snapshot";
                    else if (o.Key.Contains("pre")) IsSnapshot = "Pre-release";
                    releases.Add(new Release {  Version = o.Key.Split('/')[0],
                                                Size = (o.Size / 1024).ToString() + "KB",
                                                Uploaded = DateTime.Parse(o.LastModified),
                                                Type = IsSnapshot,
                                                Key = o.Key} );
                }
            }
            while (Result.IsTruncated);
            releases.Sort(new Comparison<Release>((x, y) => DateTime.Compare(y.Uploaded, x.Uploaded)));
            _Releases.Clear();
            foreach (Release r in releases)
            {
                _Releases.Add(r);
            }
            Client.Dispose();
            Result.Dispose();
        }
예제 #2
0
        public static async System.Threading.Tasks.Task <bool> Delete(this string fileNameGuid, string _awsAccessKey, string _awsSecretKey, string _bucketName)
        {
            IAmazonS3 client;
            var       s3Client = RegionEndpoint.USEast1;

            try
            {
                using (client = new Amazon.S3.AmazonS3Client(_awsAccessKey, _awsSecretKey, s3Client))
                {
                    DeleteObjectRequest request = new DeleteObjectRequest()
                    {
                        BucketName = _bucketName,
                        Key        = fileNameGuid,
                    };

                    await client.DeleteObjectAsync(request);

                    client.Dispose();
                }
            }
            catch (Exception exception)
            {
                Logging.Log("Upload Documents failure", "S3 File upload Extension Method", exception);
                return(false);
            }

            return(true);
        }
예제 #3
0
        public static void Main()
        {
            Debug.WriteLine("============================================");
            Debug.WriteLine("Welcome to the AWS .NET SDK! Ready, Set, Go!");
            Debug.WriteLine("============================================");

            //The Amazon S3 client allows you to manage buckets and objects programmatically.
            IAmazonS3 s3Client = new AmazonS3Client();

            try
            {
                ListBucketsResponse response = s3Client.ListBuckets();
                int numBuckets = 0;
                if (response.Buckets != null && response.Buckets.Count > 0)
                {
                    numBuckets = response.Buckets.Count;
                }
                Debug.WriteLine("You have " + numBuckets + " Amazon S3 bucket(s)");
            }
            catch (Amazon.S3.AmazonS3Exception S3Exception)
            {
                //AmazonServiceException represents an error response from an AWS service.
                //AWS service received the request but either found it invalid or encountered an error trying to execute it.
                if (S3Exception.ErrorCode != null && (S3Exception.ErrorCode.Equals("InvalidAccessKeyId") || S3Exception.ErrorCode.Equals("InvalidSecurity")))
                {
                    Debug.WriteLine("Please check the provided AWS Credentials.");
                    Debug.Write("If you haven't signed up for Amazon S3, please visit http://aws.amazon.com/s3");
                    Debug.WriteLine(S3Exception.Message, S3Exception.InnerException);
                }
                else
                {
                    Debug.WriteLine("Error Message:    " + S3Exception.Message);
                    Debug.WriteLine("HTTP Status Code: " + S3Exception.StatusCode);
                    Debug.WriteLine("AWS Error Code:   " + S3Exception.ErrorCode);
                    Debug.WriteLine("Request ID:       " + S3Exception.RequestId);
                }
            }
            finally
            {
                s3Client.Dispose();
            };
        }