Fix Agent Job rename (#657)

This commit is contained in:
Karl Burtram
2018-07-16 13:18:47 -07:00
committed by GitHub
parent c0e5225187
commit b8c31e1138
2 changed files with 24 additions and 17 deletions

View File

@@ -275,6 +275,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
{
var result = await ConfigureAgentJob(
parameters.OwnerUri,
parameters.Job.Name,
parameters.Job,
ConfigAction.Create,
ManagementUtils.asRunType(parameters.TaskExecutionMode));
@@ -290,6 +291,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
{
var result = await ConfigureAgentJob(
parameters.OwnerUri,
parameters.OriginalJobName,
parameters.Job,
ConfigAction.Update,
ManagementUtils.asRunType(parameters.TaskExecutionMode));
@@ -305,6 +307,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
{
var result = await ConfigureAgentJob(
parameters.OwnerUri,
parameters.Job.Name,
parameters.Job,
ConfigAction.Drop,
ManagementUtils.asRunType(parameters.TaskExecutionMode));
@@ -837,6 +840,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
internal async Task<Tuple<bool, string>> ConfigureAgentJob(
string ownerUri,
string originalJobName,
AgentJobInfo jobInfo,
ConfigAction configAction,
RunType runType)
@@ -847,7 +851,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
{
JobData jobData;
CDataContainer dataContainer;
CreateJobData(ownerUri, jobInfo.Name, out dataContainer, out jobData, jobInfo);
CreateJobData(ownerUri, originalJobName, out dataContainer, out jobData, configAction, jobInfo);
using (JobActions actions = new JobActions(dataContainer, jobData, configAction))
{
@@ -1032,20 +1036,22 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
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);
param.SetParam("job", string.Empty);
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);
jobData = new JobData(dataContainer, jobInfo, configAction);
}
public static XmlDocument CreateJobXmlDocument(string svrName, string jobName)

View File

@@ -275,7 +275,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
}
}
public String Description
public string Description
{
get
{
@@ -601,7 +601,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
#endregion
#region construction
public JobData(CDataContainer data, AgentJobInfo jobInfo = null)
public JobData(CDataContainer data, AgentJobInfo jobInfo = null, ConfigAction configAction = ConfigAction.Create)
{
this.context = data;
@@ -632,10 +632,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
this.targetLocalServer = false;
}
// we are in properties mode.
if (this.originalName.Length > 0 || !string.IsNullOrEmpty(this.jobIdString))
if (configAction == ConfigAction.Update)
{
this.mode = ActionMode.Edit;
CheckAndLoadGeneralData();
}
else if (this.script.Length > 0)
{
@@ -653,13 +653,14 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
// 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.description = jobInfo.Description;
this.enabled = jobInfo.Enabled;
}
}
#endregion
@@ -758,7 +759,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
Job job = this.Job;
this.currentName = this.originalName;
this.currentName = job.Name;
this.description = job.Description;
this.enabled = job.IsEnabled;
// this.source = job.Source;
@@ -1112,8 +1113,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
this.mode = creating ? ActionMode.Create : ActionMode.Edit;
///Before any job posting if donem make sure that if this is an MSX job that the user has selected at
///least one Target Server.
// Before any job posting if donem make sure that if this is an MSX job that the user has selected at
// least one Target Server.
if (!this.targetLocalServer)
{
for (int i = 0; i < this.AvailableTargetServers.Length; ++i)
@@ -1126,7 +1127,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
}
if (!targetServerSelected)
{
///Not target servers selected. Throw error.
// Not target servers selected. Throw error.
throw new ApplicationException(SR.TargetServerNotSelected);
}
}
@@ -1267,8 +1268,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
, job.JobID));
}
//Do not attempt to save the job alert if we are in scripting mode, since the job id does not
//yet exists.
// Do not attempt to save the job alert if we are in scripting mode, since the job id does not
// yet exists.
if (jobAlerts != null && !scripting)
{
this.jobAlerts.ApplyChanges(job);