Fix a couple bugs with Alert update (#651)

* Alert bugs WIP

* Alert updates

* Convert tabs to spaces
This commit is contained in:
Karl Burtram
2018-07-06 08:57:07 -07:00
committed by GitHub
parent 21cccd7eaa
commit 5d267303ae
3 changed files with 42 additions and 16 deletions

View File

@@ -468,6 +468,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
{ {
var result = await ConfigureAgentAlert( var result = await ConfigureAgentAlert(
parameters.OwnerUri, parameters.OwnerUri,
parameters.Alert.Name,
parameters.Alert, parameters.Alert,
ConfigAction.Create, ConfigAction.Create,
RunType.RunNow); RunType.RunNow);
@@ -486,6 +487,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
{ {
var result = await ConfigureAgentAlert( var result = await ConfigureAgentAlert(
parameters.OwnerUri, parameters.OwnerUri,
parameters.OriginalAlertName,
parameters.Alert, parameters.Alert,
ConfigAction.Update, ConfigAction.Update,
RunType.RunNow); RunType.RunNow);
@@ -504,6 +506,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
{ {
var result = await ConfigureAgentAlert( var result = await ConfigureAgentAlert(
parameters.OwnerUri, parameters.OwnerUri,
parameters.Alert.Name,
parameters.Alert, parameters.Alert,
ConfigAction.Drop, ConfigAction.Drop,
RunType.RunNow); RunType.RunNow);
@@ -881,6 +884,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
internal async Task<Tuple<bool, string>> ConfigureAgentAlert( internal async Task<Tuple<bool, string>> ConfigureAgentAlert(
string ownerUri, string ownerUri,
string alertName,
AgentAlertInfo alert, AgentAlertInfo alert,
ConfigAction configAction, ConfigAction configAction,
RunType runType) RunType runType)
@@ -893,11 +897,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
ConnectionServiceInstance.TryFindConnection(ownerUri, out connInfo); ConnectionServiceInstance.TryFindConnection(ownerUri, out connInfo);
CDataContainer dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true); CDataContainer dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true);
STParameters param = new STParameters(dataContainer.Document); STParameters param = new STParameters(dataContainer.Document);
param.SetParam("alert", alert.Name); param.SetParam("alert", alertName);
if (alert != null) if (alert != null)
{ {
using (AgentAlertActions agentAlert = new AgentAlertActions(dataContainer, alert, configAction)) using (AgentAlertActions agentAlert = new AgentAlertActions(dataContainer, alertName, alert, configAction))
{ {
var executionHandler = new ExecutonHandler(agentAlert); var executionHandler = new ExecutonHandler(agentAlert);
executionHandler.RunNow(runType, this); executionHandler.RunNow(runType, this);

View File

@@ -44,11 +44,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent.Contracts
public string JobName { get; set; } public string JobName { get; set; }
public string LastOccurrenceDate { get; set; } public string LastOccurrenceDate { get; set; }
public string LastResponseDate { get; set; } public string LastResponseDate { get; set; }
public int MessageId { get; set; } public int? MessageId { get; set; }
public string NotificationMessage { get; set; } public string NotificationMessage { get; set; }
public int OccurrenceCount { get; set; } public int OccurrenceCount { get; set; }
public string PerformanceCondition { get; set; } public string PerformanceCondition { get; set; }
public int Severity { get; set; } public int? Severity { get; set; }
public string DatabaseName { get; set; } public string DatabaseName { get; set; }
public string CountResetDate { get; set; } public string CountResetDate { get; set; }
public string CategoryName { get; set; } public string CategoryName { get; set; }

View File

@@ -11,11 +11,11 @@ using Microsoft.SqlTools.ServiceLayer.Management;
namespace Microsoft.SqlTools.ServiceLayer.Agent namespace Microsoft.SqlTools.ServiceLayer.Agent
{ {
/// <summary> /// <summary>
/// AgentAlert class /// AgentAlert class
/// </summary> /// </summary>
internal class AgentAlertActions : ManagementActionBase internal class AgentAlertActions : ManagementActionBase
{ {
/// <summary> /// <summary>
/// Agent alert info instance /// Agent alert info instance
/// </summary> /// </summary>
@@ -23,12 +23,17 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
private ConfigAction configAction; private ConfigAction configAction;
private string originalAlertName = 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(CDataContainer dataContainer, AgentAlertInfo alertInfo, ConfigAction configAction) public AgentAlertActions(
CDataContainer dataContainer, string originalAlertName,
AgentAlertInfo alertInfo, ConfigAction configAction)
{ {
this.originalAlertName = originalAlertName;
this.alertInfo = alertInfo; this.alertInfo = alertInfo;
this.DataContainer = dataContainer; this.DataContainer = dataContainer;
this.configAction = configAction; this.configAction = configAction;
@@ -134,6 +139,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
return false; return false;
} }
alert.Alter(); alert.Alter();
if (!string.IsNullOrWhiteSpace(this.alertInfo.Name) && !string.Equals(alert.Name, this.alertInfo.Name))
{
alert.Rename(this.alertInfo.Name);
}
} }
return true; return true;
@@ -160,10 +170,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
throw new ArgumentNullException("alert"); throw new ArgumentNullException("alert");
} }
if (!string.IsNullOrWhiteSpace(this.DataContainer.ConnectionInfo.DatabaseName)) alert.DatabaseName = !string.IsNullOrWhiteSpace(this.alertInfo.DatabaseName)
{ ? this.alertInfo.DatabaseName : string.Empty;
alert.DatabaseName = this.DataContainer.ConnectionInfo.DatabaseName;
}
if (!string.IsNullOrWhiteSpace(this.alertInfo.CategoryName)) if (!string.IsNullOrWhiteSpace(this.alertInfo.CategoryName))
{ {
@@ -174,12 +182,26 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
if (alertInfo.AlertType == Contracts.AlertType.SqlServerEvent) if (alertInfo.AlertType == Contracts.AlertType.SqlServerEvent)
{ {
alert.Severity = this.alertInfo.Severity; if (this.alertInfo.MessageId.HasValue)
alert.MessageID = this.alertInfo.MessageId; {
alert.Severity = 0;
alert.MessageID = this.alertInfo.MessageId.Value;
}
else if (this.alertInfo.Severity.HasValue)
{
alert.Severity = this.alertInfo.Severity.Value;
alert.MessageID = 0;
}
if (!string.IsNullOrWhiteSpace(this.alertInfo.EventDescriptionKeyword)) if (!string.IsNullOrWhiteSpace(this.alertInfo.EventDescriptionKeyword))
{ {
alert.EventDescriptionKeyword = this.alertInfo.EventDescriptionKeyword; alert.EventDescriptionKeyword = this.alertInfo.EventDescriptionKeyword;
} }
// clear out other alert type fields
alert.PerformanceCondition = string.Empty;
alert.WmiEventNamespace = string.Empty;
alert.WmiEventQuery = string.Empty;
} }
} }
} }