public override void ExecuteCmdlet()
        {
            if (this.IsParameterBound(c => c.ResourceId))
            {
                var resourceIdentifier = new ResourceIdentifier(this.ResourceId);
                this.ResourceGroupName = resourceIdentifier.ResourceGroupName;
                this.WorkspaceName     = resourceIdentifier.ParentResource;
                this.WorkspaceName     = this.WorkspaceName.Substring(this.WorkspaceName.LastIndexOf('/') + 1);
                this.Name = resourceIdentifier.ResourceName;
            }

            if (this.IsParameterBound(c => c.WorkspaceObject))
            {
                this.ResourceGroupName = new ResourceIdentifier(this.WorkspaceObject.Id).ResourceGroupName;
                this.WorkspaceName     = this.WorkspaceObject.Name;
            }

            if (!string.IsNullOrEmpty(this.Name))
            {
                var result = new PSSynapseSqlDatabase(this.SynapseAnalyticsClient.GetSqlDatabase(this.ResourceGroupName, this.WorkspaceName, this.Name));
                WriteObject(result);
            }
            else
            {
                var result = this.SynapseAnalyticsClient.ListSqlDatabases(this.ResourceGroupName, this.WorkspaceName).Select(r => new PSSynapseSqlDatabase(r));
                WriteObject(result, true);
            }
        }
Exemplo n.º 2
0
        public override void ExecuteCmdlet()
        {
            if (this.IsParameterBound(c => c.WorkspaceObject))
            {
                this.ResourceGroupName = new ResourceIdentifier(this.WorkspaceObject.Id).ResourceGroupName;
                this.WorkspaceName     = this.WorkspaceObject.Name;
            }

            if (string.IsNullOrEmpty(this.ResourceGroupName))
            {
                this.ResourceGroupName = this.SynapseAnalyticsClient.GetResourceGroupByWorkspaceName(this.WorkspaceName);
            }

            var existingWorkspace = this.SynapseAnalyticsClient.GetWorkspaceOrDefault(this.ResourceGroupName, this.WorkspaceName);

            if (existingWorkspace == null)
            {
                throw new AzPSResourceNotFoundCloudException(string.Format(Resources.WorkspaceDoesNotExist, this.WorkspaceName));
            }

            var existingSqlDatabase = this.SynapseAnalyticsClient.GetSqlDatabaseOrDefault(this.ResourceGroupName, this.WorkspaceName, this.Name);

            if (existingSqlDatabase != null)
            {
                throw new AzPSInvalidOperationException(string.Format(Resources.SynapseSqlDatabaseExists, this.Name, this.ResourceGroupName, this.WorkspaceName));
            }

            var createParams = new SqlDatabase
            {
                Location = existingWorkspace.Location,
                Tags     = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true)
            };

            switch (this.ParameterSetName)
            {
            case CreateByNameParameterSet:
            case CreateByParentObjectParameterSet:
                createParams.MaxSizeBytes = this.MaxSizeInBytes;
                createParams.Collation    = this.IsParameterBound(c => c.Collation) ? this.Collation : SynapseConstants.DefaultCollation;
                break;

            default: throw new AzPSInvalidOperationException(string.Format(Resources.InvalidParameterSet, this.ParameterSetName));
            }

            if (this.ShouldProcess(this.Name, string.Format(Resources.CreatingSynapseSqlDatabase, this.ResourceGroupName, this.WorkspaceName, this.Name)))
            {
                var result = new PSSynapseSqlDatabase(this.SynapseAnalyticsClient.CreateSqlDatabase(this.ResourceGroupName, this.WorkspaceName, this.Name, createParams));
                WriteObject(result);
            }
        }