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

View File

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

View File

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