// // 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 { /// /// Agent Operators management class /// internal class AgentOperatorActions : ManagementActionBase { private AgentOperatorInfo operatorInfo; private AgentOperatorsData operatorsData = null; private ConfigAction configAction; /// /// Constructor /// 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"); } } /// /// Clean up any resources being used. /// protected override void Dispose(bool disposing) { if(disposing) { } base.Dispose(disposing); } // /// called by PreProcessExecution to enable derived classes to take over execution /// /// /// /// /// true if regular execution should take place, false if everything, /// has been done by this function /// 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; } } }