private void rdToFolder_CheckedChanged(object sender, EventArgs e)
 {
     _destination = ScriptDestination.Folder;
 }
Exemple #2
0
        public override void Execute()
        {
            SqlScriptPublishModel publishModel = null;

            try
            {
                this.CancellationToken.ThrowIfCancellationRequested();

                this.ValidateScriptDatabaseParams();

                publishModel = BuildPublishModel();
                publishModel.ScriptItemsCollected += this.OnPublishModelScriptItemsCollected;
                publishModel.ScriptProgress       += this.OnPublishModelScriptProgress;
                publishModel.ScriptError          += this.OnPublishModelScriptError;

                ScriptDestination destination = !string.IsNullOrWhiteSpace(this.Parameters.ScriptDestination)
                    ? (ScriptDestination)Enum.Parse(typeof(ScriptDestination), this.Parameters.ScriptDestination)
                    : ScriptDestination.ToSingleFile;

                // SMO is currently hardcoded to produce UTF-8 encoding when running on dotnet core.
                ScriptOutputOptions outputOptions = new ScriptOutputOptions
                {
                    SaveFileMode      = ScriptFileMode.Overwrite,
                    SaveFileName      = this.Parameters.FilePath,
                    ScriptDestination = destination,
                };

                this.CancellationToken.ThrowIfCancellationRequested();

                publishModel.GenerateScript(outputOptions);

                this.CancellationToken.ThrowIfCancellationRequested();

                Logger.Write(
                    LogLevel.Verbose,
                    string.Format(
                        "Sending script complete notification event for operation {0}, sequence number {1} with total count {2} and scripted count {3}",
                        this.OperationId,
                        this.eventSequenceNumber,
                        this.totalScriptedObjectCount,
                        this.scriptedObjectCount));

                this.SendCompletionNotificationEvent(new ScriptingCompleteParams
                {
                    Success = true,
                });
            }
            catch (Exception e)
            {
                if (e.IsOperationCanceledException())
                {
                    Logger.Write(LogLevel.Normal, string.Format("Scripting operation {0} was canceled", this.OperationId));
                    this.SendCompletionNotificationEvent(new ScriptingCompleteParams
                    {
                        Canceled = true,
                    });
                }
                else
                {
                    Logger.Write(LogLevel.Error, string.Format("Scripting operation {0} failed with exception {1}", this.OperationId, e));
                    this.SendCompletionNotificationEvent(new ScriptingCompleteParams
                    {
                        HasError     = true,
                        ErrorMessage = e.Message,
                        ErrorDetails = e.ToString(),
                    });
                }
            }
            finally
            {
                if (publishModel != null)
                {
                    publishModel.ScriptItemsCollected -= this.OnPublishModelScriptItemsCollected;
                    publishModel.ScriptProgress       -= this.OnPublishModelScriptProgress;
                    publishModel.ScriptError          -= this.OnPublishModelScriptError;
                }
            }
        }
 private void rdToWindow_CheckedChanged(object sender, EventArgs e)
 {
     _destination = ScriptDestination.Window;
 }