public virtual DeploymentWhatIfAtTenantScopeOperation WhatIf(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  = _deploymentsRestClient.WhatIfAtTenantScope(Id.Name, location, properties, cancellationToken);
                    var operation = new DeploymentWhatIfAtTenantScopeOperation(_clientDiagnostics, Pipeline, _deploymentsRestClient.CreateWhatIfAtTenantScopeRequest(Id.Name, location, properties).Request, response);
                    if (waitForCompletion)
                    {
                        operation.WaitForCompletion(cancellationToken);
                    }
                    return(operation);
                }
                else if (Id.Parent.ResourceType == ManagementGroup.ResourceType)
                {
                    var response  = _deploymentsRestClient.WhatIfAtManagementGroupScope(Id.Parent.Name, Id.Name, location, properties, cancellationToken);
                    var operation = new DeploymentWhatIfAtTenantScopeOperation(_clientDiagnostics, Pipeline, _deploymentsRestClient.CreateWhatIfAtManagementGroupScopeRequest(Id.Parent.Name, Id.Name, location, properties).Request, response);
                    if (waitForCompletion)
                    {
                        operation.WaitForCompletion(cancellationToken);
                    }
                    return(operation);
                }
                else if (Id.Parent.ResourceType == Subscription.ResourceType)
                {
                    var response  = _deploymentsRestClient.WhatIfAtSubscriptionScope(Id.SubscriptionId, Id.Name, properties, location, cancellationToken);
                    var operation = new DeploymentWhatIfAtTenantScopeOperation(_clientDiagnostics, Pipeline, _deploymentsRestClient.CreateWhatIfAtSubscriptionScopeRequest(Id.SubscriptionId, Id.Name, properties, location).Request, response);
                    if (waitForCompletion)
                    {
                        operation.WaitForCompletion(cancellationToken);
                    }
                    return(operation);
                }
                else if (Id.Parent.ResourceType == ResourceGroup.ResourceType)
                {
                    var response  = _deploymentsRestClient.WhatIf(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, properties, location, cancellationToken);
                    var operation = new DeploymentWhatIfAtTenantScopeOperation(_clientDiagnostics, Pipeline, _deploymentsRestClient.CreateWhatIfRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, properties, location).Request, response);
                    if (waitForCompletion)
                    {
                        operation.WaitForCompletion(cancellationToken);
                    }
                    return(operation);
                }
                else
                {
                    throw new InvalidOperationException($"{Id.Parent.ResourceType} is not supported here");
                }
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
Exemple #2
0
        public virtual DeploymentWhatIfOperation WhatIf(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  = _restClient.WhatIf(Id.Parent.Parent.Name, Id.Parent.Name, Id.Name, properties, location, cancellationToken);
                    var operation = new DeploymentWhatIfOperation(_clientDiagnostics, Pipeline, _restClient.CreateWhatIfRequest(Id.Parent.Parent.Name, Id.Parent.Name, Id.Name, properties, location).Request, response);
                    if (waitForCompletion)
                    {
                        operation.WaitForCompletion(cancellationToken);
                    }
                    return(operation);
                }
                else if (Id.TryGetSubscriptionId(out _))
                {
                    var response  = _restClient.WhatIfAtSubscriptionScope(Id.Parent.Name, Id.Name, properties, location, cancellationToken);
                    var operation = new DeploymentWhatIfOperation(_clientDiagnostics, Pipeline, _restClient.CreateWhatIfAtSubscriptionScopeRequest(Id.Parent.Name, Id.Name, properties, location).Request, response);
                    if (waitForCompletion)
                    {
                        operation.WaitForCompletion(cancellationToken);
                    }
                    return(operation);
                }
                else
                {
                    var parent = Id;
                    while (parent.Parent != ResourceIdentifier.RootResourceIdentifier)
                    {
                        parent = parent.Parent;
                    }
                    if (parent.ResourceType.Equals(ManagementGroup.ResourceType))
                    {
                        var response  = _restClient.WhatIfAtManagementGroupScope(Id.Parent.Name, Id.Name, location, properties, cancellationToken);
                        var operation = new DeploymentWhatIfOperation(_clientDiagnostics, Pipeline, _restClient.CreateWhatIfAtManagementGroupScopeRequest(Id.Parent.Name, Id.Name, location, properties).Request, response);
                        if (waitForCompletion)
                        {
                            operation.WaitForCompletion(cancellationToken);
                        }
                        return(operation);
                    }
                    else
                    {
                        var response  = _restClient.WhatIfAtTenantScope(Id.Name, location, properties, cancellationToken);
                        var operation = new DeploymentWhatIfOperation(_clientDiagnostics, Pipeline, _restClient.CreateWhatIfAtTenantScopeRequest(Id.Name, location, properties).Request, response);
                        if (waitForCompletion)
                        {
                            operation.WaitForCompletion(cancellationToken);
                        }
                        return(operation);
                    }
                }
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
        public virtual ArmOperation <WhatIfOperationResult> WhatIf(bool waitForCompletion, string location, DeploymentWhatIfProperties properties, CancellationToken cancellationToken = default)
        {
            Argument.AssertNotNull(location, nameof(location));
            Argument.AssertNotNull(properties, nameof(properties));

            using var scope = _deploymentClientDiagnostics.CreateScope("Deployment.WhatIf");
            scope.Start();
            try
            {
                if (Id.Parent.ResourceType == Tenant.ResourceType)
                {
                    var response  = _deploymentRestClient.WhatIfAtTenantScope(Id.Name, location, properties, cancellationToken);
                    var operation = new ResourcesArmOperation <WhatIfOperationResult>(new WhatIfOperationResultOperationSource(), _deploymentClientDiagnostics, Pipeline, _deploymentRestClient.CreateWhatIfAtTenantScopeRequest(Id.Name, location, properties).Request, response, OperationFinalStateVia.Location);
                    if (waitForCompletion)
                    {
                        operation.WaitForCompletion(cancellationToken);
                    }
                    return(operation);
                }
                else if (Id.Parent.ResourceType == ManagementGroup.ResourceType)
                {
                    var response  = _deploymentRestClient.WhatIfAtManagementGroupScope(Id.Parent.Name, Id.Name, location, properties, cancellationToken);
                    var operation = new ResourcesArmOperation <WhatIfOperationResult>(new WhatIfOperationResultOperationSource(), _deploymentClientDiagnostics, Pipeline, _deploymentRestClient.CreateWhatIfAtManagementGroupScopeRequest(Id.Parent.Name, Id.Name, location, properties).Request, response, OperationFinalStateVia.Location);
                    if (waitForCompletion)
                    {
                        operation.WaitForCompletion(cancellationToken);
                    }
                    return(operation);
                }
                else if (Id.Parent.ResourceType == Subscription.ResourceType)
                {
                    var response  = _deploymentRestClient.WhatIfAtSubscriptionScope(Id.SubscriptionId, Id.Name, properties, location, cancellationToken);
                    var operation = new ResourcesArmOperation <WhatIfOperationResult>(new WhatIfOperationResultOperationSource(), _deploymentClientDiagnostics, Pipeline, _deploymentRestClient.CreateWhatIfAtSubscriptionScopeRequest(Id.SubscriptionId, Id.Name, properties, location).Request, response, OperationFinalStateVia.Location);
                    if (waitForCompletion)
                    {
                        operation.WaitForCompletion(cancellationToken);
                    }
                    return(operation);
                }
                else if (Id.Parent.ResourceType == ResourceGroup.ResourceType)
                {
                    var response  = _deploymentRestClient.WhatIf(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, properties, location, cancellationToken);
                    var operation = new ResourcesArmOperation <WhatIfOperationResult>(new WhatIfOperationResultOperationSource(), _deploymentClientDiagnostics, Pipeline, _deploymentRestClient.CreateWhatIfRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Name, properties, location).Request, response, OperationFinalStateVia.Location);
                    if (waitForCompletion)
                    {
                        operation.WaitForCompletion(cancellationToken);
                    }
                    return(operation);
                }
                else
                {
                    throw new InvalidOperationException($"{Id.Parent.ResourceType} is not supported here");
                }
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }