Microsoft.Azure.Commands.DataFactories.DataFactoryClient.CreateOrUpdateGateway C# (CSharp) Method

CreateOrUpdateGateway() public method

public CreateOrUpdateGateway ( string resourceGroupName, string dataFactoryName, PSDataFactoryGateway gateway ) : PSDataFactoryGateway
resourceGroupName string
dataFactoryName string
gateway Microsoft.Azure.Commands.DataFactories.Models.PSDataFactoryGateway
return Microsoft.Azure.Commands.DataFactories.Models.PSDataFactoryGateway
        public virtual PSDataFactoryGateway CreateOrUpdateGateway(string resourceGroupName, string dataFactoryName, PSDataFactoryGateway gateway)
        {
            if (gateway == null)
            {
                throw new ArgumentNullException("gateway");
            }

            var response = DataPipelineManagementClient.Gateways.CreateOrUpdate(
                resourceGroupName, dataFactoryName, new GatewayCreateOrUpdateParameters { Gateway = gateway.ToGatewayDefinition() });

            Gateway createdGateway = response.Gateway;
            if (createdGateway.Properties != null &&
                !DataFactoryCommonUtilities.IsSucceededProvisioningState(createdGateway.Properties.ProvisioningState))
            {
                // ToDo: service side should set the error message for provisioning failures.
                throw new ProvisioningFailedException(Resources.GatewayProvisioningFailed);
            }

            return new PSDataFactoryGateway(createdGateway);
        }

Usage Example

        public override void ExecuteCmdlet()
        {
            if (ParameterSetName == ByFactoryObject)
            {
                if (DataFactory == null)
                {
                    throw new PSArgumentNullException(string.Format(CultureInfo.InvariantCulture, Resources.DataFactoryArgumentInvalid));
                }

                DataFactoryName   = DataFactory.DataFactoryName;
                ResourceGroupName = DataFactory.ResourceGroupName;
            }

            PSDataFactoryGateway gateway = null;

            try
            {
                gateway = DataFactoryClient.GetGateway(ResourceGroupName, DataFactoryName, Name);
            }
            catch (CloudException ex)
            {
                if (ex.Response.StatusCode != HttpStatusCode.NotFound)
                {
                    throw;
                }
            }

            if (gateway != null)
            {
                throw new PSInvalidOperationException(string.Format(CultureInfo.InvariantCulture, Resources.DataFactoryGatewayExists, Name, DataFactoryName));
            }

            var request = new PSDataFactoryGateway
            {
                Name        = Name,
                Location    = NormalizeLocation(Location),
                Description = Description
            };

            PSDataFactoryGateway response = DataFactoryClient.CreateOrUpdateGateway(ResourceGroupName, DataFactoryName, request);

            WriteObject(response);
        }