mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-21 01:25:42 -05:00
Added more options to job changes and elaborated error messages (#775)
* job step type and error message details change * added newline for both environments * checked for inner exceptions * sorted imports
This commit is contained in:
@@ -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<Tuple<bool, string>>.Run(() =>
|
||||
{
|
||||
@@ -967,9 +975,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
return new Tuple<bool, string>(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<Tuple<bool, string>>.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<bool>.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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -188,6 +188,21 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SubSystem
|
||||
/// </summary>
|
||||
public AgentSubSystem Subsystem
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.subSystem;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.subSystem = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// indicates whether the job exists on the server
|
||||
/// </summary>
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user