Пример #1
0
 private static dynamic CreateBucket()
 {
     try {
         Console.WriteLine("**** Creating bucket: " + BucketKey);
         PostBucketsPayload.PolicyKeyEnum bucketType = PostBucketsPayload.PolicyKeyEnum.Persistent;
         PostBucketsPayload payload  = new PostBucketsPayload(BucketKey, null, bucketType);
         dynamic            response = BucketAPI.CreateBucketAsyncWithHttpInfo(payload, region.ToString());
         return(response);
     } catch (Exception) {
         Console.WriteLine("**** Failed creating bucket: " + BucketKey);
         return(null);
     }
 }
Пример #2
0
        private async void CreateBucket_Click(object sender, RoutedEventArgs e)
        {
            Handled(e);
            CreateBucket wnd = new CreateBucket();

            wnd.Owner = this;
            Nullable <bool> dialogResult = wnd.ShowDialog();

            if (dialogResult.Value == false)
            {
                return;
            }

            try {
                BucketsApi ossBuckets = new BucketsApi();
                ossBuckets.Configuration.AccessToken = accessToken;
                PostBucketsPayload.PolicyKeyEnum bucketType = (PostBucketsPayload.PolicyKeyEnum)Enum.Parse(typeof(PostBucketsPayload.PolicyKeyEnum), wnd.BucketType.Text, true);
                string                region   = wnd.BucketRegion.Text;
                PostBucketsPayload    payload  = new PostBucketsPayload(wnd.BucketName.Text, null, bucketType);
                ApiResponse <dynamic> response = await ossBuckets.CreateBucketAsyncWithHttpInfo(payload, region);

                httpErrorHandler(response, "Failed to create bucket");
                if (region == (string)ForgeRegion.SelectedItem)
                {
                    BucketsInRegion.Items.Add(wnd.BucketName.Text);
                    BucketsInRegion.SelectedItem = wnd.BucketName.Text;
                }
                else
                {
                    MessageBox.Show("Bucket successfully created!", APP_NAME, MessageBoxButton.OK, MessageBoxImage.Information);
                }
            } catch (ApiException apiex) {
                if (apiex.ErrorCode != 409)                   // Already exists - we're good
                {
                    MessageBox.Show("Exception when calling BucketsApi.CreateBucketAsyncWithHttpInfo: " + apiex.Message, APP_NAME, MessageBoxButton.OK, MessageBoxImage.Error);
                }
                else
                {
                    MessageBox.Show("This bucket already exist, choose another name!", APP_NAME, MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            } catch (Exception ex) {
                MessageBox.Show("Exception when calling BucketsApi.CreateBucketAsyncWithHttpInfo: " + ex.Message, APP_NAME, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }