internal async Task <Tuple <bool, string> > ConfigureAgentJob( string ownerUri, AgentJobInfo jobInfo, ConfigAction configAction, RunType runType) { return(await Task <Tuple <bool, string> > .Run(() => { try { JobData jobData; CDataContainer dataContainer; CreateJobData(ownerUri, jobInfo.Name, out dataContainer, out jobData, jobInfo); using (JobActions jobActions = new JobActions(dataContainer, jobData, configAction)) { var executionHandler = new ExecutonHandler(jobActions); executionHandler.RunNow(runType, this); } return new Tuple <bool, string>(true, string.Empty); } catch (Exception ex) { return new Tuple <bool, string>(false, ex.ToString()); } })); }
internal async Task <Tuple <bool, string> > ConfigureAgentJob( string ownerUri, string originalJobName, AgentJobInfo jobInfo, ConfigAction configAction, RunType runType) { return(await Task <Tuple <bool, string> > .Run(() => { try { JobData jobData; CDataContainer dataContainer; CreateJobData(ownerUri, originalJobName, out dataContainer, out jobData, configAction, jobInfo); using (JobActions actions = new JobActions(dataContainer, jobData, configAction)) { ExecuteAction(actions, runType); } return new Tuple <bool, string>(true, string.Empty); } catch (Exception ex) { return new Tuple <bool, string>(false, ex.ToString()); } })); }
private void CreateJobData( string ownerUri, string jobName, out CDataContainer dataContainer, out JobData jobData, ConfigAction configAction = ConfigAction.Create, AgentJobInfo jobInfo = null) { ConnectionInfo connInfo; ConnectionServiceInstance.TryFindConnection(ownerUri, out connInfo); dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true); XmlDocument jobDoc = CreateJobXmlDocument(dataContainer.Server.Name.ToUpper(), jobName); dataContainer.Init(jobDoc.InnerXml); STParameters param = new STParameters(dataContainer.Document); string originalName = jobInfo != null && !string.Equals(jobName, jobInfo.Name) ? jobName : string.Empty; param.SetParam("job", configAction == ConfigAction.Update ? jobName : string.Empty); param.SetParam("jobid", string.Empty); jobData = new JobData(dataContainer, jobInfo, configAction); }
public static async Task CleanupJob( TestConnectionResult connectionResult, AgentJobInfo job) { var service = new AgentService(); await DeleteAgentJob(service, connectionResult, job); }
internal async Task <Tuple <bool, string> > ConfigureAgentJob( string ownerUri, string originalJobName, AgentJobInfo jobInfo, ConfigAction configAction, RunType runType) { return(await Task <Tuple <bool, string> > .Run(async() => { try { JobData jobData; CDataContainer dataContainer; CreateJobData(ownerUri, originalJobName, out dataContainer, out jobData, configAction, jobInfo); using (JobActions actions = new JobActions(dataContainer, jobData, configAction)) { ExecuteAction(actions, runType); } // Execute step actions if they exist if (jobInfo.JobSteps != null && jobInfo.JobSteps.Length > 0) { foreach (AgentJobStepInfo step in jobInfo.JobSteps) { await ConfigureAgentJobStep(ownerUri, step, configAction, runType); } } // Execute schedule actions if they exist if (jobInfo.JobSchedules != null && jobInfo.JobSchedules.Length > 0) { foreach (AgentScheduleInfo schedule in jobInfo.JobSchedules) { await ConfigureAgentSchedule(ownerUri, schedule, configAction, runType); } } // Execute alert actions if they exist if (jobInfo.Alerts != null && jobInfo.Alerts.Length > 0) { foreach (AgentAlertInfo alert in jobInfo.Alerts) { alert.JobId = jobData.Job.JobID.ToString(); await ConfigureAgentAlert(ownerUri, alert.Name, alert, configAction, runType); } } return new Tuple <bool, string>(true, string.Empty); } catch (Exception ex) { return new Tuple <bool, string>(false, ex.ToString()); } })); }
internal static async Task CreateAgentJob( AgentService service, TestConnectionResult connectionResult, AgentJobInfo job) { var context = new Mock <RequestContext <CreateAgentJobResult> >(); await service.HandleCreateAgentJobRequest(new CreateAgentJobParams { OwnerUri = connectionResult.ConnectionInfo.OwnerUri, Job = job }, context.Object); context.VerifyAll(); }
internal static async Task UpdateAgentJob( AgentService service, TestConnectionResult connectionResult, AgentJobInfo job) { job.Description = "Update job description"; var context = new Mock <RequestContext <UpdateAgentJobResult> >(); await service.HandleUpdateAgentJobRequest(new UpdateAgentJobParams { OwnerUri = connectionResult.ConnectionInfo.OwnerUri, Job = job }, context.Object); context.VerifyAll(); }
internal static AgentJobStepInfo GetTestJobStepInfo( TestConnectionResult connectionResult, AgentJobInfo job, string stepName = "Test Job Step1") { return(new AgentJobStepInfo() { Id = 1, JobName = job.Name, StepName = stepName, SubSystem = "T-SQL", Script = "SELECT @@VERSION", DatabaseName = connectionResult.ConnectionInfo.ConnectionDetails.DatabaseName, DatabaseUserName = connectionResult.ConnectionInfo.ConnectionDetails.UserName, Server = connectionResult.ConnectionInfo.ConnectionDetails.ServerName }); }
internal static async Task DeleteAgentJob( AgentService service, TestConnectionResult connectionResult, AgentJobInfo job, bool verify = true) { var context = new Mock <RequestContext <ResultStatus> >(); await service.HandleDeleteAgentJobRequest(new DeleteAgentJobParams { OwnerUri = connectionResult.ConnectionInfo.OwnerUri, Job = job }, context.Object); if (verify) { context.VerifyAll(); } }
public JobData(CDataContainer data, AgentJobInfo jobInfo = null, ConfigAction configAction = ConfigAction.Create) { this.context = data; // get the job information STParameters parameters = new STParameters(this.context.Document); parameters.GetParam("job", ref this.originalName); parameters.GetParam("jobid", ref this.jobIdString); parameters.GetParam("script", ref this.script); parameters.GetParam("scriptName", ref this.scriptName); // get the Urn string urn = string.Empty; parameters.GetParam("urn", ref urn); if (urn != null && urn.Length > 0) { this.urn = new Urn(urn); } bool isMsxJob = false; parameters.GetParam("msxjob", ref isMsxJob); //If this is an MSX, initially set TargetLocalServers to false; if (isMsxJob) { this.targetLocalServer = false; } // we are in properties mode. if (configAction == ConfigAction.Update) { this.mode = ActionMode.Edit; CheckAndLoadGeneralData(); } else if (this.script.Length > 0) { // we are creating a new job, but prepopulating // one step with the script passed to us this.mode = ActionMode.Create; this.Name = this.scriptName; SetDefaults(); this.jobSteps = new JobStepsData(context, script, this); } // creating a new job else { this.mode = ActionMode.Create; // set defaults that do not involve going to the server to retrieve SetDefaults(); } // load AgentJobInfo data if (jobInfo != null) { this.currentName = jobInfo.Name; this.owner = jobInfo.Owner; this.description = jobInfo.Description; this.enabled = jobInfo.Enabled; } }