diff --git a/src/Microsoft.SqlTools.ServiceLayer/Agent/AgentService.cs b/src/Microsoft.SqlTools.ServiceLayer/Agent/AgentService.cs index 017da4ee..382f6aa7 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Agent/AgentService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Agent/AgentService.cs @@ -299,6 +299,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent { result.Success = false; result.ErrorMessage = e.Message; + Exception exception = e.InnerException; + while (exception != null) + { + result.ErrorMessage += Environment.NewLine + "\t" + exception.Message; + exception = exception.InnerException; + } await requestContext.SendResult(result); } }); @@ -920,7 +926,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent break; } } - await ConfigureAgentJobStep(ownerUri, step, configAction, runType); + await ConfigureAgentJobStep(ownerUri, step, configAction, runType, jobData, dataContainer); } } @@ -929,7 +935,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent { foreach (AgentScheduleInfo schedule in jobInfo.JobSchedules) { - await ConfigureAgentSchedule(ownerUri, schedule, configAction, runType); + await ConfigureAgentSchedule(ownerUri, schedule, configAction, runType, jobData, dataContainer); } } @@ -939,7 +945,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent foreach (AgentAlertInfo alert in jobInfo.Alerts) { alert.JobId = jobData.Job.JobID.ToString(); - await ConfigureAgentAlert(ownerUri, alert.Name, alert, configAction, runType); + await ConfigureAgentAlert(ownerUri, alert.Name, alert, configAction, runType, jobData, dataContainer); } } @@ -956,7 +962,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent string ownerUri, AgentJobStepInfo stepInfo, ConfigAction configAction, - RunType runType) + RunType runType, + JobData jobData = null, + CDataContainer dataContainer = null) { return await Task>.Run(() => { @@ -967,9 +975,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent return new Tuple(false, "JobName cannot be null"); } - JobData jobData; - CDataContainer dataContainer; - CreateJobData(ownerUri, stepInfo.JobName, out dataContainer, out jobData); + if (jobData == null) + { + CreateJobData(ownerUri, stepInfo.JobName, out dataContainer, out jobData); + } using (var actions = new JobStepsActions(dataContainer, jobData, stepInfo, configAction)) { @@ -991,14 +1000,14 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent string alertName, AgentAlertInfo alert, ConfigAction configAction, - RunType runType) + RunType runType, + JobData jobData = null, + CDataContainer dataContainer = null) { return await Task>.Run(() => { try { - CDataContainer dataContainer; - JobData jobData = null; // If the alert is being created outside of a job if (string.IsNullOrWhiteSpace(alert.JobName)) { @@ -1007,9 +1016,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true); } else - { - // If the alert is being created inside a job - CreateJobData(ownerUri, alert.JobName, out dataContainer, out jobData); + { + if (jobData == null) + { + // If the alert is being created inside a job + CreateJobData(ownerUri, alert.JobName, out dataContainer, out jobData); + } } STParameters param = new STParameters(dataContainer.Document); param.SetParam("alert", alertName); @@ -1095,15 +1107,18 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent string ownerUri, AgentScheduleInfo schedule, ConfigAction configAction, - RunType runType) + RunType runType, + JobData jobData = null, + CDataContainer dataContainer = null) { return await Task.Run(() => { try { - JobData jobData; - CDataContainer dataContainer; - CreateJobData(ownerUri, schedule.JobName, out dataContainer, out jobData); + if (jobData == null) + { + CreateJobData(ownerUri, schedule.JobName, out dataContainer, out jobData); + } const string UrnFormatStr = "Server[@Name='{0}']/JobServer[@Name='{0}']/Job[@Name='{1}']/Schedule[@Name='{2}']"; string serverName = dataContainer.Server.Name.ToUpper(); diff --git a/src/Microsoft.SqlTools.ServiceLayer/Agent/Common/AgentUtilities.cs b/src/Microsoft.SqlTools.ServiceLayer/Agent/Common/AgentUtilities.cs index c5cc675c..6cdaba93 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Agent/Common/AgentUtilities.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Agent/Common/AgentUtilities.cs @@ -9,6 +9,7 @@ using System.Collections.Generic; using System.Text; using Microsoft.SqlServer.Management.Common; using Microsoft.SqlServer.Management.Sdk.Sfc; +using Microsoft.SqlServer.Management.Smo; using Microsoft.SqlServer.Management.Smo.Agent; using Microsoft.SqlTools.ServiceLayer.Agent.Contracts; @@ -33,8 +34,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent public const string UrnRetriesAttempted = "RetriesAttempted"; public const string UrnServer = "Server"; internal const string UrnServerTime = "CurrentDate"; - - public static AgentJobInfo ConvertToAgentJobInfo(JobProperties job) + + public static AgentJobInfo ConvertToAgentJobInfo(JobProperties job) { return new AgentJobInfo { @@ -217,5 +218,20 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent } return jobs; } + + public static AgentSubSystem ConvertToAgentSubSytem(string subSystem) + { + switch(subSystem) + { + case ("Transact-SQL script (T-SQL"): + return AgentSubSystem.TransactSql; + case ("Operating system (CmdExec)"): + return AgentSubSystem.CmdExec; + case ("PowerShell"): + return AgentSubSystem.PowerShell; + default: + return AgentSubSystem.TransactSql; + } + } } } \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/JobData.cs b/src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/JobData.cs index a3d338d2..65461506 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/JobData.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/JobData.cs @@ -659,10 +659,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent if (jobInfo != null) { this.currentName = jobInfo.Name; - this.owner = jobInfo.Owner; - this.description = jobInfo.Description; - this.enabled = jobInfo.Enabled; + this.Owner = jobInfo.Owner; + this.Description = jobInfo.Description; + this.Enabled = jobInfo.Enabled; this.startStepID = jobInfo.StartStepId; + this.Category = ConvertStringToCategory(jobInfo.Category); } } #endregion diff --git a/src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/JobStepData.cs b/src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/JobStepData.cs index 46fa34b5..135b2654 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/JobStepData.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/JobStepData.cs @@ -188,6 +188,21 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent } } + /// + /// SubSystem + /// + public AgentSubSystem Subsystem + { + get + { + return this.subSystem; + } + set + { + this.subSystem = value; + } + } + /// /// indicates whether the job exists on the server /// diff --git a/src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/JobStepsActions.cs b/src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/JobStepsActions.cs index c34fbdbf..8b7e361a 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/JobStepsActions.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/JobStepsActions.cs @@ -5,6 +5,7 @@ using System; using Microsoft.SqlServer.Management.Smo.Agent; +using Microsoft.SqlTools.ServiceLayer.Agent; using Microsoft.SqlTools.ServiceLayer.Agent.Contracts; using Microsoft.SqlTools.ServiceLayer.Management; @@ -43,6 +44,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent this.data.ID = stepInfo.Id; this.data.Name = stepInfo.StepName; this.data.Command = stepInfo.Command; + this.data.Subsystem = AgentUtilities.ConvertToAgentSubSytem(stepInfo.SubSystem); } protected override bool DoPreProcessExecution(RunType runType, out ExecutionMode executionResult)