示例#1
0
        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, "Table");

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

            WriteObject(DataFactoryClient.CreatePSTable(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, "Table");

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

            WriteObject(DataFactoryClient.CreatePSTable(parameters));
        }
示例#3
0
        public virtual PSTable CreatePSTable(CreatePSTableParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            PSTable table       = null;
            Action  createTable = () =>
            {
                table =
                    new PSTable(CreateOrUpdateTable(
                                    parameters.ResourceGroupName,
                                    parameters.DataFactoryName,
                                    parameters.Name,
                                    parameters.RawJsonContent))
                {
                    ResourceGroupName = parameters.ResourceGroupName,
                    DataFactoryName   = parameters.DataFactoryName
                };

                if (!DataFactoryCommonUtilities.IsSucceededProvisioningState(table.ProvisioningState))
                {
                    string errorMessage = table.Properties == null
                        ? string.Empty
                        : table.Properties.ErrorMessage;
                    throw new ProvisioningFailedException(errorMessage);
                }
            };

            if (parameters.Force)
            {
                // If user decides to overwrite anyway, then there is no need to check if the table exists or not.
                createTable();
            }
            else
            {
                bool tableExists = CheckTableExists(parameters.ResourceGroupName, parameters.DataFactoryName,
                                                    parameters.Name);

                parameters.ConfirmAction(
                    !tableExists,  // prompt only if the table exists
                    string.Format(
                        CultureInfo.InvariantCulture,
                        Resources.TableExists,
                        parameters.Name,
                        parameters.DataFactoryName),
                    string.Format(
                        CultureInfo.InvariantCulture,
                        Resources.TableCreating,
                        parameters.Name,
                        parameters.DataFactoryName),
                    parameters.Name,
                    createTable);
            }

            return(table);
        }
        public virtual PSTable CreatePSTable(CreatePSTableParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            PSTable table = null;
            Action createTable = () =>
            {
                table =
                    new PSTable(CreateOrUpdateTable(
                        parameters.ResourceGroupName,
                        parameters.DataFactoryName,
                        parameters.Name,
                        parameters.RawJsonContent))
                    {
                        ResourceGroupName = parameters.ResourceGroupName,
                        DataFactoryName = parameters.DataFactoryName
                    };
            };

            if (parameters.Force)
            {
                // If user decides to overwrite anyway, then there is no need to check if the table exists or not.
                createTable();
            }
            else
            {
                bool tableExists = CheckTableExists(parameters.ResourceGroupName, parameters.DataFactoryName,
                    parameters.Name);

                parameters.ConfirmAction(
                    !tableExists,  // prompt only if the table exists
                    string.Format(
                        CultureInfo.InvariantCulture,
                        Resources.TableExists,
                        parameters.Name,
                        parameters.DataFactoryName),
                    string.Format(
                        CultureInfo.InvariantCulture,
                        Resources.TableCreating,
                        parameters.Name,
                        parameters.DataFactoryName),
                    parameters.Name,
                    createTable);
            }

            if (!DataFactoryCommonUtilities.IsSucceededProvisioningState(table.ProvisioningState))
            {
                string errorMessage = table.Properties == null
                    ? string.Empty
                    : table.Properties.ErrorMessage;
                throw new ProvisioningFailedException(errorMessage);
            }

            return table;
        }