示例#1
0
 public PSSqlScriptResource(SqlScriptResource sqlscriptResource, string workspaceName)
     : base(sqlscriptResource?.Id,
            sqlscriptResource?.Name,
            sqlscriptResource?.Type,
            sqlscriptResource?.Etag)
 {
     this.WorkspaceName = workspaceName;
     this.Properties    = new PSSqlScript(sqlscriptResource?.Properties);
 }
示例#2
0
        public async Task TestDeleteSparkJob()
        {
            SqlScriptClient client = CreateClient();

            SqlScriptResource resource = await DisposableSqlScript.CreateResource(client, Recording);

            SqlScriptDeleteSqlScriptOperation deleteOperation = await client.StartDeleteSqlScriptAsync(resource.Name);

            await deleteOperation.WaitAndAssertSuccessfulCompletion();
        }
示例#3
0
        public async Task TestGetScripts()
        {
            SqlScriptClient client = CreateClient();

            await using DisposableSqlScript singleScript = await DisposableSqlScript.Create(client, Recording);

            IList <SqlScriptResource> scripts = await client.GetSqlScriptsByWorkspaceAsync().ToListAsync();

            Assert.GreaterOrEqual(scripts.Count, 1);

            foreach (SqlScriptResource script in scripts)
            {
                SqlScriptResource actualScript = await client.GetSqlScriptAsync(script.Name);

                Assert.AreEqual(actualScript.Name, script.Name);
                Assert.AreEqual(actualScript.Id, script.Id);
                Assert.AreEqual(actualScript.Type, script.Type);
            }
        }
示例#4
0
        public async Task TestRenameSparkJob()
        {
            SqlScriptClient client = CreateClient();

            SqlScriptResource resource = await DisposableSqlScript.CreateResource(client, Recording);

            string newScriptName = Recording.GenerateId("SqlScript", 16);

            SqlScriptRenameSqlScriptOperation renameOperation = await client.StartRenameSqlScriptAsync(resource.Name, new ArtifactRenameRequest()
            {
                NewName = newScriptName
            });

            await renameOperation.WaitForCompletionResponseAsync();

            SqlScriptResource sparkJob = await client.GetSqlScriptAsync(newScriptName);

            Assert.AreEqual(newScriptName, sparkJob.Name);

            SqlScriptDeleteSqlScriptOperation deleteOperation = await client.StartDeleteSqlScriptAsync(newScriptName);

            await deleteOperation.WaitForCompletionResponseAsync();
        }
        public virtual SqlScriptCreateOrUpdateSqlScriptOperation StartCreateOrUpdateSqlScript(string sqlScriptName, SqlScriptResource sqlScript, string ifMatch = null, CancellationToken cancellationToken = default)
        {
            if (sqlScriptName == null)
            {
                throw new ArgumentNullException(nameof(sqlScriptName));
            }
            if (sqlScript == null)
            {
                throw new ArgumentNullException(nameof(sqlScript));
            }

            using var scope = _clientDiagnostics.CreateScope("SqlScriptClient.StartCreateOrUpdateSqlScript");
            scope.Start();
            try
            {
                var originalResponse = RestClient.CreateOrUpdateSqlScript(sqlScriptName, sqlScript, ifMatch, cancellationToken);
                return(new SqlScriptCreateOrUpdateSqlScriptOperation(_clientDiagnostics, _pipeline, RestClient.CreateCreateOrUpdateSqlScriptRequest(sqlScriptName, sqlScript, ifMatch).Request, originalResponse));
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
示例#6
0
 private DisposableSqlScript(SqlScriptClient client, SqlScriptResource resource)
 {
     _client  = client;
     Resource = resource;
 }
示例#7
0
 public virtual Response <SqlScriptResource> CreateOrUpdateSqlScript(string sqlScriptName, SqlScriptResource sqlScript, string ifMatch = null, CancellationToken cancellationToken = default)
 {
     using var scope = _clientDiagnostics.CreateScope("SqlScriptClient.CreateOrUpdateSqlScript");
     scope.Start();
     try
     {
         return(RestClient.CreateOrUpdateSqlScript(sqlScriptName, sqlScript, ifMatch, cancellationToken));
     }
     catch (Exception e)
     {
         scope.Failed(e);
         throw;
     }
 }
 public SqlScriptResource CreateOrUpdateSqlScript(string sqlScriptName, SqlScriptResource resource)
 {
     return(_sqlScriptClient.StartCreateOrUpdateSqlScript(sqlScriptName, resource).Poll().Value);
 }
        public override void ExecuteCmdlet()
        {
            if (this.IsParameterBound(c => c.WorkspaceObject))
            {
                this.WorkspaceName = this.WorkspaceObject.Name;
            }

            if (!this.IsParameterBound(c => c.Name))
            {
                string path = this.TryResolvePath(DefinitionFile);
                this.Name = Path.GetFileNameWithoutExtension(path);
            }

            if (this.ShouldProcess(this.WorkspaceName, String.Format(Resources.SettingSynapseSqlScript, this.Name, this.WorkspaceName)))
            {
                string        query             = this.ReadFileAsText(DefinitionFile);
                SqlConnection currentConnection = new SqlConnection();

                if (this.IsParameterBound(c => c.SqlPoolName))
                {
                    if (SqlPoolName.ToLower() == "built-in")
                    {
                        currentConnection.PoolName     = "Built-in";
                        currentConnection.Type         = SqlConnectionType.SqlOnDemand;
                        currentConnection.DatabaseName = this.SqlDatabaseName;
                    }
                    else
                    {
                        currentConnection.Type         = SqlConnectionType.SqlPool;
                        currentConnection.PoolName     = this.SqlPoolName;
                        currentConnection.DatabaseName = this.SqlDatabaseName;
                    }
                }
                else
                {
                    currentConnection.PoolName     = "Built-in";
                    currentConnection.Type         = SqlConnectionType.SqlOnDemand;
                    currentConnection.DatabaseName = "master";
                }

                SqlScriptMetadata metadata = new SqlScriptMetadata
                {
                    Language = "sql"
                };

                SqlScriptContent content = new SqlScriptContent(query);
                content.CurrentConnection = currentConnection;
                content.Metadata          = metadata;
                content.ResultLimit       = ResultLimit;

                SqlScript sqlscript = new SqlScript(content);
                sqlscript.Type = SqlScriptType.SqlQuery;
                if (this.IsParameterBound(c => c.FolderPath))
                {
                    SqlScriptFolder folder = new SqlScriptFolder();
                    folder.Name      = FolderPath;
                    sqlscript.Folder = folder;
                }
                if (this.IsParameterBound(c => c.Description))
                {
                    sqlscript.Description = Description;
                }

                SqlScriptResource sqlscriptResource = new SqlScriptResource(this.Name, sqlscript);

                WriteObject(new PSSqlScriptResource(SynapseAnalyticsClient.CreateOrUpdateSqlScript(this.Name, sqlscriptResource), this.WorkspaceName));
            }
        }