mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-17 02:51:45 -05:00
Additional edit alert updates (#652)
This commit is contained in:
@@ -372,15 +372,15 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
CDataContainer dataContainer;
|
CDataContainer dataContainer;
|
||||||
CreateJobData(parameters.OwnerUri, "default", out dataContainer, out jobData);
|
CreateJobData(parameters.OwnerUri, "default", out dataContainer, out jobData);
|
||||||
|
|
||||||
// current connection user name for
|
// current connection user name for
|
||||||
result.Owner = dataContainer.ServerConnection.TrueLogin;
|
result.Owner = dataContainer.ServerConnection.TrueLogin;
|
||||||
|
|
||||||
var categories = jobData.Categories;
|
var categories = jobData.Categories;
|
||||||
result.Categories = new AgentJobCategory[categories.Length];
|
result.Categories = new AgentJobCategory[categories.Length];
|
||||||
for (int i = 0; i < categories.Length; ++i)
|
for (int i = 0; i < categories.Length; ++i)
|
||||||
{
|
{
|
||||||
result.Categories[i] = new AgentJobCategory
|
result.Categories[i] = new AgentJobCategory
|
||||||
{
|
{
|
||||||
Id = categories[i].SmoCategory.ID,
|
Id = categories[i].SmoCategory.ID,
|
||||||
Name = categories[i].SmoCategory.Name
|
Name = categories[i].SmoCategory.Name
|
||||||
};
|
};
|
||||||
@@ -438,7 +438,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
MessageId = alert.MessageID,
|
MessageId = alert.MessageID,
|
||||||
NotificationMessage = alert.NotificationMessage,
|
NotificationMessage = alert.NotificationMessage,
|
||||||
OccurrenceCount = alert.OccurrenceCount,
|
OccurrenceCount = alert.OccurrenceCount,
|
||||||
PerformanceCondition = alert.PerformanceCondition,
|
PerformanceCondition = alert.PerformanceCondition,
|
||||||
Severity = alert.Severity,
|
Severity = alert.Severity,
|
||||||
DatabaseName = alert.DatabaseName,
|
DatabaseName = alert.DatabaseName,
|
||||||
CountResetDate = alert.CountResetDate.ToString(),
|
CountResetDate = alert.CountResetDate.ToString(),
|
||||||
@@ -477,7 +477,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
{
|
{
|
||||||
Success = result.Item1,
|
Success = result.Item1,
|
||||||
ErrorMessage = result.Item2
|
ErrorMessage = result.Item2
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -573,13 +573,13 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal async Task HandleCreateAgentOperatorRequest(
|
internal async Task HandleCreateAgentOperatorRequest(
|
||||||
CreateAgentOperatorParams parameters,
|
CreateAgentOperatorParams parameters,
|
||||||
RequestContext<AgentOperatorResult> requestContext)
|
RequestContext<AgentOperatorResult> requestContext)
|
||||||
{
|
{
|
||||||
var result = await ConfigureAgentOperator(
|
var result = await ConfigureAgentOperator(
|
||||||
parameters.OwnerUri,
|
parameters.OwnerUri,
|
||||||
parameters.Operator,
|
parameters.Operator,
|
||||||
ConfigAction.Create,
|
ConfigAction.Create,
|
||||||
RunType.RunNow);
|
RunType.RunNow);
|
||||||
|
|
||||||
await requestContext.SendResult(new AgentOperatorResult()
|
await requestContext.SendResult(new AgentOperatorResult()
|
||||||
@@ -591,13 +591,13 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal async Task HandleUpdateAgentOperatorRequest(
|
internal async Task HandleUpdateAgentOperatorRequest(
|
||||||
UpdateAgentOperatorParams parameters,
|
UpdateAgentOperatorParams parameters,
|
||||||
RequestContext<AgentOperatorResult> requestContext)
|
RequestContext<AgentOperatorResult> requestContext)
|
||||||
{
|
{
|
||||||
var result = await ConfigureAgentOperator(
|
var result = await ConfigureAgentOperator(
|
||||||
parameters.OwnerUri,
|
parameters.OwnerUri,
|
||||||
parameters.Operator,
|
parameters.Operator,
|
||||||
ConfigAction.Update,
|
ConfigAction.Update,
|
||||||
RunType.RunNow);
|
RunType.RunNow);
|
||||||
|
|
||||||
await requestContext.SendResult(new AgentOperatorResult()
|
await requestContext.SendResult(new AgentOperatorResult()
|
||||||
@@ -609,13 +609,13 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal async Task HandleDeleteAgentOperatorRequest(
|
internal async Task HandleDeleteAgentOperatorRequest(
|
||||||
DeleteAgentOperatorParams parameters,
|
DeleteAgentOperatorParams parameters,
|
||||||
RequestContext<ResultStatus> requestContext)
|
RequestContext<ResultStatus> requestContext)
|
||||||
{
|
{
|
||||||
var result = await ConfigureAgentOperator(
|
var result = await ConfigureAgentOperator(
|
||||||
parameters.OwnerUri,
|
parameters.OwnerUri,
|
||||||
parameters.Operator,
|
parameters.Operator,
|
||||||
ConfigAction.Drop,
|
ConfigAction.Drop,
|
||||||
RunType.RunNow);
|
RunType.RunNow);
|
||||||
|
|
||||||
await requestContext.SendResult(new ResultStatus()
|
await requestContext.SendResult(new ResultStatus()
|
||||||
@@ -623,7 +623,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
Success = result.Item1,
|
Success = result.Item1,
|
||||||
ErrorMessage = result.Item2
|
ErrorMessage = result.Item2
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion // "Operator Handlers"
|
#endregion // "Operator Handlers"
|
||||||
|
|
||||||
@@ -640,7 +640,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
ConnectionInfo connInfo;
|
ConnectionInfo connInfo;
|
||||||
ConnectionServiceInstance.TryFindConnection(parameters.OwnerUri, out connInfo);
|
ConnectionServiceInstance.TryFindConnection(parameters.OwnerUri, out connInfo);
|
||||||
CDataContainer dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true);
|
CDataContainer dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true);
|
||||||
|
|
||||||
int proxyCount = dataContainer.Server.JobServer.ProxyAccounts.Count;
|
int proxyCount = dataContainer.Server.JobServer.ProxyAccounts.Count;
|
||||||
var proxies = new AgentProxyInfo[proxyCount];
|
var proxies = new AgentProxyInfo[proxyCount];
|
||||||
for (int i = 0; i < proxyCount; ++i)
|
for (int i = 0; i < proxyCount; ++i)
|
||||||
@@ -730,7 +730,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
ConnectionInfo connInfo;
|
ConnectionInfo connInfo;
|
||||||
ConnectionServiceInstance.TryFindConnection(parameters.OwnerUri, out connInfo);
|
ConnectionServiceInstance.TryFindConnection(parameters.OwnerUri, out connInfo);
|
||||||
CDataContainer dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true);
|
CDataContainer dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true);
|
||||||
|
|
||||||
int scheduleCount = dataContainer.Server.JobServer.SharedSchedules.Count;
|
int scheduleCount = dataContainer.Server.JobServer.SharedSchedules.Count;
|
||||||
var schedules = new AgentScheduleInfo[scheduleCount];
|
var schedules = new AgentScheduleInfo[scheduleCount];
|
||||||
for (int i = 0; i < scheduleCount; ++i)
|
for (int i = 0; i < scheduleCount; ++i)
|
||||||
@@ -740,7 +740,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
schedules[i].Id = schedule.ID;
|
schedules[i].Id = schedule.ID;
|
||||||
schedules[i].Name = schedule.Name;
|
schedules[i].Name = schedule.Name;
|
||||||
schedules[i].IsEnabled = schedule.IsEnabled;
|
schedules[i].IsEnabled = schedule.IsEnabled;
|
||||||
schedules[i].FrequencyTypes = (Contracts.FrequencyTypes)schedule.FrequencyTypes;
|
schedules[i].FrequencyTypes = (Contracts.FrequencyTypes)schedule.FrequencyTypes;
|
||||||
schedules[i].FrequencySubDayTypes = (Contracts.FrequencySubDayTypes)schedule.FrequencySubDayTypes;
|
schedules[i].FrequencySubDayTypes = (Contracts.FrequencySubDayTypes)schedule.FrequencySubDayTypes;
|
||||||
schedules[i].FrequencySubDayInterval = schedule.FrequencySubDayInterval;
|
schedules[i].FrequencySubDayInterval = schedule.FrequencySubDayInterval;
|
||||||
schedules[i].FrequencyRelativeIntervals = (Contracts.FrequencyRelativeIntervals)schedule.FrequencyRelativeIntervals;
|
schedules[i].FrequencyRelativeIntervals = (Contracts.FrequencyRelativeIntervals)schedule.FrequencyRelativeIntervals;
|
||||||
@@ -755,7 +755,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
schedules[i].ScheduleUid = schedule.ScheduleUid;
|
schedules[i].ScheduleUid = schedule.ScheduleUid;
|
||||||
}
|
}
|
||||||
result.Schedules = schedules;
|
result.Schedules = schedules;
|
||||||
result.Success = true;
|
result.Success = true;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -818,6 +818,23 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
|
|
||||||
#region "Helpers"
|
#region "Helpers"
|
||||||
|
|
||||||
|
internal void ExecuteAction(ManagementActionBase action, RunType runType)
|
||||||
|
{
|
||||||
|
var executionHandler = new ExecutonHandler(action);
|
||||||
|
executionHandler.RunNow(runType, this);
|
||||||
|
if (executionHandler.ExecutionResult == ExecutionMode.Failure)
|
||||||
|
{
|
||||||
|
if (executionHandler.ExecutionFailureException != null)
|
||||||
|
{
|
||||||
|
throw executionHandler.ExecutionFailureException;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception("Failed to execute action");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
internal async Task<Tuple<bool, string>> ConfigureAgentJob(
|
internal async Task<Tuple<bool, string>> ConfigureAgentJob(
|
||||||
string ownerUri,
|
string ownerUri,
|
||||||
AgentJobInfo jobInfo,
|
AgentJobInfo jobInfo,
|
||||||
@@ -832,10 +849,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
CDataContainer dataContainer;
|
CDataContainer dataContainer;
|
||||||
CreateJobData(ownerUri, jobInfo.Name, out dataContainer, out jobData, jobInfo);
|
CreateJobData(ownerUri, jobInfo.Name, out dataContainer, out jobData, jobInfo);
|
||||||
|
|
||||||
using (JobActions jobActions = new JobActions(dataContainer, jobData, configAction))
|
using (JobActions actions = new JobActions(dataContainer, jobData, configAction))
|
||||||
{
|
{
|
||||||
var executionHandler = new ExecutonHandler(jobActions);
|
ExecuteAction(actions, runType);
|
||||||
executionHandler.RunNow(runType, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Tuple<bool, string>(true, string.Empty);
|
return new Tuple<bool, string>(true, string.Empty);
|
||||||
@@ -866,10 +882,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
CDataContainer dataContainer;
|
CDataContainer dataContainer;
|
||||||
CreateJobData(ownerUri, stepInfo.JobName, out dataContainer, out jobData);
|
CreateJobData(ownerUri, stepInfo.JobName, out dataContainer, out jobData);
|
||||||
|
|
||||||
using (var jobStep = new JobStepsActions(dataContainer, jobData, stepInfo, configAction))
|
using (var actions = new JobStepsActions(dataContainer, jobData, stepInfo, configAction))
|
||||||
{
|
{
|
||||||
var executionHandler = new ExecutonHandler(jobStep);
|
ExecuteAction(actions, runType);
|
||||||
executionHandler.RunNow(runType, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Tuple<bool, string>(true, string.Empty);
|
return new Tuple<bool, string>(true, string.Empty);
|
||||||
@@ -901,12 +916,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
|
|
||||||
if (alert != null)
|
if (alert != null)
|
||||||
{
|
{
|
||||||
using (AgentAlertActions agentAlert = new AgentAlertActions(dataContainer, alertName, alert, configAction))
|
using (AgentAlertActions actions = new AgentAlertActions(dataContainer, alertName, alert, configAction))
|
||||||
{
|
{
|
||||||
var executionHandler = new ExecutonHandler(agentAlert);
|
ExecuteAction(actions, runType);
|
||||||
executionHandler.RunNow(runType, this);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Tuple<bool, string>(true, string.Empty);
|
return new Tuple<bool, string>(true, string.Empty);
|
||||||
}
|
}
|
||||||
@@ -933,10 +947,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
STParameters param = new STParameters(dataContainer.Document);
|
STParameters param = new STParameters(dataContainer.Document);
|
||||||
param.SetParam("operator", operatorInfo.Name);
|
param.SetParam("operator", operatorInfo.Name);
|
||||||
|
|
||||||
using (AgentOperatorActions agentOperator = new AgentOperatorActions(dataContainer, operatorInfo, configAction))
|
using (AgentOperatorActions actions = new AgentOperatorActions(dataContainer, operatorInfo, configAction))
|
||||||
{
|
{
|
||||||
var executionHandler = new ExecutonHandler(agentOperator);
|
ExecuteAction(actions, runType);
|
||||||
executionHandler.RunNow(runType, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Tuple<bool, string>(true, string.Empty);
|
return new Tuple<bool, string>(true, string.Empty);
|
||||||
@@ -965,10 +978,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
STParameters param = new STParameters(dataContainer.Document);
|
STParameters param = new STParameters(dataContainer.Document);
|
||||||
param.SetParam("proxyaccount", accountName);
|
param.SetParam("proxyaccount", accountName);
|
||||||
|
|
||||||
using (AgentProxyAccountActions agentProxy = new AgentProxyAccountActions(dataContainer, proxy, configAction))
|
using (AgentProxyAccountActions actions = new AgentProxyAccountActions(dataContainer, proxy, configAction))
|
||||||
{
|
{
|
||||||
var executionHandler = new ExecutonHandler(agentProxy);
|
ExecuteAction(actions, runType);
|
||||||
executionHandler.RunNow(runType, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Tuple<bool, string>(true, string.Empty);
|
return new Tuple<bool, string>(true, string.Empty);
|
||||||
@@ -1003,8 +1015,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
|
|
||||||
using (JobSchedulesActions actions = new JobSchedulesActions(dataContainer, jobData, schedule, configAction))
|
using (JobSchedulesActions actions = new JobSchedulesActions(dataContainer, jobData, schedule, configAction))
|
||||||
{
|
{
|
||||||
var executionHandler = new ExecutonHandler(actions);
|
ExecuteAction(actions, runType);
|
||||||
executionHandler.RunNow(runType, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Tuple<bool, string>(true, string.Empty);
|
return new Tuple<bool, string>(true, string.Empty);
|
||||||
@@ -1017,7 +1028,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void CreateJobData(
|
private void CreateJobData(
|
||||||
string ownerUri,
|
string ownerUri,
|
||||||
string jobName,
|
string jobName,
|
||||||
out CDataContainer dataContainer,
|
out CDataContainer dataContainer,
|
||||||
out JobData jobData,
|
out JobData jobData,
|
||||||
@@ -1031,7 +1042,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
dataContainer.Init(jobDoc.InnerXml);
|
dataContainer.Init(jobDoc.InnerXml);
|
||||||
|
|
||||||
STParameters param = new STParameters(dataContainer.Document);
|
STParameters param = new STParameters(dataContainer.Document);
|
||||||
param.SetParam("job", string.Empty);
|
param.SetParam("job", string.Empty);
|
||||||
param.SetParam("jobid", string.Empty);
|
param.SetParam("jobid", string.Empty);
|
||||||
|
|
||||||
jobData = new JobData(dataContainer, jobInfo);
|
jobData = new JobData(dataContainer, jobInfo);
|
||||||
@@ -1055,10 +1066,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
|
|
||||||
xmlWriter.WriteElementString(XmlJobElementName, jobName);
|
xmlWriter.WriteElementString(XmlJobElementName, jobName);
|
||||||
xmlWriter.WriteElementString(XmlUrnElementName, string.Format(UrnFormatStr, svrName, jobName));
|
xmlWriter.WriteElementString(XmlUrnElementName, string.Format(UrnFormatStr, svrName, jobName));
|
||||||
|
|
||||||
xmlWriter.WriteEndElement();
|
xmlWriter.WriteEndElement();
|
||||||
xmlWriter.WriteEndElement();
|
xmlWriter.WriteEndElement();
|
||||||
|
|
||||||
xmlWriter.Close();
|
xmlWriter.Close();
|
||||||
|
|
||||||
// Create an XML document.
|
// Create an XML document.
|
||||||
@@ -1079,7 +1090,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
var dt = server.JobServer.EnumJobHistory(filter);
|
var dt = server.JobServer.EnumJobHistory(filter);
|
||||||
var sqlConnInfo = new SqlConnectionInfo(serverConnection, SqlServer.Management.Common.ConnectionType.SqlConnection);
|
var sqlConnInfo = new SqlConnectionInfo(serverConnection, SqlServer.Management.Common.ConnectionType.SqlConnection);
|
||||||
return new Tuple<SqlConnectionInfo, DataTable, ServerConnection>(sqlConnInfo, dt, serverConnection);
|
return new Tuple<SqlConnectionInfo, DataTable, ServerConnection>(sqlConnInfo, dt, serverConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion // "Helpers"
|
#endregion // "Helpers"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -182,12 +182,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
|||||||
|
|
||||||
if (alertInfo.AlertType == Contracts.AlertType.SqlServerEvent)
|
if (alertInfo.AlertType == Contracts.AlertType.SqlServerEvent)
|
||||||
{
|
{
|
||||||
if (this.alertInfo.MessageId.HasValue)
|
if (this.alertInfo.MessageId.HasValue && this.alertInfo.MessageId > 0)
|
||||||
{
|
{
|
||||||
alert.Severity = 0;
|
alert.Severity = 0;
|
||||||
alert.MessageID = this.alertInfo.MessageId.Value;
|
alert.MessageID = this.alertInfo.MessageId.Value;
|
||||||
}
|
}
|
||||||
else if (this.alertInfo.Severity.HasValue)
|
else if (this.alertInfo.Severity.HasValue && this.alertInfo.Severity > 0)
|
||||||
{
|
{
|
||||||
alert.Severity = this.alertInfo.Severity.Value;
|
alert.Severity = this.alertInfo.Severity.Value;
|
||||||
alert.MessageID = 0;
|
alert.MessageID = 0;
|
||||||
|
|||||||
@@ -123,6 +123,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Management
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private ExecutionMode executionResult;
|
private ExecutionMode executionResult;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// exception that caused execution failure
|
||||||
|
/// </summary>
|
||||||
|
private Exception executionFailureException;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// text of the generated script if RunNow method was called last time with scripting option
|
/// text of the generated script if RunNow method was called last time with scripting option
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -155,6 +160,17 @@ namespace Microsoft.SqlTools.ServiceLayer.Management
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// exception that caused execution failure
|
||||||
|
/// </summary>
|
||||||
|
public Exception ExecutionFailureException
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return this.executionFailureException;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// text of the generated script if RunNow method was called last time with scripting option
|
/// text of the generated script if RunNow method was called last time with scripting option
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -325,7 +341,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Management
|
|||||||
private void ProcessExceptionDuringExecution(Exception ex)
|
private void ProcessExceptionDuringExecution(Exception ex)
|
||||||
{
|
{
|
||||||
// show the error
|
// show the error
|
||||||
this.executionResult = ExecutionMode.Failure;
|
this.executionResult = ExecutionMode.Failure;
|
||||||
|
this.executionFailureException = ex;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user