示例#1
0
        private void ListBucket(String bucketName)
        {
            try
            {
                this.listBoxObjects.Items.Clear();

                // The first thing we need to do is check for the presence of a Temporary Redirect.  These occur for a few
                // minutes after an EU bucket is created, while S3 creates the DNS entries.  If we get one, we need to pull
                // the bucket listing from the redirect URL

                String redirectUrl = null;
                using (BucketListRequest testRequest = new BucketListRequest(bucketName))
                {
                    testRequest.Method = "HEAD";
                    using (BucketListResponse testResponse = service.BucketList(testRequest))
                    {
                        if (testResponse.StatusCode == System.Net.HttpStatusCode.TemporaryRedirect)
                        {
                            redirectUrl = testResponse.Headers["Location"].ToString();
                        }
                    }
                }

                bool   isTruncated = true;
                string marker      = string.Empty;

                // The while-loop is here because S3 will only return a maximum of 1000 items at a time, so if the list
                // was truncated, we need to make another call and get the rest
                while (isTruncated)
                {
                    using (BucketListRequest request = new BucketListRequest(bucketName))
                    {
                        request.RedirectUrl = redirectUrl;
                        if (!string.IsNullOrEmpty(marker))
                        {
                            request.QueryList.Add("marker", marker);
                        }
                        using (BucketListResponse response = service.BucketList(request))
                        {
                            XmlDocument bucketXml = response.StreamResponseToXmlDocument();

                            XmlNodeList objects = bucketXml.SelectNodes("//*[local-name()='Key']");
                            foreach (XmlNode obj in objects)
                            {
                                marker = obj.InnerText;
                                this.listBoxObjects.Items.Add(marker);
                            }

                            isTruncated = bool.Parse(bucketXml.SelectSingleNode("//*[local-name()='IsTruncated']").InnerXml);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#2
0
        private void BindBucketNames()
        {
            this.comboBoxBucketNames.Items.Clear();

            using (BucketListRequest request = new BucketListRequest(null))
                using (BucketListResponse response = service.BucketList(request))
                {
                    XmlDocument bucketXml = response.StreamResponseToXmlDocument();

                    XmlNodeList buckets = bucketXml.SelectNodes("//*[local-name()='Name']");
                    foreach (XmlNode bucket in buckets)
                    {
                        this.comboBoxBucketNames.Items.Add(bucket.InnerXml);
                    }
                }
        }