Пример #1
0
 public IEnumerable <S3Bucket> GetBuckets()
 {
     using (var request = new BucketListRequest(null))
         using (var response = client.BucketList(request))
         {
             var xml = response.StreamResponseToString();
             return(XDocument.Parse(xml)
                    .Root
                    .Element(GetXName("Buckets"))
                    .Elements()
                    .Select(e => new S3Bucket(GetElementValue(e, "Name"), DateTime.Parse(GetElementValue(e, "CreationDate")))));
         }
 }
Пример #2
0
        private void buttonDeleteObject_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.listBoxObjects.SelectedItem == null)
                {
                    return;
                }

                ConfirmDeleteForm confirmDeleteForm = new ConfirmDeleteForm(this.listBoxObjects.SelectedItem.ToString());
                if (confirmDeleteForm.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                // 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 delete
                // the file from the redirect URL

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

                using (ObjectDeleteRequest request = new ObjectDeleteRequest(this.comboBoxBucketNames.SelectedItem.ToString(), this.listBoxObjects.SelectedItem.ToString()))
                {
                    request.RedirectUrl = redirectUrl;
                    using (ObjectDeleteResponse response = service.ObjectDelete(request))
                    { }
                }
                this.ListBucket(this.comboBoxBucketNames.SelectedItem.ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }