public async Task <IList <TreeNode> > GetTreeDataAsync([FromUri] string id) { IList <TreeNode> nodes = new List <TreeNode>(); dynamic oauth = await Utility.OAuth.Get2LeggedTokenAsync(new Scope[] { Scope.BucketRead, Scope.DataRead }); if (id == "#") // root { // in this case, let's return all buckets BucketsApi appBckets = new BucketsApi(); appBckets.Configuration.AccessToken = oauth.access_token; dynamic buckets = await appBckets.GetBucketsAsync(Enum.GetName(typeof(Utility.Buckets.Region), Utility.Buckets.Region.US), 100); foreach (KeyValuePair <string, dynamic> bucket in new DynamicDictionaryItems(buckets.items)) { nodes.Add(new TreeNode(bucket.Value.bucketKey, bucket.Value.bucketKey, "bucket", true)); } } else { // as we have the id (bucketKey), let's return all ObjectsApi objects = new ObjectsApi(); objects.Configuration.AccessToken = oauth.access_token; var objectsList = objects.GetObjects(id); foreach (KeyValuePair <string, dynamic> objInfo in new DynamicDictionaryItems(objectsList.items)) { nodes.Add(new TreeNode(((string)objInfo.Value.objectId).Base64Encode(), objInfo.Value.objectKey, "object", false)); } } return(nodes); }
private async Task <string> GetBuckets(string region, string startAt = null, int limit = 10) { try { BucketsApi ossBuckets = new BucketsApi(); ossBuckets.Configuration.AccessToken = accessToken; ApiResponse <dynamic> response = await ossBuckets.GetBucketsAsyncWithHttpInfo( region, limit, startAt ); httpErrorHandler(response, "Failed to access bucket list"); foreach (KeyValuePair <string, dynamic> objInfo in new DynamicDictionaryItems(response.Data.items)) { _bucketsCache [region].Add(objInfo.Value.bucketKey); } if (!hasOwnProperty(response.Data, "next")) { return(null); } var uri = new Uri(response.Data.next); NameValueCollection url_parts = System.Web.HttpUtility.ParseQueryString(uri.Query); return(url_parts ["startAt"]); } catch (Exception ex) { Debug.WriteLine(ex.Message); } return(null); }
public async Task <List <string> > GetBuckets() { var isAuthorized = await IsAuthorized(); if (!isAuthorized) { _logger.Log(LogType.Error, "Cannot be authorized for getting buckets"); return(null); } var bucketList = new List <string>(); var bucketApi = new BucketsApi { Configuration = { AccessToken = AuthenticationToken.AccessToken } }; dynamic buckets; try { buckets = await bucketApi.GetBucketsAsync(); } catch (Exception e) { _logger.Log(LogType.Error, "Exception when getting Buckets: " + e); return(null); } foreach (KeyValuePair <string, dynamic> bucket in new DynamicDictionaryItems(buckets.items)) { bucketList.Add(bucket.Value.bucketKey); } return(bucketList); }
public async Task <bool> CreateBucket(string bucketKey) { if (bucketKey == null) { throw new ArgumentNullException("bucketKey"); } var isAuthorized = await IsAuthorized(); if (!isAuthorized) { _logger.Log(LogType.Error, "Cannot be authorized for creating bucket"); return(false); } var bucketsApi = new BucketsApi { Configuration = { AccessToken = AuthenticationToken.AccessToken } }; var postBuckets = new PostBucketsPayload(bucketKey.ToLower(), null, PostBucketsPayload.PolicyKeyEnum.Transient); try { await bucketsApi.CreateBucketAsync(postBuckets); } catch (Exception e) { _logger.Log(LogType.Error, "Exception when creating the Bucket: " + e); return(false); } return(true); }
private async void btnRefreshToken_Click(object sender, EventArgs e) { treeBuckets.Nodes.Clear(); BucketsApi bucketApi = new BucketsApi(); bucketApi.Configuration.AccessToken = AccessToken; // control GetBucket pagination string lastBucket = null; Buckets buckets = null; do { buckets = (await bucketApi.GetBucketsAsync(cmbRegion.Text, 100, lastBucket)).ToObject <Buckets>(); foreach (var bucket in buckets.Items) { TreeNode nodeBucket = new TreeNode(bucket.BucketKey); nodeBucket.Tag = bucket.BucketKey; treeBuckets.Nodes.Add(nodeBucket); lastBucket = bucket.BucketKey; // after the loop, this will contain the last bucketKey } } while (buckets.Items.Count > 0); // for each bucket, show the objects foreach (TreeNode n in treeBuckets.Nodes) { if (n != null) // async? { await ShowBucketObjects(n); } } }
/// <summary> /// The RunAsync. /// </summary> /// <returns>The <see cref="Task"/>.</returns> public async Task RunAsync() { if (string.IsNullOrEmpty(Owner)) { Console.WriteLine("Please provide non-empty Owner."); return; } if (string.IsNullOrEmpty(UploadUrl)) { Console.WriteLine($"Creating Bucket...."); dynamic oauth = await GetInternalAsync(); // 1. ensure bucket existis string bucketKey = Owner.ToLower(); Console.WriteLine($"Creating Bucket {bucketKey}...."); BucketsApi buckets = new BucketsApi(); buckets.Configuration.AccessToken = oauth.access_token; try { PostBucketsPayload bucketPayload = new PostBucketsPayload(bucketKey, null, PostBucketsPayload.PolicyKeyEnum.Transient); dynamic bucketsRes = await buckets.CreateBucketAsync(bucketPayload, "US"); } catch { // in case bucket already exists Console.WriteLine($"\tBucket {bucketKey} exists"); }; ObjectsApi objects = new ObjectsApi(); objects.Configuration.AccessToken = oauth.access_token; //2. Upload input file and get signed URL string inputFileNameOSS = string.Format("{0}_input_{1}", DateTime.Now.ToString("yyyyMMddhhmmss"), Path.GetFileName(FilePaths.InputFile)); Console.WriteLine($"Uploading input file {inputFileNameOSS} to {bucketKey}..... "); using (StreamReader streamReader = new StreamReader(FilePaths.InputFile)) { dynamic res = await objects.UploadObjectAsync(bucketKey, inputFileNameOSS, (int)streamReader.BaseStream.Length, streamReader.BaseStream, "application/octet-stream"); } try { PostBucketsSigned bucketsSigned = new PostBucketsSigned(60); dynamic signedResp = await objects.CreateSignedResourceAsync(bucketKey, inputFileNameOSS, bucketsSigned, "read"); downloadUrl = signedResp.signedUrl; Console.WriteLine($"\tSuccess: File uploaded to... \n\t{downloadUrl}"); } catch { } } if (!await SetupOwnerAsync()) { Console.WriteLine("Exiting."); return; } await SubmitWorkItemAsync(ActivityName); }
public async Task <dynamic> CreateBucket([FromBody] BucketModel bucket) { dynamic NewBucket = null; BucketsApi buckets = new BucketsApi(); dynamic token = await OAuthController.GetInternalAsync(); buckets.Configuration.AccessToken = token.access_token; PostBucketsPayload bucketPayload = new PostBucketsPayload(string.Format("{0}-{1}", ClientId, bucket.bucketKey.ToLower()), null, PostBucketsPayload.PolicyKeyEnum.Transient); try { NewBucket = await buckets.CreateBucketAsync(bucketPayload, bucketRegion); } catch (Exception e) { if (e.Message == "Error calling CreateBucket: {\"reason\":\"Bucket already exists\"}") { dynamic allBuckets = await buckets.GetBucketsAsync("US", 100); foreach (KeyValuePair <string, dynamic> actualBucket in new DynamicDictionaryItems(allBuckets.items)) { string bucketName = actualBucket.Value.bucketKey; if (bucketName.Contains(BucketName)) //kitchenconfig designautomation { NewBucket = actualBucket; } } } } return(NewBucket); }
public async Task <IList <TreeNode> > GetOSSAsync(string id) { IList <TreeNode> nodes = new List <TreeNode>(); dynamic oauth = await OAuthController.GetInternalAsync(); if (id == "#") // root { // in this case, let's return all buckets BucketsApi appBckets = new BucketsApi(); appBckets.Configuration.AccessToken = oauth.access_token; // to simplify, let's return only the first 100 buckets dynamic buckets = await appBckets.GetBucketsAsync("US", 100); string clientId = await GetClientIdAsync(); foreach (KeyValuePair <string, dynamic> bucket in new DynamicDictionaryItems(buckets.items)) { nodes.Add(new TreeNode(bucket.Value.bucketKey, bucket.Value.bucketKey.Replace(clientId + "-", string.Empty), "bucket", true)); } } else { // as we have the id (bucketKey), let's return all ObjectsApi objects = new ObjectsApi(); objects.Configuration.AccessToken = oauth.access_token; var objectsList = objects.GetObjects(id); foreach (KeyValuePair <string, dynamic> objInfo in new DynamicDictionaryItems(objectsList.items)) { nodes.Add(new TreeNode(Base64Encode((string)objInfo.Value.objectId), objInfo.Value.objectKey, "object", false)); } } return(nodes); }
public async void DeleteBucket([FromBody] DeleteBucketModel bucket) { BucketsApi buckets = new BucketsApi(); dynamic token = await OAuthController.GetInternalAsync(); buckets.Configuration.AccessToken = token.access_token; buckets.DeleteBucket(bucket.bucketKey); }
public async Task<dynamic> CreateBucket([FromBody] CreateBucketModel bucket) { BucketsApi buckets = new BucketsApi(); dynamic token = await OAuthController.GetInternalAsync(); buckets.Configuration.AccessToken = token.access_token; PostBucketsPayload bucketPayload = new PostBucketsPayload(string.Format("{0}-{1}", ClientId, bucket.bucketKey.ToLower()), null, PostBucketsPayload.PolicyKeyEnum.Transient); return await buckets.CreateBucketAsync(bucketPayload, "US"); }
public async Task <dynamic> CreateBucketAsync([FromBody] BucketModel bucket) { BucketsApi buckets = new BucketsApi(); dynamic token = await OAuthController.GetInternalAsync(); buckets.Configuration.AccessToken = token.access_token; PostBucketsPayload bucketPayload = new PostBucketsPayload(bucket.bucketKey, null, bucket.policyKey); return(await buckets.CreateBucketAsync(bucketPayload, "US")); }
/// <summary> /// Run action against Buckets OSS API. /// </summary> /// <remarks>The action runs with retry policy to handle API token expiration.</remarks> private async Task <T> WithBucketApiAsync <T>(Func <BucketsApi, Task <T> > action) { return(await _ossResiliencyPolicy.ExecuteAsync(async() => { var api = new BucketsApi { Configuration = { AccessToken = await TwoLeggedAccessToken } }; return await action(api); })); }
private void OnDestroy() { _bucketData = null; _bucketsApi = null; _entriesApi = null; _contentApi = null; _releasesApi = null; Debug.Log("Destroy Cloud Content Window"); }
public async Task <IActionResult> DeleteBucketAsync([FromBody] BucketModel bucket) { BucketsApi buckets = new BucketsApi(); dynamic token = await OAuthController.GetInternalAsync(); buckets.Configuration.AccessToken = token.access_token; await buckets.DeleteBucketAsync(bucket.bucketKey); return(Ok()); }
/// <summary> /// Create a bucket. /// </summary> private async static Task <dynamic> CreateBucket() { string bucketKey = "forgeapp" + Guid.NewGuid().ToString("N").ToLower(); PostBucketsPayload postBucket = new PostBucketsPayload(bucketKey, null, PostBucketsPayload.PolicyKeyEnum.Transient /* erase after 24h*/); BucketsApi bucketsApi = new BucketsApi(); bucketsApi.Configuration.AccessToken = InternalToken.access_token; //bearer is returned from 2 legged token dynamic newBucket = await bucketsApi.CreateBucketAsync(postBucket); return(newBucket); }
/// <summary> /// Creates Bucket /// </summary> /// <returns>Newly created bucket</returns> private async static Task <dynamic> CreateBucket() { string bucketKey = "inventorio" + Guid.NewGuid().ToString("N").ToLower(); PostBucketsPayload postBucket = new PostBucketsPayload(bucketKey, null, PostBucketsPayload.PolicyKeyEnum.Transient); BucketsApi bucketsApi = new BucketsApi(); bucketsApi.Configuration.AccessToken = InternalToken.access_token; dynamic newBucket = await bucketsApi.CreateBucketAsync(postBucket); return(newBucket); }
public async Task RunAsync() { if (string.IsNullOrEmpty(Owner)) { Console.WriteLine("Please provide non-empty Owner."); return; } if (string.IsNullOrEmpty(UploadUrl)) { Console.WriteLine("Creating Bucket and OSS Object"); dynamic oauth = await GetInternalAsync(); // 1. ensure bucket existis string bucketKey = Owner.ToLower(); BucketsApi buckets = new BucketsApi(); buckets.Configuration.AccessToken = oauth.access_token; dynamic bucketsRes = null; try { PostBucketsPayload bucketPayload = new PostBucketsPayload(bucketKey, null, PostBucketsPayload.PolicyKeyEnum.Transient); bucketsRes = await buckets.CreateBucketAsync(bucketPayload, "US"); } catch { Console.WriteLine($"\tBucket {bucketKey} exists"); }; // in case bucket already exists string outputFileNameOSS = "output.zip"; ObjectsApi objects = new ObjectsApi(); objects.Configuration.AccessToken = oauth.access_token; try { PostBucketsSigned bucketsSigned = new PostBucketsSigned(60); dynamic signedResp = await objects.CreateSignedResourceAsync(bucketKey, outputFileNameOSS, bucketsSigned, "readwrite"); UploadUrl = signedResp.signedUrl; } catch {} } if (!await SetupOwnerAsync()) { Console.WriteLine("Exiting."); return; } var myApp = await SetupAppBundleAsync(); var myActivity = await SetupActivityAsync(myApp); await SubmitWorkItemAsync(myActivity); }
public async Task <dynamic> CreateBucket([FromBody] CreateBucketModel bucket) { BucketsApi buckets = new BucketsApi(); // Credentials credentials = await Credentials.FromSessionAsync(base.Request.Cookies, Response.Cookies); // //dynamic token = await OAuthController.GetInternalAsync(); buckets.Configuration.AccessToken = credentials.TokenInternal; PostBucketsPayload bucketPayload = new PostBucketsPayload(bucket.bucketKey, null, PostBucketsPayload.PolicyKeyEnum.Transient); return(await buckets.CreateBucketAsync(bucketPayload, "US")); }
private async Task <dynamic> CreateBucketsApi(BucketsApi bucketsApi, string bucketKey) { try { PostBucketsPayload postBucketsPayload = new PostBucketsPayload(bucketKey, null, PostBucketsPayload.PolicyKeyEnum.Transient); var result = await bucketsApi.CreateBucketAsync(postBucketsPayload, "US"); return(result); } catch (Exception e) { throw e; } }
private async void btnCreateBucket_Click(object sender, EventArgs e) { string bucketKey = string.Empty; if (Prompt.ShowDialog("Enter bucket name: ", "Create new bucket", txtClientId.Text.ToLower() + DateTime.Now.Ticks.ToString(), out bucketKey) == DialogResult.OK) { BucketsApi buckets = new BucketsApi(); buckets.Configuration.AccessToken = AccessToken; PostBucketsPayload bucketPayload = new PostBucketsPayload(bucketKey.ToLower(), null, PostBucketsPayload.PolicyKeyEnum.Transient); await buckets.CreateBucketAsync(bucketPayload, cmbRegion.Text); btnRefreshToken_Click(null, null); } }
public async Task <dynamic> DeleteBucket([FromBody] DeleteBucketModel objInfo) { // get the bucket... BucketsApi Buck = new BucketsApi(); dynamic token = await OAuthController.GetInternalAsync(); Buck.Configuration.AccessToken = token.access_token; await Buck.DeleteBucketAsync(objInfo.bucketKey); return(Task.CompletedTask); }
public async Task <dynamic> DeleteBucket([FromBody] CreateBucketModel bucket) { BucketsApi buckets = new BucketsApi(); dynamic token = await OAuthController.GetInternalAsync(); buckets.Configuration.AccessToken = token.access_token; await buckets.DeleteBucketAsync(bucket.bucketKey); //or //buckets.DeleteBucket(bucket.bucketKey); return(Task.CompletedTask); }
public async Task <IList <TreeNode> > GetOSSAsync(string id) { IList <TreeNode> nodes = new List <TreeNode>(); dynamic oauth = await OAuthController.GetInternalAsync(); if (id == "#") // root { // in this case, let's return all buckets BucketsApi appBckets = new BucketsApi(); appBckets.Configuration.AccessToken = oauth.access_token; // to simplify, let's return only the first 100 buckets dynamic buckets = await appBckets.GetBucketsAsync("US", 100); foreach (KeyValuePair <string, dynamic> bucket in new DynamicDictionaryItems(buckets.items)) { string actualBucket = bucket.Value.bucketKey; if (actualBucket.Contains(BucketName)) //kitchenconfig designautomation { nodes.Add(new TreeNode(bucket.Value.bucketKey, bucket.Value.bucketKey.Replace(ClientId + "-", string.Empty), "bucket", true)); } } } else { // as we have the id (bucketKey), let's return all ObjectsApi objects = new ObjectsApi(); objects.Configuration.AccessToken = oauth.access_token; var objectsList = objects.GetObjects(id); foreach (KeyValuePair <string, dynamic> objInfo in new DynamicDictionaryItems(objectsList.items)) { string fileName = objInfo.Value.objectKey; fileName.ToLower(); if (fileName.Contains("zip") && fileName.Contains("output")) //result output { nodes.Add(new TreeNode(Base64Encode((string)objInfo.Value.objectId), objInfo.Value.objectKey, "zipfile", false)); } /* ovaj deo mi ne treba ovde jer neću da prikazujem ništa što nije rezult*.zip * else * { * nodes.Add(new TreeNode(Base64Encode((string)objInfo.Value.objectId), * objInfo.Value.objectKey, "object", false)); * }*/ } } return(nodes); }
public async Task <dynamic> CreateBucket([FromBody] CreateBucketModel bucket) { if (!Utility.Buckets.IsValidBucketKey(bucket.bucketKey)) { return(null); } BucketsApi buckets = new BucketsApi(); dynamic token = await Utility.OAuth.Get2LeggedTokenAsync(new Scope[] { Scope.BucketCreate }); buckets.Configuration.AccessToken = token.access_token; PostBucketsPayload bucketPayload = new PostBucketsPayload(bucket.bucketKey, null, bucket.policyKey); return(await buckets.CreateBucketAsync(bucketPayload, Enum.GetName(typeof(Region), bucket.region))); }
public async Task <IList <Model.TreeNode> > GetOSSAsync(string id) { IList <Model.TreeNode> nodes = new List <Model.TreeNode>(); dynamic oauth = await OAuthController.GetInternalAsync(); // 3LO //string oauth = objCredentials.TokenInternal; objCredentials = await Model.Credentials.FromSessionAsync(base.Request.Cookies, Response.Cookies); if (objCredentials == null) { return(null); } if (id == "#") // root { // in this case, let's return all buckets BucketsApi appBckets = new BucketsApi(); appBckets.Configuration.AccessToken = oauth.access_token; // 3LO //appBckets.Configuration.AccessToken = oauth; // to simplify, let's return only the first 100 buckets dynamic buckets = await appBckets.GetBucketsAsync(sRegion, iBucketNumber); foreach (KeyValuePair <string, dynamic> bucket in new DynamicDictionaryItems(buckets.items)) { nodes.Add(new Model.TreeNode(bucket.Value.bucketKey, bucket.Value.bucketKey.Replace(objCredentials.ClientId + "-", string.Empty), "bucket", true)); } } else { // as we have the id (bucketKey), let's return all ObjectsApi objects = new ObjectsApi(); objects.Configuration.AccessToken = oauth.access_token; // 3LO //objects.Configuration.AccessToken = oauth; var objectsList = objects.GetObjects(id); foreach (KeyValuePair <string, dynamic> objInfo in new DynamicDictionaryItems(objectsList.items)) { nodes.Add(new Model.TreeNode(ServiceClass.Service.Base64Encode((string)objInfo.Value.objectId), objInfo.Value.objectKey, "object", false)); } } return(nodes); }
public async Task <IActionResult> Upload([FromForm] StartWorkitemInput input) { JObject workItemData = JObject.Parse(input.data); browserConnectionId = workItemData["browserConnectionId"].Value <string>(); var fileSavePath = Path.Combine(_env.ContentRootPath, Path.GetFileName(input.inputFile.FileName)); using (var stream = new FileStream(fileSavePath, FileMode.Create)) { await input.inputFile.CopyToAsync(stream); } dynamic oauth = await GetInternalASync(); // upload file to OSS Bucket // 1. ensure bucket exists BucketKey = String.Format("{0}_{1}", BucketKey, DateTime.Now.ToString("yyyyMMddhhmmss").ToLower()); BucketsApi buckets = new BucketsApi(); buckets.Configuration.AccessToken = oauth.access_token; try { PostBucketsPayload bucketPayload = new PostBucketsPayload(BucketKey, null, PostBucketsPayload.PolicyKeyEnum.Transient); await buckets.CreateBucketAsync(bucketPayload, "US"); } catch { }; // in case bucket already exists ObjectsApi objects = new ObjectsApi(); objects.Configuration.AccessToken = oauth.access_token; inputFileNameOSS = string.Format("{0}_input_{1}", DateTime.Now.ToString("yyyyMMddhhmmss"), Path.GetFileName(input.inputFile.FileName)); // avoid overriding object res = default; using (StreamReader streamReader = new StreamReader(fileSavePath)) { res = await objects.UploadObjectAsync(BucketKey, inputFileNameOSS, (int)streamReader.BaseStream.Length, streamReader.BaseStream, "application/octet-stream"); } var json = JsonConvert.SerializeObject(res, Formatting.Indented); var response = Response; await response.WriteJsonAsync(json); // delete server copy System.IO.File.Delete(fileSavePath); return(new EmptyResult()); }
/// <summary> /// Creates Bucket /// </summary> /// <returns>Newly created bucket</returns> public async static Task <dynamic> CreateBucket() { string bucketKey = "inventorilogicda" + ConsumerKey.ToLower(); BucketsApi bucketsApi = new BucketsApi(); bucketsApi.Configuration.AccessToken = InternalToken.access_token; dynamic buckets = await bucketsApi.GetBucketsAsync(); bool bucketExists = buckets.items.ToString().Contains(bucketKey); if (!bucketExists) { PostBucketsPayload postBucket = new PostBucketsPayload(bucketKey, null, PostBucketsPayload.PolicyKeyEnum.Transient); dynamic newbucket = await bucketsApi.CreateBucketAsync(postBucket); } return(bucketKey); }
public async Task <IActionResult> UploadOssFiles([FromBody] JObject appBundleSpecs) { if (OAuthController.GetAppSetting("DISABLE_SETUP") == "true") { return(Unauthorized()); } System.Diagnostics.Debug.WriteLine("UploadOssFiles"); // OAuth token dynamic oauth = await OAuthController.GetInternalAsync(); ObjectsApi objects = new ObjectsApi(); objects.Configuration.AccessToken = oauth.access_token; DerivativesApi derivatives = new DerivativesApi(); derivatives.Configuration.AccessToken = oauth.access_token; // upload file to OSS Bucket // 1. ensure bucket existis BucketsApi buckets = new BucketsApi(); buckets.Configuration.AccessToken = oauth.access_token; try { PostBucketsPayload bucketPayload = new PostBucketsPayload(BucketKey, null, PostBucketsPayload.PolicyKeyEnum.Transient); await buckets.CreateBucketAsync(bucketPayload, "US"); } catch { }; // in case bucket already exists string [] filePaths = System.IO.Directory.GetFiles(LocalFilesFolder); foreach (string filePath in filePaths) { string fileName = System.IO.Path.GetFileName(filePath); using (StreamReader streamReader = new StreamReader(filePath)) { dynamic res = await objects.UploadObjectAsync(BucketKey, fileName, (int)streamReader.BaseStream.Length, streamReader.BaseStream, "application/octet-stream"); TranslateFile(res.objectId, null); } } return(Ok()); }
private async Task EnsureBucketExists(string bucketKey) { var auth = await GetAccessToken(INTERNAL_TOKEN_SCOPES); var client = new BucketsApi(); client.Configuration.AccessToken = auth.AccessToken; var buckets = await client.GetBucketsAsync(); foreach (KeyValuePair <string, dynamic> bucket in new DynamicDictionaryItems(buckets.items)) { if (bucket.Value.bucketKey == bucketKey) { return; } } await client.CreateBucketAsync(new PostBucketsPayload { BucketKey = bucketKey, PolicyKey = PostBucketsPayload.PolicyKeyEnum.Temporary }); }
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); } }