public bool ApplyChanges()

in src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/JobStepData.cs [813:1039]


        public bool ApplyChanges(Job job, bool forceCreate)
        {
            if (!HaveLoadedExpandedData && forceCreate)
            {
                CheckAndLoadExpandedInformation();
            }
            if (this.IsReadOnly || !this.HaveLoadedExpandedData)
            {
                return false;
            }

            bool changesMade = false;

            JobStep jobStep = null;
            bool scripting = job.Parent.Parent.ConnectionContext.SqlExecutionModes == SqlExecutionModes.CaptureSql;

            try
            {
                bool creating = !this.alreadyCreated || forceCreate;
                // creating a new jobstep

                if (creating)
                {
                    jobStep = new JobStep(job, this.Name);
                    this.originalName = this.currentName;
                }
                else
                {
                    jobStep = parent.Job.JobSteps[this.originalName];
                    if (jobStep == null)
                    {
                        throw new InvalidOperationException();
                    }
                    if (jobStep.ID != this.id)
                    {
                        // delete
                        jobStep.Drop();
                        // recreate
                        this.alreadyCreated = false;
                        return ApplyChanges(job);
                    }
                }

                if (creating)
                {
                    jobStep.ID = this.id;
                    jobStep.JobStepFlags = JobStepFlags.None;
                    changesMade = true;
                }
                if (creating || jobStep.Command != this.Command)
                {
                    jobStep.Command = this.Command;
                    changesMade = true;
                }
                if (creating || jobStep.CommandExecutionSuccessCode != this.CommandExecutionSuccessCode)
                {
                    jobStep.CommandExecutionSuccessCode = this.CommandExecutionSuccessCode;
                    changesMade = true;
                }
                if (creating || jobStep.DatabaseName != this.DatabaseName)
                {
                    jobStep.DatabaseName = this.DatabaseName;
                    changesMade = true;
                }
                if (creating || jobStep.DatabaseUserName != this.DatabaseUserName)
                {
                    jobStep.DatabaseUserName = this.DatabaseUserName;
                    changesMade = true;
                }
                if (creating || jobStep.Server != this.Server)
                {
                    jobStep.Server = this.Server;
                    changesMade = true;
                }
                if (creating || jobStep.OnFailAction != this.FailureAction)
                {
                    jobStep.OnFailAction = this.FailureAction;
                    changesMade = true;
                }
                if (jobStep.OnFailAction == StepCompletionAction.GoToStep &&
                                (creating || (this.FailStep != null
                                              && jobStep.OnFailStep != this.FailStep.ID)))
                {
                    jobStep.OnFailStep = this.FailStep.ID;
                    changesMade = true;
                }
                if (creating || jobStep.OnSuccessAction != this.SuccessAction)
                {
                    jobStep.OnSuccessAction = this.SuccessAction;
                    changesMade = true;
                }
                // if this is the last step, make sure that it does not have a
                // success action of next step. Don't store this as the user could add
                // more steps later
                if (this.ID == Parent.Steps.Count && jobStep.OnSuccessAction == StepCompletionAction.GoToNextStep)
                {
                    jobStep.OnSuccessAction = StepCompletionAction.QuitWithSuccess;
                    changesMade = true;
                }
                if (jobStep.OnSuccessAction == StepCompletionAction.GoToStep
                                && (creating || (this.SuccessStep != null
                                                  && jobStep.OnSuccessStep != this.SuccessStep.ID)))
                {
                    jobStep.OnSuccessStep = this.SuccessStep.ID;
                    changesMade = true;
                }
                if (creating || jobStep.OSRunPriority != this.Priority)
                {
                    jobStep.OSRunPriority = this.Priority;
                    changesMade = true;
                }
                if (creating || jobStep.OutputFileName != this.OutputFileName)
                {
                    jobStep.OutputFileName = this.OutputFileName;
                    changesMade = true;
                }

                JobStepFlags jobStepFlags = JobStepFlags.None;
                if (this.AppendToLogFile)
                {
                    jobStepFlags |= JobStepFlags.AppendToLogFile;
                    changesMade = true;
                }

                JobStepFlags historyOutputMask = JobStepFlags.AppendToJobHistory;
                if (this.SubSystem == AgentSubSystem.CmdExec ||
                    this.SubSystem == AgentSubSystem.Ssis || 
                    this.subSystem == AgentSubSystem.PowerShell)
                {
                    // for cmdexec, PowerShell and ssis subsystems, the history output flag 
                    // is different, but it's the same UI checkbox.
                    historyOutputMask = JobStepFlags.AppendAllCmdExecOutputToJobHistory;
                }

                if (this.AppendToStepHistory)
                {
                    jobStepFlags |= historyOutputMask;
                    changesMade = true;
                }
                if (this.CanLogToTable && this.WriteLogToTable)
                {
                    if (this.AppendLogToTable)
                    {
                        jobStepFlags |= (JobStepFlags)16;
                    }
                    else
                    {
                        jobStepFlags |= (JobStepFlags)8;
                    }
                }

                // if this is a Cmd subsystem step, then don't lose
                // the ProvideStopProcessEvent flag.
                if (this.SubSystem == AgentSubSystem.CmdExec)
                {
                    if (0 != (jobStep.JobStepFlags & JobStepFlags.ProvideStopProcessEvent))
                    {
                        jobStepFlags |= JobStepFlags.ProvideStopProcessEvent;
                    }
                }

                if (creating || jobStep.JobStepFlags != jobStepFlags)
                {
                    jobStep.JobStepFlags = jobStepFlags;
                    changesMade = true;
                }
                if (creating || jobStep.RetryAttempts != this.RetryAttempts)
                {
                    jobStep.RetryAttempts = this.RetryAttempts;
                    changesMade = true;
                }
                if (creating || jobStep.RetryInterval != this.RetryInterval)
                {
                    jobStep.RetryInterval = this.RetryInterval;
                    changesMade = true;
                }
                if (creating || jobStep.SubSystem != this.SubSystem)
                {
                    jobStep.SubSystem = this.SubSystem;
                    changesMade = true;
                }
                if (job.Parent.Parent.ConnectionContext.ServerVersion.Major >= 9 &&
                    (creating
                    || jobStep.ProxyName != this.proxyName))
                {
                    jobStep.ProxyName = this.proxyName;
                    changesMade = true;
                }

                if (creating)
                {
                    jobStep.Create();
                    if (!scripting)
                    {
                        this.urn = jobStep.Urn;
                        this.originalId = this.id;
                        this.alreadyCreated = true;
                    }
                }
                else
                {
                    jobStep.Alter();
                    // handle rename
                    if (this.originalName != this.currentName)
                    {
                        jobStep.Rename(currentName);
                        this.originalName = this.currentName;
                        this.urn = jobStep.Urn;
                        changesMade = true;
                    }
                }

            }
            catch (Exception)
            {
                if (!scripting && jobStep != null && jobStep.State != SMO.SqlSmoState.Existing)
                {
                    if (job.JobSteps.Contains(this.Name))
                    {
                        job.JobSteps.Remove(this.Name);
                    }
                }

                throw;
            }
            return changesMade;
        }