示例#1
0
        public async virtual Task <DeploymentWhatIfOperation> WhatIfAsync(DeploymentWhatIfProperties properties, string location = null, bool waitForCompletion = true, CancellationToken cancellationToken = default)
        {
            if (properties == null)
            {
                throw new ArgumentNullException(nameof(properties));
            }

            using var scope = _clientDiagnostics.CreateScope("DeploymentExtended.WhatIf");
            scope.Start();
            try
            {
                if (Id.TryGetResourceGroupName(out _))
                {
                    var response = await _restClient.WhatIfAsync(Id.Parent.Parent.Name, Id.Parent.Name, Id.Name, properties, location, cancellationToken).ConfigureAwait(false);

                    var operation = new DeploymentWhatIfOperation(_clientDiagnostics, Pipeline, _restClient.CreateWhatIfRequest(Id.Parent.Parent.Name, Id.Parent.Name, Id.Name, properties, location).Request, response);
                    if (waitForCompletion)
                    {
                        await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false);
                    }
                    return(operation);
                }
                else if (Id.TryGetSubscriptionId(out _))
                {
                    var response = await _restClient.WhatIfAtSubscriptionScopeAsync(Id.Parent.Name, Id.Name, properties, location, cancellationToken).ConfigureAwait(false);

                    var operation = new DeploymentWhatIfOperation(_clientDiagnostics, Pipeline, _restClient.CreateWhatIfAtSubscriptionScopeRequest(Id.Parent.Name, Id.Name, properties, location).Request, response);
                    if (waitForCompletion)
                    {
                        await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false);
                    }
                    return(operation);
                }
                else
                {
                    var parent = Id;
                    while (parent.Parent != ResourceIdentifier.RootResourceIdentifier)
                    {
                        parent = parent.Parent;
                    }
                    if (parent.ResourceType.Equals(ManagementGroup.ResourceType))
                    {
                        var response = await _restClient.WhatIfAtManagementGroupScopeAsync(Id.Parent.Name, Id.Name, location, properties, cancellationToken).ConfigureAwait(false);

                        var operation = new DeploymentWhatIfOperation(_clientDiagnostics, Pipeline, _restClient.CreateWhatIfAtManagementGroupScopeRequest(Id.Parent.Name, Id.Name, location, properties).Request, response);
                        if (waitForCompletion)
                        {
                            await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false);
                        }
                        return(operation);
                    }
                    else
                    {
                        var response = await _restClient.WhatIfAtTenantScopeAsync(Id.Name, location, properties, cancellationToken).ConfigureAwait(false);

                        var operation = new DeploymentWhatIfOperation(_clientDiagnostics, Pipeline, _restClient.CreateWhatIfAtTenantScopeRequest(Id.Name, location, properties).Request, response);
                        if (waitForCompletion)
                        {
                            await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false);
                        }
                        return(operation);
                    }
                }
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
示例#2
0
        public async virtual Task <ArmOperation <WhatIfOperationResult> > WhatIfAsync(bool waitForCompletion, DeploymentWhatIf parameters, CancellationToken cancellationToken = default)
        {
            Argument.AssertNotNull(parameters, nameof(parameters));

            using var scope = _deploymentClientDiagnostics.CreateScope("Deployment.WhatIf");
            scope.Start();
            try
            {
                if (Id.Parent.ResourceType == Tenant.ResourceType)
                {
                    var response = await _deploymentRestClient.WhatIfAtTenantScopeAsync(Id.Name, parameters, cancellationToken).ConfigureAwait(false);

                    var operation = new ResourcesArmOperation <WhatIfOperationResult>(new WhatIfOperationResultOperationSource(), _deploymentClientDiagnostics, Pipeline, _deploymentRestClient.CreateWhatIfAtTenantScopeRequest(Id.Name, parameters).Request, response, OperationFinalStateVia.Location);
                    if (waitForCompletion)
                    {
                        await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false);
                    }
                    return(operation);
                }
                else if (Id.Parent.ResourceType == ManagementGroup.ResourceType)
                {
                    var response = await _deploymentRestClient.WhatIfAtManagementGroupScopeAsync(Id.Parent.Name, Id.Name, parameters, cancellationToken).ConfigureAwait(false);

                    var operation = new ResourcesArmOperation <WhatIfOperationResult>(new WhatIfOperationResultOperationSource(), _deploymentClientDiagnostics, Pipeline, _deploymentRestClient.CreateWhatIfAtManagementGroupScopeRequest(Id.Parent.Name, Id.Name, parameters).Request, response, OperationFinalStateVia.Location);
                    if (waitForCompletion)
                    {
                        await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false);
                    }
                    return(operation);
                }
                else if (Id.Parent.ResourceType == Subscription.ResourceType)
                {
                    var response = await _deploymentRestClient.WhatIfAtSubscriptionScopeAsync(Id.SubscriptionId, Id.Name, parameters, cancellationToken).ConfigureAwait(false);

                    var operation = new ResourcesArmOperation <WhatIfOperationResult>(new WhatIfOperationResultOperationSource(), _deploymentClientDiagnostics, Pipeline, _deploymentRestClient.CreateWhatIfAtSubscriptionScopeRequest(Id.SubscriptionId, Id.Name, parameters).Request, response, OperationFinalStateVia.Location);
                    if (waitForCompletion)
                    {
                        await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false);
                    }
                    return(operation);
                }
                else if (Id.Parent.ResourceType == ResourceGroup.ResourceType)
                {
                    var response = await _deploymentRestClient.WhatIfAsync(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, parameters, cancellationToken).ConfigureAwait(false);

                    var operation = new ResourcesArmOperation <WhatIfOperationResult>(new WhatIfOperationResultOperationSource(), _deploymentClientDiagnostics, Pipeline, _deploymentRestClient.CreateWhatIfRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, parameters).Request, response, OperationFinalStateVia.Location);
                    if (waitForCompletion)
                    {
                        await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false);
                    }
                    return(operation);
                }
                else
                {
                    throw new InvalidOperationException($"{Id.Parent.ResourceType} is not supported here");
                }
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
        public async virtual Task <DeploymentWhatIfAtTenantScopeOperation> WhatIfAsync(string location, DeploymentWhatIfProperties properties, bool waitForCompletion = true, CancellationToken cancellationToken = default)
        {
            if (location == null)
            {
                throw new ArgumentNullException(nameof(location));
            }
            if (properties == null)
            {
                throw new ArgumentNullException(nameof(properties));
            }

            using var scope = _clientDiagnostics.CreateScope("Deployment.WhatIf");
            scope.Start();
            try
            {
                if (Id.Parent.ResourceType == Tenant.ResourceType)
                {
                    var response = await _deploymentsRestClient.WhatIfAtTenantScopeAsync(Id.Name, location, properties, cancellationToken).ConfigureAwait(false);

                    var operation = new DeploymentWhatIfAtTenantScopeOperation(_clientDiagnostics, Pipeline, _deploymentsRestClient.CreateWhatIfAtTenantScopeRequest(Id.Name, location, properties).Request, response);
                    if (waitForCompletion)
                    {
                        await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false);
                    }
                    return(operation);
                }
                else if (Id.Parent.ResourceType == ManagementGroup.ResourceType)
                {
                    var response = await _deploymentsRestClient.WhatIfAtManagementGroupScopeAsync(Id.Parent.Name, Id.Name, location, properties, cancellationToken).ConfigureAwait(false);

                    var operation = new DeploymentWhatIfAtTenantScopeOperation(_clientDiagnostics, Pipeline, _deploymentsRestClient.CreateWhatIfAtManagementGroupScopeRequest(Id.Parent.Name, Id.Name, location, properties).Request, response);
                    if (waitForCompletion)
                    {
                        await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false);
                    }
                    return(operation);
                }
                else if (Id.Parent.ResourceType == Subscription.ResourceType)
                {
                    var response = await _deploymentsRestClient.WhatIfAtSubscriptionScopeAsync(Id.SubscriptionId, Id.Name, properties, location, cancellationToken).ConfigureAwait(false);

                    var operation = new DeploymentWhatIfAtTenantScopeOperation(_clientDiagnostics, Pipeline, _deploymentsRestClient.CreateWhatIfAtSubscriptionScopeRequest(Id.SubscriptionId, Id.Name, properties, location).Request, response);
                    if (waitForCompletion)
                    {
                        await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false);
                    }
                    return(operation);
                }
                else if (Id.Parent.ResourceType == ResourceGroup.ResourceType)
                {
                    var response = await _deploymentsRestClient.WhatIfAsync(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, properties, location, cancellationToken).ConfigureAwait(false);

                    var operation = new DeploymentWhatIfAtTenantScopeOperation(_clientDiagnostics, Pipeline, _deploymentsRestClient.CreateWhatIfRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, properties, location).Request, response);
                    if (waitForCompletion)
                    {
                        await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false);
                    }
                    return(operation);
                }
                else
                {
                    throw new InvalidOperationException($"{Id.Parent.ResourceType} is not supported here");
                }
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }