mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-25 01:25:40 -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,
|
||||
RunType runType)
|
||||
{
|
||||
return await Task<Tuple<bool, string>>.Run(() =>
|
||||
return await Task<Tuple<bool, string>>.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -895,6 +895,34 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
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)
|
||||
@@ -949,15 +977,25 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
try
|
||||
{
|
||||
ConnectionInfo connInfo;
|
||||
ConnectionServiceInstance.TryFindConnection(ownerUri, out connInfo);
|
||||
CDataContainer dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true);
|
||||
CDataContainer dataContainer;
|
||||
JobData jobData = null;
|
||||
// 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);
|
||||
param.SetParam("alert", alertName);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -25,18 +25,25 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
|
||||
private string originalAlertName = null;
|
||||
|
||||
private JobData jobData = null;
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor that will be used to create dialog
|
||||
/// </summary>
|
||||
/// <param name="dataContainer"></param>
|
||||
public AgentAlertActions(
|
||||
CDataContainer dataContainer, string originalAlertName,
|
||||
AgentAlertInfo alertInfo, ConfigAction configAction)
|
||||
AgentAlertInfo alertInfo, ConfigAction configAction,
|
||||
JobData jobData = null)
|
||||
{
|
||||
this.originalAlertName = originalAlertName;
|
||||
this.alertInfo = alertInfo;
|
||||
this.DataContainer = dataContainer;
|
||||
this.configAction = configAction;
|
||||
if (jobData != null)
|
||||
{
|
||||
this.jobData = jobData;
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetAlertName(CDataContainer container)
|
||||
@@ -92,6 +99,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
if (alert != null)
|
||||
{
|
||||
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)
|
||||
{
|
||||
alert.Create();
|
||||
if (this.jobData != null)
|
||||
{
|
||||
JobAlertData alertData = new JobAlertData(alert);
|
||||
this.jobData.JobAlerts.AddAlert(alertData);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -169,6 +186,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
throw new ArgumentNullException("alert");
|
||||
}
|
||||
if (this.alertInfo.JobId != null)
|
||||
{
|
||||
alert.JobID = new Guid(this.alertInfo.JobId);
|
||||
}
|
||||
|
||||
alert.DatabaseName = !string.IsNullOrWhiteSpace(this.alertInfo.DatabaseName)
|
||||
? this.alertInfo.DatabaseName : string.Empty;
|
||||
|
||||
Reference in New Issue
Block a user