Exemple #1
0
        //this constructor is for file deserialization to work.



        internal async Task DeployAsync(IEnumerable <SqlScriptFile> scriptFiles)
        {
            SqlScriptFile    currentFile    = null;
            SqlScriptContent currentContent = null;

            try
            {
                this.Context.BeginTransaction();
                foreach (var scriptFile in scriptFiles)
                {
                    currentFile = scriptFile;
                    foreach (var script in scriptFile.Scripts)
                    {
                        currentContent = script;
                        await Context.ExecuteNonQueryAsync(script.Content);
                    }
                }
                this.Context.CommitTransaction();
            }
            catch (Exception ex)
            {
                this.Context.RollbackTransaction();
                throw new DeploymentException("Deployment error", ex, currentFile, currentContent);
            }
            finally
            {
                this.Context.FinishConnection();
            }
            return;
        }
        //this constructor is for file deserialization to work.



        internal async Task DeployAsync(IEnumerable <SqlScriptFile> scriptFiles, CancellationToken ct)
        {
            if (ct.IsCancellationRequested)
            {
                return;
            }
            SqlScriptFile    currentFile    = null;
            SqlScriptContent currentContent = null;

            try
            {
                this.Context.BeginTransaction();
                foreach (var scriptFile in scriptFiles)
                {
                    currentFile = scriptFile;
                    //EBORJA
                    if (scriptFile.Checked)
                    {
                        foreach (var script in scriptFile.Scripts)
                        {
                            currentContent = script;
                            await Context.ExecuteNonQueryAsync(script.Content, CommandTimeout, ct);
                        }
                    }
                }
                this.Context.CommitTransaction();
            }
            catch (OperationCanceledException ex)
            {
                this.Context?.RollbackTransaction();
                throw ex;
            }
            catch (Exception ex)
            {
                this.Context?.RollbackTransaction();
                ThrowIfSqlClientCancellationRequested(ct, ex);
                throw new DeploymentException("Deployment error", ex, currentFile, currentContent);
            }
            finally
            {
                this.Context.FinishConnection();
            }
            return;
        }
        //this constructor is for file deserialization to work.

        internal async Task DeployAsync(IEnumerable <SqlScriptFile> scriptFiles, CancellationToken ct)
        {
            if (ct.IsCancellationRequested)
            {
                return;
            }
            SqlScriptFile    currentFile    = null;
            SqlScriptContent currentContent = null;

            try
            {
                Context.BeginTransaction();
                foreach (var scriptFile in scriptFiles)
                {
                    currentFile = scriptFile;
                    foreach (var script in scriptFile.Scripts)
                    {
                        currentContent = script;
                        await Context.ExecuteNonQueryAsync(script.Content, CommandTimeout, ct);
                    }
                }

                Context.CommitTransaction();
                //In case more than one target fails, automaticaly deselect those who succceded so the user just have to click deploy to deploy the failed ones.
                this.Selected = false;
            }
            catch (OperationCanceledException ex)
            {
                Context?.RollbackTransaction();
                throw ex;
            }
            catch (Exception ex)
            {
                Context?.RollbackTransaction();
                ThrowIfSqlClientCancellationRequested(ct, ex);
                throw new DeploymentException("Deployment error", ex, currentFile, currentContent);
            }
            finally
            {
                Context.FinishConnection();
            }
            return;
        }