public async Task Update()
        {
            var          rgName       = Recording.GenerateAssetName("testrg");
            Subscription subscription = await Client.GetDefaultSubscriptionAsync().ConfigureAwait(false);

            var rg1Op = await subscription.GetResourceGroups().CreateOrUpdateAsync(rgName, new ResourceGroupData(Location.WestUS2));

            ResourceGroup rg1        = rg1Op.Value;
            var           parameters = new ResourceGroupPatchable
            {
                Name = rgName
            };
            ResourceGroup rg2 = await rg1.UpdateAsync(parameters);

            Assert.AreEqual(rg1.Data.Name, rg2.Data.Name);
            Assert.AreEqual(rg1.Data.Id, rg2.Data.Id);
            Assert.AreEqual(rg1.Data.Type, rg2.Data.Type);
            Assert.AreEqual(rg1.Data.Properties.ProvisioningState, rg2.Data.Properties.ProvisioningState);
            Assert.AreEqual(rg1.Data.Location, rg2.Data.Location);
            Assert.AreEqual(rg1.Data.ManagedBy, rg2.Data.ManagedBy);
            Assert.AreEqual(rg1.Data.Tags, rg2.Data.Tags);

            Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await rg1.UpdateAsync(null));

            rg1.Id.Name = null;
            Assert.ThrowsAsync <ArgumentNullException>(async() => _ = await rg1.UpdateAsync(parameters));
        }
        public async Task <ArmOperation <ResourceGroup> > StartAddTagAsync(string name, string value, CancellationToken cancellationToken = default)
        {
            var patch = new ResourceGroupPatchable();

            patch.Tags[name] = value;
            return(new PhArmOperation <ResourceGroup, Azure.ResourceManager.Resources.Models.ResourceGroup>(await Operations.UpdateAsync(Id.Name, patch, cancellationToken), g =>
            {
                Resource = new ResourceGroupData(g);
                return new ResourceGroup(ClientOptions, Resource as ResourceGroupData);
            }));
        }
        public ArmOperation <ResourceGroup> StartAddTag(string name, string value)
        {
            var patch = new ResourceGroupPatchable();

            patch.Tags[name] = value;
            return(new PhArmOperation <ResourceGroup, Azure.ResourceManager.Resources.Models.ResourceGroup>(Operations.Update(Id.Name, patch), g =>
            {
                Resource = new ResourceGroupData(g);
                return new ResourceGroup(ClientOptions, Resource as ResourceGroupData);
            }));
        }
 public virtual Response <ResourceGroup> Update(string resourceGroupName, ResourceGroupPatchable parameters, CancellationToken cancellationToken = default)
 {
     using var scope = _clientDiagnostics.CreateScope("ResourceGroupsOperations.Update");
     scope.Start();
     try
     {
         return(RestClient.Update(resourceGroupName, parameters, cancellationToken));
     }
     catch (Exception e)
     {
         scope.Failed(e);
         throw;
     }
 }
        /// <summary>
        /// Add a tag to a ResourceGroup.
        /// If the tag already exists it will be modified.
        /// </summary>
        /// <param name="name"> The key for the tag. </param>
        /// <param name="value"> The value for the tag. </param>
        /// <param name="cancellationToken"> A token to allow the caller to cancel the call to the service. The default value is <see cref="P:System.Threading.CancellationToken.None" />. </param>
        /// /// <returns> A <see cref="Task"/> that on completion returns a response with the <see cref="ArmOperation{ResourceGroup}"/> operation for this resource. </returns>
        /// <remarks>
        /// <see href="https://azure.github.io/azure-sdk/dotnet_introduction.html#dotnet-longrunning">Details on long running operation object.</see>
        /// </remarks>
        public async Task <ArmOperation <ResourceGroup> > StartAddTagAsync(string name, string value, CancellationToken cancellationToken = default)
        {
            var patch = new ResourceGroupPatchable();

            if (object.ReferenceEquals(patch.Tags, null))
            {
                patch.Tags = new Dictionary <string, string>();
            }

            patch.Tags[name] = value;
            return(new PhArmOperation <ResourceGroup, Azure.ResourceManager.Resources.Models.ResourceGroup>(await Operations.UpdateAsync(Id.Name, patch, cancellationToken), g =>
            {
                return new ResourceGroup(this, new ResourceGroupData(g));
            }));
        }
Exemple #6
0
 /// <summary> Resource groups can be updated through a simple PATCH operation to a group address. The format of the request is the same as that for creating a resource group. If a field is unspecified, the current value is retained. </summary>
 /// <param name="parameters"> Parameters supplied to update a resource group. </param>
 /// <param name="cancellationToken"> The cancellation token to use. </param>
 public virtual Response <ResourceGroup> Update(ResourceGroupPatchable parameters, CancellationToken cancellationToken = default)
 {
     using var scope = Diagnostics.CreateScope("ResourceGroupOperations.Update");
     scope.Start();
     try
     {
         var originalResponse = RestClient.Update(Id.Name, parameters, cancellationToken);
         return(Response.FromValue(new ResourceGroup(this, originalResponse), originalResponse.GetRawResponse()));
     }
     catch (Exception e)
     {
         scope.Failed(e);
         throw;
     }
 }
        /// <summary>
        /// Add a tag to a ResourceGroup.
        /// If the tag already exists it will be modified.
        /// </summary>
        /// <param name="name"> The key for the tag. </param>
        /// <param name="value"> The value for the tag. </param>
        /// <returns> A response with the <see cref="ArmOperation{ResourceGroup}"/> operation for this resource. </returns>
        /// <remarks>
        /// <see href="https://azure.github.io/azure-sdk/dotnet_introduction.html#dotnet-longrunning">Details on long running operation object.</see>
        /// </remarks>
        public ArmOperation <ResourceGroup> StartAddTag(string name, string value)
        {
            var patch = new ResourceGroupPatchable();

            if (object.ReferenceEquals(patch.Tags, null))
            {
                patch.Tags = new Dictionary <string, string>();
            }

            patch.Tags[name] = value;
            return(new PhArmOperation <ResourceGroup, Azure.ResourceManager.Resources.Models.ResourceGroup>(Operations.Update(Id.Name, patch), g =>
            {
                return new ResourceGroup(this, new ResourceGroupData(g));
            }));
        }
        /// <summary> Resource groups can be updated through a simple PATCH operation to a group address. The format of the request is the same as that for creating a resource group. If a field is unspecified, the current value is retained. </summary>
        /// <param name="parameters"> Parameters supplied to update a resource group. </param>
        /// <param name="cancellationToken"> The cancellation token to use. </param>
        public virtual async Task <Response <ResourceGroup> > UpdateAsync(ResourceGroupPatchable parameters, CancellationToken cancellationToken = default)
        {
            using var scope = _clientDiagnostics.CreateScope("ResourceGroup.Update");
            scope.Start();
            try
            {
                var originalResponse = await _restClient.UpdateAsync(Id.Name, parameters, cancellationToken).ConfigureAwait(false);

                return(Response.FromValue(new ResourceGroup(this, originalResponse), originalResponse.GetRawResponse()));
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
Exemple #9
0
        /// <inheritdoc/>
        public async Task <ArmOperation <ResourceGroup> > StartRemoveTagAsync(string key, CancellationToken cancellationToken = default)
        {
            var resource = GetResource();
            var patch    = new ResourceGroupPatchable()
            {
                Tags = resource.Data.Tags
            };

            if (object.ReferenceEquals(patch.Tags, null))
            {
                patch.Tags = new Dictionary <string, string>();
            }

            DeleteTag(key, patch.Tags);
            return(new PhArmOperation <ResourceGroup, Azure.ResourceManager.Resources.Models.ResourceGroup>(await Operations.UpdateAsync(Id.Name, patch, cancellationToken), g =>
            {
                return new ResourceGroup(this, new ResourceGroupData(g));
            }));
        }
Exemple #10
0
        /// <inheritdoc/>
        public ArmOperation <ResourceGroup> StartRemoveTag(string key)
        {
            var resource = GetResource();
            var patch    = new ResourceGroupPatchable()
            {
                Tags = resource.Data.Tags
            };

            if (object.ReferenceEquals(patch.Tags, null))
            {
                patch.Tags = new Dictionary <string, string>();
            }

            DeleteTag(key, patch.Tags);
            return(new PhArmOperation <ResourceGroup, Azure.ResourceManager.Resources.Models.ResourceGroup>(Operations.Update(Id.Name, patch), g =>
            {
                return new ResourceGroup(this, new ResourceGroupData(g));
            }));
        }
Exemple #11
0
        /// <inheritdoc/>
        public ArmResponse <ResourceGroup> SetTags(IDictionary <string, string> tags)
        {
            var resource = GetResource();
            var patch    = new ResourceGroupPatchable()
            {
                Tags = resource.Data.Tags
            };

            if (object.ReferenceEquals(patch.Tags, null))
            {
                patch.Tags = new Dictionary <string, string>();
            }

            ReplaceTags(tags, patch.Tags);
            return(new PhArmResponse <ResourceGroup, Azure.ResourceManager.Resources.Models.ResourceGroup>(Operations.Update(Id.Name, patch), g =>
            {
                return new ResourceGroup(this, new ResourceGroupData(g));
            }));
        }
        public virtual Response <ResourceGroup> Update(ResourceGroupPatchable parameters, CancellationToken cancellationToken = default)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            using var scope = _resourceGroupClientDiagnostics.CreateScope("ResourceGroup.Update");
            scope.Start();
            try
            {
                var response = _resourceGroupRestClient.Update(Id.SubscriptionId, Id.ResourceGroupName, parameters, cancellationToken);
                return(Response.FromValue(new ResourceGroup(ArmClient, response.Value), response.GetRawResponse()));
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
        /// <inheritdoc/>
        public async Task <ArmOperation <ResourceGroup> > StartRemoveTagAsync(string key, CancellationToken cancellationToken = default)
        {
            if (string.IsNullOrWhiteSpace(key))
            {
                throw new ArgumentException(nameof(key), $"{nameof(key)} provided cannot be null or a whitespace.");
            }

            var resource = GetResource();
            var patch    = new ResourceGroupPatchable()
            {
                Tags = resource.Data.Tags
            };

            if (object.ReferenceEquals(patch.Tags, null))
            {
                patch.Tags = new Dictionary <string, string>();
            }

            DeleteTag(key, patch.Tags);
            return(new PhArmOperation <ResourceGroup, Azure.ResourceManager.Resources.Models.ResourceGroup>(await Operations.UpdateAsync(Id.Name, patch, cancellationToken), g =>
            {
                return new ResourceGroup(this, new ResourceGroupData(g));
            }));
        }
        /// <inheritdoc/>
        public ArmResponse <ResourceGroup> RemoveTag(string key)
        {
            if (string.IsNullOrWhiteSpace(key))
            {
                throw new ArgumentException($"{nameof(key)} provided cannot be null or a whitespace.", nameof(key));
            }

            var resource = GetResource();
            var patch    = new ResourceGroupPatchable()
            {
                Tags = resource.Data.Tags
            };

            if (object.ReferenceEquals(patch.Tags, null))
            {
                patch.Tags = new Dictionary <string, string>();
            }

            DeleteTag(key, patch.Tags);
            return(new PhArmResponse <ResourceGroup, Azure.ResourceManager.Resources.Models.ResourceGroup>(Operations.Update(Id.Name, patch), g =>
            {
                return new ResourceGroup(this, new ResourceGroupData(g));
            }));
        }
        /// <inheritdoc/>
        public async Task <ArmOperation <ResourceGroup> > StartSetTagsAsync(IDictionary <string, string> tags, CancellationToken cancellationToken = default)
        {
            if (tags == null)
            {
                throw new ArgumentNullException(nameof(tags));
            }

            var resource = GetResource();
            var patch    = new ResourceGroupPatchable()
            {
                Tags = resource.Data.Tags
            };

            if (object.ReferenceEquals(patch.Tags, null))
            {
                patch.Tags = new Dictionary <string, string>();
            }

            ReplaceTags(tags, patch.Tags);
            return(new PhArmOperation <ResourceGroup, Azure.ResourceManager.Resources.Models.ResourceGroup>(await Operations.UpdateAsync(Id.Name, patch, cancellationToken), g =>
            {
                return new ResourceGroup(this, new ResourceGroupData(g));
            }));
        }
 public virtual async Task <Response <ResourceGroup> > UpdateAsync(string resourceGroupName, ResourceGroupPatchable parameters, CancellationToken cancellationToken = default)
 {
     using var scope = _clientDiagnostics.CreateScope("ResourceGroupsClient.Update");
     scope.Start();
     try
     {
         return(await RestClient.UpdateAsync(resourceGroupName, parameters, cancellationToken).ConfigureAwait(false));
     }
     catch (Exception e)
     {
         scope.Failed(e);
         throw;
     }
 }
Exemple #17
0
 /// <summary>
 /// Updates a resource group.
 /// </summary>
 /// <remarks>
 /// Resource groups can be updated through a simple PATCH operation to a group
 /// address. The format of the request is the same as that for creating a
 /// resource group. If a field is unspecified, the current value is retained.
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group to update. The name is case insensitive.
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to update a resource group.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <ResourceGroup> UpdateAsync(this IResourceGroupsOperations operations, string resourceGroupName, ResourceGroupPatchable parameters, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.UpdateWithHttpMessagesAsync(resourceGroupName, parameters, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
Exemple #18
0
 /// <summary>
 /// Updates a resource group.
 /// </summary>
 /// <remarks>
 /// Resource groups can be updated through a simple PATCH operation to a group
 /// address. The format of the request is the same as that for creating a
 /// resource group. If a field is unspecified, the current value is retained.
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group to update. The name is case insensitive.
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to update a resource group.
 /// </param>
 public static ResourceGroup Update(this IResourceGroupsOperations operations, string resourceGroupName, ResourceGroupPatchable parameters)
 {
     return(operations.UpdateAsync(resourceGroupName, parameters).GetAwaiter().GetResult());
 }