mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-29 17:24:34 -05:00
SQL Agent configuration for Operators, Alerts and Proxies (WIP) (#621)
* Initial non-refactored SQL Agent alert classes (WIP) * Move agent classes into subdirectories * Refactor the agent config code a bit more * Add more implementation for handlers * Add more code to the create alert handler * Clean up agent alert class * Clean up alert methods a bit * Initial Operator contracts * Additonal SQL Agent config changes * More Proxy config cleanup * Cleanup AgentProxy class * Additional cleanups * Run SRGen * Add security service to create credential objects
This commit is contained in:
100
src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/JobHelper.cs
Normal file
100
src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/JobHelper.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
//
|
||||
// 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 System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Microsoft.SqlServer.Management.Common;
|
||||
using Microsoft.SqlServer.Management.Sdk.Sfc;
|
||||
using Microsoft.SqlServer.Management.Smo.Agent;
|
||||
using SMO = Microsoft.SqlServer.Management.Smo;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
internal class JobHelper
|
||||
{
|
||||
private JobHelper()
|
||||
{
|
||||
}
|
||||
|
||||
private ServerConnection connection = null;
|
||||
private string jobName = string.Empty;
|
||||
private SMO.Server server = null;
|
||||
private Job job = null;
|
||||
|
||||
//
|
||||
// ServerConnection object should be passed from caller,
|
||||
// who gets it from CDataContainer.ServerConnection
|
||||
//
|
||||
public JobHelper(ServerConnection connection)
|
||||
{
|
||||
this.connection = connection;
|
||||
server = new SMO.Server(connection);
|
||||
}
|
||||
|
||||
public string JobName
|
||||
{
|
||||
get
|
||||
{
|
||||
return jobName;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (server != null)
|
||||
{
|
||||
Job j = server.JobServer.Jobs[value];
|
||||
if (j != null)
|
||||
{
|
||||
job = j;
|
||||
jobName = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException("Job not found");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
if (job != null)
|
||||
{
|
||||
job.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
if (job != null)
|
||||
{
|
||||
job.Start();
|
||||
}
|
||||
}
|
||||
|
||||
public void Delete()
|
||||
{
|
||||
if (job != null)
|
||||
{
|
||||
job.Drop();
|
||||
|
||||
//
|
||||
// you can't do anything with
|
||||
// a job after you drop it!
|
||||
//
|
||||
job = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void Enable(bool enable)
|
||||
{
|
||||
if (job != null && job.IsEnabled != enable)
|
||||
{
|
||||
job.IsEnabled = enable;
|
||||
job.Alter();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user