Compartilhar via


DeploymentEnvironmentsClient.CreateOrUpdateEnvironmentAsync Method

Definition

Overloads

CreateOrUpdateEnvironmentAsync(WaitUntil, String, String, DevCenterEnvironment, CancellationToken)

Creates or updates an environment.

CreateOrUpdateEnvironmentAsync(WaitUntil, String, String, String, RequestContent, RequestContext)

[Protocol Method] Creates or updates an environment.

  • This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.

CreateOrUpdateEnvironmentAsync(WaitUntil, String, String, DevCenterEnvironment, CancellationToken)

Source:
DeploymentEnvironmentsClient.cs

Creates or updates an environment.

public virtual System.Threading.Tasks.Task<Azure.Operation<Azure.Developer.DevCenter.Models.DevCenterEnvironment>> CreateOrUpdateEnvironmentAsync (Azure.WaitUntil waitUntil, string projectName, string userId, Azure.Developer.DevCenter.Models.DevCenterEnvironment environment, System.Threading.CancellationToken cancellationToken = default);
abstract member CreateOrUpdateEnvironmentAsync : Azure.WaitUntil * string * string * Azure.Developer.DevCenter.Models.DevCenterEnvironment * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Operation<Azure.Developer.DevCenter.Models.DevCenterEnvironment>>
override this.CreateOrUpdateEnvironmentAsync : Azure.WaitUntil * string * string * Azure.Developer.DevCenter.Models.DevCenterEnvironment * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Operation<Azure.Developer.DevCenter.Models.DevCenterEnvironment>>
Public Overridable Function CreateOrUpdateEnvironmentAsync (waitUntil As WaitUntil, projectName As String, userId As String, environment As DevCenterEnvironment, Optional cancellationToken As CancellationToken = Nothing) As Task(Of Operation(Of DevCenterEnvironment))

Parameters

waitUntil
WaitUntil

Completed if the method should wait to return until the long-running operation has completed on the service; Started if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples.

projectName
String

The DevCenter Project upon which to execute operations.

userId
String

The AAD object id of the user. If value is 'me', the identity is taken from the authentication context.

environment
DevCenterEnvironment

Represents an environment.

cancellationToken
CancellationToken

The cancellation token to use.

Returns

Exceptions

projectName, userId or environment is null.

projectName or userId is an empty string, and was expected to be non-empty.

Examples

    This sample shows how to call CreateOrUpdateEnvironmentAsync.
Uri endpoint = new Uri("<https://my-service.azure.com>");
TokenCredential credential = new DefaultAzureCredential();
DeploymentEnvironmentsClient client = new DeploymentEnvironmentsClient(endpoint, credential);

DevCenterEnvironment environment = new DevCenterEnvironment("<environmentName>", "<environmentType>", "<catalogName>", "<environmentDefinitionName>");
Operation<DevCenterEnvironment> operation = await client.CreateOrUpdateEnvironmentAsync(WaitUntil.Completed, "<projectName>", "<userId>", environment);
DevCenterEnvironment responseData = operation.Value;
    This sample shows how to call CreateOrUpdateEnvironmentAsync with all parameters.
Uri endpoint = new Uri("<https://my-service.azure.com>");
TokenCredential credential = new DefaultAzureCredential();
DeploymentEnvironmentsClient client = new DeploymentEnvironmentsClient(endpoint, credential);

DevCenterEnvironment environment = new DevCenterEnvironment("<environmentName>", "<environmentType>", "<catalogName>", "<environmentDefinitionName>")
{
    Parameters =
    {
        ["key"] = BinaryData.FromObjectAsJson(new object())
    },
};
Operation<DevCenterEnvironment> operation = await client.CreateOrUpdateEnvironmentAsync(WaitUntil.Completed, "<projectName>", "<userId>", environment);
DevCenterEnvironment responseData = operation.Value;

Applies to

CreateOrUpdateEnvironmentAsync(WaitUntil, String, String, String, RequestContent, RequestContext)

Source:
DeploymentEnvironmentsClient.cs
Source:
DeploymentEnvironmentsClient.cs

[Protocol Method] Creates or updates an environment.

  • This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
public virtual System.Threading.Tasks.Task<Azure.Operation<BinaryData>> CreateOrUpdateEnvironmentAsync (Azure.WaitUntil waitUntil, string projectName, string userId, string environmentName, Azure.Core.RequestContent content, Azure.RequestContext context = default);
abstract member CreateOrUpdateEnvironmentAsync : Azure.WaitUntil * string * string * string * Azure.Core.RequestContent * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Operation<BinaryData>>
override this.CreateOrUpdateEnvironmentAsync : Azure.WaitUntil * string * string * string * Azure.Core.RequestContent * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Operation<BinaryData>>
Public Overridable Function CreateOrUpdateEnvironmentAsync (waitUntil As WaitUntil, projectName As String, userId As String, environmentName As String, content As RequestContent, Optional context As RequestContext = Nothing) As Task(Of Operation(Of BinaryData))

Parameters

waitUntil
WaitUntil

Completed if the method should wait to return until the long-running operation has completed on the service; Started if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples.

projectName
String

The DevCenter Project upon which to execute operations.

userId
String

The AAD object id of the user. If value is 'me', the identity is taken from the authentication context.

environmentName
String

The name of the environment.

content
RequestContent

The content to send as the body of the request.

context
RequestContext

The request context, which can override default behaviors of the client pipeline on a per-call basis.

Returns

The Operation representing an asynchronous operation on the service.

Exceptions

projectName, userId, environmentName or content is null.

projectName, userId or environmentName is an empty string, and was expected to be non-empty.

Service returned a non-success status code.

Examples

This sample shows how to call CreateOrUpdateEnvironmentAsync and parse the result.

Uri endpoint = new Uri("<https://my-service.azure.com>");
TokenCredential credential = new DefaultAzureCredential();
DeploymentEnvironmentsClient client = new DeploymentEnvironmentsClient(endpoint, credential);

using RequestContent content = RequestContent.Create(new
{
    environmentType = "<environmentType>",
    catalogName = "<catalogName>",
    environmentDefinitionName = "<environmentDefinitionName>",
});
Operation<BinaryData> operation = await client.CreateOrUpdateEnvironmentAsync(WaitUntil.Completed, "<projectName>", "<userId>", "<environmentName>", content);
BinaryData responseData = operation.Value;

JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement;
Console.WriteLine(result.GetProperty("name").ToString());
Console.WriteLine(result.GetProperty("environmentType").ToString());
Console.WriteLine(result.GetProperty("catalogName").ToString());
Console.WriteLine(result.GetProperty("environmentDefinitionName").ToString());

This sample shows how to call CreateOrUpdateEnvironmentAsync with all parameters and request content and parse the result.

Uri endpoint = new Uri("<https://my-service.azure.com>");
TokenCredential credential = new DefaultAzureCredential();
DeploymentEnvironmentsClient client = new DeploymentEnvironmentsClient(endpoint, credential);

using RequestContent content = RequestContent.Create(new
{
    parameters = new
    {
        key = new object(),
    },
    environmentType = "<environmentType>",
    catalogName = "<catalogName>",
    environmentDefinitionName = "<environmentDefinitionName>",
});
Operation<BinaryData> operation = await client.CreateOrUpdateEnvironmentAsync(WaitUntil.Completed, "<projectName>", "<userId>", "<environmentName>", content);
BinaryData responseData = operation.Value;

JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement;
Console.WriteLine(result.GetProperty("parameters").GetProperty("<key>").ToString());
Console.WriteLine(result.GetProperty("name").ToString());
Console.WriteLine(result.GetProperty("environmentType").ToString());
Console.WriteLine(result.GetProperty("user").ToString());
Console.WriteLine(result.GetProperty("provisioningState").ToString());
Console.WriteLine(result.GetProperty("resourceGroupId").ToString());
Console.WriteLine(result.GetProperty("catalogName").ToString());
Console.WriteLine(result.GetProperty("environmentDefinitionName").ToString());
Console.WriteLine(result.GetProperty("error").GetProperty("code").ToString());
Console.WriteLine(result.GetProperty("error").GetProperty("message").ToString());
Console.WriteLine(result.GetProperty("error").GetProperty("target").ToString());
Console.WriteLine(result.GetProperty("error").GetProperty("innererror").GetProperty("code").ToString());

Applies to