mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-17 02:51:45 -05:00
Drop job step and Create\Update alert handlers (#636)
* Add Delete Job Step implementation * Update create\update agent alert handlers to use execution handler * Cleanup create/update/delete operator request handlers
This commit is contained in:
@@ -4,14 +4,8 @@
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Data;
|
||||
using Microsoft.SqlServer.Management.Common;
|
||||
using Microsoft.SqlServer.Management.Diagnostics;
|
||||
using Microsoft.SqlServer.Management.Sdk.Sfc;
|
||||
using Microsoft.SqlServer.Management.Smo;
|
||||
using Microsoft.SqlServer.Management.Smo.Agent;
|
||||
using Microsoft.SqlTools.ServiceLayer.Admin;
|
||||
using Microsoft.SqlTools.ServiceLayer.Agent.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Management;
|
||||
|
||||
@@ -27,14 +21,17 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
/// </summary>
|
||||
private AgentAlertInfo alertInfo = null;
|
||||
|
||||
private ConfigAction configAction;
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor that will be used to create dialog
|
||||
/// </summary>
|
||||
/// <param name="dataContainer"></param>
|
||||
public AgentAlertActions(CDataContainer dataContainer, AgentAlertInfo alertInfo)
|
||||
public AgentAlertActions(CDataContainer dataContainer, AgentAlertInfo alertInfo, ConfigAction configAction)
|
||||
{
|
||||
this.alertInfo = alertInfo;
|
||||
this.DataContainer = dataContainer;
|
||||
this.configAction = configAction;
|
||||
}
|
||||
|
||||
private static string GetAlertName(CDataContainer container)
|
||||
@@ -44,7 +41,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
parameters.SetDocument(container.Document);
|
||||
if (parameters.GetParam("alert", ref alertName) == false || string.IsNullOrWhiteSpace(alertName))
|
||||
{
|
||||
throw new Exception("SRError.AlertNameCannotBeBlank");
|
||||
throw new Exception(SR.AlertNameCannotBeBlank);
|
||||
}
|
||||
return alertName.Trim();
|
||||
}
|
||||
@@ -59,8 +56,18 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
protected override bool DoPreProcessExecution(RunType runType, out ExecutionMode executionResult)
|
||||
{
|
||||
base.DoPreProcessExecution(runType, out executionResult);
|
||||
return false;
|
||||
}
|
||||
if (this.configAction == ConfigAction.Drop)
|
||||
{
|
||||
Drop();
|
||||
}
|
||||
else
|
||||
{
|
||||
CreateOrUpdate();
|
||||
}
|
||||
|
||||
// regular execution always takes place
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Drop()
|
||||
{
|
||||
@@ -136,11 +143,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
ApplicationException applicationException;
|
||||
if (createNewAlert)
|
||||
{
|
||||
applicationException = new ApplicationException("AgentAlertSR.CannotCreateNewAlert", e);
|
||||
applicationException = new ApplicationException(SR.CannotCreateNewAlert, e);
|
||||
}
|
||||
else
|
||||
{
|
||||
applicationException = new ApplicationException("AgentAlertSR.CannotAlterAlert", e);
|
||||
applicationException = new ApplicationException(SR.CannotAlterAlert, e);
|
||||
}
|
||||
throw applicationException;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System;
|
||||
using Microsoft.SqlTools.ServiceLayer.Agent.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Management;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
/// <summary>
|
||||
/// Agent Operators management class
|
||||
/// </summary>
|
||||
internal class AgentOperatorActions : ManagementActionBase
|
||||
{
|
||||
private AgentOperatorInfo operatorInfo;
|
||||
private AgentOperatorsData operatorsData = null;
|
||||
private ConfigAction configAction;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
public AgentOperatorActions(
|
||||
CDataContainer dataContainer,
|
||||
AgentOperatorInfo operatorInfo,
|
||||
ConfigAction configAction)
|
||||
{
|
||||
if (dataContainer == null)
|
||||
{
|
||||
throw new ArgumentNullException("dataContainer");
|
||||
}
|
||||
|
||||
if (operatorInfo == null)
|
||||
{
|
||||
throw new ArgumentNullException("operatorInfo");
|
||||
}
|
||||
|
||||
this.operatorInfo = operatorInfo;
|
||||
this.DataContainer = dataContainer;
|
||||
this.configAction = configAction;
|
||||
|
||||
STParameters parameters = new STParameters();
|
||||
parameters.SetDocument(dataContainer.Document);
|
||||
|
||||
string agentOperatorName = null;
|
||||
if (parameters.GetParam("operator", ref agentOperatorName))
|
||||
{
|
||||
this.operatorsData = new AgentOperatorsData(
|
||||
dataContainer,
|
||||
agentOperatorName,
|
||||
createMode: configAction == ConfigAction.Create);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentNullException("agentOperatorName");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if(disposing)
|
||||
{
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
// <summary>
|
||||
/// called by PreProcessExecution to enable derived classes to take over execution
|
||||
/// </summary>
|
||||
/// <param name="runType"></param>
|
||||
/// <param name="executionResult"></param>
|
||||
/// <returns>
|
||||
/// true if regular execution should take place, false if everything,
|
||||
/// has been done by this function
|
||||
/// </returns>
|
||||
protected override bool DoPreProcessExecution(RunType runType, out ExecutionMode executionResult)
|
||||
{
|
||||
base.DoPreProcessExecution(runType, out executionResult);
|
||||
|
||||
if (this.configAction == ConfigAction.Drop)
|
||||
{
|
||||
var currentOperator = this.operatorsData.Operator;
|
||||
if (currentOperator != null)
|
||||
{
|
||||
currentOperator.DropIfExists();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.operatorsData.ApplyChanges(this.operatorInfo);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,158 +4,15 @@
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Threading;
|
||||
using Microsoft.SqlServer.Management.Common;
|
||||
using Microsoft.SqlServer.Management.Diagnostics;
|
||||
using Microsoft.SqlServer.Management.Sdk.Sfc;
|
||||
using Microsoft.SqlServer.Management.Smo;
|
||||
using Microsoft.SqlServer.Management.Smo.Agent;
|
||||
using Microsoft.SqlTools.ServiceLayer.Admin;
|
||||
using Microsoft.SqlTools.ServiceLayer.Agent.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Management;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
/// <summary>
|
||||
/// Agent Operators management class
|
||||
/// </summary>
|
||||
internal class AgentOperator : ManagementActionBase
|
||||
{
|
||||
private AgentOperatorInfo operatorInfo;
|
||||
|
||||
AgentOperatorsData operatorsData = null;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
public AgentOperator(CDataContainer dataContainer, AgentOperatorInfo operatorInfo)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (dataContainer == null)
|
||||
{
|
||||
throw new ArgumentNullException("dataContainer");
|
||||
}
|
||||
|
||||
if (operatorInfo == null)
|
||||
{
|
||||
throw new ArgumentNullException("operatorInfo");
|
||||
}
|
||||
|
||||
this.operatorInfo = operatorInfo;
|
||||
this.DataContainer = dataContainer;
|
||||
|
||||
STParameters parameters = new STParameters();
|
||||
parameters.SetDocument(dataContainer.Document);
|
||||
|
||||
string agentOperatorName = null;
|
||||
if (parameters.GetParam("operator", ref agentOperatorName))
|
||||
{
|
||||
this.operatorsData = new AgentOperatorsData(dataContainer, agentOperatorName);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentNullException("agentOperatorName");
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
throw new ApplicationException("AgentOperatorsSR.FailedToCreateInitializeAgentOperatorDialog", e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if(disposing)
|
||||
{
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
public bool CreateOrUpdate()
|
||||
{
|
||||
this.operatorsData.ApplyChanges(this.operatorInfo);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
#region internal structures
|
||||
/// <summary>
|
||||
/// Provides data to be consumed in the job notification grid
|
||||
/// </summary>
|
||||
internal struct AgentJobNotificationHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// constructor
|
||||
/// </summary>
|
||||
/// <param name="name">job name</param>
|
||||
/// <param name="notifyEmail"></param>
|
||||
/// <param name="notifyPager"></param>
|
||||
public AgentJobNotificationHelper(string name, CompletionAction notifyEmail, CompletionAction notifyPager)
|
||||
{
|
||||
this.Name = name;
|
||||
this.NotifyEmail = notifyEmail;
|
||||
this.NotifyPager = notifyPager;
|
||||
}
|
||||
/// <summary>
|
||||
/// Name of the job
|
||||
/// </summary>
|
||||
public string Name;
|
||||
/// <summary>
|
||||
/// job email notification action
|
||||
/// </summary>
|
||||
public CompletionAction NotifyEmail;
|
||||
/// <summary>
|
||||
/// job pager notification action
|
||||
/// </summary>
|
||||
public CompletionAction NotifyPager;
|
||||
}
|
||||
/// <summary>
|
||||
/// Provides data to be consumed in the alert notification grid
|
||||
/// </summary>
|
||||
internal struct AgentAlertNotificationHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// constructor
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the alert</param>
|
||||
/// <param name="notifyEmail"></param>
|
||||
/// <param name="notifyPager"></param>
|
||||
/// <param name="alert">Alert object</param>
|
||||
public AgentAlertNotificationHelper(string name, bool notifyEmail, bool notifyPager, Alert alert)
|
||||
{
|
||||
this.Name = name;
|
||||
this.NotifyEmail = notifyEmail;
|
||||
this.NotifyPager = notifyPager;
|
||||
this.Alert = alert;
|
||||
}
|
||||
/// <summary>
|
||||
/// Alert name
|
||||
/// </summary>
|
||||
public string Name;
|
||||
/// <summary>
|
||||
/// Indicates whether the alert will notify the operator through email
|
||||
/// </summary>
|
||||
public bool NotifyEmail;
|
||||
/// <summary>
|
||||
/// Indicates whether the alert will notify the operator through pager
|
||||
/// </summary>
|
||||
public bool NotifyPager;
|
||||
/// <summary>
|
||||
/// Alert object. optimisation to stop us having to lookup the alert object when needed
|
||||
/// </summary>
|
||||
public Alert Alert;
|
||||
}
|
||||
#endregion
|
||||
/// <summary>
|
||||
/// Proxy class for the AgentOperators dialog and property pages.
|
||||
/// Performs lazy instantiation of groups of data based around the operators dialog property pages
|
||||
@@ -170,7 +27,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
/// <summary>
|
||||
/// Original operator name. Empty if we are creating a new operator
|
||||
/// </summary>
|
||||
string originalOperatorName = String.Empty;
|
||||
string originalOperatorName = string.Empty;
|
||||
/// <summary>
|
||||
/// Indicates whether we are creating an operator or not
|
||||
/// </summary>
|
||||
@@ -209,6 +66,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
/// will be null if the alert notifications have not been initialised
|
||||
/// </summary>
|
||||
IList<AgentAlertNotificationHelper> alertNotifications;
|
||||
|
||||
/// <summary>
|
||||
/// will be null if the job notifications have not been initialised
|
||||
/// </summary>
|
||||
@@ -222,6 +80,19 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
#endregion
|
||||
|
||||
#region properties
|
||||
|
||||
/// <summary>
|
||||
/// the current Operator SMO object
|
||||
/// </summary>
|
||||
public Operator Operator
|
||||
{
|
||||
get
|
||||
{
|
||||
JobServer jobServer = GetJobServer();
|
||||
return jobServer.Operators[this.originalOperatorName];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// indicates if the data is in create mode
|
||||
/// </summary>
|
||||
@@ -232,6 +103,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
return this.createMode;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// name of the object
|
||||
/// </summary>
|
||||
@@ -248,6 +120,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
name = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates if the dataobject is readonly
|
||||
/// </summary>
|
||||
@@ -275,6 +148,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
enabled = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// email address of this operator
|
||||
/// </summary>
|
||||
@@ -291,6 +165,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
this.emailAddress = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// pager address of this operator
|
||||
/// </summary>
|
||||
@@ -324,6 +199,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
this.pagerDays = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Weekday start time for this operator to be active
|
||||
/// </summary>
|
||||
@@ -340,6 +216,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
this.weekdayStartTime = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Weekday end time for this operator to be active
|
||||
/// </summary>
|
||||
@@ -356,6 +233,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
this.weekdayEndTime = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saturday start time for this operator to be active
|
||||
/// </summary>
|
||||
@@ -372,6 +250,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
this.saturdayStartTime = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saturday end time for this operator to be active
|
||||
/// </summary>
|
||||
@@ -388,6 +267,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
this.saturdayEndTime = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sunday start time for this operator to be active
|
||||
/// </summary>
|
||||
@@ -404,6 +284,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
this.sundayStartTime = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saturday end time for this operator to be active
|
||||
/// </summary>
|
||||
@@ -438,6 +319,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
this.alertNotifications = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Jobs that notify this operator. This has to be set through the jobs dialog and is read only
|
||||
/// </summary>
|
||||
@@ -463,6 +345,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
return this.lastEmailDate;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Date this operator was last paged
|
||||
/// </summary>
|
||||
@@ -480,7 +363,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
|
||||
#region Constructors
|
||||
|
||||
public AgentOperatorsData(CDataContainer dataContainer, string operatorName)
|
||||
public AgentOperatorsData(CDataContainer dataContainer, string operatorName, bool createMode)
|
||||
{
|
||||
if (dataContainer == null)
|
||||
{
|
||||
@@ -497,7 +380,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
this.originalOperatorName = operatorName;
|
||||
this.name = operatorName;
|
||||
|
||||
this.createMode = operatorName.Length == 0;
|
||||
this.createMode = createMode;
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -541,6 +424,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
this.generalInitialized = true;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Load the data for the jobs that notify this operator. Can be called multiple times and will
|
||||
/// only load the data initially, or after a reset.
|
||||
@@ -577,6 +461,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Load alerts that notify this operator
|
||||
/// </summary>
|
||||
@@ -824,9 +709,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
/// </summary>
|
||||
private void LoadGeneralDefaults()
|
||||
{
|
||||
name = String.Empty;
|
||||
this.emailAddress = String.Empty;
|
||||
this.pagerAddress = String.Empty;
|
||||
name = string.Empty;
|
||||
this.emailAddress = string.Empty;
|
||||
this.pagerAddress = string.Empty;
|
||||
enabled = true;
|
||||
pagerDays = 0;
|
||||
|
||||
@@ -835,6 +720,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
|
||||
this.generalInitialized = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set job notification defaults. This is just an empty list
|
||||
/// </summary>
|
||||
@@ -842,6 +728,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
this.jobNotifications = new List<AgentJobNotificationHelper>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// set the alert notification defaults. This list will contain all of the alerts
|
||||
/// </summary>
|
||||
@@ -858,6 +745,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
this.alertNotifications.Add(alertNotification);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// load defaults for the history page
|
||||
/// </summary>
|
||||
@@ -878,9 +766,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
private JobServer GetJobServer()
|
||||
{
|
||||
JobServer jobServer = this.dataContainer.Server.JobServer;
|
||||
if(jobServer == null)
|
||||
if (jobServer == null)
|
||||
{
|
||||
throw new ApplicationException("AgentOperatorsSR.JobServerIsNotAvailable");
|
||||
throw new ApplicationException(SR.JobServerIsNotAvailable);
|
||||
}
|
||||
return jobServer;
|
||||
}
|
||||
@@ -894,7 +782,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
private Operator GetCurrentOperator()
|
||||
{
|
||||
JobServer jobServer = GetJobServer();
|
||||
|
||||
Operator currentOperator = jobServer.Operators[this.originalOperatorName];
|
||||
this.createMode = (currentOperator == null);
|
||||
if (this.createMode)
|
||||
@@ -913,6 +800,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
return new TimeSpan(dateTime.Hour, dateTime.Minute, dateTime.Second);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
@@ -944,4 +832,81 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
#region internal structures
|
||||
/// <summary>
|
||||
/// Provides data to be consumed in the job notification grid
|
||||
/// </summary>
|
||||
internal struct AgentJobNotificationHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// constructor
|
||||
/// </summary>
|
||||
/// <param name="name">job name</param>
|
||||
/// <param name="notifyEmail"></param>
|
||||
/// <param name="notifyPager"></param>
|
||||
public AgentJobNotificationHelper(string name, CompletionAction notifyEmail, CompletionAction notifyPager)
|
||||
{
|
||||
this.Name = name;
|
||||
this.NotifyEmail = notifyEmail;
|
||||
this.NotifyPager = notifyPager;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Name of the job
|
||||
/// </summary>
|
||||
public string Name;
|
||||
|
||||
/// <summary>
|
||||
/// job email notification action
|
||||
/// </summary>
|
||||
public CompletionAction NotifyEmail;
|
||||
|
||||
/// <summary>
|
||||
/// job pager notification action
|
||||
/// </summary>
|
||||
public CompletionAction NotifyPager;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides data to be consumed in the alert notification grid
|
||||
/// </summary>
|
||||
internal struct AgentAlertNotificationHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// constructor
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the alert</param>
|
||||
/// <param name="notifyEmail"></param>
|
||||
/// <param name="notifyPager"></param>
|
||||
/// <param name="alert">Alert object</param>
|
||||
public AgentAlertNotificationHelper(string name, bool notifyEmail, bool notifyPager, Alert alert)
|
||||
{
|
||||
this.Name = name;
|
||||
this.NotifyEmail = notifyEmail;
|
||||
this.NotifyPager = notifyPager;
|
||||
this.Alert = alert;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Alert name
|
||||
/// </summary>
|
||||
public string Name;
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the alert will notify the operator through email
|
||||
/// </summary>
|
||||
public bool NotifyEmail;
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the alert will notify the operator through pager
|
||||
/// </summary>
|
||||
public bool NotifyPager;
|
||||
|
||||
/// <summary>
|
||||
/// Alert object. optimisation to stop us having to lookup the alert object when needed
|
||||
/// </summary>
|
||||
public Alert Alert;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -64,7 +64,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
private ILogEntry m_currentEntry = null;
|
||||
private int m_index = 0;
|
||||
private bool m_isClosed = false;
|
||||
private TypedColumnCollection columnTypes;
|
||||
private IServiceProvider serviceProvider = null;
|
||||
|
||||
private static string historyTableDeclaration = "declare @tmp_sp_help_jobhistory table";
|
||||
|
||||
@@ -19,6 +19,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
private JobStepData data;
|
||||
private JobData jobData;
|
||||
private ConfigAction configAction;
|
||||
|
||||
public JobStepsActions(
|
||||
CDataContainer dataContainer,
|
||||
@@ -26,17 +27,18 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
AgentJobStepInfo stepInfo,
|
||||
ConfigAction configAction)
|
||||
{
|
||||
this.configAction = configAction;
|
||||
this.DataContainer = dataContainer;
|
||||
this.jobData = jobData;
|
||||
|
||||
if (configAction == ConfigAction.Update)
|
||||
if (configAction == ConfigAction.Create)
|
||||
{
|
||||
JobStep jobStep = GetJobStep(this.jobData, stepInfo.StepName);
|
||||
this.data = new JobStepData(jobStep, jobData.JobSteps);
|
||||
this.data = new JobStepData(jobData.JobSteps);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.data = new JobStepData(jobData.JobSteps);
|
||||
JobStep jobStep = GetJobStep(this.jobData, stepInfo.StepName);
|
||||
this.data = new JobStepData(jobStep, jobData.JobSteps);
|
||||
}
|
||||
|
||||
// load properties from AgentJobStepInfo
|
||||
@@ -48,27 +50,36 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
protected override bool DoPreProcessExecution(RunType runType, out ExecutionMode executionResult)
|
||||
{
|
||||
base.DoPreProcessExecution(runType, out executionResult);
|
||||
|
||||
// Make sure the job step name is not blank.
|
||||
if (this.data.Name == null || this.data.Name.Length == 0)
|
||||
if (this.configAction == ConfigAction.Drop)
|
||||
{
|
||||
throw new Exception(SR.JobStepNameCannotBeBlank);
|
||||
}
|
||||
|
||||
// Check to make sure that the user has not entered a job step name that already exists.
|
||||
for (int stepIndex = 0; stepIndex < this.data.Parent.Steps.Count; ++stepIndex)
|
||||
{
|
||||
// don't compare if the id's are the same.
|
||||
if (data.ID != ((JobStepData)this.data.Parent.Steps[stepIndex]).ID && data.Name == ((JobStepData)this.data.Parent.Steps[stepIndex]).Name)
|
||||
if (this.data.JobStep != null)
|
||||
{
|
||||
// Throw an error if the job step name already exists
|
||||
throw new Exception(SR.JobStepNameAlreadyExists(this.data.Name));
|
||||
this.data.JobStep.DropIfExists();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Make sure the job step name is not blank.
|
||||
if (this.data.Name == null || this.data.Name.Length == 0)
|
||||
{
|
||||
throw new Exception(SR.JobStepNameCannotBeBlank);
|
||||
}
|
||||
|
||||
if (runType == RunType.RunNow)
|
||||
{
|
||||
this.data.ApplyChanges(this.jobData.Job);
|
||||
// Check to make sure that the user has not entered a job step name that already exists.
|
||||
for (int stepIndex = 0; stepIndex < this.data.Parent.Steps.Count; ++stepIndex)
|
||||
{
|
||||
// don't compare if the id's are the same.
|
||||
if (data.ID != ((JobStepData)this.data.Parent.Steps[stepIndex]).ID && data.Name == ((JobStepData)this.data.Parent.Steps[stepIndex]).Name)
|
||||
{
|
||||
// Throw an error if the job step name already exists
|
||||
throw new Exception(SR.JobStepNameAlreadyExists(this.data.Name));
|
||||
}
|
||||
}
|
||||
|
||||
if (runType == RunType.RunNow)
|
||||
{
|
||||
this.data.ApplyChanges(this.jobData.Job);
|
||||
}
|
||||
}
|
||||
|
||||
// regular execution always takes place
|
||||
|
||||
@@ -7,7 +7,6 @@ using System;
|
||||
using System.Collections;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
@@ -16,6 +15,7 @@ using Microsoft.SqlServer.Management.Diagnostics;
|
||||
using Microsoft.SqlServer.Management.Sdk.Sfc;
|
||||
using Microsoft.SqlServer.Management.Smo;
|
||||
using Microsoft.SqlServer.Management.Smo.Agent;
|
||||
using Microsoft.SqlTools.ServiceLayer.Management;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
@@ -30,16 +30,16 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
#endregion
|
||||
|
||||
#region private struct members
|
||||
private String name;
|
||||
private String description;
|
||||
private System.Int32 id;
|
||||
private System.Int32 activeEndDate;
|
||||
private System.Int32 activeEndTimeOfDay;
|
||||
private System.Int32 activeStartDate;
|
||||
private System.Int32 activeStartTimeOfDay;
|
||||
private System.Int32 frequencyInterval;
|
||||
private System.Int32 frequencyRecurrenceFactor;
|
||||
private System.Int32 frequencySubDayInterval;
|
||||
private string name;
|
||||
private string description;
|
||||
private int id;
|
||||
private int activeEndDate;
|
||||
private int activeEndTimeOfDay;
|
||||
private int activeStartDate;
|
||||
private int activeStartTimeOfDay;
|
||||
private int frequencyInterval;
|
||||
private int frequencyRecurrenceFactor;
|
||||
private int frequencySubDayInterval;
|
||||
private FrequencyTypes frequencyTypes;
|
||||
private FrequencySubDayTypes frequencySubDayTypes;
|
||||
private FrequencyRelativeIntervals frequencyRelativeIntervals;
|
||||
@@ -289,7 +289,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
if (this.FrequencyInterval == 0)
|
||||
{
|
||||
return String.Empty;
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
StringBuilder daysOfWeek = new StringBuilder();
|
||||
@@ -347,7 +347,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
get
|
||||
{
|
||||
string format = String.Empty;
|
||||
string format = string.Empty;
|
||||
|
||||
switch (this.FrequencyTypes)
|
||||
{
|
||||
@@ -508,43 +508,43 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
#endregion
|
||||
|
||||
#region public properties
|
||||
public System.Int32 ActiveEndDate
|
||||
public int ActiveEndDate
|
||||
{
|
||||
get { return activeEndDate; }
|
||||
set { activeEndDate = value; }
|
||||
}
|
||||
|
||||
public System.Int32 ActiveEndTimeOfDay
|
||||
public int ActiveEndTimeOfDay
|
||||
{
|
||||
get { return activeEndTimeOfDay; }
|
||||
set { activeEndTimeOfDay = value; }
|
||||
}
|
||||
|
||||
public System.Int32 ActiveStartDate
|
||||
public int ActiveStartDate
|
||||
{
|
||||
get { return activeStartDate; }
|
||||
set { activeStartDate = value; }
|
||||
}
|
||||
|
||||
public System.Int32 ActiveStartTimeOfDay
|
||||
public int ActiveStartTimeOfDay
|
||||
{
|
||||
get { return activeStartTimeOfDay; }
|
||||
set { activeStartTimeOfDay = value; }
|
||||
}
|
||||
|
||||
public System.Int32 FrequencyInterval
|
||||
public int FrequencyInterval
|
||||
{
|
||||
get { return frequencyInterval; }
|
||||
set { frequencyInterval = value; }
|
||||
}
|
||||
|
||||
public System.Int32 FrequencyRecurrenceFactor
|
||||
public int FrequencyRecurrenceFactor
|
||||
{
|
||||
get { return frequencyRecurrenceFactor; }
|
||||
set { frequencyRecurrenceFactor = value; }
|
||||
}
|
||||
|
||||
public System.Int32 FrequencySubDayInterval
|
||||
public int FrequencySubDayInterval
|
||||
{
|
||||
get { return frequencySubDayInterval; }
|
||||
set { frequencySubDayInterval = value; }
|
||||
@@ -592,7 +592,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
}
|
||||
}
|
||||
|
||||
public System.Int32 ID
|
||||
public int ID
|
||||
{
|
||||
get { return id; }
|
||||
set { id = value; }
|
||||
@@ -1147,16 +1147,16 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
|
||||
if (jobSchedules != null && version.Major < 9)
|
||||
{
|
||||
///Check to see if a duplicate job schedule name has been entered. This condition is permissable
|
||||
///in SQL 9, but not in previous versions.
|
||||
// Check to see if a duplicate job schedule name has been entered. This condition is permissable
|
||||
// in SQL 9, but not in previous versions.
|
||||
for (int index = 0; index < jobSchedules.Count; index++)
|
||||
{
|
||||
//If the schedule name matches an existing job, throw an error and ask user to enter another
|
||||
//name.
|
||||
// If the schedule name matches an existing job, throw an error and ask user to enter another
|
||||
// name.
|
||||
if (((JobScheduleData)jobSchedules[index]).Name == this.Name &&
|
||||
this.currentName != this.originalName)
|
||||
{
|
||||
sbError.Append("SRError.ScheduleNameAlreadyExists(this.Name)" + "\n");
|
||||
sbError.Append(SR.ScheduleNameAlreadyExists(this.Name) + "\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1165,40 +1165,39 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
// weekly schdule - ensure that the start date is less than the end date
|
||||
if (this.ActiveStartDate > this.ActiveEndDate)
|
||||
{
|
||||
sbError.Append("SRError.StartDateGreaterThanEndDate" + "\n");
|
||||
sbError.Append(SR.StartDateGreaterThanEndDate + "\n");
|
||||
}
|
||||
|
||||
//One Time events validations
|
||||
// One Time events validations
|
||||
if (this.FrequencyTypes == FrequencyTypes.OneTime)
|
||||
{
|
||||
//Check to make sure that the start time is greater than the baseline
|
||||
//date of 01/01/1990
|
||||
// Check to make sure that the start time is greater than the baseline
|
||||
// date of 01/01/1990
|
||||
if (this.ActiveStartDate < minStartDate)
|
||||
{
|
||||
sbError.Append("SRError.InvalidStartDate" + "\n");
|
||||
sbError.Append(SR.InvalidStartDate + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Recurring schdule. Start time must be less than the end time.
|
||||
// Recurring schdule. Start time must be less than the end time.
|
||||
if (this.FrequencyTypes != FrequencyTypes.OneTime &&
|
||||
this.FrequencyTypes != FrequencyTypes.OnIdle)
|
||||
{
|
||||
//Check to make sure that the start time is greater than the baseline
|
||||
//date of 01/01/1990
|
||||
// Check to make sure that the start time is greater than the baseline
|
||||
// date of 01/01/1990
|
||||
if (this.ActiveStartDate < minStartDate)
|
||||
{
|
||||
sbError.Append("SRError.InvalidStartDate" + "\n");
|
||||
sbError.Append(SR.InvalidStartDate + "\n");
|
||||
}
|
||||
|
||||
|
||||
//Check to ensure that the StartTime != to the EndTime
|
||||
// Check to ensure that the StartTime != to the EndTime
|
||||
if (this.ActiveStartTime == this.ActiveEndTime)
|
||||
{
|
||||
sbError.Append("SRError.EndTimeEqualToStartTime" + "\n");
|
||||
sbError.Append(SR.EndTimeEqualToStartTime + "\n");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// weekly schedule - at least one day should be selected
|
||||
@@ -1206,12 +1205,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
if (this.FrequencyInterval == 0)
|
||||
{
|
||||
sbError.Append("SRError.InvalidWeeklySchedule" + "\n");
|
||||
sbError.Append(SR.InvalidWeeklySchedule + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
// $FUTURE add extra checks in future - e.g. 147675 - starttime/endtime startdate/enddate and thier format
|
||||
|
||||
// return error
|
||||
if (sbError.ToString().Length > 0)
|
||||
{
|
||||
@@ -1243,6 +1240,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
this.alreadyCreated = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provide context to create a new schedule.
|
||||
/// </summary>
|
||||
@@ -1259,6 +1257,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
this.source = schedule;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return this.GetSimpleJobDescription();
|
||||
@@ -1322,6 +1321,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
this.alreadyCreated = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// set defaults assuming no parent.
|
||||
/// </summary>
|
||||
@@ -1362,14 +1362,14 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
|
||||
#region static constants
|
||||
/// <summary>
|
||||
/// Maximum date supported by SSMS.
|
||||
/// This is the same as the culture max date because SQl Agent range is larger than all cultures' ranges.
|
||||
/// Maximum date supported
|
||||
/// This is the same as the culture max date because SQL Agent range is larger than all cultures' ranges.
|
||||
/// </summary>
|
||||
public static DateTime MaxAgentDateValue
|
||||
{
|
||||
get
|
||||
{
|
||||
return DateTime.Now; // Utils.GetMaxCultureDateTime().Date;
|
||||
return Utils.GetMaxCultureDateTime().Date;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#if false
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
@@ -182,3 +183,4 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,3 +1,4 @@
|
||||
#if false
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
@@ -605,11 +606,4 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,3 +1,4 @@
|
||||
#if false
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
@@ -466,3 +467,4 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,3 +1,4 @@
|
||||
#if false
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
@@ -155,3 +156,4 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,3 +1,4 @@
|
||||
#if false
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
@@ -250,10 +251,4 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,3 +1,4 @@
|
||||
#if false
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
@@ -108,3 +109,4 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,3 +1,4 @@
|
||||
#if false
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
@@ -28,17 +29,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
/// </summary>
|
||||
internal class SqlServerAgentPropertiesJobSystem : ManagementActionBase
|
||||
{
|
||||
#region Private members
|
||||
|
||||
private int shutDownWaitTime;
|
||||
private bool sysAdminOnly;
|
||||
private string domainUser = string.Empty;
|
||||
private string userName = string.Empty;
|
||||
private string passwdMask = new string('*', 16);
|
||||
private SecureString securePasswd = new SecureString();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Implementation
|
||||
|
||||
private void ApplyChanges()
|
||||
@@ -148,11 +138,4 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user