mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 18:47:57 -05:00
Agent/improvements (#720)
* add steps and schedules to edit job * added alerts to edit data logic * fixed c# style
This commit is contained in:
@@ -882,7 +882,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
ConfigAction configAction,
|
ConfigAction configAction,
|
||||||
RunType runType)
|
RunType runType)
|
||||||
{
|
{
|
||||||
return await Task<Tuple<bool, string>>.Run(() =>
|
return await Task<Tuple<bool, string>>.Run(async () =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -895,6 +895,34 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
ExecuteAction(actions, runType);
|
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);
|
return new Tuple<bool, string>(true, string.Empty);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -949,15 +977,25 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ConnectionInfo connInfo;
|
CDataContainer dataContainer;
|
||||||
ConnectionServiceInstance.TryFindConnection(ownerUri, out connInfo);
|
JobData jobData = null;
|
||||||
CDataContainer dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true);
|
// If the alert is being created outside of a job
|
||||||
|
if (string.IsNullOrWhiteSpace(alert.JobName))
|
||||||
|
{
|
||||||
|
ConnectionInfo connInfo;
|
||||||
|
ConnectionServiceInstance.TryFindConnection(ownerUri, out connInfo);
|
||||||
|
dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// If the alert is being created inside a job
|
||||||
|
CreateJobData(ownerUri, alert.JobName, out dataContainer, out jobData);
|
||||||
|
}
|
||||||
STParameters param = new STParameters(dataContainer.Document);
|
STParameters param = new STParameters(dataContainer.Document);
|
||||||
param.SetParam("alert", alertName);
|
param.SetParam("alert", alertName);
|
||||||
|
|
||||||
if (alert != null)
|
if (alert != null)
|
||||||
{
|
{
|
||||||
using (AgentAlertActions actions = new AgentAlertActions(dataContainer, alertName, alert, configAction))
|
using (AgentAlertActions actions = new AgentAlertActions(dataContainer, alertName, alert, configAction, jobData))
|
||||||
{
|
{
|
||||||
ExecuteAction(actions, runType);
|
ExecuteAction(actions, runType);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,18 +25,25 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
|
|
||||||
private string originalAlertName = null;
|
private string originalAlertName = null;
|
||||||
|
|
||||||
|
private JobData jobData = null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Default constructor that will be used to create dialog
|
/// Default constructor that will be used to create dialog
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="dataContainer"></param>
|
/// <param name="dataContainer"></param>
|
||||||
public AgentAlertActions(
|
public AgentAlertActions(
|
||||||
CDataContainer dataContainer, string originalAlertName,
|
CDataContainer dataContainer, string originalAlertName,
|
||||||
AgentAlertInfo alertInfo, ConfigAction configAction)
|
AgentAlertInfo alertInfo, ConfigAction configAction,
|
||||||
|
JobData jobData = null)
|
||||||
{
|
{
|
||||||
this.originalAlertName = originalAlertName;
|
this.originalAlertName = originalAlertName;
|
||||||
this.alertInfo = alertInfo;
|
this.alertInfo = alertInfo;
|
||||||
this.DataContainer = dataContainer;
|
this.DataContainer = dataContainer;
|
||||||
this.configAction = configAction;
|
this.configAction = configAction;
|
||||||
|
if (jobData != null)
|
||||||
|
{
|
||||||
|
this.jobData = jobData;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetAlertName(CDataContainer container)
|
private static string GetAlertName(CDataContainer container)
|
||||||
@@ -92,6 +99,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
if (alert != null)
|
if (alert != null)
|
||||||
{
|
{
|
||||||
alert.DropIfExists();
|
alert.DropIfExists();
|
||||||
|
if (this.jobData != null)
|
||||||
|
{
|
||||||
|
JobAlertData alertData = new JobAlertData(alert);
|
||||||
|
this.jobData.JobAlerts.DeleteAlert(alertData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -130,6 +142,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
if (createNewAlert)
|
if (createNewAlert)
|
||||||
{
|
{
|
||||||
alert.Create();
|
alert.Create();
|
||||||
|
if (this.jobData != null)
|
||||||
|
{
|
||||||
|
JobAlertData alertData = new JobAlertData(alert);
|
||||||
|
this.jobData.JobAlerts.AddAlert(alertData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -169,6 +186,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
{
|
{
|
||||||
throw new ArgumentNullException("alert");
|
throw new ArgumentNullException("alert");
|
||||||
}
|
}
|
||||||
|
if (this.alertInfo.JobId != null)
|
||||||
|
{
|
||||||
|
alert.JobID = new Guid(this.alertInfo.JobId);
|
||||||
|
}
|
||||||
|
|
||||||
alert.DatabaseName = !string.IsNullOrWhiteSpace(this.alertInfo.DatabaseName)
|
alert.DatabaseName = !string.IsNullOrWhiteSpace(this.alertInfo.DatabaseName)
|
||||||
? this.alertInfo.DatabaseName : string.Empty;
|
? this.alertInfo.DatabaseName : string.Empty;
|
||||||
|
|||||||
Reference in New Issue
Block a user