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;
            }

            // Resolve the file path and read the raw content
            string rawJsonContent = DataFactoryClient.ReadJsonFileContent(this.TryResolvePath(File));

            // Resolve any mismatch between -Name and the name written in JSON
            Name = ResolveResourceName(rawJsonContent, Name, "Hub");

            CreatePSHubParameters parameters = new CreatePSHubParameters()
            {
                ResourceGroupName = ResourceGroupName,
                DataFactoryName   = DataFactoryName,
                Name           = Name,
                RawJsonContent = rawJsonContent,
                Force          = Force.IsPresent,
                ConfirmAction  = ConfirmAction
            };

            WriteObject(DataFactoryClient.CreatePSHub(parameters));
        }
        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;
            }

            // Resolve the file path and read the raw content
            string rawJsonContent = DataFactoryClient.ReadJsonFileContent(this.TryResolvePath(File));

            // Resolve any mismatch between -Name and the name written in JSON
            Name = ResolveResourceName(rawJsonContent, Name, "Hub");

            CreatePSHubParameters parameters = new CreatePSHubParameters()
            {
                ResourceGroupName = ResourceGroupName,
                DataFactoryName = DataFactoryName,
                Name = Name,
                RawJsonContent = rawJsonContent,
                Force = Force.IsPresent,
                ConfirmAction = ConfirmAction
            };

            WriteObject(DataFactoryClient.CreatePSHub(parameters));
        }
Exemplo n.º 3
0
        public virtual PSHub CreatePSHub(CreatePSHubParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            PSHub  hub       = null;
            Action createHub = () =>
            {
                hub =
                    new PSHub(
                        this.CreateOrUpdateHub(
                            parameters.ResourceGroupName,
                            parameters.DataFactoryName,
                            parameters.Name,
                            parameters.RawJsonContent))
                {
                    DataFactoryName = parameters.DataFactoryName, ResourceGroupName = parameters.ResourceGroupName
                };

                if (!DataFactoryCommonUtilities.IsSucceededProvisioningState(hub.ProvisioningState))
                {
                    // ToDo: service side should set the error message for provisioning failures.
                    throw new ProvisioningFailedException(Resources.HubProvisioningFailed);
                }
            };

            if (parameters.Force)
            {
                createHub();
            }
            else
            {
                bool hubExists = this.CheckHubExists(
                    parameters.ResourceGroupName,
                    parameters.DataFactoryName,
                    parameters.Name);

                parameters.ConfirmAction(
                    !hubExists,
                    string.Format(
                        CultureInfo.InvariantCulture,
                        Resources.HubExists,
                        parameters.Name,
                        parameters.DataFactoryName),
                    string.Format(
                        CultureInfo.InvariantCulture,
                        Resources.HubCreating,
                        parameters.Name,
                        parameters.DataFactoryName),
                    parameters.Name,
                    createHub);
            }

            return(hub);
        }
        public virtual PSHub CreatePSHub(CreatePSHubParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            PSHub hub = null;
            Action createHub = () =>
            {
                hub =
                    new PSHub(
                        this.CreateOrUpdateHub(
                            parameters.ResourceGroupName,
                            parameters.DataFactoryName,
                            parameters.Name,
                            parameters.RawJsonContent))
                    {DataFactoryName = parameters.DataFactoryName, ResourceGroupName = parameters.ResourceGroupName};

                if (!DataFactoryCommonUtilities.IsSucceededProvisioningState(hub.ProvisioningState))
                {
                    // ToDo: service side should set the error message for provisioning failures.
                    throw new ProvisioningFailedException(Resources.HubProvisioningFailed);
                }
            };

            if (parameters.Force)
            {
                createHub();
            }
            else
            {
                bool hubExists = this.CheckHubExists(
                    parameters.ResourceGroupName,
                    parameters.DataFactoryName,
                    parameters.Name);

                parameters.ConfirmAction(
                    !hubExists,
                    string.Format(
                        CultureInfo.InvariantCulture,
                        Resources.HubExists,
                        parameters.Name,
                        parameters.DataFactoryName),
                    string.Format(
                        CultureInfo.InvariantCulture,
                        Resources.HubCreating,
                        parameters.Name,
                        parameters.DataFactoryName),
                    parameters.Name,
                    createHub);
            }

            return hub;
        }