public virtual Response <JitRequestDefinition> AddTag(string key, string value, CancellationToken cancellationToken = default) { if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException($"{nameof(key)} provided cannot be null or a whitespace.", nameof(key)); } using var scope = _clientDiagnostics.CreateScope("JitRequestDefinition.AddTag"); scope.Start(); try { var originalTags = TagResource.Get(cancellationToken); originalTags.Value.Data.Properties.TagsValue[key] = value; TagContainer.CreateOrUpdate(originalTags.Value.Data, cancellationToken: cancellationToken); var originalResponse = _restClient.Get(Id.ResourceGroupName, Id.Name, cancellationToken); return(Response.FromValue(new JitRequestDefinition(this, originalResponse.Value), originalResponse.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } }
public virtual Response <VirtualMachineRunCommandVirtualMachineScaleSetVM> RemoveTag(string key, CancellationToken cancellationToken = default) { if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException($"{nameof(key)} provided cannot be null or a whitespace.", nameof(key)); } using var scope = _clientDiagnostics.CreateScope("VirtualMachineRunCommandVirtualMachineScaleSetVM.RemoveTag"); scope.Start(); try { var originalTags = TagResource.Get(cancellationToken); originalTags.Value.Data.Properties.TagsValue.Remove(key); TagContainer.CreateOrUpdate(originalTags.Value.Data, cancellationToken: cancellationToken); var originalResponse = _restClient.Get(Id.ResourceGroupName, Id.Parent.Parent.Name, Id.Parent.Name, Id.Name, null, cancellationToken); return(Response.FromValue(new VirtualMachineRunCommandVirtualMachineScaleSetVM(this, originalResponse.Value), originalResponse.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } }
public virtual Response <StorageAccount> SetTags(IDictionary <string, string> tags, CancellationToken cancellationToken = default) { if (tags == null) { throw new ArgumentNullException($"{nameof(tags)} provided cannot be null.", nameof(tags)); } using var scope = _clientDiagnostics.CreateScope("StorageAccount.SetTags"); scope.Start(); try { TagResource.Delete(cancellationToken: cancellationToken); var originalTags = TagResource.Get(cancellationToken); originalTags.Value.Data.Properties.TagsValue.ReplaceWith(tags); TagContainer.CreateOrUpdate(originalTags.Value.Data, cancellationToken: cancellationToken); var originalResponse = _restClient.GetProperties(Id.ResourceGroupName, Id.Name, null, cancellationToken); return(Response.FromValue(new StorageAccount(this, originalResponse.Value), originalResponse.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } }
/// <summary> /// Removes a tag by key from the resource. /// </summary> /// <param name="key"> The key of the tag to remove. </param> /// <param name="cancellationToken"> A token to allow the caller to cancel the call to the service. The default value is <see cref="CancellationToken.None" />. </param> /// <returns> The updated resource with the tag added. </returns> public virtual Response <ResourceGroup> RemoveTag(string key, CancellationToken cancellationToken = default) { if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentException($"{nameof(key)} provided cannot be null or a whitespace.", nameof(key)); } using var scope = Diagnostics.CreateScope("ResourceGroupOperations.RemoveTag"); scope.Start(); try { var originalTags = TagResourceOperations.Get(cancellationToken).Value; originalTags.Data.Properties.TagsValue.Remove(key); TagContainer.CreateOrUpdate(originalTags.Data, cancellationToken); var originalResponse = RestClient.Get(Id.Name, cancellationToken); return(Response.FromValue(new ResourceGroup(this, originalResponse.Value), originalResponse.GetRawResponse())); } catch (Exception e) { scope.Failed(e); throw; } }