private void OnDeleteModel(DeleteModelResult deleteModelResult, Dictionary <string, object> customData) { Log.Debug("TestLanguageTranslator.OnDeleteModel()", "Language Translator - Delete model response: success: {0}", customData["json"].ToString()); _customLanguageModelId = null; Test(deleteModelResult != null); _deleteModelTested = true; }
public async Task <DeleteModelResult> DeleteImageAsync(Guid imageId) { if (imageId == Guid.Empty) { return(new DeleteModelResult(ResultStatus.Failed, "ImageId is not valid.")); } var modelResult = new DeleteModelResult(imageId); try { var request = new DeleteObjectRequest { BucketName = _configuration.GetSection("S3Buckets")["Images"], Key = modelResult.ImageId.ToString() }; await _amazonS3Client.DeleteObjectAsync(request); } catch (Exception ex) { return(new DeleteModelResult(ResultStatus.Failed, ex.Message)); } return(modelResult); }
/// <summary> /// Delete model. Deletes a custom translation model. /// </summary> /// <param name="modelId">Model ID of the model to delete.</param> /// <param name="customData">Custom data object to pass data including custom request headers.</param> /// <returns><see cref="DeleteModelResult" />DeleteModelResult</returns> public DeleteModelResult DeleteModel(string modelId, Dictionary <string, object> customData = null) { if (string.IsNullOrEmpty(modelId)) { throw new ArgumentNullException(nameof(modelId)); } DeleteModelResult result = null; try { IClient client; client = this.Client.WithAuthentication(this.UserName, this.Password); var restRequest = client.DeleteAsync($"{this.Endpoint}/v2/models/{modelId}"); if (customData != null) { restRequest.WithCustomData(customData); } result = restRequest.As <DeleteModelResult>().Result; if (result == null) { result = new DeleteModelResult(); } result.CustomData = restRequest.CustomData; } catch (AggregateException ae) { throw ae.Flatten(); } return(result); }
/// <summary> /// Delete model. /// /// Deletes a custom translation model. /// </summary> /// <param name="modelId">Model ID of the model to delete.</param> /// <param name="customData">Custom data object to pass data including custom request headers.</param> /// <returns><see cref="DeleteModelResult" />DeleteModelResult</returns> public DeleteModelResult DeleteModel(string modelId, Dictionary <string, object> customData = null) { if (string.IsNullOrEmpty(modelId)) { throw new ArgumentNullException(nameof(modelId)); } if (string.IsNullOrEmpty(VersionDate)) { throw new ArgumentNullException("versionDate cannot be null."); } DeleteModelResult result = null; try { IClient client = this.Client; if (_tokenManager != null) { client = this.Client.WithAuthentication(_tokenManager.GetToken()); } if (_tokenManager == null) { client = this.Client.WithAuthentication(this.UserName, this.Password); } var restRequest = client.DeleteAsync($"{this.Endpoint}/v3/models/{modelId}"); restRequest.WithArgument("version", VersionDate); if (customData != null) { restRequest.WithCustomData(customData); } restRequest.WithHeader("X-IBMCloud-SDK-Analytics", "service_name=language_translator;service_version=v3;operation_id=DeleteModel"); result = restRequest.As <DeleteModelResult>().Result; if (result == null) { result = new DeleteModelResult(); } result.CustomData = restRequest.CustomData; } catch (AggregateException ae) { throw ae.Flatten(); } return(result); }
/// <summary> /// Delete model. Deletes a custom translation model. /// </summary> /// <param name="modelId">Model ID of the model to delete.</param> /// <returns><see cref="DeleteModelResult" />DeleteModelResult</returns> public DeleteModelResult DeleteModel(string modelId) { if (string.IsNullOrEmpty(modelId)) { throw new ArgumentNullException(nameof(modelId)); } DeleteModelResult result = null; try { var request = this.Client.WithAuthentication(this.UserName, this.Password) .DeleteAsync($"{this.Endpoint}/v2/models/{modelId}"); result = request.As <DeleteModelResult>().Result; } catch (AggregateException ae) { throw ae.Flatten(); } return(result); }
public IEnumerator TestDeleteModel() { Log.Debug("LanguageTranslatorServiceV3IntegrationTests", "Attempting to DeleteModel..."); DeleteModelResult deleteModelResponse = null; service.DeleteModel( callback: (DetailedResponse <DeleteModelResult> response, IBMError error) => { Log.Debug("LanguageTranslatorServiceV3IntegrationTests", "DeleteModel result: {0}", response.Response); deleteModelResponse = response.Result; Assert.IsNotNull(deleteModelResponse); Assert.IsNotNull(deleteModelResponse.Status); Assert.IsTrue(deleteModelResponse.Status == "OK"); Assert.IsNull(error); }, modelId: customModelId ); while (deleteModelResponse == null) { yield return(null); } }