internal TemplateSpecVersion(ArmResource options, TemplateSpecVersionData resource) : base(options, resource.Id) { HasData = true; _data = resource; _clientDiagnostics = new ClientDiagnostics(ClientOptions); _templateSpecVersionsRestClient = new TemplateSpecVersionsRestOperations(_clientDiagnostics, Pipeline, ClientOptions, BaseUri); }
public async Task <Response <TemplateSpecVersionData> > CreateOrUpdateAsync(string resourceGroupName, string templateSpecName, string templateSpecVersion, TemplateSpecVersionData templateSpecVersionModel, CancellationToken cancellationToken = default) { if (resourceGroupName == null) { throw new ArgumentNullException(nameof(resourceGroupName)); } if (templateSpecName == null) { throw new ArgumentNullException(nameof(templateSpecName)); } if (templateSpecVersion == null) { throw new ArgumentNullException(nameof(templateSpecVersion)); } if (templateSpecVersionModel == null) { throw new ArgumentNullException(nameof(templateSpecVersionModel)); } using var message = CreateCreateOrUpdateRequest(resourceGroupName, templateSpecName, templateSpecVersion, templateSpecVersionModel); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); switch (message.Response.Status) { case 200: case 201: { TemplateSpecVersionData value = default; using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); value = TemplateSpecVersionData.DeserializeTemplateSpecVersionData(document.RootElement); return(Response.FromValue(value, message.Response)); }
public async Task <Response <TemplateSpecVersionData> > CreateOrUpdateAsync(string subscriptionId, string resourceGroupName, string templateSpecName, string templateSpecVersion, TemplateSpecVersionData data, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(subscriptionId, nameof(subscriptionId)); Argument.AssertNotNullOrEmpty(resourceGroupName, nameof(resourceGroupName)); Argument.AssertNotNullOrEmpty(templateSpecName, nameof(templateSpecName)); Argument.AssertNotNullOrEmpty(templateSpecVersion, nameof(templateSpecVersion)); Argument.AssertNotNull(data, nameof(data)); using var message = CreateCreateOrUpdateRequest(subscriptionId, resourceGroupName, templateSpecName, templateSpecVersion, data); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); switch (message.Response.Status) { case 200: case 201: { TemplateSpecVersionData value = default; using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); value = TemplateSpecVersionData.DeserializeTemplateSpecVersionData(document.RootElement); return(Response.FromValue(value, message.Response)); }
internal Azure.Core.HttpMessage CreateCreateOrUpdateRequest(string subscriptionId, string resourceGroupName, string templateSpecName, string templateSpecVersion, TemplateSpecVersionData templateSpecVersionModel) { var message = _pipeline.CreateMessage(); var request = message.Request; request.Method = RequestMethod.Put; var uri = new RawRequestUriBuilder(); uri.Reset(endpoint); uri.AppendPath("/subscriptions/", false); uri.AppendPath(subscriptionId, true); uri.AppendPath("/resourceGroups/", false); uri.AppendPath(resourceGroupName, true); uri.AppendPath("/providers/Microsoft.Resources/templateSpecs/", false); uri.AppendPath(templateSpecName, true); uri.AppendPath("/versions/", false); uri.AppendPath(templateSpecVersion, true); uri.AppendQuery("api-version", "2021-05-01", true); request.Uri = uri; request.Headers.Add("Accept", "application/json"); request.Headers.Add("Content-Type", "application/json"); var content = new Utf8JsonRequestContent(); content.JsonWriter.WriteObjectValue(templateSpecVersionModel); request.Content = content; message.SetProperty("UserAgentOverride", _userAgent); return(message); }
public virtual async Task <ArmOperation <TemplateSpecVersion> > CreateOrUpdateAsync(WaitUntil waitUntil, string templateSpecVersion, TemplateSpecVersionData templateSpecVersionModel, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(templateSpecVersion, nameof(templateSpecVersion)); Argument.AssertNotNull(templateSpecVersionModel, nameof(templateSpecVersionModel)); using var scope = _templateSpecVersionClientDiagnostics.CreateScope("TemplateSpecVersionCollection.CreateOrUpdate"); scope.Start(); try { var response = await _templateSpecVersionRestClient.CreateOrUpdateAsync(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, templateSpecVersion, templateSpecVersionModel, cancellationToken).ConfigureAwait(false); var operation = new ResourcesArmOperation <TemplateSpecVersion>(Response.FromValue(new TemplateSpecVersion(Client, response), response.GetRawResponse())); if (waitUntil == WaitUntil.Completed) { await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }
internal TemplateSpecVersion(ArmClient client, TemplateSpecVersionData data) : this(client, data.Id) { HasData = true; _data = data; }
public virtual TemplateSpecVersionCreateOrUpdateOperation CreateOrUpdate(string templateSpecVersion, TemplateSpecVersionData templateSpecVersionModel, bool waitForCompletion = true, CancellationToken cancellationToken = default) { if (templateSpecVersion == null) { throw new ArgumentNullException(nameof(templateSpecVersion)); } if (templateSpecVersionModel == null) { throw new ArgumentNullException(nameof(templateSpecVersionModel)); } using var scope = _clientDiagnostics.CreateScope("TemplateSpecVersionCollection.CreateOrUpdate"); scope.Start(); try { var response = _restClient.CreateOrUpdate(Id.ResourceGroupName, Id.Name, templateSpecVersion, templateSpecVersionModel, cancellationToken); var operation = new TemplateSpecVersionCreateOrUpdateOperation(Parent, response); if (waitForCompletion) { operation.WaitForCompletion(cancellationToken); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }
public async virtual Task <TemplateSpecVersionCreateOrUpdateOperation> CreateOrUpdateAsync(bool waitForCompletion, string templateSpecVersion, TemplateSpecVersionData templateSpecVersionModel, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(templateSpecVersion, nameof(templateSpecVersion)); if (templateSpecVersionModel == null) { throw new ArgumentNullException(nameof(templateSpecVersionModel)); } using var scope = _templateSpecVersionClientDiagnostics.CreateScope("TemplateSpecVersionCollection.CreateOrUpdate"); scope.Start(); try { var response = await _templateSpecVersionRestClient.CreateOrUpdateAsync(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, templateSpecVersion, templateSpecVersionModel, cancellationToken).ConfigureAwait(false); var operation = new TemplateSpecVersionCreateOrUpdateOperation(ArmClient, response); if (waitForCompletion) { await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }