Ejemplo n.º 1
0
        /// <summary>
        /// Replace the tags on the resource with the given set.
        /// </summary>
        /// <param name="tags"> The set of tags to use as replacement. </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> SetTags(IDictionary <string, string> tags, CancellationToken cancellationToken = default)
        {
            if (tags == null)
            {
                throw new ArgumentNullException(nameof(tags));
            }

            using var scope = Diagnostics.CreateScope("ResourceGroupOperations.SetTags");
            scope.Start();

            try
            {
                TagResourceOperations.Delete(cancellationToken);
                var newTags = TagResourceOperations.Get(cancellationToken);
                newTags.Value.Data.Properties.TagsValue.ReplaceWith(tags);
                TagContainer.CreateOrUpdate(new TagResourceData(newTags.Value.Data.Properties), 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;
            }
        }
Ejemplo n.º 2
0
 /// <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 <GenericResource> RemoveTag(string key, CancellationToken cancellationToken = default)
 {
     using var scope = Diagnostics.CreateScope("GenericResourceOperations.RemoveTag");
     scope.Start();
     try
     {
         var apiVersion   = GetApiVersion(cancellationToken);
         var originalTags = TagResourceOperations.Get(cancellationToken).Value;
         originalTags.Data.Properties.TagsValue.Remove(key);
         TagContainer.CreateOrUpdate(originalTags.Data, cancellationToken);
         var originalResponse = RestClient.GetById(Id, apiVersion, cancellationToken);
         return(Response.FromValue(new GenericResource(this, originalResponse.Value), originalResponse.GetRawResponse()));
     }
     catch (Exception e)
     {
         scope.Failed(e);
         throw;
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Replace the tags on the resource with the given set.
 /// </summary>
 /// <param name="tags"> The set of tags to use as replacement. </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 <GenericResource> SetTags(IDictionary <string, string> tags, CancellationToken cancellationToken = default)
 {
     using var scope = Diagnostics.CreateScope("GenericResourceOperations.SetTags");
     scope.Start();
     try
     {
         var apiVersion = GetApiVersion(cancellationToken);
         TagResourceOperations.Delete(cancellationToken);
         var newTags = TagResourceOperations.Get(cancellationToken);
         newTags.Value.Data.Properties.TagsValue.ReplaceWith(tags);
         TagContainer.CreateOrUpdate(new TagResourceData(newTags.Value.Data.Properties), cancellationToken);
         var originalResponse = RestClient.GetById(Id, apiVersion, cancellationToken);
         return(Response.FromValue(new GenericResource(this, originalResponse.Value), originalResponse.GetRawResponse()));
     }
     catch (Exception e)
     {
         scope.Failed(e);
         throw;
     }
 }
Ejemplo n.º 4
0
        /// <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;
            }
        }