Files
sqltoolsservice/src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/AgentOperatorActions.cs
Karl Burtram aff0f1afae 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
2018-06-13 17:49:11 -07:00

100 lines
3.1 KiB
C#

//
// 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;
}
}
}