/// <summary> /// Set defaults for a new empty job /// </summary> private void SetDefaults() { this.alreadyCreated = false; this.currentName = originalName = string.Empty; this.command = string.Empty; this.commandExecutionSuccessCode = 0; this.databaseName = "master"; this.databaseUserName = string.Empty; this.server = string.Empty; this.originalId = this.id = -1; this.failureAction = StepCompletionAction.QuitWithFailure; this.failStep = null; this.failStepId = -1; this.successAction = StepCompletionAction.GoToNextStep; this.successStep = null; this.successStepId = -1; this.priority = OSRunPriority.Normal; this.outputFileName = string.Empty; this.appendToLogFile = false; this.appendToStepHist = false; this.writeLogToTable = false; this.appendLogToTable = false; this.retryAttempts = 0; this.retryInterval = 0; this.subSystem = AgentSubSystem.TransactSql; this.proxyName = string.Empty; this.urn = null; }
// copy constructor public JobStepData(JobStepData source) { this.originalName = source.originalName; this.currentName = source.currentName; this.alreadyCreated = source.alreadyCreated; this.deleted = source.deleted; this.command = source.command; this.commandExecutionSuccessCode = source.commandExecutionSuccessCode; this.databaseName = source.databaseName; this.databaseUserName = source.databaseUserName; this.server = source.server; this.id = source.id; this.originalId = source.originalId; this.failureAction = source.failureAction; this.failStep = source.failStep; this.failStepId = source.failStepId; this.successAction = source.successAction; this.successStep = source.successStep; this.successStepId = source.successStepId; this.priority = source.priority; this.outputFileName = source.outputFileName; this.appendToLogFile = source.appendToLogFile; this.appendToStepHist = source.appendToStepHist; this.writeLogToTable = source.writeLogToTable; this.appendLogToTable = source.appendLogToTable; this.retryAttempts = source.retryAttempts; this.retryInterval = source.retryInterval; this.subSystem = source.subSystem; this.proxyName = source.proxyName; this.urn = source.urn; this.parent = source.parent; }
public JobStepsActions( CDataContainer dataContainer, JobData jobData, AgentJobStepInfo stepInfo, ConfigAction configAction) { this.configAction = configAction; this.DataContainer = dataContainer; this.jobData = jobData; if (configAction == ConfigAction.Create) { this.data = new JobStepData(jobData.JobSteps); } else { JobStep jobStep = GetJobStep(this.jobData, stepInfo.StepName); this.data = new JobStepData(jobStep, jobData.JobSteps); } // load properties from AgentJobStepInfo this.data.ID = stepInfo.Id; this.data.Name = stepInfo.StepName; this.data.Command = stepInfo.Command; this.data.Subsystem = AgentUtilities.ConvertToAgentSubSytem(stepInfo.SubSystem); }
/// <summary> /// Load a job step from a script /// </summary> /// <param name="script"></param> private void LoadFromScript(string script) { this.jobSteps = new ArrayList(); JobStepData jsd = new JobStepData(this); jsd.Command = script; jsd.SubSystem = AgentSubSystem.TransactSql; jsd.ID = 1; jsd.Name = "1"; this.jobSteps.Add(jsd); }
/// <summary> /// Load the completion actions for the step /// </summary> internal void LoadCompletionActions() { if (this.successAction == StepCompletionAction.GoToStep) { this.successStep = this.parent.GetObjectForStep(this.successStepId); } if (this.failureAction == StepCompletionAction.GoToStep) { this.failStep = this.parent.GetObjectForStep(this.failStepId); } }
/// <summary> /// Recalculate the step ids of the contained job steps /// </summary> internal void RecalculateStepIds() { for (int i = 0; i < this.jobSteps.Count; i++) { JobStepData jsd = jobSteps[i] as JobStepData; if (jsd != null) { jsd.ID = i + 1; } } OnStepOrderChanged(EventArgs.Empty); }
/// <summary> /// Checks to see if the Last steps success completion action will change. /// It will if we are editing a job, and the last steps Success Completion /// action is GoToNextStep /// </summary> /// <returns>true if changes will be automatically made to the last step</returns> public bool CheckIfLastStepCompletionActionWillChange() { bool lastStepCompletionActionWillChange = false; if (this.jobSteps.Count > 0) { // get the last step JobStepData lastStep = this.jobSteps[this.jobSteps.Count - 1] as JobStepData; if (lastStep != null && parent.Mode == JobData.ActionMode.Edit && lastStep.SuccessAction == StepCompletionAction.GoToNextStep) { lastStepCompletionActionWillChange = true; } } return(lastStepCompletionActionWillChange); }
/// <summary> /// Delete a jobstep /// </summary> /// <param name="step"></param> public void DeleteStep(JobStepData step) { if (step == null) { throw new ArgumentNullException("step"); } if (this.jobSteps.Contains(step)) { this.jobSteps.Remove(step); // make a note to delete the step this.deletedJobSteps.Add(step); step.ToBeDeleted = true; } RecalculateStepIds(); }
/// <summary> /// Get a JobStepData object for a step id /// </summary> /// <param name="stepId"></param> /// <returns></returns> public JobStepData GetObjectForStep(int stepId) { JobStepData jobStep = null; if (this.jobSteps != null) { foreach (JobStepData jsd in this.jobSteps) { if (jsd.ID == stepId) { jobStep = jsd; break; } } } return(jobStep); }
public JobStepSubSystems(CDataContainer dataContainer, JobStepData data) { this.data = data; var availableSystems = dataContainer.Server.JobServer.EnumSubSystems() .Rows.OfType <DataRow>() .Select(r => (AgentSubSystem)Convert.ToInt32(r["subsystem_id"])); foreach (var agentSubSystemId in availableSystems) { var agentSubSystem = CreateJobStepSubSystem(agentSubSystemId, dataContainer, data); // The server might have some new subsystem we don't know about, just ignore it. if (agentSubSystem != null) { subSystems[agentSubSystemId] = agentSubSystem; } } }
public void StepFailureAction(StepCompletionAction action, JobStepData step) { // parameter check. must supply step if the action is GoToStep if (action == StepCompletionAction.GoToStep && step == null) { throw new InvalidOperationException(); } // don't supply step if it's an action other than GotoStep if (action != StepCompletionAction.GoToStep && step != null) { throw new InvalidOperationException(); } else if (step == this) { throw new InvalidArgumentException("step"); } this.failureAction = action; this.failStep = step; }
private static JobStepSubSystem CreateJobStepSubSystem( AgentSubSystem agentSubSystem, CDataContainer dataContainer, JobStepData data) { switch (agentSubSystem) { case AgentSubSystem.TransactSql: return(new JobStepSubSystem(AgentSubSystem.TransactSql)); case AgentSubSystem.CmdExec: return(new JobStepSubSystem(AgentSubSystem.CmdExec)); case AgentSubSystem.Distribution: return(new JobStepSubSystem(AgentSubSystem.Distribution)); case AgentSubSystem.Merge: return(new JobStepSubSystem(AgentSubSystem.Merge)); case AgentSubSystem.QueueReader: return(new JobStepSubSystem(AgentSubSystem.QueueReader)); case AgentSubSystem.Snapshot: return(new JobStepSubSystem(AgentSubSystem.Snapshot)); case AgentSubSystem.LogReader: return(new JobStepSubSystem(AgentSubSystem.LogReader)); case AgentSubSystem.AnalysisCommand: return(new JobStepSubSystem(AgentSubSystem.AnalysisCommand)); case AgentSubSystem.AnalysisQuery: return(new JobStepSubSystem(AgentSubSystem.AnalysisQuery)); case AgentSubSystem.PowerShell: return(new JobStepSubSystem(AgentSubSystem.PowerShell)); default: return(null); } }
public JobStepAdvancedLogging(CDataContainer dataContainer, JobStepData jobStepData) { this.dataContainer = dataContainer; this.jobStepData = jobStepData; }
/// <summary> /// Insert a jobstep into an existing location /// </summary> /// <param name="index"></param> /// <param name="step"></param> public void InsertStep(int index, JobStepData step) { this.jobSteps.Insert(index, step); RecalculateStepIds(); }
/// <summary> /// Load job steps from the server /// </summary> private void LoadData() { STParameters parameters = new STParameters(this.context.Document); string urn = string.Empty; string jobIdString = string.Empty; parameters.GetParam("urn", ref urn); parameters.GetParam("jobid", ref jobIdString); // save current state of default fields StringCollection originalFields = this.context.Server.GetDefaultInitFields(typeof(JobStep)); // Get all JobStep properties since the JobStepData class is going to use themn this.context.Server.SetDefaultInitFields(typeof(JobStep), true); try { Job job = null; // If JobID is passed in look up by jobID if (!string.IsNullOrEmpty(jobIdString)) { job = this.context.Server.JobServer.Jobs.ItemById(Guid.Parse(jobIdString)); } else { // or use urn path to query job job = this.context.Server.GetSmoObject(urn) as Job; } // load the data JobStepCollection steps = job.JobSteps; // allocate the array list this.jobSteps = new ArrayList(steps.Count); for (int i = 0; i < steps.Count; i++) { // add them in step id order int ii = 0; for (; ii < this.jobSteps.Count; ii++) { if (steps[i].ID < ((JobStepData)this.jobSteps[ii]).ID) { break; } } this.jobSteps.Insert(ii, new JobStepData(steps[i], this)); } // figure out the start step this.startStep = GetObjectForStep(job.StartStepID); // fixup all of the jobsteps failure/completion actions foreach (JobStepData jobStep in this.jobSteps) { jobStep.LoadCompletionActions(); } } finally { // revert to initial default fields for this type this.context.Server.SetDefaultInitFields(typeof(JobStep), originalFields); } }
/// <summary> /// Save changes to all job steps /// </summary> /// <param name="job">owner job</param> /// <returns>True if any changes were saved</returns> public bool ApplyChanges(Job job) { bool changesMade = false; if (this.IsReadOnly) { return(false); } bool scripting = this.context.Server.ConnectionContext.SqlExecutionModes == SqlExecutionModes.CaptureSql; // delete all of the deleted steps for (int i = deletedJobSteps.Count - 1; i >= 0; i--) { JobStepData step = this.deletedJobSteps[i] as JobStepData; if (step != null) { if (step.Created) { step.Delete(); changesMade = true; } } // don't clear the list if we are just scripting the action. if (!scripting) { deletedJobSteps.RemoveAt(i); } } bool forceRebuildingOfSteps = HasStepOrderChanged; // check to see if the step id's have changed. if so we will have to // drop and recreate all of the steps if (forceRebuildingOfSteps) { for (int i = this.jobSteps.Count - 1; i >= 0; --i) { JobStepData step = this.jobSteps[i] as JobStepData; // only delete steps that exist on the server if (step.Created) { step.Delete(); changesMade = true; } } } // update the remaining steps foreach (JobStepData step in this.jobSteps) { if (step.ApplyChanges(job, forceRebuildingOfSteps)) { changesMade = true; } } // update the start step if (StartStep == null && job.StartStepID != 0) { job.StartStepID = 0; changesMade = true; } else if (parent.Mode == JobData.ActionMode.Create || job.StartStepID != this.startStep.ID) { job.StartStepID = this.startStep.ID; job.Alter(); changesMade = true; } return(changesMade); }
/// <summary> /// Add a new existing step to the end of the job step collection /// </summary> /// <param name="step"></param> public void AddStep(JobStepData step) { this.jobSteps.Add(step); RecalculateStepIds(); }