mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-12 19:18:33 -05:00
Agent configuration support classes (WIP) (#632)
* Additional SQL Agent config classes (WIP) * Fix build breaks * Clean up job step code * Add VS Code build files * Move changes to other machine * More of the action execution classes * More execution processing refactors * More refactoring * Disable tests for WIP merge * Fix break on Release config * Stage changes to other machine.
This commit is contained in:
@@ -17,6 +17,7 @@ using Microsoft.SqlTools.ServiceLayer.Admin;
|
||||
using Microsoft.SqlTools.ServiceLayer.Agent.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting;
|
||||
using Microsoft.SqlTools.ServiceLayer.Management;
|
||||
using Microsoft.SqlTools.Utility;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
@@ -26,13 +27,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
/// </summary>
|
||||
public class AgentService
|
||||
{
|
||||
internal enum AgentConfigAction
|
||||
{
|
||||
Create,
|
||||
Update,
|
||||
Drop
|
||||
}
|
||||
|
||||
private Dictionary<Guid, JobProperties> jobs = null;
|
||||
private ConnectionService connectionService = null;
|
||||
private static readonly Lazy<AgentService> instance = new Lazy<AgentService>(() => new AgentService());
|
||||
@@ -88,10 +82,21 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
public void InitializeService(ServiceHost serviceHost)
|
||||
{
|
||||
this.ServiceHost = serviceHost;
|
||||
|
||||
// Jobs request handlers
|
||||
this.ServiceHost.SetRequestHandler(AgentJobsRequest.Type, HandleAgentJobsRequest);
|
||||
this.ServiceHost.SetRequestHandler(AgentJobHistoryRequest.Type, HandleJobHistoryRequest);
|
||||
this.ServiceHost.SetRequestHandler(AgentJobActionRequest.Type, HandleJobActionRequest);
|
||||
|
||||
this.ServiceHost.SetRequestHandler(CreateAgentJobRequest.Type, HandleCreateAgentJobRequest);
|
||||
this.ServiceHost.SetRequestHandler(UpdateAgentJobRequest.Type, HandleUpdateAgentJobRequest);
|
||||
this.ServiceHost.SetRequestHandler(DeleteAgentJobRequest.Type, HandleDeleteAgentJobRequest);
|
||||
|
||||
// Job Steps request handlers
|
||||
this.ServiceHost.SetRequestHandler(CreateAgentJobStepRequest.Type, HandleCreateAgentJobStepRequest);
|
||||
this.ServiceHost.SetRequestHandler(UpdateAgentJobStepRequest.Type, HandleUpdateAgentJobStepRequest);
|
||||
this.ServiceHost.SetRequestHandler(DeleteAgentJobStepRequest.Type, HandleDeleteAgentJobStepRequest);
|
||||
|
||||
// Alerts request handlers
|
||||
this.ServiceHost.SetRequestHandler(AgentAlertsRequest.Type, HandleAgentAlertsRequest);
|
||||
this.ServiceHost.SetRequestHandler(CreateAgentAlertRequest.Type, HandleCreateAgentAlertRequest);
|
||||
@@ -112,7 +117,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
}
|
||||
|
||||
#region "Jobs Handlers"
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Handle request to get Agent job activities
|
||||
/// </summary>
|
||||
@@ -138,7 +143,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
var agentJobs = new List<AgentJobInfo>();
|
||||
if (this.jobs != null)
|
||||
{
|
||||
|
||||
|
||||
foreach (var job in this.jobs.Values)
|
||||
{
|
||||
agentJobs.Add(JobUtilities.ConvertToAgentJobInfo(job));
|
||||
@@ -154,17 +159,17 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle request to get Agent Job history
|
||||
/// </summary>
|
||||
internal async Task HandleJobHistoryRequest(AgentJobHistoryParams parameters, RequestContext<AgentJobHistoryResult> requestContext)
|
||||
internal async Task HandleJobHistoryRequest(AgentJobHistoryParams parameters, RequestContext<AgentJobHistoryResult> requestContext)
|
||||
{
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
try
|
||||
{
|
||||
var result = new AgentJobHistoryResult();
|
||||
ConnectionInfo connInfo;
|
||||
@@ -179,7 +184,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
ServerConnection connection = tuple.Item3;
|
||||
int count = dt.Rows.Count;
|
||||
List<AgentJobHistoryInfo> jobHistories = new List<AgentJobHistoryInfo>();
|
||||
if (count > 0)
|
||||
if (count > 0)
|
||||
{
|
||||
var job = dt.Rows[0];
|
||||
string jobName = Convert.ToString(job[JobUtilities.UrnJobName], System.Globalization.CultureInfo.InvariantCulture);
|
||||
@@ -198,11 +203,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
await requestContext.SendResult(result);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -213,7 +218,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
var result = new AgentJobActionResult();
|
||||
try
|
||||
try
|
||||
{
|
||||
ConnectionInfo connInfo;
|
||||
ConnectionServiceInstance.TryFindConnection(
|
||||
@@ -222,7 +227,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
if (connInfo != null)
|
||||
{
|
||||
var sqlConnection = ConnectionService.OpenSqlConnection(connInfo);
|
||||
var serverConnection = new ServerConnection(sqlConnection);
|
||||
var serverConnection = new ServerConnection(sqlConnection);
|
||||
var jobHelper = new JobHelper(serverConnection);
|
||||
jobHelper.JobName = parameters.JobName;
|
||||
switch(parameters.Action)
|
||||
@@ -249,7 +254,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
await requestContext.SendResult(result);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
result.Succeeded = false;
|
||||
result.ErrorMessage = e.Message;
|
||||
@@ -261,22 +266,171 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
private Tuple<SqlConnectionInfo, DataTable, ServerConnection> CreateSqlConnection(ConnectionInfo connInfo, String jobId)
|
||||
{
|
||||
var sqlConnection = ConnectionService.OpenSqlConnection(connInfo);
|
||||
var serverConnection = new ServerConnection(sqlConnection);
|
||||
var server = new Server(serverConnection);
|
||||
var filter = new JobHistoryFilter();
|
||||
var serverConnection = new ServerConnection(sqlConnection);
|
||||
var server = new Server(serverConnection);
|
||||
var filter = new JobHistoryFilter();
|
||||
filter.JobID = new Guid(jobId);
|
||||
var dt = server.JobServer.EnumJobHistory(filter);
|
||||
var sqlConnInfo = new SqlConnectionInfo(serverConnection, SqlServer.Management.Common.ConnectionType.SqlConnection);
|
||||
return new Tuple<SqlConnectionInfo, DataTable, ServerConnection>(sqlConnInfo, dt, serverConnection);
|
||||
}
|
||||
|
||||
internal async Task HandleCreateAgentJobRequest(CreateAgentJobParams parameters, RequestContext<CreateAgentJobResult> requestContext)
|
||||
{
|
||||
var result = await ConfigureAgentJob(
|
||||
parameters.OwnerUri,
|
||||
parameters.Job,
|
||||
ConfigAction.Create,
|
||||
ManagementUtils.asRunType(parameters.TaskExecutionMode));
|
||||
|
||||
await requestContext.SendResult(new CreateAgentJobResult()
|
||||
{
|
||||
Succeeded = result.Item1,
|
||||
ErrorMessage = result.Item2
|
||||
});
|
||||
}
|
||||
|
||||
internal async Task HandleUpdateAgentJobRequest(UpdateAgentJobParams parameters, RequestContext<UpdateAgentJobResult> requestContext)
|
||||
{
|
||||
var result = await ConfigureAgentJob(
|
||||
parameters.OwnerUri,
|
||||
parameters.Job,
|
||||
ConfigAction.Update,
|
||||
ManagementUtils.asRunType(parameters.TaskExecutionMode));
|
||||
|
||||
await requestContext.SendResult(new UpdateAgentJobResult()
|
||||
{
|
||||
Succeeded = result.Item1,
|
||||
ErrorMessage = result.Item2
|
||||
});
|
||||
}
|
||||
|
||||
internal async Task HandleDeleteAgentJobRequest(DeleteAgentJobParams parameters, RequestContext<DeleteAgentJobResult> requestContext)
|
||||
{
|
||||
var result = await ConfigureAgentJob(
|
||||
parameters.OwnerUri,
|
||||
parameters.Job,
|
||||
ConfigAction.Drop,
|
||||
ManagementUtils.asRunType(parameters.TaskExecutionMode));
|
||||
|
||||
await requestContext.SendResult(new DeleteAgentJobResult()
|
||||
{
|
||||
Succeeded = result.Item1,
|
||||
ErrorMessage = result.Item2
|
||||
});
|
||||
}
|
||||
|
||||
internal async Task HandleCreateAgentJobStepRequest(CreateAgentJobStepParams parameters, RequestContext<CreateAgentJobStepResult> requestContext)
|
||||
{
|
||||
Tuple<bool, string> result = await ConfigureAgentJobStep(
|
||||
parameters.OwnerUri,
|
||||
parameters.Step,
|
||||
ConfigAction.Create);
|
||||
|
||||
await requestContext.SendResult(new CreateAgentJobStepResult()
|
||||
{
|
||||
Succeeded = result.Item1,
|
||||
ErrorMessage = result.Item2
|
||||
});
|
||||
}
|
||||
|
||||
internal async Task HandleUpdateAgentJobStepRequest(UpdateAgentJobStepParams parameters, RequestContext<UpdateAgentJobStepResult> requestContext)
|
||||
{
|
||||
UpdateAgentJobStepResult result = new UpdateAgentJobStepResult();
|
||||
await requestContext.SendResult(result);
|
||||
}
|
||||
|
||||
internal async Task HandleDeleteAgentJobStepRequest(DeleteAgentJobStepParams parameters, RequestContext<DeleteAgentJobStepResult> requestContext)
|
||||
{
|
||||
DeleteAgentJobStepResult result = new DeleteAgentJobStepResult();
|
||||
await requestContext.SendResult(result);
|
||||
}
|
||||
|
||||
internal async Task<Tuple<bool, string>> ConfigureAgentJob(
|
||||
string ownerUri,
|
||||
AgentJobInfo jobInfo,
|
||||
ConfigAction configAction,
|
||||
RunType runType)
|
||||
{
|
||||
return await Task<Tuple<bool, string>>.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
ConnectionInfo connInfo;
|
||||
ConnectionServiceInstance.TryFindConnection(
|
||||
ownerUri,
|
||||
out connInfo);
|
||||
|
||||
CDataContainer dataContainer = AdminService.CreateDataContainer(connInfo, databaseExists: true);
|
||||
STParameters param = new STParameters(dataContainer.Document);
|
||||
param.SetParam("job", string.Empty);
|
||||
param.SetParam("jobid", jobInfo.JobId);
|
||||
|
||||
var jobData = new JobData(dataContainer, jobInfo);
|
||||
using (JobActions jobActions = new JobActions(dataContainer, jobData, configAction))
|
||||
{
|
||||
var executionHandler = new ExecutonHandler(jobActions);
|
||||
executionHandler.RunNow(runType, this);
|
||||
}
|
||||
|
||||
return new Tuple<bool, string>(true, string.Empty);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new Tuple<bool, string>(false, ex.ToString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
internal async Task<Tuple<bool, string>> ConfigureAgentJobStep(
|
||||
string ownerUri,
|
||||
AgentJobStepInfo stepInfo,
|
||||
ConfigAction configAction)
|
||||
{
|
||||
return await Task<Tuple<bool, string>>.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(stepInfo.JobId))
|
||||
{
|
||||
return new Tuple<bool, string>(false, "JobId cannot be null");
|
||||
}
|
||||
|
||||
ConnectionInfo connInfo;
|
||||
ConnectionServiceInstance.TryFindConnection(
|
||||
ownerUri,
|
||||
out connInfo);
|
||||
|
||||
CDataContainer dataContainer = AdminService.CreateDataContainer(connInfo, databaseExists: true);
|
||||
STParameters param = new STParameters(dataContainer.Document);
|
||||
param.SetParam("job", string.Empty);
|
||||
param.SetParam("jobid", stepInfo.JobId);
|
||||
param.SetParam("script", stepInfo.Script);
|
||||
param.SetParam("scriptName", stepInfo.ScriptName);
|
||||
|
||||
var jobData = new JobData(dataContainer);
|
||||
using (var jobStep = new JobStepsActions(dataContainer, jobData))
|
||||
{
|
||||
jobStep.CreateJobStep();
|
||||
}
|
||||
|
||||
return new Tuple<bool, string>(true, string.Empty);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// log exception here
|
||||
return new Tuple<bool, string>(false, ex.ToString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#endregion // "Jobs Handlers"
|
||||
|
||||
#region "Alert Handlers"
|
||||
|
||||
/// <summary>
|
||||
/// Handle request to get the alerts list
|
||||
/// </summary>
|
||||
/// </summary>
|
||||
internal async Task HandleAgentAlertsRequest(AgentAlertsParams parameters, RequestContext<AgentAlertsResult> requestContext)
|
||||
{
|
||||
await Task.Run(async () =>
|
||||
@@ -293,8 +447,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
CDataContainer dataContainer = AdminService.CreateDataContainer(connInfo, databaseExists: true);
|
||||
AlertCollection alerts = dataContainer.Server.JobServer.Alerts;
|
||||
|
||||
|
||||
}
|
||||
|
||||
await requestContext.SendResult(result);
|
||||
@@ -309,7 +461,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
|
||||
/// <summary>
|
||||
/// Handle request to create an alert
|
||||
/// </summary>
|
||||
/// </summary>
|
||||
internal async Task HandleCreateAgentAlertRequest(CreateAgentAlertParams parameters, RequestContext<CreateAgentAlertResult> requestContext)
|
||||
{
|
||||
await Task.Run(async () =>
|
||||
@@ -328,7 +480,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
|
||||
/// <summary>
|
||||
/// Handle request to update an alert
|
||||
/// </summary>
|
||||
/// </summary>
|
||||
internal async Task HandleUpdateAgentAlertRequest(UpdateAgentAlertParams parameters, RequestContext<UpdateAgentAlertResult> requestContext)
|
||||
{
|
||||
await Task.Run(async () =>
|
||||
@@ -353,7 +505,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
STParameters param = new STParameters(dataContainer.Document);
|
||||
param.SetParam("alert", alert.JobName);
|
||||
|
||||
using (AgentAlert agentAlert = new AgentAlert(dataContainer, alert))
|
||||
using (AgentAlertActions agentAlert = new AgentAlertActions(dataContainer, alert))
|
||||
{
|
||||
agentAlert.CreateOrUpdate();
|
||||
}
|
||||
@@ -362,7 +514,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
|
||||
/// <summary>
|
||||
/// Handle request to delete an alert
|
||||
/// </summary>
|
||||
/// </summary>
|
||||
internal async Task HandleDeleteAgentAlertRequest(DeleteAgentAlertParams parameters, RequestContext<DeleteAgentAlertResult> requestContext)
|
||||
{
|
||||
await Task.Run(async () =>
|
||||
@@ -380,7 +532,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
STParameters param = new STParameters(dataContainer.Document);
|
||||
param.SetParam("alert", alert.JobName);
|
||||
|
||||
using (AgentAlert agentAlert = new AgentAlert(dataContainer, alert))
|
||||
using (AgentAlertActions agentAlert = new AgentAlertActions(dataContainer, alert))
|
||||
{
|
||||
agentAlert.Drop();
|
||||
}
|
||||
@@ -447,10 +599,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
bool succeeded = await ConfigureAgentProxy(
|
||||
parameters.OwnerUri,
|
||||
parameters.Proxy.AccountName,
|
||||
parameters.Proxy,
|
||||
AgentConfigAction.Create);
|
||||
|
||||
parameters.Proxy.AccountName,
|
||||
parameters.Proxy,
|
||||
ConfigAction.Create);
|
||||
|
||||
await requestContext.SendResult(new CreateAgentProxyResult()
|
||||
{
|
||||
Succeeded = succeeded
|
||||
@@ -461,9 +613,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
bool succeeded = await ConfigureAgentProxy(
|
||||
parameters.OwnerUri,
|
||||
parameters.OriginalProxyName,
|
||||
parameters.OriginalProxyName,
|
||||
parameters.Proxy,
|
||||
AgentConfigAction.Update);
|
||||
ConfigAction.Update);
|
||||
|
||||
await requestContext.SendResult(new UpdateAgentProxyResult()
|
||||
{
|
||||
@@ -475,9 +627,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
bool succeeded = await ConfigureAgentProxy(
|
||||
parameters.OwnerUri,
|
||||
parameters.Proxy.AccountName,
|
||||
parameters.Proxy.AccountName,
|
||||
parameters.Proxy,
|
||||
AgentConfigAction.Drop);
|
||||
ConfigAction.Drop);
|
||||
|
||||
await requestContext.SendResult(new DeleteAgentProxyResult()
|
||||
{
|
||||
@@ -489,7 +641,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
string ownerUri,
|
||||
string accountName,
|
||||
AgentProxyInfo proxy,
|
||||
AgentConfigAction configAction)
|
||||
ConfigAction configAction)
|
||||
{
|
||||
return await Task<bool>.Run(() =>
|
||||
{
|
||||
@@ -506,15 +658,15 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
|
||||
using (AgentProxyAccount agentProxy = new AgentProxyAccount(dataContainer, proxy))
|
||||
{
|
||||
if (configAction == AgentConfigAction.Create)
|
||||
if (configAction == ConfigAction.Create)
|
||||
{
|
||||
return agentProxy.Create();
|
||||
}
|
||||
else if (configAction == AgentConfigAction.Update)
|
||||
else if (configAction == ConfigAction.Update)
|
||||
{
|
||||
return agentProxy.Update();
|
||||
}
|
||||
else if (configAction == AgentConfigAction.Drop)
|
||||
else if (configAction == ConfigAction.Drop)
|
||||
{
|
||||
return agentProxy.Drop();
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ using Microsoft.SqlServer.Management.Smo;
|
||||
using Microsoft.SqlServer.Management.Smo.Agent;
|
||||
using Microsoft.SqlServer.Management.UI;
|
||||
using Microsoft.SqlTools.ServiceLayer.Admin;
|
||||
using Microsoft.SqlTools.ServiceLayer.Management;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
@@ -567,7 +568,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
this.actions.CloseOnUserCancel = true;
|
||||
this.actions.QuitOnError = true;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -582,19 +582,20 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
for (int i = 0; i < this.urnParameters.Length; i++)
|
||||
{
|
||||
Job job = this.smoServer.GetSmoObject(urnParameters[i]) as Job;
|
||||
|
||||
|
||||
string selectedStep = null;
|
||||
|
||||
DataTable dtSteps = GetJobDataSteps(job);
|
||||
if (dtSteps == null || dtSteps.Rows == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (dtSteps.Rows.Count > 1) //check if job is multi step job
|
||||
{
|
||||
// selectedStep = ShowStepDialog(job, dtSteps);
|
||||
if (selectedStep == null) //check if the job was canceled
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
//Copy the LastRunTime of the job into prevRunTime before the job started.
|
||||
@@ -602,16 +603,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
this.actions.AddAction(new StartJobAction(job, selectedStep));
|
||||
this.actions.AddAction(new WaitForJobToFinishAction(job, prevRunTime));
|
||||
}
|
||||
|
||||
if (this.actions.Count <= 0)
|
||||
{
|
||||
//This is a workaround for the class dialog invocation problem
|
||||
//This dialog is invoked from two places
|
||||
//JobsActivityMonitor (JobsPanel.cs) OnStartJobAtStep method
|
||||
// and SSMS Context menu mpu\ssms\shared\SqlMgmt\src\RunningFormsTable.cs method StartFormExecution
|
||||
//It is no way for us to prevent the dialog execution from the context menu (when job was canceled), besides redisgning the architecture
|
||||
//this.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -623,13 +614,14 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
private DataTable GetJobDataSteps(Job job)
|
||||
{
|
||||
if (job == null || job.Parent == null || job.Parent.Parent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// perform an enumerator query to get the steps. We could use the
|
||||
// SMO step object but this is too inefficient as it generates a batch
|
||||
// per step.
|
||||
Request request = new Request();
|
||||
|
||||
request.Fields = new string[] {"Name", "ID", "SubSystem"};
|
||||
request.Urn = job.Urn + "/Step";
|
||||
request.OrderByList = new OrderBy[] {new OrderBy("ID", OrderBy.Direction.Asc)};
|
||||
@@ -716,7 +708,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
while (!this.abortEvent.WaitOne(WaitForJobToFinishAction.ServerPollingInterval))
|
||||
{
|
||||
if (actions.Progress.IsAborted)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
this.job.Refresh();
|
||||
// If this job hasn't started yet then don't check for its status
|
||||
@@ -725,7 +719,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
switch (this.job.CurrentRunStatus)
|
||||
{
|
||||
case JobExecutionStatus.Idle:
|
||||
|
||||
actions.Progress.UpdateActionProgress(index, 100);
|
||||
|
||||
// see if the job succeeded.
|
||||
@@ -744,36 +737,29 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
}
|
||||
|
||||
jobFinished = true;
|
||||
|
||||
break;
|
||||
|
||||
case JobExecutionStatus.Suspended:
|
||||
|
||||
actions.Progress.UpdateActionProgress(index, "AgentActionSR.Suspended");
|
||||
break;
|
||||
|
||||
case JobExecutionStatus.BetweenRetries:
|
||||
|
||||
actions.Progress.UpdateActionProgress(index, "AgentActionSR.BetweenRetries");
|
||||
break;
|
||||
|
||||
case JobExecutionStatus.Executing:
|
||||
|
||||
actions.Progress.UpdateActionProgress(index, "AgentActionSR.Executing");
|
||||
break;
|
||||
|
||||
case JobExecutionStatus.PerformingCompletionAction:
|
||||
|
||||
actions.Progress.UpdateActionProgress(index, "AgentActionSR.PerformingCompletionAction");
|
||||
break;
|
||||
|
||||
case JobExecutionStatus.WaitingForStepToFinish:
|
||||
|
||||
actions.Progress.UpdateActionProgress(index, "AgentActionSR.WaitingForStepToFinish");
|
||||
break;
|
||||
|
||||
case JobExecutionStatus.WaitingForWorkerThread:
|
||||
|
||||
actions.Progress.UpdateActionProgress(index, "AgentActionSR.WaitingForWorkerThread");
|
||||
break;
|
||||
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Utility;
|
||||
using Microsoft.SqlTools.Utility;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// SQL Agent Job activity parameters
|
||||
/// </summary>
|
||||
public class AgentJobActionParams : GeneralRequestDetails
|
||||
{
|
||||
public string OwnerUri { get; set; }
|
||||
|
||||
public string JobName { get; set; }
|
||||
|
||||
public string Action { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SQL Agent Job activity result
|
||||
/// </summary>
|
||||
public class AgentJobActionResult
|
||||
{
|
||||
public bool Succeeded { get; set; }
|
||||
|
||||
public string ErrorMessage { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SQL Agent Jobs request type
|
||||
/// </summary>
|
||||
public class AgentJobActionRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Request definition
|
||||
/// </summary>
|
||||
public static readonly
|
||||
RequestType<AgentJobActionParams, AgentJobActionResult> Type =
|
||||
RequestType<AgentJobActionParams, AgentJobActionResult>.Create("agent/jobaction");
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Utility;
|
||||
using Microsoft.SqlTools.Utility;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent.Contracts
|
||||
{
|
||||
|
||||
public class AgentJobHistoryParams : GeneralRequestDetails
|
||||
{
|
||||
public string OwnerUri { get; set; }
|
||||
|
||||
public string JobId { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SQL Agent Job activity result
|
||||
/// </summary>
|
||||
public class AgentJobHistoryResult
|
||||
{
|
||||
|
||||
public bool Succeeded { get; set; }
|
||||
|
||||
public string ErrorMessage { get; set; }
|
||||
|
||||
public AgentJobHistoryInfo[] Jobs { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SQL Agent Jobs request type
|
||||
/// </summary>
|
||||
public class AgentJobHistoryRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Request definition
|
||||
/// </summary>
|
||||
public static readonly
|
||||
RequestType<AgentJobHistoryParams, AgentJobHistoryResult> Type =
|
||||
RequestType<AgentJobHistoryParams, AgentJobHistoryResult>.Create("agent/jobhistory");
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent.Contracts
|
||||
public class AgentJobInfo
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Owner { get; set; }
|
||||
public string Description { get; set; }
|
||||
public int CurrentExecutionStatus { get; set; }
|
||||
public int LastRunOutcome { get; set; }
|
||||
public string CurrentExecutionStep { get; set; }
|
||||
@@ -30,5 +32,4 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent.Contracts
|
||||
public string NextRun { get; set; }
|
||||
public string JobId { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,218 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.TaskServices;
|
||||
using Microsoft.SqlTools.ServiceLayer.Utility;
|
||||
using Microsoft.SqlTools.Utility;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// SQL Agent Job activity parameters
|
||||
/// </summary>
|
||||
public class AgentJobsParams : GeneralRequestDetails
|
||||
{
|
||||
public string OwnerUri { get; set; }
|
||||
|
||||
public string JobId { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SQL Agent Job activity result
|
||||
/// </summary>
|
||||
public class AgentJobsResult
|
||||
{
|
||||
|
||||
public bool Succeeded { get; set; }
|
||||
|
||||
public string ErrorMessage { get; set; }
|
||||
|
||||
public AgentJobInfo[] Jobs { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SQL Agent Jobs request type
|
||||
/// </summary>
|
||||
public class AgentJobsRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Request definition
|
||||
/// </summary>
|
||||
public static readonly
|
||||
RequestType<AgentJobsParams, AgentJobsResult> Type =
|
||||
RequestType<AgentJobsParams, AgentJobsResult>.Create("agent/jobs");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SQL Agent create Job params
|
||||
/// </summary>
|
||||
public class CreateAgentJobParams : TaskRequestDetails
|
||||
{
|
||||
public string OwnerUri { get; set; }
|
||||
|
||||
public AgentJobInfo Job { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SQL Agent create Job result
|
||||
/// </summary>
|
||||
public class CreateAgentJobResult
|
||||
{
|
||||
public bool Succeeded { get; set; }
|
||||
|
||||
public string ErrorMessage { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SQL Agent create Alert request type
|
||||
/// </summary>
|
||||
public class CreateAgentJobRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Request definition
|
||||
/// </summary>
|
||||
public static readonly
|
||||
RequestType<CreateAgentJobParams, CreateAgentJobResult> Type =
|
||||
RequestType<CreateAgentJobParams, CreateAgentJobResult>.Create("agent/createjob");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SQL Agent update Job params
|
||||
/// </summary>
|
||||
public class UpdateAgentJobParams : TaskRequestDetails
|
||||
{
|
||||
public string OwnerUri { get; set; }
|
||||
|
||||
public AgentJobInfo Job { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SQL Agent update Job result
|
||||
/// </summary>
|
||||
public class UpdateAgentJobResult
|
||||
{
|
||||
public bool Succeeded { get; set; }
|
||||
|
||||
public string ErrorMessage { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SQL Agent update Job request type
|
||||
/// </summary>
|
||||
public class UpdateAgentJobRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Request definition
|
||||
/// </summary>
|
||||
public static readonly
|
||||
RequestType<UpdateAgentJobParams, UpdateAgentJobResult> Type =
|
||||
RequestType<UpdateAgentJobParams, UpdateAgentJobResult>.Create("agent/updatejob");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SQL Agent delete Alert params
|
||||
/// </summary>
|
||||
public class DeleteAgentJobParams : TaskRequestDetails
|
||||
{
|
||||
public string OwnerUri { get; set; }
|
||||
|
||||
public AgentJobInfo Job { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SQL Agent delete Job result
|
||||
/// </summary>
|
||||
public class DeleteAgentJobResult
|
||||
{
|
||||
public bool Succeeded { get; set; }
|
||||
|
||||
public string ErrorMessage { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SQL Agent delete Job request type
|
||||
/// </summary>
|
||||
public class DeleteAgentJobRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Request definition
|
||||
/// </summary>
|
||||
public static readonly
|
||||
RequestType<DeleteAgentJobParams, DeleteAgentJobResult> Type =
|
||||
RequestType<DeleteAgentJobParams, DeleteAgentJobResult>.Create("agent/deletejob");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SQL Agent Job history parameter
|
||||
/// </summary>
|
||||
public class AgentJobHistoryParams : GeneralRequestDetails
|
||||
{
|
||||
public string OwnerUri { get; set; }
|
||||
|
||||
public string JobId { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SQL Agent Job history result
|
||||
/// </summary>
|
||||
public class AgentJobHistoryResult
|
||||
{
|
||||
|
||||
public bool Succeeded { get; set; }
|
||||
|
||||
public string ErrorMessage { get; set; }
|
||||
|
||||
public AgentJobHistoryInfo[] Jobs { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SQL Agent Jobs request type
|
||||
/// </summary>
|
||||
public class AgentJobHistoryRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Request definition
|
||||
/// </summary>
|
||||
public static readonly
|
||||
RequestType<AgentJobHistoryParams, AgentJobHistoryResult> Type =
|
||||
RequestType<AgentJobHistoryParams, AgentJobHistoryResult>.Create("agent/jobhistory");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SQL Agent Job activity parameters
|
||||
/// </summary>
|
||||
public class AgentJobActionParams : GeneralRequestDetails
|
||||
{
|
||||
public string OwnerUri { get; set; }
|
||||
|
||||
public string JobName { get; set; }
|
||||
|
||||
public string Action { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SQL Agent Job activity result
|
||||
/// </summary>
|
||||
public class AgentJobActionResult
|
||||
{
|
||||
public bool Succeeded { get; set; }
|
||||
|
||||
public string ErrorMessage { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SQL Agent Jobs request type
|
||||
/// </summary>
|
||||
public class AgentJobActionRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Request definition
|
||||
/// </summary>
|
||||
public static readonly
|
||||
RequestType<AgentJobActionParams, AgentJobActionResult> Type =
|
||||
RequestType<AgentJobActionParams, AgentJobActionResult>.Create("agent/jobaction");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Utility;
|
||||
using Microsoft.SqlTools.Utility;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent.Contracts
|
||||
{
|
||||
public class AgentJobStepInfo
|
||||
{
|
||||
public string JobId { get; set; }
|
||||
|
||||
public string Script { get; set; }
|
||||
|
||||
public string ScriptName { get; set; }
|
||||
|
||||
public string StepName { get; set; }
|
||||
|
||||
public string SubSystem { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Current step id
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// action to take if the step fails
|
||||
/// </summary>
|
||||
public string FailureAction { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Action to take if the step succeeds
|
||||
/// </summary>
|
||||
public string SuccessAction { get; set; }
|
||||
|
||||
// note we will have either the id or step
|
||||
// for the steps to go to on failure
|
||||
/// <summary>
|
||||
/// step that will be executed on failure
|
||||
/// </summary>
|
||||
public int FailStepId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// step that will be executed on success
|
||||
/// </summary>
|
||||
public int SuccessStepId { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Command to execute
|
||||
/// </summary>
|
||||
public string Command { get; set; }
|
||||
/// <summary>
|
||||
/// Success code for successful execution of the command
|
||||
/// </summary>
|
||||
public int CommandExecutionSuccessCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Database this step will execute against
|
||||
/// </summary>
|
||||
public string DatabaseName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// database user name this step will execute against
|
||||
/// </summary>
|
||||
public string DatabaseUserName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Server to execute this step against
|
||||
/// </summary>
|
||||
public string Server { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// output file name
|
||||
/// </summary>
|
||||
public string OutputFileName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// indicates whether to append the output to a file
|
||||
/// </summary>
|
||||
public bool AppendToLogFile { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// indicates whether to append the output to the step history
|
||||
/// </summary>
|
||||
public bool AppendToStepHist { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// indicates whether to log to table
|
||||
/// </summary>
|
||||
public bool WriteLogToTable { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// append the output to the table
|
||||
/// </summary>
|
||||
public bool AppendLogToTable { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// number of rety attempts
|
||||
/// </summary>
|
||||
public int RetryAttempts { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// retrey interval
|
||||
/// </summary>
|
||||
public int RetryInterval { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// proxy name
|
||||
/// </summary>
|
||||
public string ProxyName { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Utility;
|
||||
using Microsoft.SqlTools.Utility;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// SQL Agent Job Steps parameters
|
||||
/// </summary>
|
||||
public class AgentJobStepsParams : GeneralRequestDetails
|
||||
{
|
||||
public string OwnerUri { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SQL Agent Job Steps result
|
||||
/// </summary>
|
||||
public class AgentJobStepsResult
|
||||
{
|
||||
|
||||
public bool Succeeded { get; set; }
|
||||
|
||||
public string ErrorMessage { get; set; }
|
||||
|
||||
public AgentJobStepInfo[] Steps { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SQL Agent Steps request type
|
||||
/// </summary>
|
||||
public class AgentJobStepsRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Request definition
|
||||
/// </summary>
|
||||
public static readonly
|
||||
RequestType<AgentJobStepsParams, AgentJobStepsResult> Type =
|
||||
RequestType<AgentJobStepsParams, AgentJobStepsResult>.Create("agent/jobsteps");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SQL Agent create Step params
|
||||
/// </summary>
|
||||
public class CreateAgentJobStepParams : GeneralRequestDetails
|
||||
{
|
||||
public string OwnerUri { get; set; }
|
||||
|
||||
public AgentJobStepInfo Step { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SQL Agent create Step result
|
||||
/// </summary>
|
||||
public class CreateAgentJobStepResult
|
||||
{
|
||||
public bool Succeeded { get; set; }
|
||||
|
||||
public string ErrorMessage { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SQL Agent create Step request type
|
||||
/// </summary>
|
||||
public class CreateAgentJobStepRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Request definition
|
||||
/// </summary>
|
||||
public static readonly
|
||||
RequestType<CreateAgentJobStepParams, CreateAgentJobStepResult> Type =
|
||||
RequestType<CreateAgentJobStepParams, CreateAgentJobStepResult>.Create("agent/createjobstep");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SQL Agent delete Step params
|
||||
/// </summary>
|
||||
public class DeleteAgentJobStepParams : GeneralRequestDetails
|
||||
{
|
||||
public string OwnerUri { get; set; }
|
||||
|
||||
public AgentJobStepInfo Step { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SQL Agent delete Step result
|
||||
/// </summary>
|
||||
public class DeleteAgentJobStepResult
|
||||
{
|
||||
public bool Succeeded { get; set; }
|
||||
|
||||
public string ErrorMessage { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SQL Agent delete Step request type
|
||||
/// </summary>
|
||||
public class DeleteAgentJobStepRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Request definition
|
||||
/// </summary>
|
||||
public static readonly
|
||||
RequestType<DeleteAgentJobStepParams, DeleteAgentJobStepResult> Type =
|
||||
RequestType<DeleteAgentJobStepParams, DeleteAgentJobStepResult>.Create("agent/deletejobstep");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SQL Agent update Step params
|
||||
/// </summary>
|
||||
public class UpdateAgentJobStepParams : GeneralRequestDetails
|
||||
{
|
||||
public string OwnerUri { get; set; }
|
||||
|
||||
public AgentJobStepInfo Step { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SQL Agent update Step result
|
||||
/// </summary>
|
||||
public class UpdateAgentJobStepResult
|
||||
{
|
||||
public bool Succeeded { get; set; }
|
||||
|
||||
public string ErrorMessage { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SQL Agent update Step request type
|
||||
/// </summary>
|
||||
public class UpdateAgentJobStepRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Request definition
|
||||
/// </summary>
|
||||
public static readonly
|
||||
RequestType<UpdateAgentJobStepParams, UpdateAgentJobStepResult> Type =
|
||||
RequestType<UpdateAgentJobStepParams, UpdateAgentJobStepResult>.Create("agent/updatejobstep");
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Utility;
|
||||
using Microsoft.SqlTools.Utility;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// SQL Agent Job activity parameters
|
||||
/// </summary>
|
||||
public class AgentJobsParams : GeneralRequestDetails
|
||||
{
|
||||
public string OwnerUri { get; set; }
|
||||
|
||||
public string JobId { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SQL Agent Job activity result
|
||||
/// </summary>
|
||||
public class AgentJobsResult
|
||||
{
|
||||
|
||||
public bool Succeeded { get; set; }
|
||||
|
||||
public string ErrorMessage { get; set; }
|
||||
|
||||
public AgentJobInfo[] Jobs { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SQL Agent Jobs request type
|
||||
/// </summary>
|
||||
public class AgentJobsRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Request definition
|
||||
/// </summary>
|
||||
public static readonly
|
||||
RequestType<AgentJobsParams, AgentJobsResult> Type =
|
||||
RequestType<AgentJobsParams, AgentJobsResult>.Create("agent/jobs");
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
/// <summary>
|
||||
/// AgentAlert class
|
||||
/// </summary>
|
||||
internal class AgentAlert : ManagementActionBase
|
||||
internal class AgentAlertActions : ManagementActionBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Agent alert info instance
|
||||
@@ -31,7 +31,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
/// Default constructor that will be used to create dialog
|
||||
/// </summary>
|
||||
/// <param name="dataContainer"></param>
|
||||
public AgentAlert(CDataContainer dataContainer, AgentAlertInfo alertInfo)
|
||||
public AgentAlertActions(CDataContainer dataContainer, AgentAlertInfo alertInfo)
|
||||
{
|
||||
this.alertInfo = alertInfo;
|
||||
this.DataContainer = dataContainer;
|
||||
@@ -49,6 +49,19 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
return alertName.Trim();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// called by ManagementActionBase.PreProcessExecution
|
||||
/// </summary>
|
||||
/// <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);
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Drop()
|
||||
{
|
||||
// fail if the user is not in the sysadmin role
|
||||
@@ -4,7 +4,6 @@
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Collections;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using Microsoft.SqlServer.Management.Sdk.Sfc;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for IJobStepPropertiesControl.
|
||||
/// </summary>
|
||||
internal interface IJobStepPropertiesControl
|
||||
{
|
||||
void Load(JobStepData data);
|
||||
void Save(JobStepData data, bool isSwitching);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
61
src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/JobActions.cs
Normal file
61
src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/JobActions.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
//
|
||||
// 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.Admin;
|
||||
using Microsoft.SqlTools.ServiceLayer.Agent.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Management;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
/// <summary>
|
||||
/// JobActions provides basic SQL Server Agent Job configuration actions
|
||||
/// </summary>
|
||||
internal class JobActions : ManagementActionBase
|
||||
{
|
||||
private JobData data;
|
||||
private ConfigAction configAction;
|
||||
|
||||
public JobActions(CDataContainer dataContainer, JobData data, ConfigAction configAction)
|
||||
{
|
||||
this.DataContainer = dataContainer;
|
||||
this.data = data;
|
||||
this.configAction = configAction;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
|
||||
//release the data object
|
||||
this.data = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// called by ManagementActionBase.PreProcessExecution
|
||||
/// </summary>
|
||||
/// <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);
|
||||
this.data.ApplyChanges(creating: true);
|
||||
if (!IsScripting(runType))
|
||||
{
|
||||
this.DataContainer.SqlDialogSubject = this.data.Job;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -266,8 +266,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
(this as IFilterDefinition).Enabled = (template as IFilterDefinition).Enabled;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// tells us if filtering is enabled or diabled
|
||||
/// a disabled filter lets everything pass and filters nothing out
|
||||
@@ -304,7 +302,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
sb.Append(" ) ");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// fetch an xpath clause used for filtering
|
||||
/// jobs fetched by the enumerator.
|
||||
@@ -342,6 +339,3 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
113
src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/JobAlertData.cs
Normal file
113
src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/JobAlertData.cs
Normal file
@@ -0,0 +1,113 @@
|
||||
//
|
||||
// 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;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Globalization;
|
||||
|
||||
using SMO = Microsoft.SqlServer.Management.Smo;
|
||||
using Microsoft.SqlServer.Management.Common;
|
||||
using Microsoft.SqlServer.Management.Sdk.Sfc;
|
||||
using Microsoft.SqlServer.Management.Smo;
|
||||
using Microsoft.SqlServer.Management.Smo.Agent;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
internal class JobAlertData
|
||||
{
|
||||
#region data members
|
||||
private string currentName;
|
||||
private string originalName;
|
||||
private bool enabled;
|
||||
private AlertType type;
|
||||
bool alreadyCreated;
|
||||
private bool isReadOnly;
|
||||
Urn urn;
|
||||
|
||||
#endregion
|
||||
|
||||
#region construction
|
||||
public JobAlertData()
|
||||
{
|
||||
SetDefaults();
|
||||
}
|
||||
public JobAlertData(Alert source)
|
||||
: this(source, false)
|
||||
{
|
||||
}
|
||||
public JobAlertData(Alert source, bool toBeCreated)
|
||||
{
|
||||
LoadData(source);
|
||||
this.alreadyCreated = toBeCreated;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region public members
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.currentName;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.currentName = value.Trim();
|
||||
}
|
||||
}
|
||||
public bool Enabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.enabled;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.enabled = value;
|
||||
}
|
||||
}
|
||||
public string Type
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.type.ToString();
|
||||
}
|
||||
}
|
||||
public bool Created
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.alreadyCreated;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsReadOnly
|
||||
{
|
||||
get { return this.isReadOnly; }
|
||||
set { this.isReadOnly = value; }
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region load data
|
||||
private void LoadData(Alert source)
|
||||
{
|
||||
currentName = originalName = source.Name;
|
||||
this.urn = source.Urn;
|
||||
this.alreadyCreated = true;
|
||||
|
||||
this.enabled = source.IsEnabled;
|
||||
this.type = source.AlertType;
|
||||
}
|
||||
private void SetDefaults()
|
||||
{
|
||||
this.alreadyCreated = false;
|
||||
currentName = originalName = String.Empty;
|
||||
this.enabled = true;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
187
src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/JobAlertsData.cs
Normal file
187
src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/JobAlertsData.cs
Normal file
@@ -0,0 +1,187 @@
|
||||
//
|
||||
// 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;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Globalization;
|
||||
using Microsoft.SqlServer.Management.Common;
|
||||
using Microsoft.SqlServer.Management.Sdk.Sfc;
|
||||
using Microsoft.SqlServer.Management.Smo;
|
||||
using Microsoft.SqlServer.Management.Smo.Agent;
|
||||
using Microsoft.SqlServer.Management.Diagnostics;
|
||||
using Microsoft.SqlTools.ServiceLayer.Admin;
|
||||
using SMO = Microsoft.SqlServer.Management.Smo;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
internal class JobAlertsData
|
||||
{
|
||||
#region data members
|
||||
// collection of job steps.
|
||||
private ArrayList jobAlerts;
|
||||
private ArrayList deletedJobAlerts;
|
||||
private JobData parent;
|
||||
private CDataContainer context;
|
||||
private bool isReadOnly;
|
||||
#endregion
|
||||
|
||||
#region construction
|
||||
public JobAlertsData(CDataContainer context, JobData parent)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException("context");
|
||||
}
|
||||
if (parent == null)
|
||||
{
|
||||
throw new ArgumentNullException("parent");
|
||||
}
|
||||
this.context = context;
|
||||
this.parent = parent;
|
||||
|
||||
this.deletedJobAlerts = new ArrayList();
|
||||
|
||||
// if we're creating a new job
|
||||
if (this.parent.Mode != JobData.ActionMode.Edit)
|
||||
{
|
||||
SetDefaults();
|
||||
}
|
||||
else
|
||||
{
|
||||
// load the JobStep objects
|
||||
LoadData();
|
||||
}
|
||||
IsReadOnly = parent.IsReadOnly;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region public methods
|
||||
public void AddAlert(JobAlertData alert)
|
||||
{
|
||||
if (alert == null)
|
||||
{
|
||||
throw new ArgumentNullException("step");
|
||||
}
|
||||
this.jobAlerts.Add(alert);
|
||||
}
|
||||
public void DeleteAlert(JobAlertData alert)
|
||||
{
|
||||
if (alert == null)
|
||||
{
|
||||
throw new ArgumentNullException("step");
|
||||
}
|
||||
if (this.jobAlerts.Contains(alert))
|
||||
{
|
||||
this.jobAlerts.Remove(alert);
|
||||
this.deletedJobAlerts.Add(alert);
|
||||
}
|
||||
}
|
||||
public ArrayList Alerts
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.jobAlerts;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsReadOnly
|
||||
{
|
||||
get { return this.isReadOnly; }
|
||||
set { this.isReadOnly = value; }
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region data loading
|
||||
private void LoadData()
|
||||
{
|
||||
STParameters parameters = new STParameters(this.context.Document);
|
||||
string urn = String.Empty;
|
||||
string jobIdString = null;
|
||||
parameters.GetParam("urn", ref urn);
|
||||
parameters.GetParam("jobid", ref jobIdString);
|
||||
|
||||
Job job = null;
|
||||
// If JobID is passed in look up by jobID
|
||||
if (!String.IsNullOrEmpty(jobIdString))
|
||||
{
|
||||
job = this.context.Server.JobServer.Jobs.ItemById(Guid.Parse(jobIdString));
|
||||
}
|
||||
else
|
||||
{
|
||||
// or use urn path to query job
|
||||
job = this.context.Server.GetSmoObject(urn) as Job;
|
||||
}
|
||||
|
||||
// load the data
|
||||
if (job != null)
|
||||
{
|
||||
AlertCollection alerts = job.Parent.Alerts;
|
||||
|
||||
// allocate the array list
|
||||
this.jobAlerts = new ArrayList();
|
||||
|
||||
for (int i = 0; i < alerts.Count; i++)
|
||||
{
|
||||
// only get alerts that point to this job.
|
||||
if (alerts[i].JobID == job.JobID)
|
||||
{
|
||||
//Since this job was just return from SMO, it is an existing object
|
||||
//Flag it with true to indicate is has already been created.
|
||||
this.jobAlerts.Add(new JobAlertData(alerts[i], true));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SetDefaults();
|
||||
}
|
||||
}
|
||||
private void SetDefaults()
|
||||
{
|
||||
this.jobAlerts = new ArrayList();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region data saving
|
||||
public void ApplyChanges(Job job)
|
||||
{
|
||||
if (this.IsReadOnly)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// add any new items to the job
|
||||
foreach (JobAlertData jobAlert in this.jobAlerts)
|
||||
{
|
||||
if (!jobAlert.Created)
|
||||
{
|
||||
Alert agentAlert = job.Parent.Alerts[jobAlert.Name];
|
||||
if (agentAlert != null)
|
||||
{
|
||||
agentAlert.JobID = job.JobID;
|
||||
agentAlert.Alter();
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (JobAlertData jobAlert in this.deletedJobAlerts)
|
||||
{
|
||||
Alert agentAlert = job.Parent.Alerts[jobAlert.Name];
|
||||
if (agentAlert != null)
|
||||
{
|
||||
agentAlert.JobID = Guid.Empty;
|
||||
agentAlert.Alter();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region events
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
1401
src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/JobData.cs
Normal file
1401
src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/JobData.cs
Normal file
File diff suppressed because it is too large
Load Diff
@@ -19,7 +19,6 @@ using SMO = Microsoft.SqlServer.Management.Smo;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// severity associated with a log entry (ILogEntry)
|
||||
// these should be ordered least severe to most severe where possible.
|
||||
@@ -49,7 +48,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
List<ILogEntry> SubEntries {get;}
|
||||
}
|
||||
|
||||
|
||||
internal class LogSourceJobHistory : ILogSource, IDisposable //, ITypedColumns, ILogCommandTarget
|
||||
{
|
||||
#region Variables
|
||||
@@ -204,48 +202,10 @@ ORDER BY [InstanceID] ASC";
|
||||
"LogViewerSR.Field_RetriesAttempted"
|
||||
};
|
||||
|
||||
columnTypes = new TypedColumnCollection();
|
||||
for (int i = 0; i < m_fieldNames.Length; i++)
|
||||
{
|
||||
columnTypes.AddColumnType(m_fieldNames[i], SourceColumnTypes[i]);
|
||||
}
|
||||
|
||||
//m_customCommandHandler = customCommandHandler;
|
||||
|
||||
this.serviceProvider = serviceProvider;
|
||||
}
|
||||
#endregion
|
||||
|
||||
private static int[] SourceColumnTypes
|
||||
{
|
||||
get
|
||||
{
|
||||
return new int[]
|
||||
{
|
||||
GridColumnType.Hyperlink,
|
||||
GridColumnType.Text,
|
||||
GridColumnType.Hyperlink,
|
||||
GridColumnType.Text,
|
||||
GridColumnType.Text,
|
||||
GridColumnType.Text,
|
||||
GridColumnType.Text,
|
||||
GridColumnType.Text,
|
||||
GridColumnType.Text,
|
||||
GridColumnType.Text,
|
||||
GridColumnType.Text,
|
||||
GridColumnType.Text,
|
||||
GridColumnType.Text
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public TypedColumnCollection ColumnTypes
|
||||
{
|
||||
get
|
||||
{
|
||||
return columnTypes;
|
||||
}
|
||||
}
|
||||
#region ILogSource interface implementation
|
||||
|
||||
bool ILogSource.OrderedByDateDescending
|
||||
@@ -345,12 +305,12 @@ ORDER BY [InstanceID] ASC";
|
||||
(this.m_sqlConnectionInfo.ServerVersion == null
|
||||
|| this.m_sqlConnectionInfo.ServerVersion.Major >= 9) ?
|
||||
|
||||
String.Format(jobHistoryQuery,
|
||||
string.Format(jobHistoryQuery,
|
||||
historyTableDeclaration,
|
||||
historyTableName,
|
||||
jobId) :
|
||||
|
||||
String.Format(jobHistoryQuery,
|
||||
string.Format(jobHistoryQuery,
|
||||
historyTableDeclaration80,
|
||||
historyTableName80,
|
||||
jobId);
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
//
|
||||
// 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;
|
||||
using Microsoft.SqlServer.Management.Smo;
|
||||
using Microsoft.SqlServer.Management.Common;
|
||||
using Microsoft.SqlServer.Management.Sdk.Sfc;
|
||||
using Microsoft.SqlServer.Management.Smo.Agent;
|
||||
using System.Globalization;
|
||||
using Microsoft.SqlTools.ServiceLayer.Management;
|
||||
using Microsoft.SqlTools.ServiceLayer.Admin;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for JobNotifications.
|
||||
/// </summary>
|
||||
internal class JobNotifications : ManagementActionBase
|
||||
{
|
||||
private JobData data;
|
||||
private bool loading = false;
|
||||
|
||||
public JobNotifications(CDataContainer dataContainer, JobData data)
|
||||
{
|
||||
this.DataContainer = dataContainer;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
public class JobProperties
|
||||
{
|
||||
private string name;
|
||||
|
||||
private int currentExecutionStatus;
|
||||
private int lastRunOutcome;
|
||||
private string currentExecutionStep;
|
||||
|
||||
310
src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/JobSchedules.cs
Normal file
310
src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/JobSchedules.cs
Normal file
@@ -0,0 +1,310 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlServer.Management.Sdk.Sfc;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using Microsoft.SqlServer.Management.Smo;
|
||||
using Microsoft.SqlServer.Management.Common;
|
||||
using Microsoft.SqlServer.Management.Smo.Agent;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using Microsoft.SqlServer.Management.SqlManagerUI;
|
||||
using Microsoft.SqlServer.Management.Diagnostics;
|
||||
using Microsoft.SqlTools.ServiceLayer.Management;
|
||||
using Microsoft.SqlTools.ServiceLayer.Admin;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for JobSchedules.
|
||||
/// </summary>
|
||||
internal class JobSchedules : ManagementActionBase
|
||||
{
|
||||
private bool sharedSchedulesSupported = false;
|
||||
private JobData data;
|
||||
|
||||
public JobSchedules(CDataContainer dataContainer, JobData data)
|
||||
{
|
||||
this.DataContainer = dataContainer;
|
||||
this.data = data;
|
||||
|
||||
this.sharedSchedulesSupported = this.DataContainer.Server.Information.Version.Major >= 9;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region ui stuff
|
||||
private void InitializeData()
|
||||
{
|
||||
if (this.data == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// load the grid
|
||||
//PopulateGrid(this.data.JobSchedules);
|
||||
}
|
||||
// private void PopulateGrid(JobSchedulesData schedules)
|
||||
// {
|
||||
// // add non-shared schedules
|
||||
// for (int i = 0; i < schedules.Schedules.Count; i++)
|
||||
// {
|
||||
// JobScheduleData schedule = schedules.Schedules[i] as JobScheduleData;
|
||||
// if (schedule != null)
|
||||
// {
|
||||
// // add rows to the grid
|
||||
// GridCellCollection row = new GridCellCollection();
|
||||
// GridCell cell;
|
||||
|
||||
// // ID
|
||||
// cell = new GridCell(ConvertIdToDisplayName(schedule.ID));
|
||||
// row.Add(cell);
|
||||
// // Name
|
||||
// cell = new GridCell(schedule.Name);
|
||||
// row.Add(cell);
|
||||
// // Enabled
|
||||
// cell = new GridCell(schedule.Enabled ? JobSR.Yes : JobSR.No);
|
||||
// row.Add(cell);
|
||||
// // Description
|
||||
// cell = new GridCell(schedule.Description);
|
||||
// row.Add(cell);
|
||||
|
||||
// // Hyperlink 'Jobs in Schedule'
|
||||
// if (this.sharedSchedulesSupported)
|
||||
// {
|
||||
// // don't add a hyperlink if the schedule has not yet been created
|
||||
// cell = new GridCell(schedule.Created ? JobSR.ViewJobsInScheduleHyperlink : String.Empty);
|
||||
// row.Add(cell);
|
||||
// }
|
||||
|
||||
// this.scheduleList.AddRow(row);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
/// <summary>
|
||||
/// Convert an id into a user friendly name. Converts new id to "new"
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
private string ConvertIdToDisplayName(int id)
|
||||
{
|
||||
string rv;
|
||||
// convert -1 into New
|
||||
if (id < 0)
|
||||
{
|
||||
rv = "JobSR.New";
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = Convert.ToString(id, System.Globalization.CultureInfo.CurrentCulture);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ui event handlers
|
||||
|
||||
|
||||
// private void addSchedule_Click(object sender, System.EventArgs e)
|
||||
// {
|
||||
// System.Diagnostics.Debug.Assert(this.DataContainer.Server.Information.Version.Major >= 9, "Shared Schedules supported only for Yukon - this button should be disabled if target server is Shiloh/Sphinx");
|
||||
|
||||
// StringBuilder excludedSchedules = this.BuildListOfScheduleId(this.data.JobSchedules.Schedules);
|
||||
// StringBuilder removedSchedules = this.BuildListOfScheduleId(this.data.JobSchedules.RemovedSchedules);
|
||||
|
||||
// STParameters param = new STParameters();
|
||||
|
||||
// param.SetDocument(this.DataContainer.Document);
|
||||
|
||||
// param.SetParam("excludedschedules", excludedSchedules.ToString());
|
||||
// if (this.data.Mode == JobData.DialogMode.Properties)
|
||||
// {
|
||||
// param.SetParam("removedschedules", removedSchedules.ToString());
|
||||
// param.SetParam("joburn", this.data.Urn);
|
||||
// }
|
||||
|
||||
// ManageSchedulesForm formPickUpSharedSchedule = new ManageSchedulesForm
|
||||
// (
|
||||
// this.DataContainer,
|
||||
// ((this.data != null) && (this.data.Name != null)) ? this.data.Name : String.Empty,
|
||||
// this.ServiceProvider
|
||||
// );
|
||||
// using (formPickUpSharedSchedule)
|
||||
// {
|
||||
// DialogResult dr = formPickUpSharedSchedule.ShowDialog();
|
||||
|
||||
// // cleanup the datacontainer
|
||||
// param.SetParam("excludedschedules", String.Empty);
|
||||
// if (this.data.Mode == JobData.DialogMode.Properties)
|
||||
// {
|
||||
// param.SetParam("removedschedules", String.Empty);
|
||||
// param.SetParam("joburn", String.Empty);
|
||||
// }
|
||||
|
||||
// if (dr == DialogResult.OK)
|
||||
// {
|
||||
// JobSchedule schedule = formPickUpSharedSchedule.SelectedSchedule;
|
||||
// System.Diagnostics.Debug.Assert(schedule != null);
|
||||
// System.Diagnostics.Debug.Assert(schedule.Name != null);
|
||||
|
||||
// bool scheduleAlreadyAdded = false;
|
||||
// foreach (object o in this.data.JobSchedules.Schedules)
|
||||
// {
|
||||
// JobScheduleData jsd = o as JobScheduleData;
|
||||
|
||||
// System.Diagnostics.Debug.Assert(jsd != null, "non JobScheduleData found in this.data.Schedules");
|
||||
// if ((jsd != null) && (jsd.ID == schedule.ID))
|
||||
// {
|
||||
// scheduleAlreadyAdded = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (scheduleAlreadyAdded == false)
|
||||
// {
|
||||
// JobScheduleData scheduleData = new JobScheduleData(schedule);
|
||||
// this.data.JobSchedules.AddSchedule(scheduleData);
|
||||
|
||||
// this.scheduleList.DeleteAllRows();
|
||||
// PopulateGrid(this.data.JobSchedules);
|
||||
// UpdateControlStatus();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
private void editSchedule_Click(object sender, System.EventArgs e)
|
||||
{
|
||||
// EditSelectedSchedule();
|
||||
}
|
||||
|
||||
// private void deleteSchedule_Click(object sender, System.EventArgs e)
|
||||
// {
|
||||
// // check that a row is selected first
|
||||
// STrace.Assert(this.scheduleList.SelectedCells.Count > 0, "there are no selected rows");
|
||||
// if (this.scheduleList.SelectedCells.Count == 0)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
// int row = (int)this.scheduleList.SelectedCells[0].Y;
|
||||
|
||||
// // check that this is a valid row
|
||||
// STrace.Assert(row <= this.data.JobSchedules.Schedules.Count, "selected row does not exist in data structures");
|
||||
// if (row > this.data.JobSchedules.Schedules.Count)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// JobScheduleData data = this.data.JobSchedules.Schedules[row] as JobScheduleData;
|
||||
// if (data != null)
|
||||
// {
|
||||
// this.data.JobSchedules.DeleteSchedule(data); // if is non-shared it will be marked for deletion here
|
||||
|
||||
// this.scheduleList.DeleteAllRows();
|
||||
// PopulateGrid(this.data.JobSchedules);
|
||||
// }
|
||||
// UpdateControlStatus();
|
||||
// }
|
||||
|
||||
// private void EditSelectedSchedule()
|
||||
// {
|
||||
// // check that a row is selected first
|
||||
// STrace.Assert(this.scheduleList.SelectedCells.Count > 0, "there are no selected rows");
|
||||
// if (this.scheduleList.SelectedCells.Count == 0)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
// int row = (int)this.scheduleList.SelectedCells[0].Y;
|
||||
|
||||
// // check that this is a valid row
|
||||
// STrace.Assert(row <= this.data.JobSchedules.Schedules.Count, "selected row does not exist in data structures");
|
||||
// if (row > this.data.JobSchedules.Schedules.Count)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// JobScheduleData data = this.data.JobSchedules.Schedules[row] as JobScheduleData;
|
||||
// if (data != null)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// using (ScheduleDialog jobSchedule = new ScheduleDialog(data,
|
||||
// this.data.JobSchedules.Schedules,
|
||||
// this.DataContainer,
|
||||
// this.ServiceProvider))
|
||||
// {
|
||||
// jobSchedule.Text = JobSR.EditSchedule(data.Name);
|
||||
// jobSchedule.SetSite(this.ServiceProvider);
|
||||
|
||||
// try
|
||||
// {
|
||||
// if (DialogResult.OK == jobSchedule.ShowDialog())
|
||||
// {
|
||||
// this.scheduleList.DeleteAllRows();
|
||||
// PopulateGrid(this.data.JobSchedules);
|
||||
// UpdateControlStatus();
|
||||
// }
|
||||
// }
|
||||
// catch (ApplicationException error)
|
||||
// {
|
||||
// DisplayExceptionMessage(error);
|
||||
// jobSchedule.DialogResult = DialogResult.None;
|
||||
// }
|
||||
|
||||
// }
|
||||
// }
|
||||
// catch (ApplicationException error)
|
||||
// {
|
||||
// DisplayExceptionMessage(error);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// }
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// enumerates schedules list and returns back as s string in format 1,2,3
|
||||
/// </summary>
|
||||
/// <param name="schedules"></param>
|
||||
/// <returns></returns>
|
||||
private StringBuilder BuildListOfScheduleId(List<JobScheduleData> schedules)
|
||||
{
|
||||
if (schedules == null)
|
||||
{
|
||||
throw new ArgumentNullException("schedules");
|
||||
}
|
||||
StringBuilder scheduleIdList = new StringBuilder();
|
||||
foreach (JobScheduleData schedule in schedules)
|
||||
{
|
||||
if (schedule != null)
|
||||
{
|
||||
if (scheduleIdList.Length > 0)
|
||||
{
|
||||
scheduleIdList.AppendFormat(CultureInfo.InvariantCulture, ", {0}", schedule.ID);
|
||||
}
|
||||
else
|
||||
{
|
||||
scheduleIdList.Append(schedule.ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
return scheduleIdList;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,322 @@
|
||||
//
|
||||
// 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;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Globalization;
|
||||
using Microsoft.SqlServer.Management.Common;
|
||||
using Microsoft.SqlServer.Management.Sdk.Sfc;
|
||||
using Microsoft.SqlServer.Management.Smo;
|
||||
using Microsoft.SqlServer.Management.Smo.Agent;
|
||||
using Microsoft.SqlServer.Management.Diagnostics;
|
||||
using Microsoft.SqlTools.ServiceLayer.Admin;
|
||||
using SMO = Microsoft.SqlServer.Management.Smo;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
internal class JobSchedulesData
|
||||
{
|
||||
#region data members
|
||||
|
||||
// Typed List of job schedules (unshared)
|
||||
private List<JobScheduleData> jobSchedules = new List<JobScheduleData>();
|
||||
private List<JobScheduleData> deletedJobSchedues = new List<JobScheduleData>();
|
||||
|
||||
private JobData parent;
|
||||
private CDataContainer context;
|
||||
private bool isReadOnly;
|
||||
private bool allowEnableDisable;
|
||||
|
||||
#endregion
|
||||
|
||||
#region construction
|
||||
public JobSchedulesData(CDataContainer context, JobData parent)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException("context");
|
||||
}
|
||||
|
||||
if (parent == null)
|
||||
{
|
||||
throw new ArgumentNullException("parent");
|
||||
}
|
||||
|
||||
this.context = context;
|
||||
this.parent = parent;
|
||||
|
||||
this.isReadOnly = parent.IsReadOnly;
|
||||
this.allowEnableDisable = parent.AllowEnableDisable;
|
||||
|
||||
// if we're creating a new job
|
||||
if (this.parent.Mode != JobData.ActionMode.Edit)
|
||||
{
|
||||
this.SetDefaults();
|
||||
}
|
||||
else
|
||||
{
|
||||
// load the schedule data from server to local copy
|
||||
this.LoadData();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region public methods/properties
|
||||
|
||||
/// <summary>
|
||||
/// List of JobScheduleData - in memory copy
|
||||
/// </summary>
|
||||
public List<JobScheduleData> Schedules
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.jobSchedules;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List of removed schedules - in memory copy
|
||||
/// </summary>
|
||||
public List<JobScheduleData> RemovedSchedules
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.deletedJobSchedues;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a schedule to JobScheduleData list - this does not apply changes on server
|
||||
/// </summary>
|
||||
/// <param name="schedule"></param>
|
||||
public void AddSchedule(JobScheduleData schedule)
|
||||
{
|
||||
if (schedule == null)
|
||||
{
|
||||
throw new ArgumentNullException("schedule");
|
||||
}
|
||||
|
||||
this.jobSchedules.Add(schedule);
|
||||
|
||||
// check to see if it has been previously removed, if so delete it from the
|
||||
// removed schedules list
|
||||
for (int i = deletedJobSchedues.Count - 1; i >= 0; i--)
|
||||
{
|
||||
JobScheduleData removedSchedule = this.deletedJobSchedues[i] as JobScheduleData;
|
||||
if (removedSchedule.ID == schedule.ID)
|
||||
{
|
||||
this.deletedJobSchedues.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// delete a schedule from JobScheduleData list - this does not apply changes on server
|
||||
/// </summary>
|
||||
/// <param name="schedule"></param>
|
||||
public void DeleteSchedule(JobScheduleData schedule)
|
||||
{
|
||||
if (schedule == null)
|
||||
{
|
||||
throw new ArgumentNullException("schedule");
|
||||
}
|
||||
if (this.jobSchedules.Contains(schedule))
|
||||
{
|
||||
this.jobSchedules.Remove(schedule);
|
||||
// if it exists on the server then mark it for deletion later. Otherwise just discard the schedule.
|
||||
if (schedule.Created)
|
||||
{
|
||||
this.deletedJobSchedues.Add(schedule);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsReadOnly
|
||||
{
|
||||
get { return isReadOnly; }
|
||||
}
|
||||
|
||||
public bool AllowEnableDisable
|
||||
{
|
||||
get { return this.allowEnableDisable; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region data loading
|
||||
private void LoadData()
|
||||
{
|
||||
Job job = this.Job;
|
||||
// load the data
|
||||
if (job != null)
|
||||
{
|
||||
JobScheduleCollection schedules = job.JobSchedules;
|
||||
|
||||
for (int i = 0; i < schedules.Count; i++)
|
||||
{
|
||||
this.jobSchedules.Add(new JobScheduleData(schedules[i], this.IsReadOnly, this.AllowEnableDisable));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SetDefaults();
|
||||
}
|
||||
}
|
||||
private void SetDefaults()
|
||||
{
|
||||
this.jobSchedules.Clear();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region events
|
||||
|
||||
#endregion
|
||||
|
||||
#region private helpers
|
||||
private Job Job
|
||||
{
|
||||
get
|
||||
{
|
||||
// try and do the lookup at the parent level
|
||||
Job job = null;
|
||||
if (this.parent != null)
|
||||
{
|
||||
job = parent.Job;
|
||||
}
|
||||
else if (this.context != null)
|
||||
{
|
||||
STParameters parameters = new STParameters(this.context.Document);
|
||||
string urn = String.Empty;
|
||||
parameters.GetParam("urn", ref urn);
|
||||
|
||||
job = this.context.Server.GetSmoObject(new Urn(urn)) as Job;
|
||||
}
|
||||
return job;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region saving
|
||||
/// <summary>
|
||||
/// Save changes to the job schedules - this applies changes to server
|
||||
/// </summary>
|
||||
/// <param name="job">owner job</param>
|
||||
/// <returns>true if any changes were commited</returns>
|
||||
public bool ApplyChanges(Job job)
|
||||
{
|
||||
bool changesMade = false;
|
||||
if (!this.IsReadOnly)
|
||||
{
|
||||
// delete any deleted schedules;
|
||||
foreach (JobScheduleData schedule in this.deletedJobSchedues)
|
||||
{
|
||||
if (!this.IsSharedSchedule(job.Parent as JobServer, schedule))
|
||||
{
|
||||
// non-shared
|
||||
if (schedule.Created)
|
||||
{
|
||||
schedule.SetJob(job);
|
||||
schedule.Delete();
|
||||
changesMade = true;
|
||||
}
|
||||
}
|
||||
else if (null != job.JobSchedules.ItemById(schedule.ID))
|
||||
{
|
||||
// shared
|
||||
// Remove the selected schedule from the job. If no other jobs use the schedule, the schedule is deleted from the database.
|
||||
// This is now the default behavior of RemoveSharedSchedule thus we do not need an extra parameter (false) with it.
|
||||
job.RemoveSharedSchedule(schedule.ID);
|
||||
changesMade = true;
|
||||
}
|
||||
}
|
||||
|
||||
// clear the deleted Job ScheduleList
|
||||
this.deletedJobSchedues.Clear();
|
||||
|
||||
// update the remaining schedules
|
||||
foreach (JobScheduleData schedule in this.jobSchedules)
|
||||
{
|
||||
if (!this.IsSharedSchedule(job.Parent as JobServer, schedule))
|
||||
{
|
||||
// non-shared
|
||||
schedule.SetJob(job);
|
||||
if (schedule.ApplyChanges())
|
||||
{
|
||||
changesMade = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// create and attach if the the schedule is not shared
|
||||
if (!schedule.Created)
|
||||
{
|
||||
schedule.SetJob(job);
|
||||
changesMade = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
job.AddSharedSchedule(schedule.ID);
|
||||
}
|
||||
if (schedule.ApplyChanges())
|
||||
{
|
||||
changesMade = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (this.AllowEnableDisable)
|
||||
{
|
||||
// if the schedules are readonly give them an opportunity to update themselves
|
||||
foreach (JobScheduleData schedule in this.jobSchedules)
|
||||
{
|
||||
if (schedule.ApplyChanges())
|
||||
{
|
||||
changesMade = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return changesMade;
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// check if given schedule data is shared schedule or not
|
||||
/// </summary>
|
||||
/// <param name="js"></param>
|
||||
/// <param name="jobScheduleData"></param>
|
||||
/// <returns></returns>
|
||||
private bool IsSharedSchedule(JobServer js, JobScheduleData jobScheduleData)
|
||||
{
|
||||
if (js == null)
|
||||
{
|
||||
throw new ArgumentNullException("js");
|
||||
}
|
||||
|
||||
SqlServer.Management.Smo.Server srv = js.Parent as SqlServer.Management.Smo.Server;
|
||||
|
||||
if ((srv == null) || (srv.Information.Version.Major < 9))
|
||||
{
|
||||
// Shared Schedules not supported prior Yukon
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// with Yukon all schedules are now shared
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,506 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlServer.Management.Sdk.Sfc;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Data;
|
||||
using System.Globalization;
|
||||
using Microsoft.SqlServer.Management.Diagnostics;
|
||||
using Microsoft.SqlServer.Management.Common;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Microsoft.SqlServer.Management.Smo;
|
||||
using Microsoft.SqlServer.Management.Smo.Agent;
|
||||
using Microsoft.SqlTools.ServiceLayer.Admin;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for JobStepAdvancedLogging.
|
||||
/// </summary>
|
||||
internal sealed class JobStepAdvancedLogging : IJobStepPropertiesControl
|
||||
{
|
||||
private CDataContainer dataContainer = null;
|
||||
// private IMessageBoxProvider messageProvider = null;
|
||||
// private System.Windows.Forms.Label fileLabel;
|
||||
// private System.Windows.Forms.TextBox outputFile;
|
||||
// private System.Windows.Forms.Button browse;
|
||||
// private System.Windows.Forms.CheckBox appendOutput;
|
||||
|
||||
private bool userIsSysAdmin = false;
|
||||
private bool canViewFileLog = false;
|
||||
private bool canSetFileLog = false;
|
||||
|
||||
private JobStepData jobStepData;
|
||||
// private CheckBox logToTable;
|
||||
// private CheckBox appendToFile;
|
||||
// private CheckBox appendToTable;
|
||||
// private Button viewFileLog;
|
||||
// private Button viewTableLog;
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.Container components = null;
|
||||
|
||||
public JobStepAdvancedLogging()
|
||||
{
|
||||
// This call is required by the Windows.Forms Form Designer.
|
||||
InitializeComponent();
|
||||
|
||||
// TODO: Add any initialization after the InitForm call
|
||||
|
||||
}
|
||||
|
||||
public JobStepAdvancedLogging(CDataContainer dataContainer, JobStepData jobStepData)
|
||||
{
|
||||
this.dataContainer = dataContainer;
|
||||
this.jobStepData = jobStepData;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
// protected override void Dispose(bool disposing)
|
||||
// {
|
||||
// if (disposing)
|
||||
// {
|
||||
// if (components != null)
|
||||
// {
|
||||
// components.Dispose();
|
||||
// }
|
||||
// }
|
||||
// base.Dispose(disposing);
|
||||
// }
|
||||
|
||||
#region Component Designer generated code
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
// System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(JobStepAdvancedLogging));
|
||||
// this.fileLabel = new System.Windows.Forms.Label();
|
||||
// this.outputFile = new System.Windows.Forms.TextBox();
|
||||
// this.browse = new System.Windows.Forms.Button();
|
||||
// this.appendOutput = new System.Windows.Forms.CheckBox();
|
||||
// this.logToTable = new System.Windows.Forms.CheckBox();
|
||||
// this.appendToFile = new System.Windows.Forms.CheckBox();
|
||||
// this.appendToTable = new System.Windows.Forms.CheckBox();
|
||||
// this.viewFileLog = new System.Windows.Forms.Button();
|
||||
// this.viewTableLog = new System.Windows.Forms.Button();
|
||||
// this.SuspendLayout();
|
||||
// this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
// this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
// //
|
||||
// // fileLabel
|
||||
// //
|
||||
// resources.ApplyResources(this.fileLabel, "fileLabel");
|
||||
// this.fileLabel.Name = "fileLabel";
|
||||
// //
|
||||
// // outputFile
|
||||
// //
|
||||
// resources.ApplyResources(this.outputFile, "outputFile");
|
||||
// this.outputFile.Name = "outputFile";
|
||||
// this.outputFile.TextChanged += new System.EventHandler(this.outputFile_TextChanged);
|
||||
// //
|
||||
// // browse
|
||||
// //
|
||||
// resources.ApplyResources(this.browse, "browse");
|
||||
// this.browse.Name = "browse";
|
||||
// this.browse.Click += new System.EventHandler(this.browse_Click);
|
||||
// //
|
||||
// // appendOutput
|
||||
// //
|
||||
// resources.ApplyResources(this.appendOutput, "appendOutput");
|
||||
// this.appendOutput.Name = "appendOutput";
|
||||
// //
|
||||
// // logToTable
|
||||
// //
|
||||
// resources.ApplyResources(this.logToTable, "logToTable");
|
||||
// this.logToTable.Name = "logToTable";
|
||||
// this.logToTable.CheckedChanged += new System.EventHandler(this.logToTable_CheckedChanged);
|
||||
// //
|
||||
// // appendToFile
|
||||
// //
|
||||
// resources.ApplyResources(this.appendToFile, "appendToFile");
|
||||
// this.appendToFile.Name = "appendToFile";
|
||||
// //
|
||||
// // appendToTable
|
||||
// //
|
||||
// resources.ApplyResources(this.appendToTable, "appendToTable");
|
||||
// this.appendToTable.Name = "appendToTable";
|
||||
// //
|
||||
// // viewFileLog
|
||||
// //
|
||||
// resources.ApplyResources(this.viewFileLog, "viewFileLog");
|
||||
// this.viewFileLog.Name = "viewFileLog";
|
||||
// this.viewFileLog.Click += new System.EventHandler(this.viewFileLog_Click);
|
||||
// //
|
||||
// // viewTableLog
|
||||
// //
|
||||
// resources.ApplyResources(this.viewTableLog, "viewTableLog");
|
||||
// this.viewTableLog.Name = "viewTableLog";
|
||||
// this.viewTableLog.Click += new System.EventHandler(this.viewTableLog_Click);
|
||||
// //
|
||||
// // JobStepAdvancedLogging
|
||||
// //
|
||||
// this.Controls.Add(this.viewTableLog);
|
||||
// this.Controls.Add(this.viewFileLog);
|
||||
// this.Controls.Add(this.appendToTable);
|
||||
// this.Controls.Add(this.appendToFile);
|
||||
// this.Controls.Add(this.logToTable);
|
||||
// this.Controls.Add(this.appendOutput);
|
||||
// this.Controls.Add(this.browse);
|
||||
// this.Controls.Add(this.outputFile);
|
||||
// this.Controls.Add(this.fileLabel);
|
||||
// this.Name = "JobStepAdvancedLogging";
|
||||
// resources.ApplyResources(this, "$this");
|
||||
// this.ResumeLayout(false);
|
||||
// this.PerformLayout();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IJobStepPropertiesControl implementation
|
||||
void IJobStepPropertiesControl.Load(JobStepData data)
|
||||
{
|
||||
// this.outputFile.Text = data.OutputFileName;
|
||||
// this.appendToFile.Checked = data.AppendToLogFile;
|
||||
// this.appendOutput.Checked = data.AppendToStepHistory;
|
||||
|
||||
// this.logToTable.Checked = data.WriteLogToTable;
|
||||
// this.logToTable.Enabled = data.CanLogToTable;
|
||||
|
||||
// this.appendToTable.Checked = data.AppendLogToTable;
|
||||
|
||||
this.userIsSysAdmin = (data.Parent.Parent.UserRole & UserRoles.SysAdmin) > 0;
|
||||
this.canViewFileLog = this.userIsSysAdmin && data.Version.Major <= 8;
|
||||
// must be sysadmin to set log in yukon
|
||||
this.canSetFileLog = (data.Version.Major <= 8 || this.userIsSysAdmin);
|
||||
|
||||
if (this.canSetFileLog)
|
||||
{
|
||||
// Managed Instance doesn't allow setting this path.
|
||||
//
|
||||
if (this.dataContainer != null &&
|
||||
this.dataContainer.Server != null &&
|
||||
this.dataContainer.Server.DatabaseEngineEdition == DatabaseEngineEdition.SqlManagedInstance)
|
||||
{
|
||||
this.canSetFileLog = false;
|
||||
}
|
||||
}
|
||||
|
||||
UpdateControlStatus();
|
||||
|
||||
}
|
||||
void IJobStepPropertiesControl.Save(JobStepData data, bool isSwitching)
|
||||
{
|
||||
// if (this.appendToFile.Checked && this.outputFile.Text.Trim().Length == 0)
|
||||
// {
|
||||
// throw new ApplicationException(SRError.MissingOutputLogFileName);
|
||||
// }
|
||||
|
||||
// data.OutputFileName = this.outputFile.Text;
|
||||
// data.AppendToLogFile = this.appendToFile.Checked;
|
||||
// data.AppendToStepHistory = this.appendOutput.Checked;
|
||||
|
||||
// data.WriteLogToTable = this.logToTable.Checked;
|
||||
// if (this.logToTable.Checked)
|
||||
// {
|
||||
// data.AppendLogToTable = this.appendToTable.Checked;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// data.AppendLogToTable = false;
|
||||
// }
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region event handlers
|
||||
/// <summary>
|
||||
/// Called when the user clicks on the browse for file button. Will allow the
|
||||
/// user to either enter a new file, or pick an existing one for logging on the server
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void browse_Click(object sender, System.EventArgs e)
|
||||
{
|
||||
// using (BrowseFolder browse = new BrowseFolder(this.dataContainer.Server.ConnectionContext,
|
||||
// this.messageProvider))
|
||||
// {
|
||||
// browse.Font = this.Font;
|
||||
// browse.BrowseForFiles = true;
|
||||
|
||||
// if (browse.ShowDialog() == DialogResult.OK)
|
||||
// {
|
||||
// this.outputFile.Text = browse.SelectedFullFileName;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void outputFile_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
UpdateControlStatus();
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// User wishes to view the file log
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void viewFileLog_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Cursor originalCursor = Cursor.Current;
|
||||
// try
|
||||
// {
|
||||
// Cursor.Current = Cursors.WaitCursor;
|
||||
// try
|
||||
// {
|
||||
// string tempFileName = String.Empty;
|
||||
// if (CheckFileExistsAndIsValid(this.outputFile.Text))
|
||||
// {
|
||||
// tempFileName = ReadLogToFile(this.outputFile.Text);
|
||||
// }
|
||||
|
||||
// ViewLog(tempFileName);
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// messageProvider.ShowMessage(
|
||||
// ex
|
||||
// , SRError.SQLWorkbench
|
||||
// , Microsoft.NetEnterpriseServers.ExceptionMessageBoxButtons.OK
|
||||
// , Microsoft.NetEnterpriseServers.ExceptionMessageBoxSymbol.Error
|
||||
// , this);
|
||||
// }
|
||||
// }
|
||||
// finally
|
||||
// {
|
||||
// Cursor.Current = originalCursor;
|
||||
// }
|
||||
}
|
||||
/// <summary>
|
||||
/// user wishes to view the table log
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void logToTable_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
UpdateControlStatus();
|
||||
}
|
||||
private void viewTableLog_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Cursor originalCursor = Cursor.Current;
|
||||
// try
|
||||
// {
|
||||
// Cursor.Current = Cursors.WaitCursor;
|
||||
// try
|
||||
// {
|
||||
// JobStep step = this.jobStepData.JobStep;
|
||||
// String tempFileName = String.Empty;
|
||||
|
||||
// if (step != null)
|
||||
// {
|
||||
// tempFileName = ReadStepLogToFile(step);
|
||||
// }
|
||||
// // Note that ViewLog deletes the temp file after showing it.
|
||||
// ViewLog(tempFileName);
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// messageProvider.ShowMessage(
|
||||
// ex
|
||||
// , SRError.SQLWorkbench
|
||||
// , Microsoft.NetEnterpriseServers.ExceptionMessageBoxButtons.OK
|
||||
// , Microsoft.NetEnterpriseServers.ExceptionMessageBoxSymbol.Error
|
||||
// , this);
|
||||
// }
|
||||
|
||||
// }
|
||||
// finally
|
||||
// {
|
||||
// Cursor.Current = originalCursor;
|
||||
// }
|
||||
}
|
||||
|
||||
private void ViewLog(string tempFileName)
|
||||
{
|
||||
// if (tempFileName == null || tempFileName.Length == 0)
|
||||
// {
|
||||
// messageProvider.ShowMessage(
|
||||
// SRError.LogNotYetCreated
|
||||
// , SRError.SQLWorkbench
|
||||
// , Microsoft.NetEnterpriseServers.ExceptionMessageBoxButtons.OK
|
||||
// , Microsoft.NetEnterpriseServers.ExceptionMessageBoxSymbol.Information
|
||||
// , this);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// String notepadProcess = String.Format(CultureInfo.InvariantCulture
|
||||
// , "{0}\\notepad.exe"
|
||||
// , System.Environment.SystemDirectory);
|
||||
|
||||
// System.Diagnostics.Process.Start(notepadProcess, tempFileName);
|
||||
// System.Threading.Thread.Sleep(1000);
|
||||
// }
|
||||
// finally
|
||||
// {
|
||||
// System.IO.File.Delete(tempFileName);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region internal helpers
|
||||
/// <summary>
|
||||
/// Update the enabled/disabled status of controls
|
||||
/// </summary>
|
||||
private void UpdateControlStatus()
|
||||
{
|
||||
// this.appendToTable.Enabled = this.logToTable.Checked;
|
||||
// this.viewTableLog.Enabled = this.logToTable.Checked;
|
||||
// this.viewFileLog.Enabled = this.canViewFileLog
|
||||
// && this.outputFile.Text.Length > 0
|
||||
// && this.outputFile.Text[this.outputFile.Text.Length - 1] != '\\';
|
||||
// this.outputFile.Enabled = this.canSetFileLog;
|
||||
// this.browse.Enabled = this.canSetFileLog;
|
||||
// this.appendToFile.Enabled = this.canSetFileLog
|
||||
// && this.outputFile.Text.Length > 0
|
||||
// && this.outputFile.Text[this.outputFile.Text.Length - 1] != '\\';
|
||||
// if (!this.appendToFile.Enabled) this.appendToFile.Checked = false;
|
||||
}
|
||||
/// <summary>
|
||||
/// Check that a file exists on the server, and validates the path.
|
||||
/// It will throw if the file is either a directoty, or it's parent
|
||||
/// path is invalid.
|
||||
/// </summary>
|
||||
/// <param name="file">File name</param>
|
||||
/// <returns>true if the file already exists</returns>
|
||||
private bool CheckFileExistsAndIsValid(string file)
|
||||
{
|
||||
bool fileExists = false;
|
||||
// check to see that the file exists.
|
||||
// ServerConnection connection = this.dataContainer.ServerConnection;
|
||||
|
||||
// string query = String.Format(CultureInfo.InvariantCulture
|
||||
// , "EXECUTE master.dbo.xp_fileexist {0}"
|
||||
// , SqlSmoObject.MakeSqlString(file));
|
||||
|
||||
// DataSet data = connection.ExecuteWithResults(query);
|
||||
|
||||
// STrace.Assert(data.Tables.Count == 1, "Unexpected number of result sets returned from query");
|
||||
|
||||
// if (data.Tables.Count > 0)
|
||||
// {
|
||||
// DataTable table = data.Tables[0];
|
||||
|
||||
// STrace.Assert(table.Rows.Count == 1, "Unexpected number of rows returned");
|
||||
// STrace.Assert(table.Columns.Count == 3, "Unexpected number of columns returned");
|
||||
|
||||
// if (table.Rows.Count > 0 && table.Columns.Count > 2)
|
||||
// {
|
||||
// DataRow row = table.Rows[0];
|
||||
|
||||
// fileExists = ((byte)row[0] == 1);
|
||||
// bool fileIsDirectory = ((byte)row[1] == 1);
|
||||
|
||||
// if (fileIsDirectory)
|
||||
// {
|
||||
// throw new ApplicationException(SRError.FileIsDirectory);
|
||||
// }
|
||||
|
||||
// bool parentDiectoryExists = ((byte)row[2] == 1);
|
||||
// if (!parentDiectoryExists)
|
||||
// {
|
||||
// throw new ApplicationException(SRError.FileLocationInvalid);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
return fileExists;
|
||||
}
|
||||
/// <summary>
|
||||
/// read a log on the server to a local file. This method is only supported on
|
||||
/// pre 9.0 servers
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
/// <returns></returns>
|
||||
private string ReadLogToFile(string fileName)
|
||||
{
|
||||
ServerConnection connection = this.dataContainer.ServerConnection;
|
||||
|
||||
string query = string.Format(CultureInfo.InvariantCulture
|
||||
, "EXECUTE master.dbo.xp_readerrorlog -1, {0}"
|
||||
, SqlSmoObject.MakeSqlString(fileName));
|
||||
|
||||
DataSet data = connection.ExecuteWithResults(query);
|
||||
|
||||
if (data.Tables.Count > 0)
|
||||
{
|
||||
DataTable table = data.Tables[0];
|
||||
|
||||
string tempFileName = string.Format(System.Globalization.CultureInfo.InvariantCulture,
|
||||
"{0}{1}", Path.GetTempPath(), "JobSR.StepOutput(Path.GetFileName(fileName))");
|
||||
|
||||
StreamWriter writer = new StreamWriter(tempFileName, false, Encoding.Unicode);
|
||||
|
||||
foreach(DataRow row in table.Rows)
|
||||
{
|
||||
writer.Write(row[0].ToString());
|
||||
if ((byte)row[1] == 0)
|
||||
{
|
||||
writer.WriteLine();
|
||||
}
|
||||
}
|
||||
|
||||
writer.Close();
|
||||
|
||||
return tempFileName;
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read the step log to a file. This is only supported on a 9.0 Server
|
||||
/// </summary>
|
||||
/// <param name="step"></param>
|
||||
/// <returns></returns>
|
||||
private string ReadStepLogToFile(JobStep step)
|
||||
{
|
||||
DataTable table = step.EnumLogs();
|
||||
|
||||
String tempFileName = Path.GetTempFileName();
|
||||
|
||||
StreamWriter writer = new StreamWriter(tempFileName, false, Encoding.Unicode);
|
||||
|
||||
foreach(DataRow row in table.Rows)
|
||||
{
|
||||
writer.WriteLine(row["Log"].ToString());
|
||||
}
|
||||
|
||||
writer.Close();
|
||||
|
||||
return tempFileName;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
1041
src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/JobStepData.cs
Normal file
1041
src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/JobStepData.cs
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,78 @@
|
||||
//
|
||||
// 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;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using Microsoft.SqlServer.Management.Common;
|
||||
using Microsoft.SqlServer.Management.Sdk.Sfc;
|
||||
using Microsoft.SqlServer.Management.Smo;
|
||||
using Microsoft.SqlServer.Management.Smo.Agent;
|
||||
using Microsoft.SqlServer.Management.Diagnostics;
|
||||
using Microsoft.SqlTools.ServiceLayer.Admin;
|
||||
using Microsoft.SqlTools.ServiceLayer.Management;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for JobStepProperties.
|
||||
/// </summary>
|
||||
internal class JobStepProperties : ManagementActionBase
|
||||
{
|
||||
private JobStepSubSystems subSystems;
|
||||
private JobStepSubSystem selectedSubSystem = null;
|
||||
private bool needToUpdate = false;
|
||||
private const int jobIdLowerBound= 1;
|
||||
private int currentStepID = jobIdLowerBound;
|
||||
private int stepsCount = jobIdLowerBound;
|
||||
private IJobStepPropertiesControl activeControl = null;
|
||||
private JobStepData data;
|
||||
// used to persist state between job step types
|
||||
private JobStepData runtimeData;
|
||||
|
||||
internal JobStepProperties(CDataContainer dataContainer, JobStepData context)
|
||||
{
|
||||
this.DataContainer = dataContainer;
|
||||
this.data = context;
|
||||
this.runtimeData = new JobStepData(this.data);
|
||||
currentStepID = this.data.ID;
|
||||
stepsCount = this.data.StepCount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
private JobStepSubSystems SubSystems
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.subSystems == null)
|
||||
{
|
||||
this.subSystems = new JobStepSubSystems(this.DataContainer, this.data);
|
||||
}
|
||||
return this.subSystems;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
//
|
||||
// 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;
|
||||
using System.Globalization;
|
||||
using Microsoft.SqlServer.Management.Common;
|
||||
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.Management;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for JobStepPropertySheet.
|
||||
/// </summary>
|
||||
internal class JobStepPropertySheet : ManagementActionBase
|
||||
{
|
||||
private JobStepData data = null;
|
||||
|
||||
public JobStepPropertySheet(CDataContainer dataContainer, JobStepData data)
|
||||
{
|
||||
this.DataContainer = dataContainer;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public void Init()
|
||||
{
|
||||
JobStepProperties general = new JobStepProperties(this.DataContainer, this.data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if(disposing)
|
||||
{
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
public bool Create()
|
||||
{
|
||||
// Make sure the job step name is not blank.
|
||||
if (string.IsNullOrWhiteSpace(this.data.Name))
|
||||
{
|
||||
throw new Exception("SRError.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)
|
||||
{
|
||||
// Throw an error if the job step name already exists
|
||||
throw new Exception("JobSR.JobStepNameAlreadyExists(this.data.Name)");
|
||||
}
|
||||
}
|
||||
|
||||
this.data.ApplyChanges(this.GetCurrentJob());
|
||||
|
||||
// regular execution always takes place
|
||||
return true;
|
||||
}
|
||||
|
||||
private Job GetCurrentJob()
|
||||
{
|
||||
Job job = null;
|
||||
string urn = string.Empty;
|
||||
string jobIdString = null;
|
||||
STParameters parameters = new STParameters(this.DataContainer.Document);
|
||||
parameters.GetParam("urn", ref urn);
|
||||
parameters.GetParam("jobid", ref jobIdString);
|
||||
|
||||
// If JobID is passed in look up by jobID
|
||||
if (!string.IsNullOrEmpty(jobIdString))
|
||||
{
|
||||
job = this.DataContainer.Server.JobServer.Jobs.ItemById(Guid.Parse(jobIdString));
|
||||
}
|
||||
else
|
||||
{
|
||||
// or use urn path to query job
|
||||
job = this.DataContainer.Server.GetSmoObject(urn) as Job;
|
||||
}
|
||||
|
||||
return job;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// We don't own the CDataContainer that we get from our creator. We need to
|
||||
/// return false here so that the base class won't dispose it in its Dispose method
|
||||
/// </summary>
|
||||
protected override bool OwnDataContainer
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
//
|
||||
// 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.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Microsoft.SqlServer.Management.Sdk.Sfc;
|
||||
using Microsoft.SqlServer.Management.Smo;
|
||||
using Microsoft.SqlServer.Management.Smo.Agent;
|
||||
using Microsoft.SqlTools.ServiceLayer.Admin;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for JobStepSubSystems.
|
||||
/// </summary>
|
||||
internal class JobStepSubSystems
|
||||
{
|
||||
private IDictionary<AgentSubSystem, JobStepSubSystem> subSystems = new Dictionary<AgentSubSystem, JobStepSubSystem>();
|
||||
JobStepData data;
|
||||
|
||||
public JobStepSubSystems(CDataContainer dataContainer)
|
||||
: this(dataContainer, null)
|
||||
{
|
||||
}
|
||||
|
||||
public JobStepSubSystems(CDataContainer dataContainer, JobStepData data)
|
||||
{
|
||||
this.data = data;
|
||||
var availableSystems =
|
||||
dataContainer.Server.JobServer.EnumSubSystems()
|
||||
.Rows.OfType<DataRow>()
|
||||
.Select(r => (AgentSubSystem)Convert.ToInt32(r["subsystem_id"]));
|
||||
|
||||
foreach (var agentSubSystemId in availableSystems)
|
||||
{
|
||||
var agentSubSystem = CreateJobStepSubSystem(agentSubSystemId, dataContainer, data);
|
||||
// The server might have some new subsystem we don't know about, just ignore it.
|
||||
if (agentSubSystem != null)
|
||||
{
|
||||
subSystems[agentSubSystemId] = agentSubSystem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public JobStepSubSystem[] AvailableSubSystems
|
||||
{
|
||||
get { return this.subSystems.Keys.OrderBy(k => (int) k).Select(k => this.subSystems[k]).ToArray(); }
|
||||
}
|
||||
|
||||
public JobStepSubSystem Lookup(AgentSubSystem key)
|
||||
{
|
||||
JobStepSubSystem rv = null;
|
||||
if (this.subSystems.ContainsKey(key))
|
||||
{
|
||||
return this.subSystems[key];
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
private static TypeConverter typeConverter = TypeDescriptor.GetConverter(typeof (AgentSubSystem));
|
||||
// Returns name of the subsystem for a given enum value
|
||||
public static string LookupFriendlyName(AgentSubSystem key)
|
||||
{
|
||||
return (string)typeConverter.ConvertToString((Enum)key);
|
||||
}
|
||||
|
||||
// Returns name of the subsystem for a given enum value
|
||||
public static string LookupName(AgentSubSystem key)
|
||||
{
|
||||
// Have to subtract first enum value to bring the
|
||||
// index to 0-based index
|
||||
return typeConverter.ConvertToInvariantString((Enum) key);
|
||||
}
|
||||
|
||||
private static JobStepSubSystem CreateJobStepSubSystem(
|
||||
AgentSubSystem agentSubSystem,
|
||||
CDataContainer dataContainer,
|
||||
JobStepData data)
|
||||
{
|
||||
switch (agentSubSystem)
|
||||
{
|
||||
case AgentSubSystem.TransactSql:
|
||||
return new JobStepSubSystem(AgentSubSystem.TransactSql);
|
||||
|
||||
case AgentSubSystem.CmdExec:
|
||||
return new JobStepSubSystem(AgentSubSystem.CmdExec);
|
||||
|
||||
case AgentSubSystem.Distribution:
|
||||
return new JobStepSubSystem(AgentSubSystem.Distribution);
|
||||
|
||||
case AgentSubSystem.Merge:
|
||||
return new JobStepSubSystem(AgentSubSystem.Merge);
|
||||
|
||||
case AgentSubSystem.QueueReader:
|
||||
return new JobStepSubSystem(AgentSubSystem.QueueReader);
|
||||
|
||||
case AgentSubSystem.Snapshot:
|
||||
return new JobStepSubSystem(AgentSubSystem.Snapshot);
|
||||
|
||||
case AgentSubSystem.LogReader:
|
||||
return new JobStepSubSystem(AgentSubSystem.LogReader);
|
||||
|
||||
case AgentSubSystem.AnalysisCommand:
|
||||
return new JobStepSubSystem(AgentSubSystem.AnalysisCommand);
|
||||
|
||||
case AgentSubSystem.AnalysisQuery:
|
||||
return new JobStepSubSystem(AgentSubSystem.AnalysisQuery);
|
||||
|
||||
case AgentSubSystem.PowerShell:
|
||||
return new JobStepSubSystem(AgentSubSystem.PowerShell);
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class JobStepSubSystem
|
||||
{
|
||||
#region data members
|
||||
private AgentSubSystem subSystemKey;
|
||||
#endregion
|
||||
|
||||
#region construction
|
||||
public JobStepSubSystem(AgentSubSystem key)
|
||||
{
|
||||
this.subSystemKey = key;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region overrides
|
||||
public override string ToString()
|
||||
{
|
||||
return this.FriendlyName;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region properties
|
||||
public AgentSubSystem Key
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.subSystemKey;
|
||||
}
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return JobStepSubSystems.LookupName(this.subSystemKey);
|
||||
}
|
||||
}
|
||||
|
||||
public string FriendlyName
|
||||
{
|
||||
get
|
||||
{
|
||||
return JobStepSubSystems.LookupFriendlyName(this.subSystemKey);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
//
|
||||
// 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;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
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.Management;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for JobSteps.
|
||||
/// </summary>
|
||||
internal class JobStepsActions : ManagementActionBase
|
||||
{
|
||||
private bool validated = true;
|
||||
|
||||
private JobData data;
|
||||
|
||||
public JobStepsActions(CDataContainer dataContainer, JobData data)
|
||||
{
|
||||
this.DataContainer = dataContainer;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
#region ISupportValidation
|
||||
/// <summary>
|
||||
/// Validate the Job step data.
|
||||
/// This is limited to two checks
|
||||
/// 1. See if all steps are reachable
|
||||
/// 2. If we are editing rather than creating check to see if the last steps completion
|
||||
/// action will change from GoToNext to QuitWithSuccess.
|
||||
/// </summary>
|
||||
/// <returns>true if the checks passed, or the user has ok the warning</returns>
|
||||
public bool Validate()
|
||||
{
|
||||
// Only validate once after the user has made changes. Validate() is called when the
|
||||
// user navigates away from the JobSteps page, and if they navigate back and then out
|
||||
// again they'd be prompted twice. This annoys our users.
|
||||
if (this.validated)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool valid = true;
|
||||
// Get the unreachable steps
|
||||
List<JobStepData> unreachableSteps = this.data.JobSteps.FindUnreachableJobSteps();
|
||||
// see if the last step success completion action will change
|
||||
bool lastStepWillChange = this.data.JobSteps.CheckIfLastStepCompletionActionWillChange();
|
||||
|
||||
// warning message
|
||||
StringBuilder warningMessage = new StringBuilder();
|
||||
|
||||
// if there are unreachable steps, add the warning and each problematic step
|
||||
if (unreachableSteps.Count > 0)
|
||||
{
|
||||
warningMessage.AppendLine("JobSR.UnreachableStepHeader");
|
||||
foreach (JobStepData jobStep in unreachableSteps)
|
||||
{
|
||||
warningMessage.AppendLine("JobSR.UnreachableStepFormat(jobStep.ID, jobStep.Name)");
|
||||
}
|
||||
warningMessage.AppendLine(string.Empty);
|
||||
}
|
||||
|
||||
// add a warning if the last step will change
|
||||
if (lastStepWillChange)
|
||||
{
|
||||
warningMessage.AppendLine("JobSR.LastStepSuccessWillChange");
|
||||
warningMessage.AppendLine(string.Empty);
|
||||
}
|
||||
|
||||
// if anything was wrong tell the user and see if they are ok with it
|
||||
if (warningMessage.Length > 0)
|
||||
{
|
||||
warningMessage.Append("JobSR.AreYouSure");
|
||||
}
|
||||
|
||||
this.validated = valid;
|
||||
return valid;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
// private void PopulateGrid(JobStepsData steps)
|
||||
// {
|
||||
// for (int i = 0; i < steps.Steps.Count; i++)
|
||||
// {
|
||||
// JobStepData step = steps.Steps[i] as JobStepData;
|
||||
// if (step != null)
|
||||
// {
|
||||
// // add rows to the grid
|
||||
// GridCellCollection row = new GridCellCollection();
|
||||
// GridCell cell;
|
||||
|
||||
// // id
|
||||
// cell = new GridCell(step.ID.ToString(CultureInfo.InvariantCulture));
|
||||
// row.Add(cell);
|
||||
// // step name
|
||||
// cell = new GridCell(step.Name);
|
||||
// row.Add(cell);
|
||||
// // subsystem
|
||||
// cell = new GridCell(JobStepSubSystems.LookupFriendlyName(step.SubSystem));
|
||||
// row.Add(cell);
|
||||
// // on success
|
||||
// cell = new GridCell(GetFriendlyNameForAction(step.SuccessAction, step.SuccessStep));
|
||||
// row.Add(cell);
|
||||
// // on failure
|
||||
// cell = new GridCell(GetFriendlyNameForAction(step.FailureAction, step.FailStep));
|
||||
// row.Add(cell);
|
||||
|
||||
// this.jobStepList.AddRow(row);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
/// <summary>
|
||||
/// Convert an action and it's target step to a localizable user friendly name
|
||||
/// </summary>
|
||||
/// <param name="action"></param>
|
||||
/// <param name="targetStep"></param>
|
||||
/// <returns></returns>
|
||||
// private static string GetFriendlyNameForAction(StepCompletionAction action, JobStepData targetStep)
|
||||
// {
|
||||
// String friendlyName = String.Empty;
|
||||
// // switch (action)
|
||||
// // {
|
||||
// // case StepCompletionAction.GoToNextStep:
|
||||
// // friendlyName = JobSR.GotoNextStep;
|
||||
// // break;
|
||||
// // case StepCompletionAction.QuitWithFailure:
|
||||
// // friendlyName = JobSR.QuitWithFailure;
|
||||
// // break;
|
||||
// // case StepCompletionAction.QuitWithSuccess:
|
||||
// // friendlyName = JobSR.QuitWithSuccess;
|
||||
// // break;
|
||||
// // case StepCompletionAction.GoToStep:
|
||||
// // STrace.Assert(targetStep != null, "Action type is goto step, but the target step is null");
|
||||
// // if (targetStep != null)
|
||||
// // {
|
||||
// // friendlyName = JobSR.GotoStep(targetStep.ID, targetStep.Name);
|
||||
// // }
|
||||
// // break;
|
||||
// // default:
|
||||
// // STrace.Assert(false, "Unknown jobstep completion action");
|
||||
// // break;
|
||||
// // }
|
||||
// return friendlyName;
|
||||
// }
|
||||
|
||||
|
||||
public void CreateJobStep()
|
||||
{
|
||||
//JobStepData data = new JobStepData(this.data.JobSteps);
|
||||
JobStepData data = this.data.JobSteps.Steps[0] as JobStepData;
|
||||
JobStepPropertySheet jsProp = new JobStepPropertySheet(this.DataContainer, data);
|
||||
|
||||
jsProp.Init();
|
||||
jsProp.Create();
|
||||
}
|
||||
}
|
||||
}
|
||||
625
src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/JobStepsData.cs
Normal file
625
src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/JobStepsData.cs
Normal file
@@ -0,0 +1,625 @@
|
||||
//
|
||||
// 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;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Data;
|
||||
using System.Globalization;
|
||||
using Microsoft.SqlServer.Management.Common;
|
||||
using Microsoft.SqlServer.Management.Sdk.Sfc;
|
||||
using Microsoft.SqlServer.Management.Smo;
|
||||
using Microsoft.SqlServer.Management.Smo.Agent;
|
||||
using Microsoft.SqlTools.ServiceLayer.Admin;
|
||||
using SMO = Microsoft.SqlServer.Management.Smo;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
internal class JobStepsData
|
||||
{
|
||||
#region fields
|
||||
/// <summary>
|
||||
/// collection of job steps.
|
||||
/// </summary>
|
||||
private ArrayList jobSteps;
|
||||
/// <summary>
|
||||
/// List of job steps to be deleted
|
||||
/// </summary>
|
||||
private ArrayList deletedJobSteps;
|
||||
/// <summary>
|
||||
/// Parent JobData
|
||||
/// </summary>
|
||||
private JobData parent;
|
||||
/// <summary>
|
||||
/// Server context
|
||||
/// </summary>
|
||||
private CDataContainer context;
|
||||
/// <summary>
|
||||
/// Start Step
|
||||
/// </summary>
|
||||
private JobStepData startStep;
|
||||
/// <summary>
|
||||
/// list of available databases
|
||||
/// </summary>
|
||||
private string[] databases = null;
|
||||
#endregion
|
||||
|
||||
#region public properties
|
||||
/// <summary>
|
||||
/// JobData structure this object is part of
|
||||
/// </summary>
|
||||
public JobData Parent
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.parent;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Server Version
|
||||
/// </summary>
|
||||
public Version Version
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.parent.Version;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Mode in which the dialog has been launched
|
||||
/// </summary>
|
||||
JobData.ActionMode Mode
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.parent != null)
|
||||
{
|
||||
return this.parent.Mode;
|
||||
}
|
||||
else
|
||||
{
|
||||
return JobData.ActionMode.Unknown;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// List of steps in this job
|
||||
/// </summary>
|
||||
public ArrayList Steps
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.jobSteps;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// The default start step
|
||||
/// </summary>
|
||||
public JobStepData StartStep
|
||||
{
|
||||
get
|
||||
{
|
||||
// we can't point to a step that is marked for deletion
|
||||
if (this.startStep != null && this.startStep.ToBeDeleted == true)
|
||||
{
|
||||
this.startStep = null;
|
||||
}
|
||||
// if the start step is null, and we have job steps, just point
|
||||
// the start step to the first one.
|
||||
if (this.startStep == null && this.jobSteps.Count > 0)
|
||||
{
|
||||
this.startStep = (JobStepData)this.jobSteps[0];
|
||||
}
|
||||
|
||||
return this.startStep;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.startStep = value;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// List of all available databases on the server
|
||||
/// </summary>
|
||||
public string[] Databases
|
||||
{
|
||||
get
|
||||
{
|
||||
CheckAndLoadDatabases();
|
||||
return this.databases;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Indicates whether or not the order of the steps has changed
|
||||
/// </summary>
|
||||
public bool HasStepOrderChanged
|
||||
{
|
||||
get
|
||||
{
|
||||
bool orderChanged = false;
|
||||
foreach (JobStepData jsd in this.jobSteps)
|
||||
{
|
||||
if (jsd.StepIdChanged == true)
|
||||
{
|
||||
orderChanged = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return orderChanged;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Indicates whether or not the Job is read only
|
||||
/// </summary>
|
||||
public bool IsReadOnly
|
||||
{
|
||||
get { return parent.IsReadOnly; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
public event EventHandler StepOrderChanged;
|
||||
#endregion
|
||||
|
||||
#region construction
|
||||
/// <summary>
|
||||
/// Create a new JobStepsData object with a new job step
|
||||
/// </summary>
|
||||
/// <param name="context">server context</param>
|
||||
/// <param name="script">script for the job step</param>
|
||||
/// <param name="parent">owning data object</param>
|
||||
public JobStepsData(CDataContainer context, string script, JobData parent)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException("context");
|
||||
}
|
||||
if (script == null)
|
||||
{
|
||||
throw new ArgumentNullException("strint");
|
||||
}
|
||||
if (parent == null)
|
||||
{
|
||||
throw new ArgumentNullException("parent");
|
||||
}
|
||||
CommonInit(context, parent, script);
|
||||
}
|
||||
/// <summary>
|
||||
/// Create a new jobsteps data object
|
||||
/// </summary>
|
||||
/// <param name="context">server context</param>
|
||||
/// <param name="parent">owning data object</param>
|
||||
public JobStepsData(CDataContainer context, JobData parent)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
throw new ArgumentNullException("context");
|
||||
}
|
||||
if (parent == null)
|
||||
{
|
||||
throw new ArgumentNullException("parent");
|
||||
}
|
||||
CommonInit(context, parent, null);
|
||||
}
|
||||
/// <summary>
|
||||
/// Common initialization routines for constructrs
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <param name="parent"></param>
|
||||
/// <param name="script"></param>
|
||||
private void CommonInit(CDataContainer context, JobData parent, string script)
|
||||
{
|
||||
this.context = context;
|
||||
this.parent = parent;
|
||||
|
||||
this.deletedJobSteps = new ArrayList();
|
||||
|
||||
// if we're creating a new job
|
||||
if (this.parent.Mode != JobData.ActionMode.Edit)
|
||||
{
|
||||
SetDefaults();
|
||||
if (script != null && script.Length != 0)
|
||||
{
|
||||
LoadFromScript(script);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// load the JobStep objects
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public methods
|
||||
/// <summary>
|
||||
/// Add a new existing step to the end of the job step collection
|
||||
/// </summary>
|
||||
/// <param name="step"></param>
|
||||
public void AddStep(JobStepData step)
|
||||
{
|
||||
this.jobSteps.Add(step);
|
||||
RecalculateStepIds();
|
||||
}
|
||||
/// <summary>
|
||||
/// Insert a jobstep into an existing location
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
/// <param name="step"></param>
|
||||
public void InsertStep(int index, JobStepData step)
|
||||
{
|
||||
this.jobSteps.Insert(index, step);
|
||||
RecalculateStepIds();
|
||||
}
|
||||
/// <summary>
|
||||
/// Delete a jobstep
|
||||
/// </summary>
|
||||
/// <param name="step"></param>
|
||||
public void DeleteStep(JobStepData step)
|
||||
{
|
||||
if (step == null)
|
||||
{
|
||||
throw new ArgumentNullException("step");
|
||||
}
|
||||
if (this.jobSteps.Contains(step))
|
||||
{
|
||||
this.jobSteps.Remove(step);
|
||||
// make a note to delete the step
|
||||
this.deletedJobSteps.Add(step);
|
||||
step.ToBeDeleted = true;
|
||||
}
|
||||
RecalculateStepIds();
|
||||
}
|
||||
/// <summary>
|
||||
/// Get a JobStepData object for a step id
|
||||
/// </summary>
|
||||
/// <param name="stepId"></param>
|
||||
/// <returns></returns>
|
||||
public JobStepData GetObjectForStep(int stepId)
|
||||
{
|
||||
JobStepData jobStep = null;
|
||||
|
||||
if (this.jobSteps != null)
|
||||
{
|
||||
foreach (JobStepData jsd in this.jobSteps)
|
||||
{
|
||||
if (jsd.ID == stepId)
|
||||
{
|
||||
jobStep = jsd;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return jobStep;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check for any job steps that are unreachable.
|
||||
/// Because there are only two paths and we don't care about circular references
|
||||
/// we can use a simplified search, rather than a full graph dfs or bfs.
|
||||
/// </summary>
|
||||
/// <returns>List of unreachable steps, or an empty list if there are none</returns>
|
||||
public List<JobStepData> FindUnreachableJobSteps()
|
||||
{
|
||||
// array used to keep track of whether or not a step is reachable
|
||||
bool[] stepReachable = new bool[this.jobSteps.Count];
|
||||
|
||||
// mark the start step as reachable
|
||||
if (this.startStep != null && this.startStep.ID > 0 && this.startStep.ID <= this.jobSteps.Count)
|
||||
{
|
||||
stepReachable[this.startStep.ID - 1] = true;
|
||||
}
|
||||
|
||||
// steps indexes start at 1
|
||||
foreach (JobStepData step in this.jobSteps)
|
||||
{
|
||||
// check success actions
|
||||
if (step.SuccessAction == StepCompletionAction.GoToNextStep)
|
||||
{
|
||||
// if we aren't on the last step mark the next step as valid
|
||||
if (step.ID < this.jobSteps.Count)
|
||||
{
|
||||
stepReachable[step.ID] = true;
|
||||
}
|
||||
}
|
||||
else if (step.SuccessAction == StepCompletionAction.GoToStep)
|
||||
{
|
||||
if (step.SuccessStep != null && step.SuccessStep.ID <= this.jobSteps.Count)
|
||||
{
|
||||
stepReachable[step.SuccessStep.ID - 1] = true;
|
||||
}
|
||||
}
|
||||
|
||||
// check failure actions
|
||||
if (step.FailureAction == StepCompletionAction.GoToNextStep)
|
||||
{
|
||||
// if we aren't on the last step mark the next step as valid
|
||||
if (step.ID < this.jobSteps.Count)
|
||||
{
|
||||
stepReachable[step.ID] = true;
|
||||
}
|
||||
}
|
||||
else if (step.FailureAction == StepCompletionAction.GoToStep)
|
||||
{
|
||||
if (step.FailStep != null && step.FailStep.ID <= this.jobSteps.Count)
|
||||
{
|
||||
stepReachable[step.FailStep.ID - 1] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// walk through the array indicating if a step is reachable, and
|
||||
// add any that are not to the list of unreachable steps
|
||||
List<JobStepData> unreachableSteps = new List<JobStepData>();
|
||||
for (int i = 0; i < stepReachable.Length; i++)
|
||||
{
|
||||
if (stepReachable[i] == false)
|
||||
{
|
||||
unreachableSteps.Add(this.jobSteps[i] as JobStepData);
|
||||
}
|
||||
}
|
||||
return unreachableSteps;
|
||||
}
|
||||
/// <summary>
|
||||
/// Checks to see if the Last steps success completion action will change.
|
||||
/// It will if we are editing a job, and the last steps Success Completion
|
||||
/// action is GoToNextStep
|
||||
/// </summary>
|
||||
/// <returns>true if changes will be automatically made to the last step</returns>
|
||||
public bool CheckIfLastStepCompletionActionWillChange()
|
||||
{
|
||||
bool lastStepCompletionActionWillChange = false;
|
||||
if(this.jobSteps.Count > 0)
|
||||
{
|
||||
// get the last step
|
||||
JobStepData lastStep = this.jobSteps[this.jobSteps.Count-1] as JobStepData;
|
||||
if (lastStep != null && parent.Mode == JobData.ActionMode.Edit && lastStep.SuccessAction == StepCompletionAction.GoToNextStep)
|
||||
{
|
||||
lastStepCompletionActionWillChange = true;
|
||||
}
|
||||
}
|
||||
return lastStepCompletionActionWillChange;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region private/internal helpers
|
||||
/// <summary>
|
||||
/// Recalculate the step ids of the contained job steps
|
||||
/// </summary>
|
||||
internal void RecalculateStepIds()
|
||||
{
|
||||
for (int i = 0; i < this.jobSteps.Count; i++)
|
||||
{
|
||||
JobStepData jsd = jobSteps[i] as JobStepData;
|
||||
|
||||
if (jsd != null)
|
||||
{
|
||||
jsd.ID = i + 1;
|
||||
}
|
||||
}
|
||||
OnStepOrderChanged(EventArgs.Empty);
|
||||
}
|
||||
/// <summary>
|
||||
/// Delayed loading of database information
|
||||
/// </summary>
|
||||
private void CheckAndLoadDatabases()
|
||||
{
|
||||
if (this.databases != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// load databases collection
|
||||
this.databases = new string[this.context.Server.Databases.Count];
|
||||
for (int i = 0; i < this.context.Server.Databases.Count; i++)
|
||||
{
|
||||
this.databases[i] = this.context.Server.Databases[i].Name;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// fire the StepOrderChanged event
|
||||
/// </summary>
|
||||
private void OnStepOrderChanged(EventArgs args)
|
||||
{
|
||||
if (this.StepOrderChanged != null)
|
||||
{
|
||||
this.StepOrderChanged(this, args);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// SMO job object we are manipulating
|
||||
/// </summary>
|
||||
internal Job Job
|
||||
{
|
||||
get
|
||||
{
|
||||
Job job = null;
|
||||
if (this.parent != null)
|
||||
{
|
||||
job = parent.Job;
|
||||
}
|
||||
return job;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region data loading
|
||||
/// <summary>
|
||||
/// Load a job step from a script
|
||||
/// </summary>
|
||||
/// <param name="script"></param>
|
||||
private void LoadFromScript(string script)
|
||||
{
|
||||
this.jobSteps = new ArrayList();
|
||||
JobStepData jsd = new JobStepData(this);
|
||||
jsd.Command = script;
|
||||
jsd.SubSystem = AgentSubSystem.TransactSql;
|
||||
jsd.ID = 1;
|
||||
jsd.Name = "1";
|
||||
this.jobSteps.Add(jsd);
|
||||
}
|
||||
/// <summary>
|
||||
/// Load job steps from the server
|
||||
/// </summary>
|
||||
private void LoadData()
|
||||
{
|
||||
STParameters parameters = new STParameters(this.context.Document);
|
||||
string urn = string.Empty;
|
||||
string jobIdString = string.Empty;
|
||||
parameters.GetParam("urn", ref urn);
|
||||
parameters.GetParam("jobid", ref jobIdString);
|
||||
|
||||
// save current state of default fields
|
||||
StringCollection originalFields = this.context.Server.GetDefaultInitFields(typeof(JobStep));
|
||||
|
||||
// Get all JobStep properties since the JobStepData class is going to use themn
|
||||
this.context.Server.SetDefaultInitFields(typeof(JobStep), true);
|
||||
|
||||
try
|
||||
{
|
||||
Job job = null;
|
||||
// If JobID is passed in look up by jobID
|
||||
if (!string.IsNullOrEmpty(jobIdString))
|
||||
{
|
||||
job = this.context.Server.JobServer.Jobs.ItemById(Guid.Parse(jobIdString));
|
||||
}
|
||||
else
|
||||
{
|
||||
// or use urn path to query job
|
||||
job = this.context.Server.GetSmoObject(urn) as Job;
|
||||
}
|
||||
|
||||
// load the data
|
||||
JobStepCollection steps = job.JobSteps;
|
||||
|
||||
// allocate the array list
|
||||
this.jobSteps = new ArrayList(steps.Count);
|
||||
|
||||
for (int i = 0; i < steps.Count; i++)
|
||||
{
|
||||
// add them in step id order
|
||||
int ii = 0;
|
||||
for (; ii < this.jobSteps.Count; ii++)
|
||||
{
|
||||
if (steps[i].ID < ((JobStepData)this.jobSteps[ii]).ID)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.jobSteps.Insert(ii, new JobStepData(steps[i], this));
|
||||
}
|
||||
// figure out the start step
|
||||
this.startStep = GetObjectForStep(job.StartStepID);
|
||||
|
||||
// fixup all of the jobsteps failure/completion actions
|
||||
foreach (JobStepData jobStep in this.jobSteps)
|
||||
{
|
||||
jobStep.LoadCompletionActions();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
// revert to initial default fields for this type
|
||||
this.context.Server.SetDefaultInitFields(typeof(JobStep), originalFields);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set default values for a new empty job
|
||||
/// </summary>
|
||||
private void SetDefaults()
|
||||
{
|
||||
this.jobSteps = new ArrayList();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region saving
|
||||
/// <summary>
|
||||
/// Save changes to all job steps
|
||||
/// </summary>
|
||||
/// <param name="job">owner job</param>
|
||||
/// <returns>True if any changes were saved</returns>
|
||||
public bool ApplyChanges(Job job)
|
||||
{
|
||||
bool changesMade = false;
|
||||
|
||||
if (this.IsReadOnly)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
bool scripting = this.context.Server.ConnectionContext.SqlExecutionModes == SqlExecutionModes.CaptureSql;
|
||||
// delete all of the deleted steps
|
||||
for (int i = deletedJobSteps.Count - 1; i >= 0; i--)
|
||||
{
|
||||
JobStepData step = this.deletedJobSteps[i] as JobStepData;
|
||||
if (step != null)
|
||||
{
|
||||
if (step.Created)
|
||||
{
|
||||
step.Delete();
|
||||
changesMade = true;
|
||||
}
|
||||
}
|
||||
// don't clear the list if we are just scripting the action.
|
||||
if (!scripting)
|
||||
{
|
||||
deletedJobSteps.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
|
||||
bool forceRebuildingOfSteps = HasStepOrderChanged;
|
||||
// check to see if the step id's have changed. if so we will have to
|
||||
// drop and recreate all of the steps
|
||||
if (forceRebuildingOfSteps)
|
||||
{
|
||||
for (int i = this.jobSteps.Count - 1; i >= 0; --i)
|
||||
{
|
||||
JobStepData step = this.jobSteps[i] as JobStepData;
|
||||
// only delete steps that exist on the server
|
||||
if (step.Created)
|
||||
{
|
||||
step.Delete();
|
||||
changesMade = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// update the remaining steps
|
||||
foreach (JobStepData step in this.jobSteps)
|
||||
{
|
||||
if (step.ApplyChanges(job, forceRebuildingOfSteps))
|
||||
{
|
||||
changesMade = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// update the start step
|
||||
if (StartStep == null && job.StartStepID != 0)
|
||||
{
|
||||
job.StartStepID = 0;
|
||||
changesMade = true;
|
||||
}
|
||||
else if (parent.Mode == JobData.ActionMode.Create || job.StartStepID != this.startStep.ID)
|
||||
{
|
||||
job.StartStepID = this.startStep.ID;
|
||||
job.Alter();
|
||||
changesMade = true;
|
||||
}
|
||||
|
||||
return changesMade;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,890 @@
|
||||
//
|
||||
// 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;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Data;
|
||||
using Microsoft.SqlServer.Management.Sdk.Sfc;
|
||||
using Microsoft.SqlServer.Management.Smo;
|
||||
using Microsoft.SqlServer.Management.Smo.Agent;
|
||||
using Microsoft.SqlTools.ServiceLayer.Management;
|
||||
using Microsoft.SqlTools.ServiceLayer.Admin;
|
||||
|
||||
namespace Microsoft.SqlServer.Management.SqlManagerUI
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for JobsReferencingScheduleControl.
|
||||
/// </summary>
|
||||
#if DEBUG || EXPOSE_MANAGED_INTERNALS
|
||||
public
|
||||
#else
|
||||
internal
|
||||
#endif
|
||||
class JobsReferencingScheduleControl : ManagementActionBase
|
||||
{
|
||||
#region Constants
|
||||
private static double[] columnRatios = new double[] {
|
||||
0.10,
|
||||
0.35,
|
||||
0.10,
|
||||
0.35,
|
||||
0.90
|
||||
};
|
||||
|
||||
private const int colJobSelected = 0;
|
||||
private const int colJobName = 1;
|
||||
private const int colJobEnabled = 2;
|
||||
private const int colJobCategory = 3;
|
||||
private const int colJobDescription = 4;
|
||||
|
||||
/// <summary>
|
||||
/// column that stores inside the cell.Tag and SMO Job object
|
||||
/// </summary>
|
||||
private const int colTagSmoObject = colJobName;
|
||||
#endregion
|
||||
|
||||
#region UI Variables
|
||||
// private System.Windows.Forms.Panel panelEntireUserInterface;
|
||||
// private System.Windows.Forms.Label labelStaticSchedule;
|
||||
// private System.Windows.Forms.TextBox textBoxSchedule;
|
||||
// private System.Windows.Forms.Label labelStaticSelectJobs;
|
||||
// private System.Windows.Forms.Panel panelGridContainer;
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.Container components = null;
|
||||
#endregion
|
||||
|
||||
#region Non-UI Variables
|
||||
private bool panelInitialized = false;
|
||||
private int m_scheduleId = -1; // used to unique identify the schedule (since duplicate schedule names are allowed)
|
||||
private string m_scheduleName = null;
|
||||
private bool m_readOnlyMode = false;
|
||||
private Urn jobUrn = null;
|
||||
#endregion
|
||||
|
||||
#region Public - ApplyChanges() , NoOfSelectedJobs
|
||||
private int m_noOfSelectedJobs = -1;
|
||||
public int NoOfSelectedJobs
|
||||
{
|
||||
get
|
||||
{
|
||||
//System.Diagnostics.Debug.Assert(m_grid != null);
|
||||
// System.Diagnostics.Debug.Assert(m_noOfSelectedJobs != -1, "ask for this property only after changes were applied");
|
||||
return m_noOfSelectedJobs;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// called by form container - tells control to apply user changes
|
||||
/// </summary>
|
||||
public void ApplyChanges()
|
||||
{
|
||||
SendDataToServer();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Constructors/Dispose
|
||||
/// <summary>
|
||||
/// constructor used so Win Forms designer can work
|
||||
/// </summary>
|
||||
public JobsReferencingScheduleControl()
|
||||
{
|
||||
// This call is required by the Windows.Forms Form Designer.
|
||||
InitializeComponent();
|
||||
|
||||
// CreateGrid();
|
||||
// InitializeGridColumns();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// initialization - passing context (server and actual schedule to be displayed)
|
||||
///
|
||||
/// urn from context points to the actual schedule being managed
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
public JobsReferencingScheduleControl(CDataContainer context)
|
||||
{
|
||||
//System.Diagnostics.Debug.Assert(context != null);
|
||||
|
||||
m_scheduleName = context.ObjectName;
|
||||
m_readOnlyMode = false;
|
||||
|
||||
DataContainer = context;
|
||||
|
||||
// InitializeComponent();
|
||||
// CreateGrid();
|
||||
|
||||
// IPanelForm ip = this as IPanelForm;
|
||||
|
||||
// ip.OnInitialization();
|
||||
// ip.OnSelection(null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// initialization - passing context (server and actual schedule to be displayed)
|
||||
///
|
||||
/// urn from context points to some generic context from which a parent dialog was launched (Manage Schedules/Schedule Properties/New Job/Job Properties)
|
||||
/// string urnSchedule points to actual schedule
|
||||
/// </summary>
|
||||
/// <param name="context">context as it came from object explorer</param>
|
||||
/// <param name="scheduleId">unique schedule id (since name cannot be used for identification - schedules can have duplicate names - e.g. the one used by Replication team)</param>
|
||||
/// <param name="scheduleName">friendly name of schedule (used for display purposes)</param>
|
||||
/// <param name="readOnlyMode">true if dialog is diplayed in read/only mode</param>
|
||||
public JobsReferencingScheduleControl(CDataContainer context, int scheduleId, string scheduleName, bool readOnlyMode)
|
||||
{
|
||||
System.Diagnostics.Debug.Assert(context != null);
|
||||
System.Diagnostics.Debug.Assert(scheduleName != null);
|
||||
System.Diagnostics.Debug.Assert(scheduleName.Length > 0);
|
||||
|
||||
m_scheduleId = scheduleId;
|
||||
m_scheduleName = scheduleName;
|
||||
m_readOnlyMode = readOnlyMode;
|
||||
|
||||
//InitializeComponent();
|
||||
//CreateGrid();
|
||||
|
||||
DataContainer = context;
|
||||
|
||||
// IPanelForm ip = this as IPanelForm;
|
||||
|
||||
// ip.OnInitialization();
|
||||
// ip.OnSelection(null);
|
||||
|
||||
// this.HelpF1Keyword = AssemblyVersionInfo.VersionHelpKeywordPrefix + ".ag.jobsreferencingaschedule.f1";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
// if (components != null)
|
||||
// {
|
||||
// components.Dispose();
|
||||
// }
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Implementation LoadData, InitProp
|
||||
/// <summary>
|
||||
/// reads context - ensures we have
|
||||
/// valid context
|
||||
/// valid server connection
|
||||
/// valid schedule name
|
||||
/// </summary>
|
||||
private void LoadData()
|
||||
{
|
||||
System.Diagnostics.Debug.Assert(DataContainer != null);
|
||||
System.Diagnostics.Debug.Assert(DataContainer.Server != null);
|
||||
System.Diagnostics.Debug.Assert(m_scheduleName != null);
|
||||
System.Diagnostics.Debug.Assert(m_scheduleId != -1);
|
||||
|
||||
string urnString = String.Empty;
|
||||
|
||||
STParameters param = new STParameters();
|
||||
param.SetDocument(DataContainer.Document);
|
||||
|
||||
param.GetParam("joburn", ref urnString);
|
||||
|
||||
if (urnString != null)
|
||||
{
|
||||
this.jobUrn = new Urn(urnString);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// create and initialize ui with real data
|
||||
/// </summary>
|
||||
private void InitProp()
|
||||
{
|
||||
// InitializeGridColumns();
|
||||
// ResetUIToInitialValues();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ResetUIToInitialValues, SendDataToServer
|
||||
/// <summary>
|
||||
/// initialize ui with data
|
||||
/// </summary>
|
||||
private void ResetUIToInitialValues()
|
||||
{
|
||||
// FillGridWithData();
|
||||
// UpdateDialogTitle();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// applies changes
|
||||
/// </summary>
|
||||
private void SendDataToServer()
|
||||
{
|
||||
// System.Diagnostics.Debug.Assert(m_grid != null);
|
||||
// System.Diagnostics.Debug.Assert(DataContainer != null);
|
||||
// System.Diagnostics.Debug.Assert(DataContainer.Server != null);
|
||||
// System.Diagnostics.Debug.Assert(DataContainer.Server.JobServer != null);
|
||||
// System.Diagnostics.Debug.Assert(DataContainer.Server.JobServer.SharedSchedules != null);
|
||||
// System.Diagnostics.Debug.Assert(m_scheduleName != null);
|
||||
// System.Diagnostics.Debug.Assert(m_scheduleId != -1);
|
||||
|
||||
// if (m_readOnlyMode == true)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// JobSchedule schedule = DataContainer.Server.JobServer.SharedSchedules.ItemById(m_scheduleId);
|
||||
// System.Diagnostics.Debug.Assert(schedule != null);
|
||||
// if (schedule == null)
|
||||
// {
|
||||
// return; // schedule deleted meanwhile
|
||||
// }
|
||||
|
||||
// m_noOfSelectedJobs = 0;
|
||||
// for (int iRow = 0; iRow < m_grid.RowsNumber; ++iRow)
|
||||
// {
|
||||
// bool isSelected = IsEmbeededCheckboxChecked(m_grid, iRow, colJobSelected);
|
||||
// bool isEnabled = IsEmbeededCheckboxChecked(m_grid, iRow, colJobEnabled);
|
||||
|
||||
// if (isSelected)
|
||||
// {
|
||||
// m_noOfSelectedJobs++;
|
||||
// }
|
||||
|
||||
// Job job = GetJobTag(m_grid, iRow);
|
||||
// bool wasSelected = GetWasSelectedTag(m_grid, iRow);
|
||||
|
||||
// bool alterRequired = false;
|
||||
|
||||
// if (isEnabled != job.IsEnabled)
|
||||
// {
|
||||
// job.IsEnabled = isEnabled;
|
||||
// alterRequired = true;
|
||||
// }
|
||||
|
||||
// if (wasSelected && !isSelected)
|
||||
// {
|
||||
// // deselect
|
||||
// // Dont remove unused schedules automatically. Let user explicitly delete it from UI if needed
|
||||
// job.RemoveSharedSchedule(schedule.ID, true);
|
||||
// alterRequired = true;
|
||||
// }
|
||||
|
||||
// if (!wasSelected && isSelected)
|
||||
// {
|
||||
// // select
|
||||
// job.AddSharedSchedule(schedule.ID);
|
||||
// alterRequired = true;
|
||||
// }
|
||||
|
||||
// if (alterRequired == true)
|
||||
// {
|
||||
// job.Alter();
|
||||
// }
|
||||
// }
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Component Designer generated code
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
// System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(JobsReferencingScheduleControl));
|
||||
// this.panelEntireUserInterface = new System.Windows.Forms.Panel();
|
||||
// this.labelStaticSchedule = new System.Windows.Forms.Label();
|
||||
// this.textBoxSchedule = new System.Windows.Forms.TextBox();
|
||||
// this.labelStaticSelectJobs = new System.Windows.Forms.Label();
|
||||
// this.panelGridContainer = new System.Windows.Forms.Panel();
|
||||
// this.panelEntireUserInterface.SuspendLayout();
|
||||
// this.SuspendLayout();
|
||||
// this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
// this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
// //
|
||||
// // panelEntireUserInterface
|
||||
// //
|
||||
// this.panelEntireUserInterface.AccessibleDescription = resources.GetString("panelEntireUserInterface.AccessibleDescription");
|
||||
// this.panelEntireUserInterface.AccessibleName = resources.GetString("panelEntireUserInterface.AccessibleName");
|
||||
// this.panelEntireUserInterface.Anchor = ((System.Windows.Forms.AnchorStyles)(resources.GetObject("panelEntireUserInterface.Anchor")));
|
||||
// this.panelEntireUserInterface.AutoScroll = ((bool)(resources.GetObject("panelEntireUserInterface.AutoScroll")));
|
||||
// this.panelEntireUserInterface.AutoScrollMargin = ((System.Drawing.Size)(resources.GetObject("panelEntireUserInterface.AutoScrollMargin")));
|
||||
// this.panelEntireUserInterface.AutoScrollMinSize = ((System.Drawing.Size)(resources.GetObject("panelEntireUserInterface.AutoScrollMinSize")));
|
||||
// this.panelEntireUserInterface.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("panelEntireUserInterface.BackgroundImage")));
|
||||
// this.panelEntireUserInterface.Controls.Add(this.panelGridContainer);
|
||||
// this.panelEntireUserInterface.Controls.Add(this.labelStaticSelectJobs);
|
||||
// this.panelEntireUserInterface.Controls.Add(this.textBoxSchedule);
|
||||
// this.panelEntireUserInterface.Controls.Add(this.labelStaticSchedule);
|
||||
// this.panelEntireUserInterface.Dock = ((System.Windows.Forms.DockStyle)(resources.GetObject("panelEntireUserInterface.Dock")));
|
||||
// this.panelEntireUserInterface.Enabled = ((bool)(resources.GetObject("panelEntireUserInterface.Enabled")));
|
||||
// this.panelEntireUserInterface.Font = ((System.Drawing.Font)(resources.GetObject("panelEntireUserInterface.Font")));
|
||||
// this.panelEntireUserInterface.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("panelEntireUserInterface.ImeMode")));
|
||||
// this.panelEntireUserInterface.Location = ((System.Drawing.Point)(resources.GetObject("panelEntireUserInterface.Location")));
|
||||
// this.panelEntireUserInterface.Name = "panelEntireUserInterface";
|
||||
// this.panelEntireUserInterface.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("panelEntireUserInterface.RightToLeft")));
|
||||
// this.panelEntireUserInterface.Size = ((System.Drawing.Size)(resources.GetObject("panelEntireUserInterface.Size")));
|
||||
// this.panelEntireUserInterface.TabIndex = ((int)(resources.GetObject("panelEntireUserInterface.TabIndex")));
|
||||
// this.panelEntireUserInterface.Text = resources.GetString("panelEntireUserInterface.Text");
|
||||
// this.panelEntireUserInterface.Visible = ((bool)(resources.GetObject("panelEntireUserInterface.Visible")));
|
||||
// //
|
||||
// // labelStaticSchedule
|
||||
// //
|
||||
// this.labelStaticSchedule.AccessibleDescription = resources.GetString("labelStaticSchedule.AccessibleDescription");
|
||||
// this.labelStaticSchedule.AccessibleName = resources.GetString("labelStaticSchedule.AccessibleName");
|
||||
// this.labelStaticSchedule.Anchor = ((System.Windows.Forms.AnchorStyles)(resources.GetObject("labelStaticSchedule.Anchor")));
|
||||
// this.labelStaticSchedule.AutoSize = ((bool)(resources.GetObject("labelStaticSchedule.AutoSize")));
|
||||
// this.labelStaticSchedule.Dock = ((System.Windows.Forms.DockStyle)(resources.GetObject("labelStaticSchedule.Dock")));
|
||||
// this.labelStaticSchedule.Enabled = ((bool)(resources.GetObject("labelStaticSchedule.Enabled")));
|
||||
// this.labelStaticSchedule.Font = ((System.Drawing.Font)(resources.GetObject("labelStaticSchedule.Font")));
|
||||
// this.labelStaticSchedule.Image = ((System.Drawing.Image)(resources.GetObject("labelStaticSchedule.Image")));
|
||||
// this.labelStaticSchedule.ImageAlign = ((System.Drawing.ContentAlignment)(resources.GetObject("labelStaticSchedule.ImageAlign")));
|
||||
// this.labelStaticSchedule.ImageIndex = ((int)(resources.GetObject("labelStaticSchedule.ImageIndex")));
|
||||
// this.labelStaticSchedule.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("labelStaticSchedule.ImeMode")));
|
||||
// this.labelStaticSchedule.Location = ((System.Drawing.Point)(resources.GetObject("labelStaticSchedule.Location")));
|
||||
// this.labelStaticSchedule.Name = "labelStaticSchedule";
|
||||
// this.labelStaticSchedule.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("labelStaticSchedule.RightToLeft")));
|
||||
// this.labelStaticSchedule.Size = ((System.Drawing.Size)(resources.GetObject("labelStaticSchedule.Size")));
|
||||
// this.labelStaticSchedule.TabIndex = ((int)(resources.GetObject("labelStaticSchedule.TabIndex")));
|
||||
// this.labelStaticSchedule.Text = resources.GetString("labelStaticSchedule.Text");
|
||||
// this.labelStaticSchedule.TextAlign = ((System.Drawing.ContentAlignment)(resources.GetObject("labelStaticSchedule.TextAlign")));
|
||||
// this.labelStaticSchedule.Visible = ((bool)(resources.GetObject("labelStaticSchedule.Visible")));
|
||||
// //
|
||||
// // textBoxSchedule
|
||||
// //
|
||||
// this.textBoxSchedule.AccessibleDescription = resources.GetString("textBoxSchedule.AccessibleDescription");
|
||||
// this.textBoxSchedule.AccessibleName = resources.GetString("textBoxSchedule.AccessibleName");
|
||||
// this.textBoxSchedule.Anchor = ((System.Windows.Forms.AnchorStyles)(resources.GetObject("textBoxSchedule.Anchor")));
|
||||
// this.textBoxSchedule.AutoSize = ((bool)(resources.GetObject("textBoxSchedule.AutoSize")));
|
||||
// this.textBoxSchedule.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("textBoxSchedule.BackgroundImage")));
|
||||
// this.textBoxSchedule.Dock = ((System.Windows.Forms.DockStyle)(resources.GetObject("textBoxSchedule.Dock")));
|
||||
// this.textBoxSchedule.Enabled = ((bool)(resources.GetObject("textBoxSchedule.Enabled")));
|
||||
// this.textBoxSchedule.Font = ((System.Drawing.Font)(resources.GetObject("textBoxSchedule.Font")));
|
||||
// this.textBoxSchedule.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("textBoxSchedule.ImeMode")));
|
||||
// this.textBoxSchedule.Location = ((System.Drawing.Point)(resources.GetObject("textBoxSchedule.Location")));
|
||||
// this.textBoxSchedule.MaxLength = ((int)(resources.GetObject("textBoxSchedule.MaxLength")));
|
||||
// this.textBoxSchedule.Multiline = ((bool)(resources.GetObject("textBoxSchedule.Multiline")));
|
||||
// this.textBoxSchedule.Name = "textBoxSchedule";
|
||||
// this.textBoxSchedule.PasswordChar = ((char)(resources.GetObject("textBoxSchedule.PasswordChar")));
|
||||
// this.textBoxSchedule.ReadOnly = true;
|
||||
// this.textBoxSchedule.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("textBoxSchedule.RightToLeft")));
|
||||
// this.textBoxSchedule.ScrollBars = ((System.Windows.Forms.ScrollBars)(resources.GetObject("textBoxSchedule.ScrollBars")));
|
||||
// this.textBoxSchedule.Size = ((System.Drawing.Size)(resources.GetObject("textBoxSchedule.Size")));
|
||||
// this.textBoxSchedule.TabIndex = ((int)(resources.GetObject("textBoxSchedule.TabIndex")));
|
||||
// this.textBoxSchedule.Text = resources.GetString("textBoxSchedule.Text");
|
||||
// this.textBoxSchedule.TextAlign = ((System.Windows.Forms.HorizontalAlignment)(resources.GetObject("textBoxSchedule.TextAlign")));
|
||||
// this.textBoxSchedule.Visible = ((bool)(resources.GetObject("textBoxSchedule.Visible")));
|
||||
// this.textBoxSchedule.WordWrap = ((bool)(resources.GetObject("textBoxSchedule.WordWrap")));
|
||||
// //
|
||||
// // labelStaticSelectJobs
|
||||
// //
|
||||
// this.labelStaticSelectJobs.AccessibleDescription = resources.GetString("labelStaticSelectJobs.AccessibleDescription");
|
||||
// this.labelStaticSelectJobs.AccessibleName = resources.GetString("labelStaticSelectJobs.AccessibleName");
|
||||
// this.labelStaticSelectJobs.Anchor = ((System.Windows.Forms.AnchorStyles)(resources.GetObject("labelStaticSelectJobs.Anchor")));
|
||||
// this.labelStaticSelectJobs.AutoSize = ((bool)(resources.GetObject("labelStaticSelectJobs.AutoSize")));
|
||||
// this.labelStaticSelectJobs.Dock = ((System.Windows.Forms.DockStyle)(resources.GetObject("labelStaticSelectJobs.Dock")));
|
||||
// this.labelStaticSelectJobs.Enabled = ((bool)(resources.GetObject("labelStaticSelectJobs.Enabled")));
|
||||
// this.labelStaticSelectJobs.Font = ((System.Drawing.Font)(resources.GetObject("labelStaticSelectJobs.Font")));
|
||||
// this.labelStaticSelectJobs.Image = ((System.Drawing.Image)(resources.GetObject("labelStaticSelectJobs.Image")));
|
||||
// this.labelStaticSelectJobs.ImageAlign = ((System.Drawing.ContentAlignment)(resources.GetObject("labelStaticSelectJobs.ImageAlign")));
|
||||
// this.labelStaticSelectJobs.ImageIndex = ((int)(resources.GetObject("labelStaticSelectJobs.ImageIndex")));
|
||||
// this.labelStaticSelectJobs.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("labelStaticSelectJobs.ImeMode")));
|
||||
// this.labelStaticSelectJobs.Location = ((System.Drawing.Point)(resources.GetObject("labelStaticSelectJobs.Location")));
|
||||
// this.labelStaticSelectJobs.Name = "labelStaticSelectJobs";
|
||||
// this.labelStaticSelectJobs.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("labelStaticSelectJobs.RightToLeft")));
|
||||
// this.labelStaticSelectJobs.Size = ((System.Drawing.Size)(resources.GetObject("labelStaticSelectJobs.Size")));
|
||||
// this.labelStaticSelectJobs.TabIndex = ((int)(resources.GetObject("labelStaticSelectJobs.TabIndex")));
|
||||
// this.labelStaticSelectJobs.Text = resources.GetString("labelStaticSelectJobs.Text");
|
||||
// this.labelStaticSelectJobs.TextAlign = ((System.Drawing.ContentAlignment)(resources.GetObject("labelStaticSelectJobs.TextAlign")));
|
||||
// this.labelStaticSelectJobs.Visible = ((bool)(resources.GetObject("labelStaticSelectJobs.Visible")));
|
||||
// //
|
||||
// // panelGridContainer
|
||||
// //
|
||||
// this.panelGridContainer.AccessibleDescription = resources.GetString("panelGridContainer.AccessibleDescription");
|
||||
// this.panelGridContainer.AccessibleName = resources.GetString("panelGridContainer.AccessibleName");
|
||||
// this.panelGridContainer.Anchor = ((System.Windows.Forms.AnchorStyles)(resources.GetObject("panelGridContainer.Anchor")));
|
||||
// this.panelGridContainer.AutoScroll = ((bool)(resources.GetObject("panelGridContainer.AutoScroll")));
|
||||
// this.panelGridContainer.AutoScrollMargin = ((System.Drawing.Size)(resources.GetObject("panelGridContainer.AutoScrollMargin")));
|
||||
// this.panelGridContainer.AutoScrollMinSize = ((System.Drawing.Size)(resources.GetObject("panelGridContainer.AutoScrollMinSize")));
|
||||
// this.panelGridContainer.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("panelGridContainer.BackgroundImage")));
|
||||
// this.panelGridContainer.Dock = ((System.Windows.Forms.DockStyle)(resources.GetObject("panelGridContainer.Dock")));
|
||||
// this.panelGridContainer.Enabled = ((bool)(resources.GetObject("panelGridContainer.Enabled")));
|
||||
// this.panelGridContainer.Font = ((System.Drawing.Font)(resources.GetObject("panelGridContainer.Font")));
|
||||
// this.panelGridContainer.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("panelGridContainer.ImeMode")));
|
||||
// this.panelGridContainer.Location = ((System.Drawing.Point)(resources.GetObject("panelGridContainer.Location")));
|
||||
// this.panelGridContainer.Name = "panelGridContainer";
|
||||
// this.panelGridContainer.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("panelGridContainer.RightToLeft")));
|
||||
// this.panelGridContainer.Size = ((System.Drawing.Size)(resources.GetObject("panelGridContainer.Size")));
|
||||
// this.panelGridContainer.TabIndex = ((int)(resources.GetObject("panelGridContainer.TabIndex")));
|
||||
// this.panelGridContainer.Text = resources.GetString("panelGridContainer.Text");
|
||||
// this.panelGridContainer.Visible = ((bool)(resources.GetObject("panelGridContainer.Visible")));
|
||||
// //
|
||||
// // JobsReferencingScheduleControl
|
||||
// //
|
||||
// this.AccessibleDescription = resources.GetString("$this.AccessibleDescription");
|
||||
// this.AccessibleName = resources.GetString("$this.AccessibleName");
|
||||
// this.AutoScroll = ((bool)(resources.GetObject("$this.AutoScroll")));
|
||||
// this.AutoScrollMargin = ((System.Drawing.Size)(resources.GetObject("$this.AutoScrollMargin")));
|
||||
// this.AutoScrollMinSize = ((System.Drawing.Size)(resources.GetObject("$this.AutoScrollMinSize")));
|
||||
// this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
|
||||
// this.Controls.Add(this.panelEntireUserInterface);
|
||||
// this.Enabled = ((bool)(resources.GetObject("$this.Enabled")));
|
||||
// this.Font = ((System.Drawing.Font)(resources.GetObject("$this.Font")));
|
||||
// this.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("$this.ImeMode")));
|
||||
// this.Location = ((System.Drawing.Point)(resources.GetObject("$this.Location")));
|
||||
// this.Name = "JobsReferencingScheduleControl";
|
||||
// this.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("$this.RightToLeft")));
|
||||
// this.Size = ((System.Drawing.Size)(resources.GetObject("$this.Size")));
|
||||
// this.panelEntireUserInterface.ResumeLayout(false);
|
||||
// this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IPanelForm interface
|
||||
|
||||
/// <summary>
|
||||
/// interface IPanelForm
|
||||
///
|
||||
/// implementation of Panel property
|
||||
/// </summary>
|
||||
// UserControl IPanelForm.Panel
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// return this;
|
||||
// }
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// interface IPanelForm
|
||||
// ///
|
||||
// /// implementation of OnSelection
|
||||
// /// </summary>
|
||||
// void IPanelForm.OnSelection(TreeNode node)
|
||||
// {
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// interface IPanelForm
|
||||
// ///
|
||||
// /// implementation of OnPanelLoseSelection
|
||||
// /// </summary>
|
||||
// /// <param name="node"></param>
|
||||
// void IPanelForm.OnPanelLoseSelection(TreeNode node)
|
||||
// {
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// interface IPanelForm
|
||||
// ///
|
||||
// /// implementation of OnReset
|
||||
// /// </summary>
|
||||
// /// <param name="node"></param>
|
||||
// public override void OnReset(object sender)
|
||||
// {
|
||||
// base.OnReset(sender);
|
||||
// if (this.panelInitialized)
|
||||
// {
|
||||
// ResetUIToInitialValues();
|
||||
// }
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// interface IPanelForm
|
||||
// ///
|
||||
// /// implementation of OnInitialization
|
||||
// /// </summary>
|
||||
// void IPanelForm.OnInitialization()
|
||||
// {
|
||||
// if (this.panelInitialized == true)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// this.panelInitialized = true;
|
||||
// try
|
||||
// {
|
||||
// this.HelpF1Keyword = AssemblyVersionInfo.VersionHelpKeywordPrefix + ".ag.jobsreferencingaschedule.f1";
|
||||
|
||||
// LoadData();
|
||||
// InitProp();
|
||||
|
||||
// IPanelForm panelform = this as IPanelForm;
|
||||
// panelform.Panel.Enabled = true;
|
||||
// }
|
||||
// catch
|
||||
// {
|
||||
// IPanelForm panelform = this as IPanelForm;
|
||||
// panelform.Panel.Enabled = false;
|
||||
|
||||
// throw;
|
||||
// }
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// interface IPanelForm
|
||||
// ///
|
||||
// /// implementation of OnPanelRunNow
|
||||
// /// </summary>
|
||||
// /// <param name="node"></param>
|
||||
// public override void OnRunNow(object sender)
|
||||
// {
|
||||
// base.OnRunNow(sender);
|
||||
// if (this.panelInitialized)
|
||||
// {
|
||||
// SendDataToServer();
|
||||
// }
|
||||
// }
|
||||
#endregion
|
||||
|
||||
#region Grid Operations
|
||||
// private SqlManagerUIDlgGrid m_grid = null;
|
||||
|
||||
// /// <summary>
|
||||
// /// dinamically create a grid control
|
||||
// ///
|
||||
// /// normally this would have been done via winforms designer
|
||||
// /// but due to Whidbey migration we had to made it this way
|
||||
// /// </summary>
|
||||
// private void CreateGrid()
|
||||
// {
|
||||
// System.Diagnostics.Debug.Assert(m_grid == null);
|
||||
|
||||
// m_grid = new SqlManagerUIDlgGrid();
|
||||
// m_grid.Dock = DockStyle.Fill;
|
||||
// m_grid.MouseButtonClicked += new Microsoft.SqlServer.Management.UI.Grid.MouseButtonClickedEventHandler(this.grid_MouseButtonClicked);
|
||||
|
||||
// try
|
||||
// {
|
||||
// this.SuspendLayout();
|
||||
// this.panelGridContainer.SuspendLayout();
|
||||
// this.panelGridContainer.Controls.Clear();
|
||||
// this.panelGridContainer.Controls.Add(m_grid);
|
||||
// }
|
||||
// finally
|
||||
// {
|
||||
// this.panelGridContainer.ResumeLayout();
|
||||
// this.ResumeLayout();
|
||||
// }
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// initialze grid columns
|
||||
// /// </summary>
|
||||
// private void InitializeGridColumns()
|
||||
// {
|
||||
// System.Diagnostics.Debug.Assert(m_grid != null);
|
||||
// Microsoft.SqlServer.Management.SqlManagerUI.SqlManagerUIDlgGrid grid = m_grid;
|
||||
|
||||
// while (grid.ColumnsNumber != 0)
|
||||
// {
|
||||
// grid.DeleteColumn(0);
|
||||
// }
|
||||
|
||||
// GridColumnInfo colInfo = null;
|
||||
// int i = 0;
|
||||
|
||||
// foreach (double fColumnRatio in columnRatios)
|
||||
// {
|
||||
// colInfo = new GridColumnInfo();
|
||||
// colInfo.ColumnWidth = (int)((double)grid.Width * fColumnRatio);
|
||||
// colInfo.WidthType = GridColumnWidthType.InPixels;
|
||||
// switch (i)
|
||||
// {
|
||||
// case colJobSelected:
|
||||
// colInfo.ColumnType = GridColumnType.Checkbox;
|
||||
// break;
|
||||
|
||||
// case colJobEnabled:
|
||||
// colInfo.ColumnType = GridColumnType.Checkbox;
|
||||
// break;
|
||||
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
// grid.AddColumn(colInfo);
|
||||
// ++i;
|
||||
// }
|
||||
|
||||
// grid.SetHeaderInfo(colJobSelected, SR.GridHeader_JobSelected, null);
|
||||
// grid.SetHeaderInfo(colJobName, SR.GridHeader_JobName, null);
|
||||
// grid.SetHeaderInfo(colJobEnabled, SR.GridHeader_JobEnabled, null);
|
||||
// grid.SetHeaderInfo(colJobCategory, SR.GridHeader_JobCategory, null);
|
||||
// grid.SetHeaderInfo(colJobDescription, SR.GridHeader_JobDescription, null);
|
||||
|
||||
// grid.EnableSortingByColumn(colJobSelected);
|
||||
// grid.EnableSortingByColumn(colJobName);
|
||||
// grid.EnableSortingByColumn(colJobEnabled);
|
||||
// grid.EnableSortingByColumn(colJobCategory);
|
||||
// grid.EnableSortingByColumn(colJobDescription);
|
||||
|
||||
// grid.FirstScrollableColumn = colJobEnabled;
|
||||
// grid.SelectionType = GridSelectionType.SingleRow;
|
||||
// grid.UpdateGrid();
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// fills grid with data
|
||||
// ///
|
||||
// /// iterates the available jobs and if they reference the schedule adds them to grid
|
||||
// /// </summary>
|
||||
// private void FillGridWithData()
|
||||
// {
|
||||
// System.Diagnostics.Debug.Assert(m_grid != null);
|
||||
// System.Diagnostics.Debug.Assert(m_scheduleName != null);
|
||||
// System.Diagnostics.Debug.Assert(m_scheduleName.Length > 0);
|
||||
// System.Diagnostics.Debug.Assert(m_scheduleId != -1);
|
||||
|
||||
// System.Diagnostics.Debug.Assert(DataContainer != null);
|
||||
// System.Diagnostics.Debug.Assert(DataContainer.Server != null);
|
||||
// System.Diagnostics.Debug.Assert(DataContainer.Server.JobServer != null);
|
||||
// System.Diagnostics.Debug.Assert(DataContainer.Server.JobServer.Jobs != null);
|
||||
|
||||
// Microsoft.SqlServer.Management.SqlManagerUI.SqlManagerUIDlgGrid grid = m_grid;
|
||||
|
||||
// grid.DeleteAllRows();
|
||||
|
||||
// Dictionary<Job, bool> jobs = new Dictionary<Job, bool>(DataContainer.Server.JobServer.Jobs.Count);
|
||||
|
||||
// JobSchedule schedule = DataContainer.Server.JobServer.SharedSchedules.ItemById(m_scheduleId);
|
||||
|
||||
// // if schedule object returned was null, it is possible that schedule specified in scheduledata
|
||||
// // is not yet created on server
|
||||
// if (null == schedule)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// Guid[] jobGuids = schedule.EnumJobReferences(); // Note that this call is expensive
|
||||
// // since it uses a cursor
|
||||
|
||||
// foreach (Guid guid in jobGuids)
|
||||
// {
|
||||
// Job job = DataContainer.Server.JobServer.Jobs.ItemById(guid);
|
||||
// System.Diagnostics.Debug.Assert(job != null);
|
||||
// jobs.Add(job, true);
|
||||
// }
|
||||
|
||||
// if (!m_readOnlyMode)
|
||||
// {
|
||||
// // If we're not in readonly mode, we need to list all jobs.
|
||||
// // ensure we have latest info - what are the available jobs
|
||||
// DataContainer.Server.JobServer.Jobs.Refresh();
|
||||
// foreach (Job job in DataContainer.Server.JobServer.Jobs)
|
||||
// {
|
||||
// // If this job wasn't already in our dictionary, then we know it doesn't use
|
||||
// // this schedule. Add it as a new, unselected entry.
|
||||
// if (!jobs.ContainsKey(job))
|
||||
// {
|
||||
// jobs.Add(job, false);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// foreach (KeyValuePair<Job, bool> jobInfo in jobs)
|
||||
// {
|
||||
// AddGridRowForJob(jobInfo.Key, jobInfo.Value);
|
||||
// }
|
||||
|
||||
// m_grid.SortByColumn(colJobName, SortingColumnState.Ascending);
|
||||
|
||||
// if ((grid.SelectedRow < 0) && (grid.RowsNumber > 0))
|
||||
// {
|
||||
// grid.SelectedRow = 0;
|
||||
// }
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// adds a new row to the grid
|
||||
// /// </summary>
|
||||
// private void AddGridRowForJob(Job job, bool selected)
|
||||
// {
|
||||
// System.Diagnostics.Debug.Assert(m_grid != null);
|
||||
// System.Diagnostics.Debug.Assert(job != null);
|
||||
|
||||
// if (selected == false && m_readOnlyMode == true)
|
||||
// {
|
||||
// // in read-only mode we display only jobs that
|
||||
// // are referencing schedule dialog
|
||||
// return;
|
||||
// }
|
||||
|
||||
// Microsoft.SqlServer.Management.SqlManagerUI.SqlManagerUIDlgGrid grid = m_grid;
|
||||
|
||||
// GridCellCollection row = new GridCellCollection();
|
||||
// GridCell cell;
|
||||
|
||||
// if (job.Urn == this.jobUrn)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// cell = new GridCell
|
||||
// (
|
||||
// (m_readOnlyMode == true) ?
|
||||
// (selected ? GridCheckBoxState.Indeterminate : GridCheckBoxState.Disabled) :
|
||||
// (selected ? GridCheckBoxState.Checked : GridCheckBoxState.Unchecked)
|
||||
// );
|
||||
// cell.Tag = selected ? job : null; row.Add(cell); // selected (all by default) - TAGGED with initial selected value
|
||||
// cell = new GridCell(job.Name); cell.Tag = job; row.Add(cell); // name - TAGGED with Job object
|
||||
// cell = new GridCell
|
||||
// (
|
||||
// (m_readOnlyMode == true) ?
|
||||
// (job.IsEnabled ? GridCheckBoxState.Indeterminate : GridCheckBoxState.Disabled) :
|
||||
// (job.IsEnabled ? GridCheckBoxState.Checked : GridCheckBoxState.Unchecked)
|
||||
// );
|
||||
// row.Add(cell); // enabled
|
||||
|
||||
// LocalizableCategory catLocalized = new LocalizableCategory(job.CategoryID, job.Category);
|
||||
// cell = new GridCell(catLocalized.Name); row.Add(cell); // category
|
||||
// cell = new GridCell(job.Description); row.Add(cell); // description
|
||||
|
||||
// grid.AddRow(row);
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// flips on/off checkboxes from grid
|
||||
// /// </summary>
|
||||
// /// <param name="rowsno"></param>
|
||||
// /// <param name="colno"></param>
|
||||
// void FlipCheckbox(SqlManagerUIDlgGrid grid, int rowno, int colno)
|
||||
// {
|
||||
// // get the storage for the cell
|
||||
// GridCell cell = grid.GetCellInfo(rowno, colno);
|
||||
// GridCheckBoxState state = (GridCheckBoxState)cell.CellData;
|
||||
|
||||
// // explicitly invert the cell state
|
||||
// switch (state)
|
||||
// {
|
||||
// case GridCheckBoxState.Checked:
|
||||
// cell.CellData = GridCheckBoxState.Unchecked;
|
||||
// break;
|
||||
|
||||
// case GridCheckBoxState.Unchecked:
|
||||
// cell.CellData = GridCheckBoxState.Checked;
|
||||
// break;
|
||||
|
||||
// case GridCheckBoxState.Indeterminate:
|
||||
// cell.CellData = GridCheckBoxState.Checked;
|
||||
// break;
|
||||
|
||||
// case GridCheckBoxState.None:
|
||||
// break;
|
||||
|
||||
// default:
|
||||
// System.Diagnostics.Debug.Assert(false, "unknown checkbox state");
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// gets status of checkbox
|
||||
// /// </summary>
|
||||
// /// <param name="grid"></param>
|
||||
// /// <param name="rowno"></param>
|
||||
// /// <param name="colno"></param>
|
||||
// /// <returns></returns>
|
||||
// bool IsEmbeededCheckboxChecked(SqlManagerUIDlgGrid grid, int rowno, int colno)
|
||||
// {
|
||||
// // get the storage for the cell
|
||||
// GridCell cell = grid.GetCellInfo(rowno, colno);
|
||||
// GridCheckBoxState state = (GridCheckBoxState)cell.CellData;
|
||||
|
||||
// return (state == GridCheckBoxState.Checked);
|
||||
// }
|
||||
|
||||
// Job GetJobTag(Microsoft.SqlServer.Management.SqlManagerUI.SqlManagerUIDlgGrid grid, int iRow)
|
||||
// {
|
||||
// System.Diagnostics.Debug.Assert(grid != null);
|
||||
// System.Diagnostics.Debug.Assert(iRow >= 0);
|
||||
// System.Diagnostics.Debug.Assert(iRow < grid.RowsNumber);
|
||||
|
||||
// GridCell cell = grid.GetCellInfo(iRow, colTagSmoObject);
|
||||
|
||||
// System.Diagnostics.Debug.Assert(cell != null);
|
||||
// System.Diagnostics.Debug.Assert(cell.Tag != null);
|
||||
|
||||
// Job job = cell.Tag as Job;
|
||||
|
||||
// System.Diagnostics.Debug.Assert(job != null);
|
||||
// return job;
|
||||
// }
|
||||
|
||||
// bool GetWasSelectedTag(Microsoft.SqlServer.Management.SqlManagerUI.SqlManagerUIDlgGrid grid, int iRow)
|
||||
// {
|
||||
// System.Diagnostics.Debug.Assert(grid != null);
|
||||
// System.Diagnostics.Debug.Assert(iRow >= 0);
|
||||
// System.Diagnostics.Debug.Assert(iRow < grid.RowsNumber);
|
||||
|
||||
// GridCell cell = grid.GetCellInfo(iRow, colJobSelected);
|
||||
|
||||
// System.Diagnostics.Debug.Assert(cell != null);
|
||||
|
||||
// object o = cell.Tag;
|
||||
// return o != null;
|
||||
// }
|
||||
#endregion
|
||||
|
||||
#region Grid Events
|
||||
/// <summary>
|
||||
/// user clicked - we flip checkboxes
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="args"></param>
|
||||
// private void grid_MouseButtonClicked(object sender, Microsoft.SqlServer.Management.UI.Grid.MouseButtonClickedEventArgs args)
|
||||
// {
|
||||
// System.Diagnostics.Debug.Assert(m_grid != null);
|
||||
// Microsoft.SqlServer.Management.SqlManagerUI.SqlManagerUIDlgGrid grid = m_grid;
|
||||
|
||||
// if (args.Button != MouseButtons.Left)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// if (m_readOnlyMode == true)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// int rowno = Convert.ToInt32(args.RowIndex);
|
||||
// int colno = Convert.ToInt32(args.ColumnIndex);
|
||||
|
||||
// switch (colno)
|
||||
// {
|
||||
// case colJobSelected: // flip checkbox
|
||||
// FlipCheckbox(grid, rowno, colno);
|
||||
// break;
|
||||
|
||||
// case colJobEnabled: // flip checkbox
|
||||
// FlipCheckbox(grid, rowno, colno);
|
||||
// break;
|
||||
|
||||
// default: // else do default action: e.g. edit - open combo - etc ...
|
||||
// // grid.StartCellEdit(rowno,colno);
|
||||
// // grid.OnMouseButtonClicked(rowno, colno, args.CellRect, args.Button);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
#endregion
|
||||
|
||||
#region Helpers
|
||||
// private void UpdateDialogTitle()
|
||||
// {
|
||||
// System.Diagnostics.Debug.Assert(m_scheduleName != null);
|
||||
// System.Diagnostics.Debug.Assert(m_scheduleId != -1);
|
||||
|
||||
// this.Text = SR.DialogTitle_JobsReferencingSchedule(m_scheduleName);
|
||||
// this.textBoxSchedule.Text = m_scheduleName;
|
||||
// }
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,447 @@
|
||||
//
|
||||
// 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.Drawing;
|
||||
using System.Collections;
|
||||
using System.ComponentModel;
|
||||
using Microsoft.SqlServer.Management.Smo.Agent;
|
||||
using Microsoft.SqlTools.ServiceLayer.Admin;
|
||||
|
||||
namespace Microsoft.SqlServer.Management.SqlManagerUI
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for JobsRefrencingScheduleForm.
|
||||
/// </summary>
|
||||
#if DEBUG || EXPOSE_MANAGED_INTERNALS
|
||||
public
|
||||
#else
|
||||
internal
|
||||
#endif
|
||||
class JobsReferencingScheduleForm
|
||||
{
|
||||
#region UI Variables
|
||||
|
||||
// private System.Windows.Forms.Panel panelContainer;
|
||||
// private Microsoft.SqlServer.Management.Controls.Separator separatorContainerFromButtons;
|
||||
// private System.Windows.Forms.Button buttonHelp;
|
||||
// private System.Windows.Forms.Button buttonOK;
|
||||
// private System.Windows.Forms.Button buttonCancel;
|
||||
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.Container components = null;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Other Variables
|
||||
|
||||
private JobsReferencingScheduleControl m_innerControl = null;
|
||||
private IServiceProvider m_serviceProvider = null;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public
|
||||
|
||||
public int NoOfSelectedJobs
|
||||
{
|
||||
get
|
||||
{
|
||||
System.Diagnostics.Debug.Assert(m_innerControl != null);
|
||||
// System.Diagnostics.Debug.Assert(this.DialogResult == DialogResult.OK,
|
||||
// "property meaningfull only if dialog dismised with OK");
|
||||
return m_innerControl.NoOfSelectedJobs;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors/Dispose
|
||||
|
||||
/// <summary>
|
||||
/// constructor used so WinForms designer can work
|
||||
/// </summary>
|
||||
public JobsReferencingScheduleForm()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// actual constuctor invoked from 'ManageSchedules' dialog
|
||||
/// </summary>
|
||||
/// <param name="context">context describing connection used, etc - similar with context in dbCommanders</param>
|
||||
/// <param name="scheduleId">shared schedule id (used to unique identify the shared schedule since duplicate names are possible)</param>
|
||||
/// <param name="scheduleName">shared schedule for which we should display the jobs (used for display purposes)</param>
|
||||
/// <param name="readOnlyMode">true if we dont allow user to modify data</param>
|
||||
/// <param name="svcProvider">provider used to show help, msg boxes, etc</param>
|
||||
public JobsReferencingScheduleForm(CDataContainer context, int scheduleId, string scheduleName,
|
||||
bool readOnlyMode, IServiceProvider svcProvider)
|
||||
{
|
||||
m_serviceProvider = svcProvider;
|
||||
|
||||
// InitializeComponent();
|
||||
// InitializeInnerUserControl(context, scheduleId, scheduleName, readOnlyMode);
|
||||
// InitializeButtonEvents();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
// /// </summary>
|
||||
// protected override void Dispose(bool disposing)
|
||||
// {
|
||||
// if (disposing)
|
||||
// {
|
||||
// if (components != null)
|
||||
// {
|
||||
// components.Dispose();
|
||||
// }
|
||||
// }
|
||||
// base.Dispose(disposing);
|
||||
// }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
// System.Resources.ResourceManager resources =
|
||||
// new System.Resources.ResourceManager(typeof (JobsReferencingScheduleForm));
|
||||
// this.panelContainer = new System.Windows.Forms.Panel();
|
||||
// this.separatorContainerFromButtons = new Microsoft.SqlServer.Management.Controls.Separator();
|
||||
// this.buttonHelp = new System.Windows.Forms.Button();
|
||||
// this.buttonOK = new System.Windows.Forms.Button();
|
||||
// this.buttonCancel = new System.Windows.Forms.Button();
|
||||
// this.SuspendLayout();
|
||||
// this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
// this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
// //
|
||||
// // panelContainer
|
||||
// //
|
||||
// this.panelContainer.AccessibleDescription = resources.GetString("panelContainer.AccessibleDescription");
|
||||
// this.panelContainer.AccessibleName = resources.GetString("panelContainer.AccessibleName");
|
||||
// this.panelContainer.Anchor =
|
||||
// ((System.Windows.Forms.AnchorStyles) (resources.GetObject("panelContainer.Anchor")));
|
||||
// this.panelContainer.AutoScroll = ((bool) (resources.GetObject("panelContainer.AutoScroll")));
|
||||
// this.panelContainer.AutoScrollMargin =
|
||||
// ((System.Drawing.Size) (resources.GetObject("panelContainer.AutoScrollMargin")));
|
||||
// this.panelContainer.AutoScrollMinSize =
|
||||
// ((System.Drawing.Size) (resources.GetObject("panelContainer.AutoScrollMinSize")));
|
||||
// this.panelContainer.BackgroundImage =
|
||||
// ((System.Drawing.Image) (resources.GetObject("panelContainer.BackgroundImage")));
|
||||
// this.panelContainer.Dock = ((System.Windows.Forms.DockStyle) (resources.GetObject("panelContainer.Dock")));
|
||||
// this.panelContainer.Enabled = ((bool) (resources.GetObject("panelContainer.Enabled")));
|
||||
// this.panelContainer.Font = ((System.Drawing.Font) (resources.GetObject("panelContainer.Font")));
|
||||
// this.panelContainer.ImeMode =
|
||||
// ((System.Windows.Forms.ImeMode) (resources.GetObject("panelContainer.ImeMode")));
|
||||
// this.panelContainer.Location = ((System.Drawing.Point) (resources.GetObject("panelContainer.Location")));
|
||||
// this.panelContainer.Name = "panelContainer";
|
||||
// this.panelContainer.RightToLeft =
|
||||
// ((System.Windows.Forms.RightToLeft) (resources.GetObject("panelContainer.RightToLeft")));
|
||||
// this.panelContainer.Size = ((System.Drawing.Size) (resources.GetObject("panelContainer.Size")));
|
||||
// this.panelContainer.TabIndex = ((int) (resources.GetObject("panelContainer.TabIndex")));
|
||||
// this.panelContainer.Text = resources.GetString("panelContainer.Text");
|
||||
// this.panelContainer.Visible = ((bool) (resources.GetObject("panelContainer.Visible")));
|
||||
// //
|
||||
// // separatorContainerFromButtons
|
||||
// //
|
||||
// this.separatorContainerFromButtons.AccessibleDescription =
|
||||
// resources.GetString("separatorContainerFromButtons.AccessibleDescription");
|
||||
// this.separatorContainerFromButtons.AccessibleName =
|
||||
// resources.GetString("separatorContainerFromButtons.AccessibleName");
|
||||
// this.separatorContainerFromButtons.Anchor =
|
||||
// ((System.Windows.Forms.AnchorStyles) (resources.GetObject("separatorContainerFromButtons.Anchor")));
|
||||
// this.separatorContainerFromButtons.AutoSize =
|
||||
// ((bool) (resources.GetObject("separatorContainerFromButtons.AutoSize")));
|
||||
// this.separatorContainerFromButtons.Dock =
|
||||
// ((System.Windows.Forms.DockStyle) (resources.GetObject("separatorContainerFromButtons.Dock")));
|
||||
// this.separatorContainerFromButtons.Enabled =
|
||||
// ((bool) (resources.GetObject("separatorContainerFromButtons.Enabled")));
|
||||
// this.separatorContainerFromButtons.Font =
|
||||
// ((System.Drawing.Font) (resources.GetObject("separatorContainerFromButtons.Font")));
|
||||
// this.separatorContainerFromButtons.ImeMode =
|
||||
// ((System.Windows.Forms.ImeMode) (resources.GetObject("separatorContainerFromButtons.ImeMode")));
|
||||
// this.separatorContainerFromButtons.Location =
|
||||
// ((System.Drawing.Point) (resources.GetObject("separatorContainerFromButtons.Location")));
|
||||
// this.separatorContainerFromButtons.Name = "separatorContainerFromButtons";
|
||||
// this.separatorContainerFromButtons.RightToLeft =
|
||||
// ((System.Windows.Forms.RightToLeft) (resources.GetObject("separatorContainerFromButtons.RightToLeft")));
|
||||
// this.separatorContainerFromButtons.Size =
|
||||
// ((System.Drawing.Size) (resources.GetObject("separatorContainerFromButtons.Size")));
|
||||
// this.separatorContainerFromButtons.TabIndex =
|
||||
// ((int) (resources.GetObject("separatorContainerFromButtons.TabIndex")));
|
||||
// this.separatorContainerFromButtons.Text = resources.GetString("separatorContainerFromButtons.Text");
|
||||
// this.separatorContainerFromButtons.TextAlign =
|
||||
// ((System.Drawing.ContentAlignment) (resources.GetObject("separatorContainerFromButtons.TextAlign")));
|
||||
// this.separatorContainerFromButtons.Visible =
|
||||
// ((bool) (resources.GetObject("separatorContainerFromButtons.Visible")));
|
||||
// //
|
||||
// // buttonHelp
|
||||
// //
|
||||
// this.buttonHelp.AccessibleDescription = resources.GetString("buttonHelp.AccessibleDescription");
|
||||
// this.buttonHelp.AccessibleName = resources.GetString("buttonHelp.AccessibleName");
|
||||
// this.buttonHelp.Anchor = ((System.Windows.Forms.AnchorStyles) (resources.GetObject("buttonHelp.Anchor")));
|
||||
// this.buttonHelp.BackgroundImage =
|
||||
// ((System.Drawing.Image) (resources.GetObject("buttonHelp.BackgroundImage")));
|
||||
// this.buttonHelp.Dock = ((System.Windows.Forms.DockStyle) (resources.GetObject("buttonHelp.Dock")));
|
||||
// this.buttonHelp.Enabled = ((bool) (resources.GetObject("buttonHelp.Enabled")));
|
||||
// this.buttonHelp.FlatStyle = ((System.Windows.Forms.FlatStyle) (resources.GetObject("buttonHelp.FlatStyle")));
|
||||
// this.buttonHelp.Font = ((System.Drawing.Font) (resources.GetObject("buttonHelp.Font")));
|
||||
// this.buttonHelp.Image = ((System.Drawing.Image) (resources.GetObject("buttonHelp.Image")));
|
||||
// this.buttonHelp.ImageAlign =
|
||||
// ((System.Drawing.ContentAlignment) (resources.GetObject("buttonHelp.ImageAlign")));
|
||||
// this.buttonHelp.ImageIndex = ((int) (resources.GetObject("buttonHelp.ImageIndex")));
|
||||
// this.buttonHelp.ImeMode = ((System.Windows.Forms.ImeMode) (resources.GetObject("buttonHelp.ImeMode")));
|
||||
// this.buttonHelp.Location = ((System.Drawing.Point) (resources.GetObject("buttonHelp.Location")));
|
||||
// this.buttonHelp.Name = "buttonHelp";
|
||||
// this.buttonHelp.RightToLeft =
|
||||
// ((System.Windows.Forms.RightToLeft) (resources.GetObject("buttonHelp.RightToLeft")));
|
||||
// this.buttonHelp.Size = ((System.Drawing.Size) (resources.GetObject("buttonHelp.Size")));
|
||||
// this.buttonHelp.TabIndex = ((int) (resources.GetObject("buttonHelp.TabIndex")));
|
||||
// this.buttonHelp.Text = resources.GetString("buttonHelp.Text");
|
||||
// this.buttonHelp.TextAlign =
|
||||
// ((System.Drawing.ContentAlignment) (resources.GetObject("buttonHelp.TextAlign")));
|
||||
// this.buttonHelp.Visible = ((bool) (resources.GetObject("buttonHelp.Visible")));
|
||||
// //
|
||||
// // buttonOK
|
||||
// //
|
||||
// this.buttonOK.AccessibleDescription = resources.GetString("buttonOK.AccessibleDescription");
|
||||
// this.buttonOK.AccessibleName = resources.GetString("buttonOK.AccessibleName");
|
||||
// this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles) (resources.GetObject("buttonOK.Anchor")));
|
||||
// this.buttonOK.BackgroundImage = ((System.Drawing.Image) (resources.GetObject("buttonOK.BackgroundImage")));
|
||||
// this.buttonOK.Dock = ((System.Windows.Forms.DockStyle) (resources.GetObject("buttonOK.Dock")));
|
||||
// this.buttonOK.Enabled = ((bool) (resources.GetObject("buttonOK.Enabled")));
|
||||
// this.buttonOK.FlatStyle = ((System.Windows.Forms.FlatStyle) (resources.GetObject("buttonOK.FlatStyle")));
|
||||
// this.buttonOK.Font = ((System.Drawing.Font) (resources.GetObject("buttonOK.Font")));
|
||||
// this.buttonOK.Image = ((System.Drawing.Image) (resources.GetObject("buttonOK.Image")));
|
||||
// this.buttonOK.ImageAlign = ((System.Drawing.ContentAlignment) (resources.GetObject("buttonOK.ImageAlign")));
|
||||
// this.buttonOK.ImageIndex = ((int) (resources.GetObject("buttonOK.ImageIndex")));
|
||||
// this.buttonOK.ImeMode = ((System.Windows.Forms.ImeMode) (resources.GetObject("buttonOK.ImeMode")));
|
||||
// this.buttonOK.Location = ((System.Drawing.Point) (resources.GetObject("buttonOK.Location")));
|
||||
// this.buttonOK.Name = "buttonOK";
|
||||
// this.buttonOK.RightToLeft =
|
||||
// ((System.Windows.Forms.RightToLeft) (resources.GetObject("buttonOK.RightToLeft")));
|
||||
// this.buttonOK.Size = ((System.Drawing.Size) (resources.GetObject("buttonOK.Size")));
|
||||
// this.buttonOK.TabIndex = ((int) (resources.GetObject("buttonOK.TabIndex")));
|
||||
// this.buttonOK.Text = resources.GetString("buttonOK.Text");
|
||||
// this.buttonOK.TextAlign = ((System.Drawing.ContentAlignment) (resources.GetObject("buttonOK.TextAlign")));
|
||||
// this.buttonOK.Visible = ((bool) (resources.GetObject("buttonOK.Visible")));
|
||||
// //
|
||||
// // buttonCancel
|
||||
// //
|
||||
// this.buttonCancel.AccessibleDescription = resources.GetString("buttonCancel.AccessibleDescription");
|
||||
// this.buttonCancel.AccessibleName = resources.GetString("buttonCancel.AccessibleName");
|
||||
// this.buttonCancel.Anchor =
|
||||
// ((System.Windows.Forms.AnchorStyles) (resources.GetObject("buttonCancel.Anchor")));
|
||||
// this.buttonCancel.BackgroundImage =
|
||||
// ((System.Drawing.Image) (resources.GetObject("buttonCancel.BackgroundImage")));
|
||||
// this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
|
||||
// this.buttonCancel.Dock = ((System.Windows.Forms.DockStyle) (resources.GetObject("buttonCancel.Dock")));
|
||||
// this.buttonCancel.Enabled = ((bool) (resources.GetObject("buttonCancel.Enabled")));
|
||||
// this.buttonCancel.FlatStyle =
|
||||
// ((System.Windows.Forms.FlatStyle) (resources.GetObject("buttonCancel.FlatStyle")));
|
||||
// this.buttonCancel.Font = ((System.Drawing.Font) (resources.GetObject("buttonCancel.Font")));
|
||||
// this.buttonCancel.Image = ((System.Drawing.Image) (resources.GetObject("buttonCancel.Image")));
|
||||
// this.buttonCancel.ImageAlign =
|
||||
// ((System.Drawing.ContentAlignment) (resources.GetObject("buttonCancel.ImageAlign")));
|
||||
// this.buttonCancel.ImageIndex = ((int) (resources.GetObject("buttonCancel.ImageIndex")));
|
||||
// this.buttonCancel.ImeMode = ((System.Windows.Forms.ImeMode) (resources.GetObject("buttonCancel.ImeMode")));
|
||||
// this.buttonCancel.Location = ((System.Drawing.Point) (resources.GetObject("buttonCancel.Location")));
|
||||
// this.buttonCancel.Name = "buttonCancel";
|
||||
// this.buttonCancel.RightToLeft =
|
||||
// ((System.Windows.Forms.RightToLeft) (resources.GetObject("buttonCancel.RightToLeft")));
|
||||
// this.buttonCancel.Size = ((System.Drawing.Size) (resources.GetObject("buttonCancel.Size")));
|
||||
// this.buttonCancel.TabIndex = ((int) (resources.GetObject("buttonCancel.TabIndex")));
|
||||
// this.buttonCancel.Text = resources.GetString("buttonCancel.Text");
|
||||
// this.buttonCancel.TextAlign =
|
||||
// ((System.Drawing.ContentAlignment) (resources.GetObject("buttonCancel.TextAlign")));
|
||||
// this.buttonCancel.Visible = ((bool) (resources.GetObject("buttonCancel.Visible")));
|
||||
// //
|
||||
// // JobsReferencingScheduleForm
|
||||
// //
|
||||
// this.AcceptButton = this.buttonOK;
|
||||
// this.AccessibleDescription = resources.GetString("$this.AccessibleDescription");
|
||||
// this.AccessibleName = resources.GetString("$this.AccessibleName");
|
||||
// this.AutoScaleBaseSize = ((System.Drawing.Size) (resources.GetObject("$this.AutoScaleBaseSize")));
|
||||
// this.AutoScroll = ((bool) (resources.GetObject("$this.AutoScroll")));
|
||||
// this.AutoScrollMargin = ((System.Drawing.Size) (resources.GetObject("$this.AutoScrollMargin")));
|
||||
// this.AutoScrollMinSize = ((System.Drawing.Size) (resources.GetObject("$this.AutoScrollMinSize")));
|
||||
// this.BackgroundImage = ((System.Drawing.Image) (resources.GetObject("$this.BackgroundImage")));
|
||||
// this.CancelButton = this.buttonCancel;
|
||||
// this.ClientSize = ((System.Drawing.Size) (resources.GetObject("$this.ClientSize")));
|
||||
// this.Controls.Add(this.buttonCancel);
|
||||
// this.Controls.Add(this.buttonOK);
|
||||
// this.Controls.Add(this.buttonHelp);
|
||||
// this.Controls.Add(this.separatorContainerFromButtons);
|
||||
// this.Controls.Add(this.panelContainer);
|
||||
// this.Enabled = ((bool) (resources.GetObject("$this.Enabled")));
|
||||
// this.Font = ((System.Drawing.Font) (resources.GetObject("$this.Font")));
|
||||
// this.Icon = ((System.Drawing.Icon) (resources.GetObject("$this.Icon")));
|
||||
// this.ImeMode = ((System.Windows.Forms.ImeMode) (resources.GetObject("$this.ImeMode")));
|
||||
// this.Location = ((System.Drawing.Point) (resources.GetObject("$this.Location")));
|
||||
// this.MaximumSize = ((System.Drawing.Size) (resources.GetObject("$this.MaximumSize")));
|
||||
// this.MinimumSize = ((System.Drawing.Size) (resources.GetObject("$this.MinimumSize")));
|
||||
// this.Name = "JobsReferencingScheduleForm";
|
||||
// this.RightToLeft = ((System.Windows.Forms.RightToLeft) (resources.GetObject("$this.RightToLeft")));
|
||||
// this.StartPosition = ((System.Windows.Forms.FormStartPosition) (resources.GetObject("$this.StartPosition")));
|
||||
// this.Text = resources.GetString("$this.Text");
|
||||
// this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Initialize Inner UserControl
|
||||
|
||||
/// <summary>
|
||||
/// used for estitic purposes only
|
||||
/// </summary>
|
||||
private void InitializeInnerUserControl()
|
||||
{
|
||||
// try
|
||||
// {
|
||||
// System.Diagnostics.Debug.Assert(m_innerControl == null, "inner control was already initialized");
|
||||
|
||||
// this.SuspendLayout();
|
||||
// this.panelContainer.SuspendLayout();
|
||||
|
||||
// System.Diagnostics.Debug.Assert(this.Parent != null);
|
||||
// if (this.Parent != null)
|
||||
// {
|
||||
// this.BackColor = Parent.BackColor;
|
||||
// this.Font = Parent.Font;
|
||||
// }
|
||||
|
||||
// m_innerControl = new JobsReferencingScheduleControl();
|
||||
// m_innerControl.Dock = DockStyle.Fill;
|
||||
|
||||
// this.panelContainer.Controls.Clear();
|
||||
// this.panelContainer.Controls.Add(m_innerControl);
|
||||
// }
|
||||
// finally
|
||||
// {
|
||||
// this.panelContainer.ResumeLayout();
|
||||
// this.ResumeLayout();
|
||||
// }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// actual initialization
|
||||
/// </summary>
|
||||
private void InitializeInnerUserControl(CDataContainer context, int scheduleId, string scheduleName,
|
||||
bool readOnlyMode)
|
||||
{
|
||||
// try
|
||||
// {
|
||||
// System.Diagnostics.Debug.Assert(m_innerControl == null, "inner control was already initialized");
|
||||
// this.SuspendLayout();
|
||||
// this.panelContainer.SuspendLayout();
|
||||
|
||||
// m_innerControl = new JobsReferencingScheduleControl(context, scheduleId, scheduleName, readOnlyMode);
|
||||
// m_innerControl.Dock = DockStyle.Fill;
|
||||
|
||||
// this.panelContainer.Controls.Clear();
|
||||
// this.panelContainer.Controls.Add(m_innerControl);
|
||||
// }
|
||||
// finally
|
||||
// {
|
||||
// this.panelContainer.ResumeLayout();
|
||||
// this.ResumeLayout();
|
||||
// }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Overrides - OnHelpRequested
|
||||
|
||||
/// <summary>
|
||||
/// hook with standard help processing
|
||||
/// </summary>
|
||||
/// <param name="hevent"></param>
|
||||
// protected override void OnHelpRequested(HelpEventArgs hevent)
|
||||
// {
|
||||
// ShowHelp();
|
||||
|
||||
// hevent.Handled = true;
|
||||
// base.OnHelpRequested(hevent);
|
||||
// }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Implementation - ShowHelp
|
||||
|
||||
// private void ShowHelp()
|
||||
// {
|
||||
// //F1 request might come in even when Help button is hidden
|
||||
// if (m_serviceProvider == null)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// string key = AssemblyVersionInfo.VersionHelpKeywordPrefix + ".ag.job.jobsreferencingaschedule.f1";
|
||||
// // pick schedule bol link
|
||||
// ILaunchFormHost2 host2 = m_serviceProvider.GetService(typeof (ILaunchFormHost2)) as ILaunchFormHost2;
|
||||
// System.Diagnostics.Debug.Assert(host2 != null,
|
||||
// "Service Provider could not provide us the ILaunchFormHost2 service required for displaying books online");
|
||||
|
||||
// if (host2 == null)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// host2.ShowHelp(key);
|
||||
// }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Buttons Initialize / Events
|
||||
|
||||
/// <summary>
|
||||
/// normaly this shouold be handled by WinForms designer
|
||||
/// but currently Rascal and Everett designers are unusuable so hooking them manually
|
||||
/// </summary>
|
||||
// private void InitializeButtonEvents()
|
||||
// {
|
||||
// this.buttonOK.Click += new EventHandler(this.OnButtonOKClick);
|
||||
// this.buttonCancel.Click += new EventHandler(this.OnButtonCancelClick);
|
||||
// this.buttonHelp.Click += new EventHandler(this.OnButtonHelpClick);
|
||||
|
||||
// if (m_serviceProvider == null)
|
||||
// {
|
||||
// this.buttonHelp.Visible = false;
|
||||
// }
|
||||
// }
|
||||
|
||||
// private void OnButtonOKClick(object source, EventArgs args)
|
||||
// {
|
||||
// System.Diagnostics.Debug.Assert(m_innerControl != null);
|
||||
|
||||
// m_innerControl.ApplyChanges();
|
||||
|
||||
// this.DialogResult = m_innerControl.NoOfSelectedJobs != -1
|
||||
// ? DialogResult.OK
|
||||
// : DialogResult.None;
|
||||
// this.Close();
|
||||
// }
|
||||
|
||||
// private void OnButtonCancelClick(object source, EventArgs args)
|
||||
// {
|
||||
// this.DialogResult = DialogResult.Cancel;
|
||||
// this.Close();
|
||||
// }
|
||||
|
||||
// private void OnButtonHelpClick(object source, EventArgs args)
|
||||
// {
|
||||
// ShowHelp();
|
||||
// }
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
//
|
||||
// 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;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Globalization;
|
||||
using Microsoft.SqlServer.Management.Common;
|
||||
using Microsoft.SqlServer.Management.Diagnostics;
|
||||
using Microsoft.SqlServer.Management.Smo;
|
||||
using Microsoft.SqlServer.Management.Smo.Agent;
|
||||
using SMO = Microsoft.SqlServer.Management.Smo;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
/// <summary>
|
||||
/// Localizable Job category. SMO just reads the string names of
|
||||
/// job categories from msdb.dbo.sysjobcategories, which is not localized.
|
||||
/// To show localized strings in the UI we have to convert it ourselves. We will
|
||||
/// use this object to do that.
|
||||
/// </summary>
|
||||
internal class LocalizableCategory
|
||||
{
|
||||
string categoryName = String.Empty;
|
||||
JobCategory category = null;
|
||||
|
||||
public LocalizableCategory(JobCategory category)
|
||||
{
|
||||
if (category == null)
|
||||
{
|
||||
throw new ArgumentNullException("category");
|
||||
}
|
||||
|
||||
this.category = category;
|
||||
categoryName = LookupLocalizableName(category);
|
||||
}
|
||||
|
||||
public LocalizableCategory(int categoryId, string defaultName)
|
||||
{
|
||||
this.category = null;
|
||||
categoryName = LookupLocalizableName(categoryId, defaultName);
|
||||
}
|
||||
|
||||
public string Name { get { return this.categoryName; } }
|
||||
public JobCategory SmoCategory { get { return this.category; } }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return this.categoryName;
|
||||
}
|
||||
|
||||
private static string LookupLocalizableName(int categoryId, string defaultName)
|
||||
{
|
||||
string localisableCategory;
|
||||
switch (categoryId)
|
||||
{
|
||||
case 0:
|
||||
localisableCategory = "LocalizableCategorySR.CategoryLocal";
|
||||
break;
|
||||
case 1:
|
||||
localisableCategory = "LocalizableCategorySR.CategoryFromMsx";
|
||||
break;
|
||||
case 2:
|
||||
localisableCategory = "LocalizableCategorySR.CategoryMultiServer";
|
||||
break;
|
||||
case 3:
|
||||
localisableCategory = "LocalizableCategorySR.CategoryDBMaint";
|
||||
break;
|
||||
case 4:
|
||||
localisableCategory = "LocalizableCategorySR.CategoryWebAssistant";
|
||||
break;
|
||||
case 5:
|
||||
localisableCategory = "LocalizableCategorySR.CategoryFullText";
|
||||
break;
|
||||
case 6:
|
||||
localisableCategory = "LocalizableCategorySR.CategoryLogShipping";
|
||||
break;
|
||||
case 7:
|
||||
localisableCategory = "LocalizableCategorySR.CategoryDBEngineTuningAdvisor";
|
||||
break;
|
||||
case 8:
|
||||
localisableCategory = "LocalizableCategorySR.CategoryDataCollector";
|
||||
break;
|
||||
case 10:
|
||||
localisableCategory = "LocalizableCategorySR.CategoryReplDistribution";
|
||||
break;
|
||||
case 11:
|
||||
localisableCategory = "LocalizableCategorySR.CategoryReplDistributionCleanup";
|
||||
break;
|
||||
case 12:
|
||||
localisableCategory = "LocalizableCategorySR.CategoryReplHistoryCleanup";
|
||||
break;
|
||||
case 13:
|
||||
localisableCategory = "LocalizableCategorySR.CategoryReplLogReader";
|
||||
break;
|
||||
case 14:
|
||||
localisableCategory = "LocalizableCategorySR.CategoryReplMerge";
|
||||
break;
|
||||
case 15:
|
||||
localisableCategory = "LocalizableCategorySR.CategoryReplSnapShot";
|
||||
break;
|
||||
case 16:
|
||||
localisableCategory = "LocalizableCategorySR.CategoryReplCheckup";
|
||||
break;
|
||||
case 17:
|
||||
localisableCategory = "LocalizableCategorySR.CategoryReplCleanup";
|
||||
break;
|
||||
case 18:
|
||||
localisableCategory = "LocalizableCategorySR.CategoryReplAlert";
|
||||
break;
|
||||
case 19:
|
||||
localisableCategory = "LocalizableCategorySR.CategoryReplQReader";
|
||||
break;
|
||||
case 20:
|
||||
localisableCategory = "LocalizableCategorySR.CategoryReplication";
|
||||
break;
|
||||
case 98:
|
||||
case 99:
|
||||
localisableCategory = "LocalizableCategorySR.CategoryUncategorized";
|
||||
break;
|
||||
default:
|
||||
localisableCategory = defaultName;
|
||||
break;
|
||||
}
|
||||
|
||||
return localisableCategory;
|
||||
}
|
||||
|
||||
private static string LookupLocalizableName(JobCategory category)
|
||||
{
|
||||
return LookupLocalizableName(category.ID, category.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,246 @@
|
||||
//
|
||||
// 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;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Data;
|
||||
using Microsoft.SqlServer.Management.Smo;
|
||||
using Microsoft.SqlServer.Management.Smo.Agent;
|
||||
using Microsoft.SqlServer.Management.Diagnostics;
|
||||
using Microsoft.SqlTools.ServiceLayer.Admin;
|
||||
using Microsoft.SqlTools.ServiceLayer.Management;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for ManageSchedulesControl.
|
||||
/// </summary>
|
||||
internal class ManageSchedulesControl : ManagementActionBase
|
||||
{
|
||||
/// <summary>
|
||||
/// any schedules that should not be shown in the list. Used when launched from
|
||||
/// the Job dialog as we don't want to list any schedules it already uses.
|
||||
/// </summary>
|
||||
private List<int> excludedScheduleId = null;
|
||||
|
||||
/// <summary>
|
||||
/// any schedules that are attached to the job, but are slated to be removed so should have job in list
|
||||
/// count decremented
|
||||
/// </summary>
|
||||
private List<int> removedScheduleId = null;
|
||||
|
||||
/// <summary>
|
||||
/// if null we are in "manage schedules" mode (OE dbCommander)
|
||||
/// if not null we are in "pick schedule" mode (modal dialog)
|
||||
/// </summary>
|
||||
private string m_jobName = null;
|
||||
|
||||
|
||||
#region Constructors/Dispose
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// initialization - passing context (coming from parent dialog)
|
||||
///
|
||||
/// display in "Pick up a schedule for job" mode
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
public ManageSchedulesControl(CDataContainer context, string jobName)
|
||||
{
|
||||
m_jobName = jobName;
|
||||
DataContainer = context;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if(disposing)
|
||||
{
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Get the list of any schedules that should not be shown in the UI.
|
||||
/// </summary>
|
||||
private void InitializeExcludedSchedules()
|
||||
{
|
||||
if(DataContainer == null)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
string excludedIdList = string.Empty;
|
||||
string removedIdList = string.Empty;
|
||||
|
||||
STParameters param = new STParameters();
|
||||
|
||||
param.SetDocument(DataContainer.Document);
|
||||
|
||||
param.GetParam("excludedschedules", ref excludedIdList);
|
||||
param.GetParam("removedschedules", ref removedIdList);
|
||||
|
||||
excludedScheduleId = ConvertCommaSeparatedIdList(excludedIdList);
|
||||
removedScheduleId = ConvertCommaSeparatedIdList(removedIdList);
|
||||
|
||||
}
|
||||
|
||||
private List<int> ConvertCommaSeparatedIdList(string list)
|
||||
{
|
||||
List<int> idList = new List<int>();
|
||||
|
||||
if(list != null && list.Length > 0)
|
||||
{
|
||||
|
||||
string[] splidId = list.Split(',');
|
||||
|
||||
int id;
|
||||
for(int i = 0; i < splidId.Length; ++i)
|
||||
{
|
||||
if(int.TryParse(splidId[i].Trim(), out id))
|
||||
{
|
||||
idList.Add(id);
|
||||
}
|
||||
}
|
||||
idList.Sort();
|
||||
}
|
||||
return idList;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// applies changes to server
|
||||
///
|
||||
/// iterates through the grid rows (list of schedules)
|
||||
/// if [ ] enabled changed update the schedule
|
||||
/// iterates through the list of schedules marked for deletion
|
||||
/// delete them
|
||||
/// </summary>
|
||||
private void SendDataToServer()
|
||||
{
|
||||
// if(m_jobName != null)
|
||||
// {
|
||||
// // we are in read-only mode
|
||||
// return;
|
||||
// }
|
||||
|
||||
// System.Diagnostics.Debug.Assert(m_grid != null);
|
||||
// Microsoft.SqlServer.Management.SqlManagerUI.SqlManagerUIDlgGrid grid = m_grid;
|
||||
|
||||
// for(int iRow = 0; iRow < grid.RowsNumber; ++iRow)
|
||||
// {
|
||||
// GridCell cell = grid.GetCellInfo(iRow, colTagSmoObject);
|
||||
// System.Diagnostics.Debug.Assert(cell != null);
|
||||
// System.Diagnostics.Debug.Assert(cell.Tag != null);
|
||||
|
||||
// JobSchedule schedule = cell.Tag as JobSchedule;
|
||||
// System.Diagnostics.Debug.Assert(schedule != null);
|
||||
|
||||
// bool enabled = IsEmbeededCheckboxChecked(grid, iRow, colScheduleEnabled);
|
||||
|
||||
// if(enabled != schedule.IsEnabled)
|
||||
// {
|
||||
// // use the schedule coming form current server (maybe switched by scriping logic)
|
||||
// schedule = this.DataContainer.Server.JobServer.SharedSchedules.ItemById(schedule.ID);
|
||||
// System.Diagnostics.Debug.Assert(schedule != null);
|
||||
|
||||
// schedule.IsEnabled = enabled;
|
||||
// schedule.Alter();
|
||||
|
||||
// ReportUpdate(schedule, (iRow * 50) / grid.RowsNumber);
|
||||
// }
|
||||
// }
|
||||
|
||||
// System.Diagnostics.Debug.Assert(m_schedulesMarkedForDelete != null);
|
||||
// int i = 0;
|
||||
// foreach(object o in m_schedulesMarkedForDelete)
|
||||
// {
|
||||
// System.Diagnostics.Debug.Assert(o != null);
|
||||
|
||||
// JobSchedule schedule = o as JobSchedule;
|
||||
// System.Diagnostics.Debug.Assert(schedule != null);
|
||||
|
||||
// // use the schedule coming form current server (maybe switched by scriping logic)
|
||||
// schedule = this.DataContainer.Server.JobServer.SharedSchedules.ItemById(schedule.ID);
|
||||
// System.Diagnostics.Debug.Assert(schedule != null);
|
||||
|
||||
// // if there are jobs referencing this schedule remove them
|
||||
// if(schedule.JobCount != 0)
|
||||
// {
|
||||
// Guid[] jobGuids = schedule.EnumJobReferences();
|
||||
|
||||
// foreach(Guid guid in jobGuids)
|
||||
// {
|
||||
// Job jobRefrencingSchedule = DataContainer.Server.JobServer.Jobs.ItemById(guid);
|
||||
|
||||
// jobRefrencingSchedule.RemoveSharedSchedule(schedule.ID);
|
||||
// jobRefrencingSchedule.Alter();
|
||||
// }
|
||||
// }
|
||||
|
||||
// schedule.Drop();
|
||||
// ReportUpdate(schedule, (i * 50) / m_schedulesMarkedForDelete.Count + 50);
|
||||
|
||||
// ++i;
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// implementation of OnPanelRunNow
|
||||
/// </summary>
|
||||
/// <param name="node"></param>
|
||||
public override void OnRunNow(object sender)
|
||||
{
|
||||
base.OnRunNow(sender);
|
||||
SendDataToServer();
|
||||
}
|
||||
|
||||
|
||||
|
||||
#region Helpers - Get Shared Schedule Description, some extra Initialization
|
||||
private string GetScheduleDescription(JobSchedule schedule)
|
||||
{
|
||||
SimpleJobSchedule sjs = SimpleJobSchedule.FromJobScheduleData
|
||||
(
|
||||
new JobScheduleData(schedule)
|
||||
);
|
||||
string description = sjs.ToString();
|
||||
|
||||
return description != null ? description : string.Empty;
|
||||
}
|
||||
|
||||
// /// <summary>
|
||||
// /// on 'New...' clicked we display Schedule Dialog in 'New Schedule' mode
|
||||
// /// </summary>
|
||||
// /// <param name="sender"></param>
|
||||
// /// <param name="e"></param>
|
||||
// private void OnNewSharedSchedule(object sender, EventArgs e)
|
||||
// {
|
||||
// JobScheduleData scheduleData = new JobScheduleData();
|
||||
// using(ScheduleDialog scheduleDialog = new ScheduleDialog(scheduleData,DataContainer,this.ServiceProvider))
|
||||
// {
|
||||
// scheduleDialog.SetSite((m_serviceProviderInPickScheduleMode != null) ? m_serviceProviderInPickScheduleMode : this.ServiceProvider);
|
||||
// if(DialogResult.OK == scheduleDialog.ShowDialog())
|
||||
// {
|
||||
// JobScheduleData jsd = scheduleDialog.Schedule;
|
||||
// jsd.SetJobServer(this.DataContainer.Server.JobServer);
|
||||
// jsd.ApplyChanges();
|
||||
// }
|
||||
|
||||
// this.OnReset(this);
|
||||
// }
|
||||
// }
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
//
|
||||
// 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;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Globalization;
|
||||
using Microsoft.SqlServer.Management.Common;
|
||||
using Microsoft.SqlServer.Management.Sdk.Sfc;
|
||||
using Microsoft.SqlServer.Management.Smo;
|
||||
using Microsoft.SqlServer.Management.Smo.Agent;
|
||||
using Microsoft.SqlServer.Management.Diagnostics;
|
||||
using SMO = Microsoft.SqlServer.Management.Smo;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
internal class MsaJobTargetServer
|
||||
{
|
||||
#region members
|
||||
private string name = string.Empty;
|
||||
// is the job currently applied to the target server
|
||||
private bool isJobAppliedToTarget = false;
|
||||
// will the job be applied to the target server in the future?
|
||||
private bool willJobBeAppliedToTarget = false;
|
||||
#endregion
|
||||
|
||||
#region properties
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
public bool IsJobAppliedToTarget
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.isJobAppliedToTarget;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.isJobAppliedToTarget = value;
|
||||
}
|
||||
}
|
||||
public bool WillJobBeAppliedToTarget
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.willJobBeAppliedToTarget;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.willJobBeAppliedToTarget = value;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region construction
|
||||
public MsaJobTargetServer()
|
||||
{
|
||||
}
|
||||
public MsaJobTargetServer(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region overrides
|
||||
public override string ToString()
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
217
src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/Schedule.cs
Normal file
217
src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/Schedule.cs
Normal file
@@ -0,0 +1,217 @@
|
||||
//
|
||||
// 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.Drawing;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Xml;
|
||||
using Microsoft.SqlServer.Management.Smo;
|
||||
using Microsoft.SqlServer.Management.Smo.Agent;
|
||||
using Microsoft.SqlServer.Management.Diagnostics;
|
||||
using Microsoft.SqlServer.Management.Sdk.Sfc;
|
||||
using Microsoft.SqlServer.Management.Common;
|
||||
using Microsoft.SqlTools.ServiceLayer.Management;
|
||||
using Microsoft.SqlTools.ServiceLayer.Admin;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for Form1.
|
||||
/// </summary>
|
||||
public sealed class ScheduleDialog : ManagementActionBase
|
||||
{
|
||||
private JobScheduleData scheduleData = null;
|
||||
|
||||
private CDataContainer dataContainerContext = null; // must be non-null to display JobsInSchedule
|
||||
|
||||
#region Constructors / Dispose
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new ScheduleDialog based upon a JobScheduleData object
|
||||
/// And provides context for that dialog so it can enable 'JobsInSchedule' button
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="context"></param>
|
||||
public ScheduleDialog(JobScheduleData source, CDataContainer context)
|
||||
{
|
||||
this.dataContainerContext = context;
|
||||
this.scheduleData = source;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
/// <summary>
|
||||
/// Underlying JobScheduleData object
|
||||
/// </summary>
|
||||
public JobScheduleData Schedule
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.scheduleData;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// SimpleJobSchedule structure
|
||||
/// </summary>
|
||||
public SimpleJobSchedule SimpleSchedule
|
||||
{
|
||||
get
|
||||
{
|
||||
SimpleJobSchedule s = SimpleJobSchedule.FromJobScheduleData(this.scheduleData);
|
||||
s.Description = this.ToString();
|
||||
return s;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.scheduleData = value.ToJobScheduleData();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// text description of the supplied schedule
|
||||
/// </summary>
|
||||
public string Description
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.ToString();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
private JobScheduleData ExtractScheduleDataFromXml(XmlDocument xmlDoc)
|
||||
{
|
||||
JobScheduleData jobscheduledata = new JobScheduleData();
|
||||
|
||||
string stringNewScheduleMode = null;
|
||||
string serverName = String.Empty;
|
||||
string scheduleUrn = String.Empty;
|
||||
|
||||
STParameters param = new STParameters();
|
||||
bool bStatus = true;
|
||||
|
||||
param.SetDocument(xmlDoc);
|
||||
|
||||
bStatus = param.GetParam("servername", ref serverName);
|
||||
bStatus = param.GetParam("urn", ref scheduleUrn);
|
||||
bStatus = param.GetParam("itemtype", ref stringNewScheduleMode);
|
||||
if ((stringNewScheduleMode != null) && (stringNewScheduleMode.Length > 0))
|
||||
{
|
||||
return jobscheduledata; // new schedule
|
||||
}
|
||||
|
||||
Microsoft.SqlServer.Management.Common.ServerConnection connInfo =
|
||||
new Microsoft.SqlServer.Management.Common.ServerConnection(serverName);
|
||||
|
||||
Enumerator en = new Enumerator();
|
||||
Request req = new Request();
|
||||
|
||||
req.Urn = scheduleUrn;
|
||||
|
||||
DataTable dt = en.Process(connInfo, req);
|
||||
|
||||
if (dt.Rows.Count == 0)
|
||||
{
|
||||
return jobscheduledata;
|
||||
}
|
||||
|
||||
DataRow dr = dt.Rows[0];
|
||||
|
||||
jobscheduledata.Enabled = Convert.ToBoolean(dr["IsEnabled"], System.Globalization.CultureInfo.InvariantCulture);
|
||||
jobscheduledata.Name = Convert.ToString(dr["Name"], System.Globalization.CultureInfo.InvariantCulture);
|
||||
jobscheduledata.FrequencyTypes = (FrequencyTypes)Convert.ToInt32(dr["FrequencyTypes"], System.Globalization.CultureInfo.InvariantCulture);
|
||||
jobscheduledata.FrequencyInterval = Convert.ToInt32(dr["FrequencyInterval"], System.Globalization.CultureInfo.InvariantCulture);
|
||||
jobscheduledata.FrequencySubDayTypes = (FrequencySubDayTypes)Convert.ToInt32(dr["FrequencySubDayTypes"], System.Globalization.CultureInfo.InvariantCulture);
|
||||
jobscheduledata.FrequencyRelativeIntervals = (FrequencyRelativeIntervals)Convert.ToInt32(dr["FrequencyRelativeIntervals"], System.Globalization.CultureInfo.InvariantCulture);
|
||||
jobscheduledata.FrequencyRecurranceFactor = Convert.ToInt32(dr["FrequencyRecurrenceFactor"], System.Globalization.CultureInfo.InvariantCulture);
|
||||
jobscheduledata.ActiveStartDate = Convert.ToDateTime(dr["ActiveStartDate"], System.Globalization.CultureInfo.InvariantCulture);
|
||||
jobscheduledata.ActiveEndDate = Convert.ToDateTime(dr["ActiveEndDate"], System.Globalization.CultureInfo.InvariantCulture);
|
||||
return jobscheduledata;
|
||||
}
|
||||
|
||||
|
||||
#region Events
|
||||
// private void OK_Click(System.Object sender, System.EventArgs e)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// if (this.textboxScheduleName.Text.Length > 128)
|
||||
// {
|
||||
// throw new ApplicationException(SR.ScheduleNameTooLong);
|
||||
// }
|
||||
|
||||
// scheduleData.Name = this.textboxScheduleName.Text;
|
||||
// this.scheduleData.Enabled = this.checkboxEnabled.Checked;
|
||||
|
||||
// if (this.comboScheduleType.SelectedIndex == 0)
|
||||
// {
|
||||
// scheduleData.FrequencyTypes = FrequencyTypes.AutoStart;
|
||||
// }
|
||||
// else if (this.comboScheduleType.SelectedIndex == 1)
|
||||
// {
|
||||
// scheduleData.FrequencyTypes = FrequencyTypes.OnIdle;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// this.recurrancePattern.SaveData(this.scheduleData);
|
||||
// }
|
||||
|
||||
// // if we're updating the server
|
||||
// if (this.applyOnClose)
|
||||
// {
|
||||
// // all validations will be performed by server
|
||||
// this.scheduleData.ApplyChanges();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// // we will perform ourselfs some mininal validations - since otherwise user will obtain some
|
||||
// // schedule definition that only later (after n-steps) will be validated and he will may not
|
||||
// // be able to fix/recover from that point - see also 149485 opened by replication
|
||||
// // If the job schedules array is null then we will pass an empty arraylist to the validate method
|
||||
// // In some cases (such as when replication components call the schedule dialog) no datacontainer
|
||||
// // will be available. In these cases, we will pass nulls for both parameters in the validate
|
||||
// // method which will by-pass the duplicate schedule checks. The other validations will still
|
||||
// // be performed, however.
|
||||
// if (this.dataContainerContext == null)
|
||||
// {
|
||||
// scheduleData.Validate();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// scheduleData.Validate(this.dataContainerContext.Server.Information.Version, this.jobSchedules);
|
||||
// }
|
||||
// }
|
||||
// this.DialogResult = DialogResult.OK;
|
||||
// this.Close();
|
||||
// }
|
||||
// catch (ApplicationException error)
|
||||
// {
|
||||
// DisplayExceptionMessage(error);
|
||||
// this.DialogResult = DialogResult.None;
|
||||
// }
|
||||
// }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
1387
src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/ScheduleData.cs
Normal file
1387
src/Microsoft.SqlTools.ServiceLayer/Agent/Jobs/ScheduleData.cs
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,184 @@
|
||||
//
|
||||
// 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.Drawing;
|
||||
using System.Collections;
|
||||
using System.Data;
|
||||
using Microsoft.SqlServer.Management.Smo;
|
||||
using Microsoft.SqlServer.Management.Smo.Agent;
|
||||
using Microsoft.SqlServer.Management.Common;
|
||||
using Microsoft.SqlServer.Management.Diagnostics;
|
||||
using Microsoft.SqlTools.ServiceLayer.Management;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for Form1.
|
||||
/// </summary>
|
||||
#if DEBUG || EXPOSE_MANAGED_INTERNALS
|
||||
public
|
||||
#else
|
||||
internal
|
||||
#endif
|
||||
sealed class ScheduleScriptExecution : ManagementActionBase
|
||||
{
|
||||
private SqlConnectionInfo ci;
|
||||
private JobScheduleData scheduleData = null;
|
||||
|
||||
#region object construction
|
||||
/// <summary>
|
||||
/// constructs an empty schedule dialog.
|
||||
/// </summary>
|
||||
public ScheduleScriptExecution()
|
||||
{
|
||||
this.scheduleData = new JobScheduleData();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new ScheduleDialog based upon an existing smo schedule. Will
|
||||
/// automatically save changes on ok.
|
||||
/// </summary>
|
||||
/// <param name="source">source schedule</param>
|
||||
public ScheduleScriptExecution(JobSchedule source)
|
||||
{
|
||||
this.scheduleData = new JobScheduleData(source);
|
||||
}
|
||||
/// <summary>
|
||||
/// Constructs a new ScheduleDialog based upon an existing smo Job. Will
|
||||
/// automatically save changes on ok.
|
||||
/// </summary>
|
||||
/// <param name="source">source schedule</param>
|
||||
public ScheduleScriptExecution(Job source)
|
||||
{
|
||||
this.scheduleData = new JobScheduleData(source);
|
||||
}
|
||||
/// <summary>
|
||||
/// Constructs a new ScheduleDialog based upon a JobScheduleData object.
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
public ScheduleScriptExecution(JobScheduleData source, SqlConnectionInfo ci)
|
||||
{
|
||||
this.scheduleData = source;
|
||||
this.ci = ci;
|
||||
}
|
||||
/// <summary>
|
||||
/// Constructs a new Schedule dialog based upon a SimpleJobSchedule structure
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
public ScheduleScriptExecution(SimpleJobSchedule source)
|
||||
{
|
||||
this.scheduleData = source.ToJobScheduleData();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region public properties
|
||||
/// <summary>
|
||||
/// Underlying JobScheduleData object
|
||||
/// </summary>
|
||||
public JobScheduleData Schedule
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.scheduleData;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SimpleJobSchedule structure
|
||||
/// </summary>
|
||||
public SimpleJobSchedule SimpleSchedule
|
||||
{
|
||||
get
|
||||
{
|
||||
SimpleJobSchedule s = SimpleJobSchedule.FromJobScheduleData(this.scheduleData);
|
||||
s.Description = this.ToString();
|
||||
return s;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.scheduleData = value.ToJobScheduleData();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region ui event handlers
|
||||
|
||||
// private void OK_Click(System.Object sender, System.EventArgs e)
|
||||
// {
|
||||
// Microsoft.SqlServer.Management.Smo.Server smoServer;
|
||||
|
||||
// scheduleData.Name = this.scheduleName.Text;
|
||||
|
||||
// if (this.scheduleType.SelectedIndex == idxAutoStartSchedule)
|
||||
// {
|
||||
// scheduleData.FrequencyTypes = FrequencyTypes.AutoStart;
|
||||
// }
|
||||
// else if (this.scheduleType.SelectedIndex == idxCpuIdleSchedule)
|
||||
// {
|
||||
// scheduleData.FrequencyTypes = FrequencyTypes.OnIdle;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// this.recurrancePattern.SaveData(this.scheduleData);
|
||||
// }
|
||||
|
||||
// ///For methods which pass a connection object, connect to smo and get information about the job server and the
|
||||
// ///job inventory to pass to the validate method
|
||||
// try
|
||||
// {
|
||||
// if (ci != null)
|
||||
// {
|
||||
// smoServer = new Microsoft.SqlServer.Management.Smo.Server(new ServerConnection(ci));
|
||||
// System.Version version = smoServer.Information.Version;
|
||||
// ///This is the creation of a new job. We won't need to pass schedule information to Validate
|
||||
// ///because this a new job.
|
||||
// ///But first make sure the job has not already been created
|
||||
// if (smoServer.JobServer.Jobs.Contains(this.jobName.Text.Trim()))
|
||||
// {
|
||||
// throw new ApplicationException(SRError.JobAlreadyExists(this.jobName.Text));
|
||||
// }
|
||||
// //If we have not failed. The job doesn't exist. Now check to make sure the schedule data
|
||||
// //is valid
|
||||
// ArrayList nullArrayList=null;
|
||||
// scheduleData.Validate(version, nullArrayList);
|
||||
// }
|
||||
// this.DialogResult = DialogResult.OK;
|
||||
// this.Close();
|
||||
// }
|
||||
// catch (ApplicationException error)
|
||||
// {
|
||||
// DisplayExceptionMessage(error);
|
||||
// this.DialogResult = DialogResult.None;
|
||||
|
||||
// }
|
||||
// finally
|
||||
// {
|
||||
// smoServer = null;
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
// private void Cancel_Click(System.Object sender, System.EventArgs e)
|
||||
// {
|
||||
// this.DialogResult = DialogResult.Cancel;
|
||||
// this.Close();
|
||||
// }
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
//
|
||||
// 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.Xml;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Microsoft.SqlServer.Management.Diagnostics;
|
||||
using Microsoft.SqlServer.Management.Sdk.Sfc;
|
||||
using Microsoft.SqlTools.ServiceLayer.Admin;
|
||||
using Microsoft.SqlTools.ServiceLayer.Management;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for SqlServerAgentPropSheet.
|
||||
/// </summary>
|
||||
internal sealed class SqlServerAgentPropSheet : ManagementActionBase
|
||||
{
|
||||
public SqlServerAgentPropSheet()
|
||||
{
|
||||
}
|
||||
|
||||
public SqlServerAgentPropSheet(CDataContainer dataContainer)
|
||||
{
|
||||
DataContainer = dataContainer;
|
||||
Initialize(dataContainer);
|
||||
}
|
||||
|
||||
public void Initialize(CDataContainer dataContainer)
|
||||
{
|
||||
// PanelTreeNode node;
|
||||
// PanelTreeNode auxNode;
|
||||
// CUtils util = new CUtils();
|
||||
// STParameters param;
|
||||
|
||||
// param = new STParameters();
|
||||
|
||||
// param.SetDocument(dataContainer.Document);
|
||||
|
||||
// UserControl AgentPropertiesGeneral = new SqlServerAgentPropertiesGeneral(dataContainer);
|
||||
// UserControl AgentPropertiesAdvanced = new SqlServerAgentPropertiesAdvanced(dataContainer);
|
||||
// UserControl AgentPropertiesJobSystem = new SqlServerAgentPropertiesJobSystem(dataContainer);
|
||||
// UserControl AgentPropertiesHistory = new SqlServerAgentPropertiesHistory(dataContainer);
|
||||
// UserControl AgentPropertiesConnection = new SqlServerAgentPropertiesConnection(dataContainer);
|
||||
// UserControl AgentPropertiesAlertSystem = new SqlServerAgentPropertiesAlertSystem(dataContainer);
|
||||
|
||||
// AddView(AgentPropertiesGeneral);
|
||||
// AddView(AgentPropertiesAdvanced);
|
||||
// AddView(AgentPropertiesAlertSystem);
|
||||
// AddView(AgentPropertiesJobSystem);
|
||||
// AddView(AgentPropertiesConnection);
|
||||
// AddView(AgentPropertiesHistory);
|
||||
|
||||
// this.Icon = util.LoadIcon("server.ico");
|
||||
|
||||
// node = new PanelTreeNode();
|
||||
// node.Text = SqlServerAgentSR.AgentPropertiesNode;
|
||||
// node.Type = eNodeType.Folder;
|
||||
// node.Tag = 1;
|
||||
|
||||
// auxNode = new PanelTreeNode();
|
||||
// auxNode.Text = SqlServerAgentSR.GeneralNode;
|
||||
// auxNode.Tag = 1;
|
||||
// auxNode.Type = eNodeType.Item;
|
||||
// node.Nodes.Add(auxNode);
|
||||
|
||||
// SelectNode(auxNode);
|
||||
|
||||
|
||||
// auxNode = new PanelTreeNode();
|
||||
// auxNode.Text = SqlServerAgentSR.AdvancedNode;
|
||||
// auxNode.Tag = 2;
|
||||
// auxNode.Type = eNodeType.Item;
|
||||
// node.Nodes.Add(auxNode);
|
||||
|
||||
// auxNode = new PanelTreeNode();
|
||||
// auxNode.Text = SqlServerAgentSR.AlertSystemNode;
|
||||
// auxNode.Tag = 3;
|
||||
// auxNode.Type = eNodeType.Item;
|
||||
// node.Nodes.Add(auxNode);
|
||||
|
||||
// auxNode = new PanelTreeNode();
|
||||
// auxNode.Text = SqlServerAgentSR.JobSystemNode;
|
||||
// auxNode.Tag = 4;
|
||||
// auxNode.Type = eNodeType.Item;
|
||||
// node.Nodes.Add(auxNode);
|
||||
|
||||
// auxNode = new PanelTreeNode();
|
||||
// auxNode.Text = SqlServerAgentSR.ConnectionNode;
|
||||
// auxNode.Tag = 5;
|
||||
// auxNode.Type = eNodeType.Item;
|
||||
// node.Nodes.Add(auxNode);
|
||||
|
||||
// auxNode = new PanelTreeNode();
|
||||
// auxNode.Text = SqlServerAgentSR.HistoryNode;
|
||||
// auxNode.Tag = 6;
|
||||
// auxNode.Type = eNodeType.Item;
|
||||
// node.Nodes.Add(auxNode);
|
||||
|
||||
|
||||
// AddNode(node);
|
||||
|
||||
// Text = SqlServerAgentSR.AgentPropertiesTitle(dataContainer.Server.Name);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Summary description for LogonUser.
|
||||
/// </summary>
|
||||
internal sealed class Impersonate
|
||||
{
|
||||
|
||||
[SuppressMessage("Microsoft.Globalization", "CA2101:SpecifyMarshalingForPInvokeStringArguments", MessageId="0", Justification="Temporary suppression: Revisit in SQL 11")]
|
||||
[SuppressMessage("Microsoft.Globalization", "CA2101:SpecifyMarshalingForPInvokeStringArguments", MessageId="1", Justification="Temporary suppression: Revisit in SQL 11")]
|
||||
[SuppressMessage("Microsoft.Globalization", "CA2101:SpecifyMarshalingForPInvokeStringArguments", MessageId="2", Justification="Temporary suppression: Revisit in SQL 11")]
|
||||
[DllImport("advapi32", SetLastError=true)]
|
||||
internal static extern bool LogonUser(String lpszUsername, String lpszDomain, String lpszPassword,
|
||||
int dwLogonType, int dwLogonProvider, out IntPtr phToken);
|
||||
|
||||
[DllImport("Kernel32")]
|
||||
internal static extern int GetLastError();
|
||||
|
||||
[DllImport("advapi32")]
|
||||
internal static extern bool CloseHandle(IntPtr phToken);
|
||||
|
||||
internal static string LogonUserManaged(string userName, string password, ref IntPtr token)
|
||||
{
|
||||
string [] pair = userName.Split("\\".ToCharArray());
|
||||
int LogonMethod = 3; // logon using blah
|
||||
|
||||
if (pair.Length > 2)
|
||||
{
|
||||
return "SRError.InvalidUsername(userName)";
|
||||
}
|
||||
|
||||
bool retval = false;
|
||||
|
||||
if (pair.Length == 2)
|
||||
{
|
||||
retval = Impersonate.LogonUser(pair[1], pair[0], password, LogonMethod, 0, out token);
|
||||
}
|
||||
else
|
||||
{
|
||||
retval = Impersonate.LogonUser(pair[0], ".", password, LogonMethod, 0, out token);
|
||||
}
|
||||
if (true == retval)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
return "SRError.LogonFailed(userName)";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,615 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlServer.Management.Sdk.Sfc;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Collections;
|
||||
using System.ComponentModel;
|
||||
using System.Xml;
|
||||
using Microsoft.SqlServer.Management.Smo;
|
||||
using Microsoft.SqlServer.Management.Common;
|
||||
using Microsoft.SqlServer.Management.Smo.Agent;
|
||||
using System.Data.SqlClient;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Resources;
|
||||
using Microsoft.SqlServer.Management.Diagnostics;
|
||||
using Microsoft.SqlTools.ServiceLayer.Management;
|
||||
using Microsoft.SqlTools.ServiceLayer.Admin;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for SqlServerAgentPropertiesAdvanced.
|
||||
/// </summary>
|
||||
//public class SqlServerAgentPropertiesAdvanced : System.Windows.Forms.Form
|
||||
internal class SqlServerAgentPropertiesAdvanced : ManagementActionBase
|
||||
{
|
||||
#region UI controls members
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
// private System.ComponentModel.Container components = null;
|
||||
// private Microsoft.SqlServer.Management.Controls.Separator separatorEventForwarding;
|
||||
// private System.Windows.Forms.CheckBox checkForwardEVents;
|
||||
// private System.Windows.Forms.Label labelServerName;
|
||||
// private System.Windows.Forms.Label labelEvents;
|
||||
// private System.Windows.Forms.RadioButton radioEventsUnhandled;
|
||||
// private System.Windows.Forms.RadioButton radioEventsAll;
|
||||
// private System.Windows.Forms.Label labelEventSeverity;
|
||||
// private System.Windows.Forms.ComboBox comboEventSeverity;
|
||||
// private Microsoft.SqlServer.Management.Controls.Separator separatorIdleCPU;
|
||||
// private System.Windows.Forms.CheckBox checkCPUIdleCondition;
|
||||
// private System.Windows.Forms.Label labelCPUAverageUsage;
|
||||
// private System.Windows.Forms.NumericUpDown numCPUUsage;
|
||||
// private System.Windows.Forms.Label labelCPUPercent;
|
||||
// private System.Windows.Forms.Label labelCPUTImeBelow;
|
||||
// private System.Windows.Forms.Label labelCPUSeconds;
|
||||
// private System.Windows.Forms.NumericUpDown textCPUTimeBelow;
|
||||
// private System.Windows.Forms.TextBox textBoxForwardingServer;
|
||||
#endregion
|
||||
|
||||
#region Trace support
|
||||
public const string m_strComponentName = "SqlServerAgentPropAdvanced";
|
||||
private string ComponentName
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_strComponentName;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ctors
|
||||
public SqlServerAgentPropertiesAdvanced()
|
||||
{
|
||||
}
|
||||
|
||||
public SqlServerAgentPropertiesAdvanced(CDataContainer dataContainer)
|
||||
{
|
||||
DataContainer = dataContainer;
|
||||
//this.HelpF1Keyword = AssemblyVersionInfo.VersionHelpKeywordPrefix + @".ag.agent.advanced.f1";
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Utils
|
||||
|
||||
// private bool VerifyUI()
|
||||
// {
|
||||
// bool allOK = true;
|
||||
// allOK = CUtils.ValidateNumeric(this.numCPUUsage,SRError.InvalidNumericalValue(SRError.ControlCpuUsage,this.numCPUUsage.Minimum,this.numCPUUsage.Maximum),true);
|
||||
// if (false == allOK)
|
||||
// {
|
||||
// return allOK;
|
||||
// }
|
||||
// allOK = CUtils.ValidateNumeric(this.textCPUTimeBelow,SRError.InvalidNumericalValue(SRError.ControlRemainsBelowLevelFor,this.textCPUTimeBelow.Minimum,this.textCPUTimeBelow.Maximum),true);
|
||||
// if (false == allOK)
|
||||
// {
|
||||
// return allOK;
|
||||
// }
|
||||
// return allOK;
|
||||
// }
|
||||
|
||||
// private void SetControlsForForwarding(bool enabled)
|
||||
// {
|
||||
// this.textBoxForwardingServer.Enabled = enabled;
|
||||
// this.radioEventsAll.Enabled = enabled;
|
||||
// this.radioEventsUnhandled.Enabled = enabled;
|
||||
// this.comboEventSeverity.Enabled = enabled;
|
||||
// }
|
||||
|
||||
// private void SetControlsForIdleCondition(bool enabled)
|
||||
// {
|
||||
// this.numCPUUsage.Enabled = enabled;
|
||||
// this.textCPUTimeBelow.Enabled = enabled;
|
||||
// }
|
||||
|
||||
// private void PopulateEventSeverityCombo()
|
||||
// {
|
||||
// this.comboEventSeverity.Items.Clear();
|
||||
// this.comboEventSeverity.Items.Add(SqlServerAgentSR.EventSeverity_001);
|
||||
// this.comboEventSeverity.Items.Add(SqlServerAgentSR.EventSeverity_002);
|
||||
// this.comboEventSeverity.Items.Add(SqlServerAgentSR.EventSeverity_003);
|
||||
// this.comboEventSeverity.Items.Add(SqlServerAgentSR.EventSeverity_004);
|
||||
// this.comboEventSeverity.Items.Add(SqlServerAgentSR.EventSeverity_005);
|
||||
// this.comboEventSeverity.Items.Add(SqlServerAgentSR.EventSeverity_006);
|
||||
// this.comboEventSeverity.Items.Add(SqlServerAgentSR.EventSeverity_007);
|
||||
// this.comboEventSeverity.Items.Add(SqlServerAgentSR.EventSeverity_008);
|
||||
// this.comboEventSeverity.Items.Add(SqlServerAgentSR.EventSeverity_009);
|
||||
// this.comboEventSeverity.Items.Add(SqlServerAgentSR.EventSeverity_010);
|
||||
// this.comboEventSeverity.Items.Add(SqlServerAgentSR.EventSeverity_011);
|
||||
// this.comboEventSeverity.Items.Add(SqlServerAgentSR.EventSeverity_012);
|
||||
// this.comboEventSeverity.Items.Add(SqlServerAgentSR.EventSeverity_013);
|
||||
// this.comboEventSeverity.Items.Add(SqlServerAgentSR.EventSeverity_014);
|
||||
// this.comboEventSeverity.Items.Add(SqlServerAgentSR.EventSeverity_015);
|
||||
// this.comboEventSeverity.Items.Add(SqlServerAgentSR.EventSeverity_016);
|
||||
// this.comboEventSeverity.Items.Add(SqlServerAgentSR.EventSeverity_017);
|
||||
// this.comboEventSeverity.Items.Add(SqlServerAgentSR.EventSeverity_018);
|
||||
// this.comboEventSeverity.Items.Add(SqlServerAgentSR.EventSeverity_019);
|
||||
// this.comboEventSeverity.Items.Add(SqlServerAgentSR.EventSeverity_020);
|
||||
// this.comboEventSeverity.Items.Add(SqlServerAgentSR.EventSeverity_021);
|
||||
// this.comboEventSeverity.Items.Add(SqlServerAgentSR.EventSeverity_022);
|
||||
// this.comboEventSeverity.Items.Add(SqlServerAgentSR.EventSeverity_023);
|
||||
// this.comboEventSeverity.Items.Add(SqlServerAgentSR.EventSeverity_024);
|
||||
// this.comboEventSeverity.Items.Add(SqlServerAgentSR.EventSeverity_025);
|
||||
// this.comboEventSeverity.SelectedIndex = 0;
|
||||
// }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Implementation
|
||||
// private void ApplyChanges()
|
||||
// {
|
||||
// this.ExecutionMode = ExecutionMode.Success;
|
||||
|
||||
// JobServer agent = DataContainer.Server.JobServer;
|
||||
|
||||
// bool AlterValuesAgent = false;
|
||||
// bool AlterValuesAlert = false;
|
||||
|
||||
// string OrigialAlertForwardingServer = agent.AlertSystem.ForwardingServer;
|
||||
// string CurrentAlertForwardingServer = "";
|
||||
// bool CurrentForwardedAlways = this.radioEventsAll.Checked;
|
||||
|
||||
// if(this.checkForwardEVents.Checked == true)
|
||||
// {
|
||||
// CurrentAlertForwardingServer = this.textBoxForwardingServer.Text;
|
||||
// }
|
||||
|
||||
// try
|
||||
// {
|
||||
// if(CurrentAlertForwardingServer != OrigialAlertForwardingServer)
|
||||
// {
|
||||
// AlterValuesAlert = true;
|
||||
// agent.AlertSystem.ForwardingServer = CurrentAlertForwardingServer;
|
||||
// }
|
||||
|
||||
// if(CurrentAlertForwardingServer.Length > 0)
|
||||
// {
|
||||
|
||||
// if(agent.AlertSystem.IsForwardedAlways != CurrentForwardedAlways)
|
||||
// {
|
||||
// AlterValuesAlert = true;
|
||||
// agent.AlertSystem.IsForwardedAlways = CurrentForwardedAlways;
|
||||
// }
|
||||
|
||||
// int SelectedSevIndex = this.comboEventSeverity.SelectedIndex;
|
||||
|
||||
// if(agent.AlertSystem.ForwardingSeverity != SelectedSevIndex + 1)
|
||||
// {
|
||||
// AlterValuesAlert = true;
|
||||
// agent.AlertSystem.ForwardingSeverity = SelectedSevIndex +1;
|
||||
// }
|
||||
// }
|
||||
|
||||
// if(agent.IsCpuPollingEnabled != this.checkCPUIdleCondition.Checked)
|
||||
// {
|
||||
// AlterValuesAgent = true;
|
||||
// agent.IsCpuPollingEnabled = this.checkCPUIdleCondition.Checked;
|
||||
// }
|
||||
// if(true == this.checkCPUIdleCondition.Checked)
|
||||
// {
|
||||
// if(this.numCPUUsage.Value != agent.IdleCpuPercentage)
|
||||
// {
|
||||
// AlterValuesAgent = true;
|
||||
// agent.IdleCpuPercentage = (int)this.numCPUUsage.Value;
|
||||
// }
|
||||
// if(this.textCPUTimeBelow.Value != agent.IdleCpuDuration)
|
||||
// {
|
||||
// AlterValuesAgent = true;
|
||||
// agent.IdleCpuDuration = (int)this.textCPUTimeBelow.Value;
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
// if(true == AlterValuesAlert)
|
||||
// {
|
||||
// agent.AlertSystem.Alter();
|
||||
// }
|
||||
// if(true == AlterValuesAgent)
|
||||
// {
|
||||
// agent.Alter();
|
||||
// }
|
||||
// }
|
||||
// catch(SmoException smoex)
|
||||
// {
|
||||
// DisplayExceptionMessage(smoex);
|
||||
// this.ExecutionMode = ExecutionMode.Failure;
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// DisplayExceptionMessage(ex);
|
||||
// this.ExecutionMode = ExecutionMode.Failure;
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
// private void InitProperties()
|
||||
// {
|
||||
// PopulateEventSeverityCombo();
|
||||
|
||||
// DataContainer.Server.Refresh();
|
||||
// DataContainer.Server.JobServer.Refresh();
|
||||
// JobServer agent = DataContainer.Server.JobServer;
|
||||
// string AlertForwardingServer = agent.AlertSystem.ForwardingServer;
|
||||
// bool managedInstance = DataContainer.Server.DatabaseEngineEdition == DatabaseEngineEdition.SqlManagedInstance;
|
||||
|
||||
// if(AlertForwardingServer.Length != 0 && !managedInstance)
|
||||
// {
|
||||
// this.checkForwardEVents.Checked = true;
|
||||
// SetControlsForForwarding(true);
|
||||
// this.textBoxForwardingServer.Text = AlertForwardingServer;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// this.checkForwardEVents.Checked = false;
|
||||
// SetControlsForForwarding(false);
|
||||
|
||||
// // Managed Instance does not allow forwarding events
|
||||
// // to a different server
|
||||
// //
|
||||
// this.checkForwardEVents.Enabled = !managedInstance;
|
||||
|
||||
// }
|
||||
// this.radioEventsAll.Checked = agent.AlertSystem.IsForwardedAlways;
|
||||
|
||||
// /// Assume that the items in the combo are int ordered from 1- 25
|
||||
// ///
|
||||
|
||||
// try
|
||||
// {
|
||||
// int RetrievedSeverityValue = agent.AlertSystem.ForwardingSeverity - 1;
|
||||
// if (RetrievedSeverityValue > this.comboEventSeverity.Items.Count - 1)
|
||||
// {
|
||||
// RetrievedSeverityValue = 0;
|
||||
// }
|
||||
|
||||
// this.comboEventSeverity.SelectedIndex = RetrievedSeverityValue;
|
||||
// }
|
||||
// catch (SmoException )
|
||||
// {
|
||||
// //DisplayExceptionMessage(se);
|
||||
// this.comboEventSeverity.Enabled = false;
|
||||
// this.comboEventSeverity.SelectedIndex = 0;
|
||||
// }
|
||||
|
||||
// bool enable = this.checkCPUIdleCondition.Checked = agent.IsCpuPollingEnabled;
|
||||
// SetControlsForIdleCondition(enable);
|
||||
// this.numCPUUsage.Tag = this.numCPUUsage.Value = agent.IdleCpuPercentage;
|
||||
// this.numCPUUsage.Text = this.numCPUUsage.Value.ToString(System.Globalization.CultureInfo.CurrentCulture);
|
||||
// this.numCPUUsage.Update();
|
||||
|
||||
// this.textCPUTimeBelow.Tag = this.textCPUTimeBelow.Value = agent.IdleCpuDuration;
|
||||
// this.textCPUTimeBelow.Text = this.textCPUTimeBelow.Value.ToString(System.Globalization.CultureInfo.CurrentCulture);
|
||||
// this.textCPUTimeBelow.Update();
|
||||
|
||||
// }
|
||||
|
||||
#endregion
|
||||
|
||||
#region IPanenForm Implementation
|
||||
|
||||
// UserControl IPanelForm.Panel
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// return this;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// /// <summary>
|
||||
// /// IPanelForm.OnInitialization
|
||||
// ///
|
||||
// /// TODO - in order to reduce IPanelForm container load time
|
||||
// /// and to improve performance, IPanelForm-s should be able
|
||||
// /// to lazy-initialize themself when IPanelForm.OnInitialization
|
||||
// /// is called (a continer like TreePanelForm calls the
|
||||
// /// OnInitialization() method before first OnSelection())
|
||||
// /// </summary>
|
||||
// void IPanelForm.OnInitialization()
|
||||
// {
|
||||
// InitProperties();
|
||||
// }
|
||||
|
||||
|
||||
// public override void OnRunNow (object sender)
|
||||
// {
|
||||
// base.OnRunNow(sender);
|
||||
// ApplyChanges();
|
||||
// }
|
||||
|
||||
|
||||
// public override void OnReset(object sender)
|
||||
// {
|
||||
// base.OnReset(sender);
|
||||
|
||||
// this.DataContainer.Server.JobServer.Refresh();
|
||||
// this.DataContainer.Server.JobServer.AlertSystem.Refresh();
|
||||
// InitProperties();
|
||||
// }
|
||||
|
||||
|
||||
// void IPanelForm.OnSelection(TreeNode node)
|
||||
// {
|
||||
// }
|
||||
|
||||
|
||||
// void IPanelForm.OnPanelLoseSelection(TreeNode node)
|
||||
// {
|
||||
// }
|
||||
|
||||
|
||||
// bool ISupportValidation.Validate()
|
||||
// {
|
||||
// if (false == VerifyUI())
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
// return base.Validate();
|
||||
// }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Dispose
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
// protected override void Dispose( bool disposing )
|
||||
// {
|
||||
// if( disposing )
|
||||
// {
|
||||
// if(components != null)
|
||||
// {
|
||||
// components.Dispose();
|
||||
// }
|
||||
// }
|
||||
// base.Dispose( disposing );
|
||||
// }
|
||||
|
||||
// #endregion
|
||||
|
||||
// #region Windows Form Designer generated code
|
||||
// /// <summary>
|
||||
// /// Required method for Designer support - do not modify
|
||||
// /// the contents of this method with the code editor.
|
||||
// /// </summary>
|
||||
// private void InitializeComponent()
|
||||
// {
|
||||
// System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SqlServerAgentPropertiesAdvanced));
|
||||
// this.separatorEventForwarding = new Microsoft.SqlServer.Management.Controls.Separator();
|
||||
// this.checkForwardEVents = new System.Windows.Forms.CheckBox();
|
||||
// this.labelServerName = new System.Windows.Forms.Label();
|
||||
// this.labelEvents = new System.Windows.Forms.Label();
|
||||
// this.radioEventsUnhandled = new System.Windows.Forms.RadioButton();
|
||||
// this.radioEventsAll = new System.Windows.Forms.RadioButton();
|
||||
// this.labelEventSeverity = new System.Windows.Forms.Label();
|
||||
// this.comboEventSeverity = new System.Windows.Forms.ComboBox();
|
||||
// this.separatorIdleCPU = new Microsoft.SqlServer.Management.Controls.Separator();
|
||||
// this.checkCPUIdleCondition = new System.Windows.Forms.CheckBox();
|
||||
// this.labelCPUAverageUsage = new System.Windows.Forms.Label();
|
||||
// this.numCPUUsage = new System.Windows.Forms.NumericUpDown();
|
||||
// this.labelCPUPercent = new System.Windows.Forms.Label();
|
||||
// this.labelCPUTImeBelow = new System.Windows.Forms.Label();
|
||||
// this.labelCPUSeconds = new System.Windows.Forms.Label();
|
||||
// this.textCPUTimeBelow = new System.Windows.Forms.NumericUpDown();
|
||||
// this.textBoxForwardingServer = new System.Windows.Forms.TextBox();
|
||||
// ((System.ComponentModel.ISupportInitialize)(this.numCPUUsage)).BeginInit();
|
||||
// ((System.ComponentModel.ISupportInitialize)(this.textCPUTimeBelow)).BeginInit();
|
||||
// this.SuspendLayout();
|
||||
// this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
// this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
// //
|
||||
// // separatorEventForwarding
|
||||
// //
|
||||
// resources.ApplyResources(this.separatorEventForwarding, "separatorEventForwarding");
|
||||
// this.separatorEventForwarding.Name = "separatorEventForwarding";
|
||||
// //
|
||||
// // checkForwardEVents
|
||||
// //
|
||||
// resources.ApplyResources(this.checkForwardEVents, "checkForwardEVents");
|
||||
// this.checkForwardEVents.Name = "checkForwardEVents";
|
||||
// this.checkForwardEVents.CheckedChanged += new System.EventHandler(this.checkForwardEVents_CheckedChanged);
|
||||
// //
|
||||
// // labelServerName
|
||||
// //
|
||||
// resources.ApplyResources(this.labelServerName, "labelServerName");
|
||||
// this.labelServerName.Name = "labelServerName";
|
||||
// //
|
||||
// // labelEvents
|
||||
// //
|
||||
// resources.ApplyResources(this.labelEvents, "labelEvents");
|
||||
// this.labelEvents.Name = "labelEvents";
|
||||
// //
|
||||
// // radioEventsUnhandled
|
||||
// //
|
||||
// resources.ApplyResources(this.radioEventsUnhandled, "radioEventsUnhandled");
|
||||
// this.radioEventsUnhandled.Checked = true;
|
||||
// this.radioEventsUnhandled.Name = "radioEventsUnhandled";
|
||||
// this.radioEventsUnhandled.TabStop = true;
|
||||
// //
|
||||
// // radioEventsAll
|
||||
// //
|
||||
// resources.ApplyResources(this.radioEventsAll, "radioEventsAll");
|
||||
// this.radioEventsAll.Name = "radioEventsAll";
|
||||
// //
|
||||
// // labelEventSeverity
|
||||
// //
|
||||
// resources.ApplyResources(this.labelEventSeverity, "labelEventSeverity");
|
||||
// this.labelEventSeverity.Name = "labelEventSeverity";
|
||||
// //
|
||||
// // comboEventSeverity
|
||||
// //
|
||||
// resources.ApplyResources(this.comboEventSeverity, "comboEventSeverity");
|
||||
// this.comboEventSeverity.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
// this.comboEventSeverity.FormattingEnabled = true;
|
||||
// this.comboEventSeverity.Name = "comboEventSeverity";
|
||||
// //
|
||||
// // separatorIdleCPU
|
||||
// //
|
||||
// resources.ApplyResources(this.separatorIdleCPU, "separatorIdleCPU");
|
||||
// this.separatorIdleCPU.Name = "separatorIdleCPU";
|
||||
// //
|
||||
// // checkCPUIdleCondition
|
||||
// //
|
||||
// resources.ApplyResources(this.checkCPUIdleCondition, "checkCPUIdleCondition");
|
||||
// this.checkCPUIdleCondition.Name = "checkCPUIdleCondition";
|
||||
// this.checkCPUIdleCondition.CheckedChanged += new System.EventHandler(this.checkCPUIdleCondition_CheckedChanged);
|
||||
// //
|
||||
// // labelCPUAverageUsage
|
||||
// //
|
||||
// resources.ApplyResources(this.labelCPUAverageUsage, "labelCPUAverageUsage");
|
||||
// this.labelCPUAverageUsage.Name = "labelCPUAverageUsage";
|
||||
// //
|
||||
// // numCPUUsage
|
||||
// //
|
||||
// resources.ApplyResources(this.numCPUUsage, "numCPUUsage");
|
||||
// this.numCPUUsage.Minimum = new decimal(new int[] {
|
||||
// 10,
|
||||
// 0,
|
||||
// 0,
|
||||
// 0});
|
||||
// this.numCPUUsage.Name = "numCPUUsage";
|
||||
// this.numCPUUsage.Value = new decimal(new int[] {
|
||||
// 10,
|
||||
// 0,
|
||||
// 0,
|
||||
// 0});
|
||||
// this.numCPUUsage.Enter += new System.EventHandler(this.numCPUUsage_Enter);
|
||||
// this.numCPUUsage.ValueChanged += new System.EventHandler(this.numCPUUsage_ValueChanged);
|
||||
// this.numCPUUsage.Leave += new System.EventHandler(this.numCPUUsage_Leave);
|
||||
// //
|
||||
// // labelCPUPercent
|
||||
// //
|
||||
// resources.ApplyResources(this.labelCPUPercent, "labelCPUPercent");
|
||||
// this.labelCPUPercent.Name = "labelCPUPercent";
|
||||
// //
|
||||
// // labelCPUTImeBelow
|
||||
// //
|
||||
// resources.ApplyResources(this.labelCPUTImeBelow, "labelCPUTImeBelow");
|
||||
// this.labelCPUTImeBelow.Name = "labelCPUTImeBelow";
|
||||
// //
|
||||
// // labelCPUSeconds
|
||||
// //
|
||||
// resources.ApplyResources(this.labelCPUSeconds, "labelCPUSeconds");
|
||||
// this.labelCPUSeconds.Name = "labelCPUSeconds";
|
||||
// //
|
||||
// // textCPUTimeBelow
|
||||
// //
|
||||
// resources.ApplyResources(this.textCPUTimeBelow, "textCPUTimeBelow");
|
||||
// this.textCPUTimeBelow.Maximum = new decimal(new int[] {
|
||||
// 86400,
|
||||
// 0,
|
||||
// 0,
|
||||
// 0});
|
||||
// this.textCPUTimeBelow.Minimum = new decimal(new int[] {
|
||||
// 20,
|
||||
// 0,
|
||||
// 0,
|
||||
// 0});
|
||||
// this.textCPUTimeBelow.Name = "textCPUTimeBelow";
|
||||
// this.textCPUTimeBelow.Value = new decimal(new int[] {
|
||||
// 600,
|
||||
// 0,
|
||||
// 0,
|
||||
// 0});
|
||||
// this.textCPUTimeBelow.Enter += new System.EventHandler(this.textCPUTimeBelow_Enter);
|
||||
// this.textCPUTimeBelow.ValueChanged += new System.EventHandler(this.textCPUTimeBelow_ValueChanged);
|
||||
// this.textCPUTimeBelow.Leave += new System.EventHandler(this.textCPUTimeBelow_Leave);
|
||||
// //
|
||||
// // textBoxForwardingServer
|
||||
// //
|
||||
// resources.ApplyResources(this.textBoxForwardingServer, "textBoxForwardingServer");
|
||||
// this.textBoxForwardingServer.Name = "textBoxForwardingServer";
|
||||
// //
|
||||
// // SqlServerAgentPropertiesAdvanced
|
||||
// //
|
||||
// this.Controls.Add(this.textBoxForwardingServer);
|
||||
// this.Controls.Add(this.textCPUTimeBelow);
|
||||
// this.Controls.Add(this.labelCPUSeconds);
|
||||
// this.Controls.Add(this.labelCPUTImeBelow);
|
||||
// this.Controls.Add(this.labelCPUPercent);
|
||||
// this.Controls.Add(this.numCPUUsage);
|
||||
// this.Controls.Add(this.labelCPUAverageUsage);
|
||||
// this.Controls.Add(this.checkCPUIdleCondition);
|
||||
// this.Controls.Add(this.separatorIdleCPU);
|
||||
// this.Controls.Add(this.comboEventSeverity);
|
||||
// this.Controls.Add(this.labelEventSeverity);
|
||||
// this.Controls.Add(this.radioEventsAll);
|
||||
// this.Controls.Add(this.radioEventsUnhandled);
|
||||
// this.Controls.Add(this.labelEvents);
|
||||
// this.Controls.Add(this.labelServerName);
|
||||
// this.Controls.Add(this.checkForwardEVents);
|
||||
// this.Controls.Add(this.separatorEventForwarding);
|
||||
// this.Name = "SqlServerAgentPropertiesAdvanced";
|
||||
// resources.ApplyResources(this, "$this");
|
||||
// ((System.ComponentModel.ISupportInitialize)(this.numCPUUsage)).EndInit();
|
||||
// ((System.ComponentModel.ISupportInitialize)(this.textCPUTimeBelow)).EndInit();
|
||||
// this.ResumeLayout(false);
|
||||
// this.PerformLayout();
|
||||
|
||||
// }
|
||||
#endregion
|
||||
|
||||
#region UI controls event handlers
|
||||
|
||||
// private void checkForwardEVents_CheckedChanged(object sender, System.EventArgs e)
|
||||
// {
|
||||
// bool IsChecked = this.checkForwardEVents.Checked;
|
||||
// SetControlsForForwarding(IsChecked);
|
||||
// }
|
||||
|
||||
// private void checkCPUIdleCondition_CheckedChanged(object sender, System.EventArgs e)
|
||||
// {
|
||||
// bool IsChecked = this.checkCPUIdleCondition.Checked;
|
||||
// SetControlsForIdleCondition(IsChecked);
|
||||
// }
|
||||
|
||||
// private void numCPUUsage_Leave(System.Object sender, System.EventArgs e)
|
||||
// {
|
||||
// //bool bOK = CUtils.ValidateNumeric(this.numCPUUsage,SRError.InvalidNumericalValue(SRError.ControlCpuUsage,this.numCPUUsage.Minimum,this.numCPUUsage.Maximum),true);
|
||||
// }
|
||||
|
||||
// private void textCPUTimeBelow_Leave(System.Object sender, System.EventArgs e)
|
||||
// {
|
||||
// //bool bOK = CUtils.ValidateNumeric(this.textCPUTimeBelow,SRError.InvalidNumericalValue(SRError.ControlRemainsBelowLevelFor,this.textCPUTimeBelow.Minimum,this.textCPUTimeBelow.Maximum),true);
|
||||
// }
|
||||
|
||||
// private void numCPUUsage_ValueChanged(System.Object sender, System.EventArgs e)
|
||||
// {
|
||||
// STrace.Trace(m_strComponentName,numCPUUsage.Value.ToString(System.Globalization.CultureInfo.CurrentCulture));
|
||||
// }
|
||||
|
||||
// private void textCPUTimeBelow_ValueChanged(System.Object sender, System.EventArgs e)
|
||||
// {
|
||||
// STrace.Trace(m_strComponentName,textCPUTimeBelow.Value.ToString(System.Globalization.CultureInfo.CurrentCulture));
|
||||
// }
|
||||
|
||||
// private void numCPUUsage_Enter(System.Object sender, System.EventArgs e)
|
||||
// {
|
||||
// this.numCPUUsage.Tag = this.numCPUUsage.Value;
|
||||
// }
|
||||
|
||||
// private void textCPUTimeBelow_Enter(System.Object sender, System.EventArgs e)
|
||||
// {
|
||||
// this.textCPUTimeBelow.Tag = this.textCPUTimeBelow.Value;
|
||||
// }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,468 @@
|
||||
//
|
||||
// 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;
|
||||
using System.Collections.Specialized;
|
||||
using System.Data.SqlClient;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Resources;
|
||||
using System.Xml;
|
||||
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.SqlServer.Management.Smo.Mail;
|
||||
using Microsoft.SqlTools.ServiceLayer.Admin;
|
||||
using Microsoft.SqlTools.ServiceLayer.Management;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for SqlServerAgentPropertiesAlertSystem.
|
||||
/// </summary>
|
||||
internal class SqlServerAgentPropertiesAlertSystem : ManagementActionBase
|
||||
{
|
||||
public override void OnRunNow(object sender)
|
||||
{
|
||||
base.OnRunNow(sender);
|
||||
ApplyChanges();
|
||||
}
|
||||
|
||||
#region ctors
|
||||
public SqlServerAgentPropertiesAlertSystem(CDataContainer dataContainer)
|
||||
{
|
||||
DataContainer = dataContainer;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Implementation
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
private void ApplyChanges()
|
||||
{
|
||||
//this.ExecutionMode = ExecutionMode.Success;
|
||||
|
||||
// JobServer agent = DataContainer.Server.JobServer;
|
||||
// bool isSQL2005 = this.DataContainer.Server.Information.Version.Major >= SQL2005;
|
||||
|
||||
// bool AlterValues = false;
|
||||
// bool AlterAlertValues = false;
|
||||
// bool MustAlterProfile = false;
|
||||
|
||||
// try
|
||||
// {
|
||||
// // mail system
|
||||
// AgentMailType mailType;
|
||||
// if (isSQL2005)
|
||||
// {
|
||||
// mailType = agent.AgentMailType;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// mailType = AgentMailType.SqlAgentMail;
|
||||
// }
|
||||
// if (null != this.comboBoxMailSystem.SelectedItem)
|
||||
// {
|
||||
// if (this.comboBoxMailSystem.SelectedItem.ToString() == SqlServerAgentSR.SQLMail)
|
||||
// {
|
||||
// if (mailType != AgentMailType.SqlAgentMail)
|
||||
// {
|
||||
// AlterValues = true;
|
||||
// MustAlterProfile = true;
|
||||
// mailType = AgentMailType.SqlAgentMail;
|
||||
// agent.AgentMailType = AgentMailType.SqlAgentMail;
|
||||
// }
|
||||
// }
|
||||
// else if (this.comboBoxMailSystem.SelectedItem.ToString() == SqlServerAgentSR.SQLIMail)
|
||||
// {
|
||||
// if (mailType != AgentMailType.DatabaseMail)
|
||||
// {
|
||||
// AlterValues = true;
|
||||
// MustAlterProfile = true;
|
||||
// mailType = AgentMailType.DatabaseMail;
|
||||
// agent.AgentMailType = AgentMailType.DatabaseMail;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// System.Diagnostics.Debug.Assert(false, "unknown selection for mail system");
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (this.checkEnableMailProfile.Checked == false)
|
||||
// {
|
||||
// // disable profiles
|
||||
// if (
|
||||
// (agent.SqlAgentMailProfile.Length != 0) ||
|
||||
// (true == isSQL2005 && agent.DatabaseMailProfile.Length != 0)
|
||||
// )
|
||||
// {
|
||||
// AlterValues = true;
|
||||
|
||||
// agent.SqlAgentMailProfile = String.Empty;
|
||||
// if (true == isSQL2005)
|
||||
// {
|
||||
// agent.DatabaseMailProfile = String.Empty;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// // enable profiles
|
||||
// if
|
||||
// (
|
||||
// (agent.SqlAgentMailProfile.Length == 0) &&
|
||||
// (true == isSQL2005 && agent.DatabaseMailProfile.Length == 0)
|
||||
// )
|
||||
// {
|
||||
// AlterValues = true;
|
||||
// MustAlterProfile = true;
|
||||
// }
|
||||
|
||||
// if
|
||||
// (
|
||||
// (mailType == AgentMailType.SqlAgentMail) &&
|
||||
// (
|
||||
// (agent.SqlAgentMailProfile != this.comboMailProfiles.Text) ||
|
||||
// (MustAlterProfile == true)
|
||||
// )
|
||||
// )
|
||||
// {
|
||||
// AlterValues = true;
|
||||
// agent.SqlAgentMailProfile = this.comboMailProfiles.Text;
|
||||
// }
|
||||
|
||||
// if
|
||||
// ((true == isSQL2005) &&
|
||||
// (mailType == AgentMailType.DatabaseMail) &&
|
||||
// (
|
||||
// (agent.DatabaseMailProfile != this.comboMailProfiles.Text) ||
|
||||
// (MustAlterProfile == true)
|
||||
// )
|
||||
// )
|
||||
// {
|
||||
// AlterValues = true;
|
||||
// agent.DatabaseMailProfile = this.comboMailProfiles.Text;
|
||||
// }
|
||||
// }
|
||||
|
||||
// // save to sent folder
|
||||
|
||||
// if (this.checkSaveMailsToSentFolder.Checked != agent.SaveInSentFolder)
|
||||
// {
|
||||
// AlterValues = true;
|
||||
// agent.SaveInSentFolder = this.checkSaveMailsToSentFolder.Checked;
|
||||
// }
|
||||
|
||||
// // rest of ui
|
||||
|
||||
// string LineTemplate = this.textToPrefix.Text;
|
||||
|
||||
// if (true == this.checkToAddress.Checked)
|
||||
// {
|
||||
// LineTemplate += AlertEnginePagerAddressToken + this.textToSuffix.Text;
|
||||
// }
|
||||
|
||||
// if (LineTemplate != agent.AlertSystem.PagerToTemplate)
|
||||
// {
|
||||
// AlterAlertValues = true;
|
||||
// agent.AlertSystem.PagerToTemplate = LineTemplate;
|
||||
// }
|
||||
|
||||
// LineTemplate = this.textCCPrfix.Text;
|
||||
// if (true == this.checkCCAddress.Checked)
|
||||
// {
|
||||
// LineTemplate += AlertEnginePagerAddressToken + this.textCCSuffix.Text;
|
||||
// }
|
||||
// if (LineTemplate != agent.AlertSystem.PagerCCTemplate)
|
||||
// {
|
||||
// AlterAlertValues = true;
|
||||
// agent.AlertSystem.PagerCCTemplate = LineTemplate;
|
||||
// }
|
||||
|
||||
// LineTemplate = this.textSubjectPrefix.Text + AlertEngineSubjectToken + this.textSubjectSuffix.Text;
|
||||
// if (LineTemplate != agent.AlertSystem.PagerSubjectTemplate &&
|
||||
// agent.AlertSystem.PagerSubjectTemplate.Length > 0)
|
||||
// {
|
||||
// AlterAlertValues = true;
|
||||
// agent.AlertSystem.PagerSubjectTemplate = LineTemplate;
|
||||
// }
|
||||
|
||||
// if (true == isSQL2005)
|
||||
// {
|
||||
// bool isTokenRplacementEnabled = this.checkBoxTokenReplacement.Checked;
|
||||
// if (isTokenRplacementEnabled != agent.ReplaceAlertTokensEnabled)
|
||||
// {
|
||||
// AlterValues = true;
|
||||
// agent.ReplaceAlertTokensEnabled = isTokenRplacementEnabled;
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (this.checkPagerIncludeBody.Checked != !agent.AlertSystem.PagerSendSubjectOnly)
|
||||
// {
|
||||
// AlterAlertValues = true;
|
||||
// agent.AlertSystem.PagerSendSubjectOnly = !this.checkPagerIncludeBody.Checked;
|
||||
// }
|
||||
|
||||
// string currentOperator = agent.AlertSystem.FailSafeOperator;
|
||||
// string selectedOperator = Convert.ToString(this.comboOperators.SelectedItem,
|
||||
// System.Globalization.CultureInfo.CurrentUICulture);
|
||||
|
||||
// if (this.checkEnableOperator.Checked &&
|
||||
// (currentOperator.Length == 0 || (currentOperator != selectedOperator)))
|
||||
// {
|
||||
// // update the operator to the new value
|
||||
// AlterAlertValues = true;
|
||||
// agent.AlertSystem.FailSafeOperator = selectedOperator;
|
||||
// }
|
||||
// else if (!this.checkEnableOperator.Checked && currentOperator.Length > 0)
|
||||
// {
|
||||
// // reset the operator
|
||||
// AlterAlertValues = true;
|
||||
// agent.AlertSystem.FailSafeOperator = string.Empty;
|
||||
// }
|
||||
|
||||
// int CurrentNotifyValue = 0;
|
||||
// if (this.checkNotifyEmail.Checked == true)
|
||||
// {
|
||||
// CurrentNotifyValue |= (int) NotifyMethods.NotifyEmail;
|
||||
// }
|
||||
|
||||
// if (this.checkNotifyPager.Checked == true)
|
||||
// {
|
||||
// CurrentNotifyValue |= (int) NotifyMethods.Pager;
|
||||
// }
|
||||
|
||||
// if (true == this.checkEnableOperator.Checked)
|
||||
// {
|
||||
// if (CurrentNotifyValue != (int) agent.AlertSystem.NotificationMethod)
|
||||
// {
|
||||
// AlterAlertValues = true;
|
||||
// agent.AlertSystem.NotificationMethod =
|
||||
// (Microsoft.SqlServer.Management.Smo.Agent.NotifyMethods) CurrentNotifyValue;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (agent.AlertSystem.NotificationMethod != NotifyMethods.None)
|
||||
// {
|
||||
// AlterAlertValues = true;
|
||||
// agent.AlertSystem.NotificationMethod = NotifyMethods.None;
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (true == AlterAlertValues)
|
||||
// {
|
||||
// agent.AlertSystem.Alter();
|
||||
// }
|
||||
|
||||
// if (true == AlterValues)
|
||||
// {
|
||||
// agent.Alter();
|
||||
// }
|
||||
// }
|
||||
// catch (SmoException smoex)
|
||||
// {
|
||||
// DisplayExceptionMessage(smoex);
|
||||
// this.ExecutionMode = ExecutionMode.Failure;
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
// private void InitProperties()
|
||||
// {
|
||||
// JobServer agent = DataContainer.Server.JobServer;
|
||||
|
||||
// bool isSql2005 = DataContainer.Server.Information.Version.Major >= SQL2005;
|
||||
// bool isSqlIMailEnabled = isSql2005 && this.DataContainer.Server.Databases["msdb"].IsMailHost == true;
|
||||
|
||||
// ExtendedStoredProcedure sendMail =
|
||||
// this.DataContainer.Server.Databases["master"].ExtendedStoredProcedures["xp_sendmail", "sys"];
|
||||
|
||||
// bool isSqlMailEnabled = (null != sendMail);
|
||||
|
||||
|
||||
// //bool isSqlMailEnabled = this.DataContainer.Server.Databases["master"].ExtendedStoredProcedures.Contains("sys.xp_sendmail");
|
||||
|
||||
// bool isMailEnabled = isSqlIMailEnabled || isSqlMailEnabled;
|
||||
|
||||
// this.checkEnableMailProfile.Enabled = isMailEnabled;
|
||||
|
||||
// this.checkEnableMailProfile.Checked = (isMailEnabled == true) &&
|
||||
// ((agent.SqlAgentMailProfile.Length != 0) ||
|
||||
// (isSql2005 && agent.DatabaseMailProfile.Length != 0));
|
||||
|
||||
// if (true == isSql2005)
|
||||
// {
|
||||
// bool isTokenReplacementEnabled = agent.ReplaceAlertTokensEnabled;
|
||||
// this.checkBoxTokenReplacement.Enabled = true;
|
||||
// this.checkBoxTokenReplacement.Checked = isTokenReplacementEnabled;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// this.checkBoxTokenReplacement.Enabled = false;
|
||||
// this.checkBoxTokenReplacement.Checked = false;
|
||||
// }
|
||||
|
||||
// string ToLineTemplate = agent.AlertSystem.PagerToTemplate;
|
||||
// int pos = ToLineTemplate.IndexOf(AlertEnginePagerAddressToken, StringComparison.Ordinal);
|
||||
// if (pos > 0)
|
||||
// {
|
||||
// this.textToPrefix.Text = ToLineTemplate.Substring(0, pos);
|
||||
// this.checkToAddress.Checked = true;
|
||||
// pos += AlertEnginePagerAddressToken.Length;
|
||||
// this.textToSuffix.Text = ToLineTemplate.Substring(pos, ToLineTemplate.Length - pos);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// this.textToPrefix.Text = ToLineTemplate;
|
||||
// this.checkToAddress.Checked = false;
|
||||
// this.textToSuffix.Enabled = false;
|
||||
// }
|
||||
|
||||
// string CcLineTemplate = agent.AlertSystem.PagerCCTemplate;
|
||||
// pos = CcLineTemplate.IndexOf(AlertEnginePagerAddressToken, StringComparison.Ordinal);
|
||||
// if (pos > 0)
|
||||
// {
|
||||
// this.textCCPrfix.Text = CcLineTemplate.Substring(0, pos);
|
||||
// this.checkCCAddress.Checked = true;
|
||||
// pos += AlertEnginePagerAddressToken.Length;
|
||||
// this.textCCSuffix.Text = CcLineTemplate.Substring(pos, CcLineTemplate.Length - pos);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// this.textCCPrfix.Text = CcLineTemplate;
|
||||
// this.checkCCAddress.Checked = false;
|
||||
// this.textCCSuffix.Enabled = false;
|
||||
// }
|
||||
|
||||
// string SubjectLineTemplate = agent.AlertSystem.PagerSubjectTemplate;
|
||||
// pos = SubjectLineTemplate.IndexOf(AlertEngineSubjectToken, StringComparison.Ordinal);
|
||||
|
||||
// if (pos > -1)
|
||||
// {
|
||||
// this.textSubjectPrefix.Text = SubjectLineTemplate.Substring(0, pos);
|
||||
// pos += AlertEngineSubjectToken.Length;
|
||||
// this.textSubjectSuffix.Text = SubjectLineTemplate.Substring(pos, SubjectLineTemplate.Length - pos);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// /// We should throw ex here
|
||||
// }
|
||||
|
||||
|
||||
// try
|
||||
// {
|
||||
// this.checkPagerIncludeBody.Checked = !agent.AlertSystem.PagerSendSubjectOnly;
|
||||
// }
|
||||
// catch (SmoException)
|
||||
// {
|
||||
// this.checkPagerIncludeBody.Checked = false;
|
||||
// this.checkPagerIncludeBody.Enabled = false;
|
||||
// }
|
||||
|
||||
// PopulateOperatorsCombo();
|
||||
|
||||
|
||||
// try
|
||||
// {
|
||||
// bool enable = this.checkEnableOperator.Checked;
|
||||
// this.checkNotifyEmail.Enabled = enable;
|
||||
// this.checkNotifyPager.Enabled = enable;
|
||||
|
||||
// this.checkNotifyEmail.Checked = ((int) NotifyMethods.NotifyEmail &
|
||||
// (int) agent.AlertSystem.NotificationMethod) > 0;
|
||||
|
||||
// this.checkNotifyPager.Checked = ((int) NotifyMethods.Pager & (int) agent.AlertSystem.NotificationMethod) >
|
||||
// 0;
|
||||
// }
|
||||
// catch (SmoException)
|
||||
// {
|
||||
// this.checkNotifyEmail.Checked = false;
|
||||
// this.checkNotifyPager.Checked = false;
|
||||
// this.checkNotifyEmail.Enabled = false;
|
||||
// this.checkNotifyPager.Enabled = false;
|
||||
// }
|
||||
|
||||
// if (true == isMailEnabled)
|
||||
// {
|
||||
// AgentMailType mailType;
|
||||
// if (isSql2005 == true)
|
||||
// {
|
||||
// if (agent.AgentMailType == AgentMailType.SqlAgentMail && true == isSqlMailEnabled &&
|
||||
// 0 < agent.SqlAgentMailProfile.Length)
|
||||
// {
|
||||
// mailType = agent.AgentMailType;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// mailType = AgentMailType.DatabaseMail;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// mailType = AgentMailType.SqlAgentMail;
|
||||
// }
|
||||
|
||||
// PopulateMailSystemsCombo(mailType, DataContainer.Server.Information.Version);
|
||||
// //PopulateMailProfilesCombo(mailType);
|
||||
// EnableDisableProfilesUI(agent);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// this.comboBoxMailSystem.Enabled = false;
|
||||
// this.comboMailProfiles.Enabled = false;
|
||||
// this.buttonTest.Enabled = false;
|
||||
// this.checkSaveMailsToSentFolder.Enabled = false;
|
||||
// }
|
||||
// }
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Enumerates the sqlmail profiles
|
||||
/// </summary>
|
||||
/// <param name="server"></param>
|
||||
/// <param name="mailProfiles"></param>
|
||||
private void EnumerateSqlMailProfiles(Microsoft.SqlServer.Management.Smo.Server server,
|
||||
StringCollection mailProfiles)
|
||||
{
|
||||
DataSet ds =
|
||||
server.ConnectionContext.ExecuteWithResults("master.dbo.xp_sqlagent_notify N'M', null, null, null, N'E'");
|
||||
if (null != ds && ds.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
foreach (DataRow dr in ds.Tables[0].Rows)
|
||||
{
|
||||
mailProfiles.Add(dr[0].ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region Dispose
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlServer.Management.Sdk.Sfc;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Collections;
|
||||
using System.ComponentModel;
|
||||
using System.Xml;
|
||||
using Microsoft.SqlServer.Management.Smo;
|
||||
using Microsoft.SqlServer.Management.Smo.Agent;
|
||||
using Microsoft.SqlServer.Management.Common;
|
||||
using System.Data.SqlClient;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Resources;
|
||||
using Microsoft.SqlServer.Management.Diagnostics;
|
||||
using System.Globalization;
|
||||
using Microsoft.SqlTools.ServiceLayer.Management;
|
||||
using Microsoft.SqlTools.ServiceLayer.Admin;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for SqlServerAgentPropertiesConnection.
|
||||
/// </summary>
|
||||
internal class SqlServerAgentPropertiesConnection : ManagementActionBase
|
||||
{
|
||||
bool SqlPasswordChanged = false;
|
||||
|
||||
|
||||
#region Implementation
|
||||
|
||||
// private void ApplyChanges()
|
||||
// {
|
||||
// this.ExecutionMode = ExecutionMode.Success;
|
||||
// JobServer agent = DataContainer.Server.JobServer;
|
||||
// string OriginalLogin = agent.HostLoginName;
|
||||
// string CurrentLogin = "";
|
||||
// bool AlterValues = false;
|
||||
// try
|
||||
// {
|
||||
// if (true == this.radioSQLAuth.Checked)
|
||||
// {
|
||||
// CurrentLogin = (this.comboLogin.SelectedItem).ToString();
|
||||
// }
|
||||
// if (String.Compare(CurrentLogin, OriginalLogin, StringComparison.OrdinalIgnoreCase) != 0 || true == SqlPasswordChanged)
|
||||
// {
|
||||
// if (CurrentLogin.Length > 0)
|
||||
// {
|
||||
// agent.SetHostLoginAccount(CurrentLogin, this.textPassword.Text);
|
||||
// VerifyLogin();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// agent.ClearHostLoginAccount();
|
||||
// }
|
||||
// }
|
||||
|
||||
// string SelectedAlias = this.comboAliases.Text;
|
||||
|
||||
// if (String.Compare(SelectedAlias, agent.LocalHostAlias, StringComparison.OrdinalIgnoreCase) != 0)
|
||||
// {
|
||||
// AlterValues = true;
|
||||
|
||||
// agent.LocalHostAlias = SelectedAlias;
|
||||
|
||||
// }
|
||||
// if (true == AlterValues)
|
||||
// {
|
||||
// agent.Alter();
|
||||
// }
|
||||
// }
|
||||
// catch (SmoException smoex)
|
||||
// {
|
||||
// DisplayExceptionMessage(smoex);
|
||||
// this.ExecutionMode = ExecutionMode.Failure;
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
// private void InitProperties()
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// JobServer agent = DataContainer.Server.JobServer;
|
||||
|
||||
// if (this.DataContainer.Server.Information.Version.Major < 9)
|
||||
// {
|
||||
|
||||
// PopulateLoginCombo();
|
||||
|
||||
// bool IsWinAuth = (agent.HostLoginName.Length == 0);
|
||||
// this.radioWinAuth.Checked = IsWinAuth;
|
||||
// this.radioSQLAuth.Checked = !IsWinAuth;
|
||||
// if (false == IsWinAuth)
|
||||
// {
|
||||
// string SqlLogin = agent.HostLoginName;
|
||||
// if (!this.comboLogin.Items.Contains(SqlLogin))
|
||||
// {
|
||||
// this.comboLogin.Items.Add(SqlLogin);
|
||||
// }
|
||||
// this.comboLogin.SelectedItem = SqlLogin;
|
||||
// this.textPassword.Text = "**********";
|
||||
// SqlPasswordChanged = false;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// this.radioWinAuth.Checked = true;
|
||||
// this.radioWinAuth.Enabled = this.radioSQLAuth.Enabled = this.comboLogin.Enabled = false;
|
||||
// this.textPassword.Enabled = this.labelLogin.Enabled = this.labelPasswd.Enabled = false;
|
||||
// }
|
||||
|
||||
// string ServerAliasHost = agent.LocalHostAlias;
|
||||
// this.comboAliases.Text = ServerAliasHost;
|
||||
|
||||
// // Managed Instances do not allow changing
|
||||
// // "alias local host server"
|
||||
// //
|
||||
// this.comboAliases.Enabled = DataContainer.Server.DatabaseEngineEdition != DatabaseEngineEdition.SqlManagedInstance;
|
||||
// }
|
||||
// catch (Exception)
|
||||
// {
|
||||
// }
|
||||
// }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region ctors
|
||||
|
||||
public SqlServerAgentPropertiesConnection(CDataContainer dataContainer)
|
||||
{
|
||||
DataContainer = dataContainer;
|
||||
//this.HelpF1Keyword = AssemblyVersionInfo.VersionHelpKeywordPrefix + @".ag.agent.connection.f1";
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Dispose
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,259 @@
|
||||
//
|
||||
// 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.ServiceProcess;
|
||||
using Microsoft.SqlServer.Management.Sdk.Sfc;
|
||||
using Microsoft.SqlServer.Management.Smo.Agent;
|
||||
using Microsoft.SqlServer.Management.Common;
|
||||
using SMO = Microsoft.SqlServer.Management.Smo;
|
||||
using Microsoft.SqlTools.ServiceLayer.Management;
|
||||
using Microsoft.SqlTools.ServiceLayer.Admin;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for SqlServerAgentPropertiesGeneral.
|
||||
/// </summary>
|
||||
internal class SqlServerAgentPropertiesGeneral : ManagementActionBase
|
||||
{
|
||||
|
||||
#region Implementation members
|
||||
private int ServerVersion = 0;
|
||||
const int Version_90 = 9;
|
||||
#endregion
|
||||
|
||||
#region ctors
|
||||
|
||||
public SqlServerAgentPropertiesGeneral(CDataContainer dataContainer)
|
||||
{
|
||||
DataContainer = dataContainer;
|
||||
ServerVersion = DataContainer.Server.Information.Version.Major;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Implementation
|
||||
|
||||
// private void ApplyChanges()
|
||||
// {
|
||||
// this.ExecutionMode = ExecutionMode.Success;
|
||||
// JobServer agent = DataContainer.Server.JobServer;
|
||||
// bool AlterValues = false;
|
||||
// try
|
||||
// {
|
||||
// if (this.checkAutoAgent.Checked != agent.SqlAgentRestart)
|
||||
// {
|
||||
// AlterValues = true;
|
||||
// agent.SqlAgentRestart = this.checkAutoAgent.Checked;
|
||||
// }
|
||||
|
||||
// if (this.checkAutoSql.Checked != agent.SqlServerRestart)
|
||||
// {
|
||||
// AlterValues = true;
|
||||
// agent.SqlServerRestart = this.checkAutoSql.Checked;
|
||||
// }
|
||||
|
||||
// if (this.textFileName.Text != agent.ErrorLogFile)
|
||||
// {
|
||||
// AlterValues = true;
|
||||
// agent.ErrorLogFile = this.textFileName.Text;
|
||||
// }
|
||||
|
||||
// if ((this.checkIncludeTrace.Checked == true && agent.AgentLogLevel != AgentLogLevels.All) || (this.checkIncludeTrace.Checked == false && agent.AgentLogLevel == AgentLogLevels.All))
|
||||
// {
|
||||
// AlterValues = true;
|
||||
// agent.AgentLogLevel = (this.checkIncludeTrace.Checked == true) ? AgentLogLevels.All : AgentLogLevels.Errors;
|
||||
// }
|
||||
// if (this.checkWriteOem.Checked != agent.WriteOemErrorLog)
|
||||
// {
|
||||
// AlterValues = true;
|
||||
// agent.WriteOemErrorLog = this.checkWriteOem.Checked;
|
||||
// }
|
||||
|
||||
// if (true == AlterValues)
|
||||
// {
|
||||
// agent.Alter();
|
||||
// }
|
||||
// }
|
||||
// catch (SMO.SmoException smoex)
|
||||
// {
|
||||
// DisplayExceptionMessage(smoex);
|
||||
// this.ExecutionMode = ExecutionMode.Failure;
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
private void InitProperties()
|
||||
{
|
||||
|
||||
SMO.Server smoServer = DataContainer.Server;
|
||||
string SqlServerName = smoServer.Information.NetName;
|
||||
bool instanceSupported = smoServer.Information.Version >= new Version(8, 0);
|
||||
string InstanceName = instanceSupported ? smoServer.InstanceName : String.Empty;
|
||||
string machineName = CUtils.GetMachineName(SqlServerName);
|
||||
|
||||
bool IsDefaultInstance = true;
|
||||
|
||||
/// Determine if we work with the default instance
|
||||
if (0 != InstanceName.Length)
|
||||
{
|
||||
/// we work with a named instance
|
||||
IsDefaultInstance = false;
|
||||
}
|
||||
|
||||
string AgentServiceName = string.Empty;
|
||||
|
||||
if (false == IsDefaultInstance)
|
||||
{
|
||||
AgentServiceName = "SQLAgent$" + InstanceName;
|
||||
}
|
||||
else
|
||||
{
|
||||
AgentServiceName = "sqlserveragent";
|
||||
}
|
||||
|
||||
// try
|
||||
// {
|
||||
// using (ServiceController agentService = new ServiceController(AgentServiceName, machineName))
|
||||
// {
|
||||
// if (agentService.Status == ServiceControllerStatus.Stopped)
|
||||
// {
|
||||
// agentStopped = true;
|
||||
// }
|
||||
// this.textServiceState.Text = GetServiceState(agentService.Status);
|
||||
// }
|
||||
// }
|
||||
// catch (Exception)
|
||||
// {
|
||||
// this.textServiceState.Text = string.Empty;
|
||||
// }
|
||||
|
||||
// this.textFileName.ReadOnly = true;
|
||||
// this.buttonBrowse.Enabled = agentStopped;
|
||||
// this.checkWriteOem.Enabled = agentStopped;
|
||||
|
||||
/// Get the job server (agent) object
|
||||
JobServer agent = smoServer.JobServer;
|
||||
|
||||
// try
|
||||
// {
|
||||
// this.checkAutoAgent.Checked = agent.SqlAgentRestart;
|
||||
// }
|
||||
// catch (SMO.SmoException)
|
||||
// {
|
||||
// this.checkAutoAgent.Enabled = false;
|
||||
// }
|
||||
|
||||
// try
|
||||
// {
|
||||
// this.checkAutoSql.Checked = agent.SqlServerRestart;
|
||||
// }
|
||||
// catch (SMO.SmoException)
|
||||
// {
|
||||
// this.checkAutoSql.Enabled = false;
|
||||
// }
|
||||
|
||||
// Managed Instances (CloudLifter) do not allow
|
||||
// changing setting related to service restarts.
|
||||
// Just disable the UI elements altogether.
|
||||
//
|
||||
// this.checkAutoAgent.Enabled = smoServer.DatabaseEngineEdition != DatabaseEngineEdition.SqlManagedInstance;
|
||||
// this.checkAutoSql.Enabled = smoServer.DatabaseEngineEdition != DatabaseEngineEdition.SqlManagedInstance;
|
||||
|
||||
// /// Error log file name
|
||||
// this.textFileName.Text = agent.ErrorLogFile;
|
||||
// this.toolTip1.SetToolTip(this.textFileName, agent.ErrorLogFile);
|
||||
|
||||
// /// Log level - All == Include trace messages
|
||||
// this.checkIncludeTrace.Checked = (agent.AgentLogLevel == AgentLogLevels.All);
|
||||
|
||||
// /// Write OEM file
|
||||
// this.checkWriteOem.Checked = agent.WriteOemErrorLog;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// private string GetServiceState(ServiceControllerStatus serviceState)
|
||||
// {
|
||||
// if (serviceState == ServiceControllerStatus.Running)
|
||||
// {
|
||||
// return SqlServerAgentSR.ServiceState_Running;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (serviceState == ServiceControllerStatus.Stopped)
|
||||
// {
|
||||
// return SqlServerAgentSR.ServiceState_Stopped;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (serviceState == ServiceControllerStatus.Paused)
|
||||
// {
|
||||
// return SqlServerAgentSR.ServiceState_Paused;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (serviceState == ServiceControllerStatus.ContinuePending)
|
||||
// {
|
||||
// return SqlServerAgentSR.ServiceState_ContinuePending;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (serviceState == ServiceControllerStatus.StartPending)
|
||||
// {
|
||||
// return SqlServerAgentSR.ServiceState_StartPending;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (serviceState == ServiceControllerStatus.PausePending)
|
||||
// {
|
||||
// return SqlServerAgentSR.ServiceState_PausePending;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (serviceState == ServiceControllerStatus.StopPending)
|
||||
// {
|
||||
// return SqlServerAgentSR.ServiceState_StopPending;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return SqlServerAgentSR.Unknown;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Dispose
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlServer.Management.Sdk.Sfc;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Collections;
|
||||
using System.ComponentModel;
|
||||
using System.Xml;
|
||||
using Microsoft.SqlServer.Management.Smo;
|
||||
using Microsoft.SqlServer.Management.Common;
|
||||
using System.Data.SqlClient;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Resources;
|
||||
using Microsoft.SqlServer.Management.Diagnostics;
|
||||
using Microsoft.SqlServer.Management.Smo.Agent;
|
||||
using Microsoft.SqlTools.ServiceLayer.Management;
|
||||
using Microsoft.SqlTools.ServiceLayer.Admin;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for SqlServerAgentPropertiesHistory.
|
||||
/// </summary>
|
||||
internal class SqlServerAgentPropertiesHistory : ManagementActionBase
|
||||
{
|
||||
|
||||
|
||||
#region ctors
|
||||
|
||||
public SqlServerAgentPropertiesHistory(CDataContainer dataContainer)
|
||||
{
|
||||
DataContainer = dataContainer;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Implementation
|
||||
|
||||
// private void ApplyChanges()
|
||||
// {
|
||||
// this.ExecutionMode = ExecutionMode.Success;
|
||||
|
||||
// JobServer agent = DataContainer.Server.JobServer;
|
||||
|
||||
// bool LimitHistory = this.checkLimitHistorySize.Checked;
|
||||
// bool DeleteHistory = this.checkRemoveHistory.Checked;
|
||||
// bool AlterValues = false;
|
||||
// int MaxLogRows = -1;
|
||||
// int MaxRowsJob = -1;
|
||||
|
||||
// try
|
||||
// {
|
||||
// if (true == LimitHistory)
|
||||
// {
|
||||
// MaxLogRows = (int) this.textMaxHistoryRows.Value;
|
||||
// MaxRowsJob = (int) this.textMaxHistoryRowsPerJob.Value;
|
||||
// }
|
||||
// if (MaxLogRows != agent.MaximumHistoryRows)
|
||||
// {
|
||||
// agent.MaximumHistoryRows = MaxLogRows;
|
||||
// AlterValues = true;
|
||||
// }
|
||||
// if (MaxRowsJob != agent.MaximumJobHistoryRows)
|
||||
// {
|
||||
// agent.MaximumJobHistoryRows = MaxRowsJob;
|
||||
// AlterValues = true;
|
||||
// }
|
||||
// if (true == DeleteHistory)
|
||||
// {
|
||||
// int timeunits = (int) this.numTimeUnits.Value;
|
||||
// JobHistoryFilter jobHistoryFilter = new JobHistoryFilter();
|
||||
// jobHistoryFilter.EndRunDate = CUtils.GetOldestDate(timeunits,
|
||||
// (TimeUnitType) (this.comboTimeUnits.SelectedIndex));
|
||||
// agent.PurgeJobHistory(jobHistoryFilter);
|
||||
// }
|
||||
|
||||
// if (true == AlterValues)
|
||||
// {
|
||||
// agent.Alter();
|
||||
// }
|
||||
// }
|
||||
// catch (SmoException smoex)
|
||||
// {
|
||||
// DisplayExceptionMessage(smoex);
|
||||
// this.ExecutionMode = ExecutionMode.Failure;
|
||||
// }
|
||||
// }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Dispose
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
//
|
||||
// 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.Drawing;
|
||||
using System.Collections;
|
||||
using System.ComponentModel;
|
||||
using System.Data.SqlClient;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Resources;
|
||||
using System.Security;
|
||||
using System.Xml;
|
||||
using Microsoft.SqlServer.Management.Sdk.Sfc;
|
||||
using Microsoft.SqlServer.Management.Smo;
|
||||
using Microsoft.SqlServer.Management.Smo.Agent;
|
||||
using Microsoft.SqlServer.Management.Common;
|
||||
using Microsoft.SqlServer.Management.Diagnostics;
|
||||
using Microsoft.SqlTools.ServiceLayer.Admin;
|
||||
using Microsoft.SqlTools.ServiceLayer.Management;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for SqlServerAgentPropertiesJobSystem.
|
||||
/// </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()
|
||||
{
|
||||
// this.ExecutionMode = ExecutionMode.Success;
|
||||
// bool AlterValues = false;
|
||||
// bool AlterProxyValues = false;
|
||||
|
||||
// JobServer agent = DataContainer.Server.JobServer;
|
||||
|
||||
// try
|
||||
// {
|
||||
// if (this.shutDownWaitTime != agent.AgentShutdownWaitTime)
|
||||
// {
|
||||
// agent.AgentShutdownWaitTime = this.shutDownWaitTime;
|
||||
// AlterValues = true;
|
||||
// }
|
||||
|
||||
// if (this.DataContainer.Server.Information.Version.Major < 9)
|
||||
// {
|
||||
// if (this.domainUser.Length != 0)
|
||||
// {
|
||||
// this.domainUser = this.domainUser + "\\" + this.userName;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// this.domainUser = this.userName;
|
||||
// }
|
||||
|
||||
// if (this.sysAdminOnly != agent.SysAdminOnly)
|
||||
// {
|
||||
// AlterProxyValues = true;
|
||||
// if (true == this.sysAdminOnly)
|
||||
// {
|
||||
// DataContainer.Server.ProxyAccount.IsEnabled = false;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// DataContainer.Server.ProxyAccount.IsEnabled = true;
|
||||
// DataContainer.Server.ProxyAccount.SetAccount(domainUser, this.securePasswd.ToString());
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (this.sysAdminOnly == false)
|
||||
// {
|
||||
// if (domainUser != DataContainer.Server.ProxyAccount.WindowsAccount)
|
||||
// {
|
||||
// AlterProxyValues = true;
|
||||
// DataContainer.Server.ProxyAccount.SetAccount(domainUser, this.securePasswd.ToString());
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (passwdMask != this.securePasswd.ToString())
|
||||
// {
|
||||
// AlterProxyValues = true;
|
||||
// DataContainer.Server.ProxyAccount.SetPassword(this.securePasswd.ToString());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (true == AlterProxyValues)
|
||||
// {
|
||||
// DataContainer.Server.ProxyAccount.Alter();
|
||||
// }
|
||||
// if(true == AlterValues)
|
||||
// {
|
||||
// agent.Alter();
|
||||
// }
|
||||
// }
|
||||
// catch(SmoException smoex)
|
||||
// {
|
||||
// DisplayExceptionMessage(smoex);
|
||||
// this.ExecutionMode = ExecutionMode.Failure;
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region ctors
|
||||
|
||||
public SqlServerAgentPropertiesJobSystem(CDataContainer dataContainer)
|
||||
{
|
||||
//InitializeComponent();
|
||||
DataContainer = dataContainer;
|
||||
//this.HelpF1Keyword = AssemblyVersionInfo.VersionHelpKeywordPrefix + @".ag.agent.job.f1";
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Dispose
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
protected override void Dispose( bool disposing )
|
||||
{
|
||||
if( disposing )
|
||||
{
|
||||
}
|
||||
base.Dispose( disposing );
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -4173,6 +4173,174 @@ namespace Microsoft.SqlTools.ServiceLayer
|
||||
}
|
||||
}
|
||||
|
||||
public static string CategoryLocal
|
||||
{
|
||||
get
|
||||
{
|
||||
return Keys.GetString(Keys.CategoryLocal);
|
||||
}
|
||||
}
|
||||
|
||||
public static string CategoryFromMsx
|
||||
{
|
||||
get
|
||||
{
|
||||
return Keys.GetString(Keys.CategoryFromMsx);
|
||||
}
|
||||
}
|
||||
|
||||
public static string CategoryMultiServer
|
||||
{
|
||||
get
|
||||
{
|
||||
return Keys.GetString(Keys.CategoryMultiServer);
|
||||
}
|
||||
}
|
||||
|
||||
public static string CategoryDBMaint
|
||||
{
|
||||
get
|
||||
{
|
||||
return Keys.GetString(Keys.CategoryDBMaint);
|
||||
}
|
||||
}
|
||||
|
||||
public static string CategoryWebAssistant
|
||||
{
|
||||
get
|
||||
{
|
||||
return Keys.GetString(Keys.CategoryWebAssistant);
|
||||
}
|
||||
}
|
||||
|
||||
public static string CategoryFullText
|
||||
{
|
||||
get
|
||||
{
|
||||
return Keys.GetString(Keys.CategoryFullText);
|
||||
}
|
||||
}
|
||||
|
||||
public static string CategoryReplDistribution
|
||||
{
|
||||
get
|
||||
{
|
||||
return Keys.GetString(Keys.CategoryReplDistribution);
|
||||
}
|
||||
}
|
||||
|
||||
public static string CategoryReplDistributionCleanup
|
||||
{
|
||||
get
|
||||
{
|
||||
return Keys.GetString(Keys.CategoryReplDistributionCleanup);
|
||||
}
|
||||
}
|
||||
|
||||
public static string CategoryReplHistoryCleanup
|
||||
{
|
||||
get
|
||||
{
|
||||
return Keys.GetString(Keys.CategoryReplHistoryCleanup);
|
||||
}
|
||||
}
|
||||
|
||||
public static string CategoryReplLogReader
|
||||
{
|
||||
get
|
||||
{
|
||||
return Keys.GetString(Keys.CategoryReplLogReader);
|
||||
}
|
||||
}
|
||||
|
||||
public static string CategoryReplMerge
|
||||
{
|
||||
get
|
||||
{
|
||||
return Keys.GetString(Keys.CategoryReplMerge);
|
||||
}
|
||||
}
|
||||
|
||||
public static string CategoryReplSnapShot
|
||||
{
|
||||
get
|
||||
{
|
||||
return Keys.GetString(Keys.CategoryReplSnapShot);
|
||||
}
|
||||
}
|
||||
|
||||
public static string CategoryReplCheckup
|
||||
{
|
||||
get
|
||||
{
|
||||
return Keys.GetString(Keys.CategoryReplCheckup);
|
||||
}
|
||||
}
|
||||
|
||||
public static string CategoryReplCleanup
|
||||
{
|
||||
get
|
||||
{
|
||||
return Keys.GetString(Keys.CategoryReplCleanup);
|
||||
}
|
||||
}
|
||||
|
||||
public static string CategoryReplAlert
|
||||
{
|
||||
get
|
||||
{
|
||||
return Keys.GetString(Keys.CategoryReplAlert);
|
||||
}
|
||||
}
|
||||
|
||||
public static string CategoryReplQReader
|
||||
{
|
||||
get
|
||||
{
|
||||
return Keys.GetString(Keys.CategoryReplQReader);
|
||||
}
|
||||
}
|
||||
|
||||
public static string CategoryReplication
|
||||
{
|
||||
get
|
||||
{
|
||||
return Keys.GetString(Keys.CategoryReplication);
|
||||
}
|
||||
}
|
||||
|
||||
public static string CategoryUncategorized
|
||||
{
|
||||
get
|
||||
{
|
||||
return Keys.GetString(Keys.CategoryUncategorized);
|
||||
}
|
||||
}
|
||||
|
||||
public static string CategoryLogShipping
|
||||
{
|
||||
get
|
||||
{
|
||||
return Keys.GetString(Keys.CategoryLogShipping);
|
||||
}
|
||||
}
|
||||
|
||||
public static string CategoryDBEngineTuningAdvisor
|
||||
{
|
||||
get
|
||||
{
|
||||
return Keys.GetString(Keys.CategoryDBEngineTuningAdvisor);
|
||||
}
|
||||
}
|
||||
|
||||
public static string CategoryDataCollector
|
||||
{
|
||||
get
|
||||
{
|
||||
return Keys.GetString(Keys.CategoryDataCollector);
|
||||
}
|
||||
}
|
||||
|
||||
public static string ConnectionServiceListDbErrorNotConnected(string uri)
|
||||
{
|
||||
return Keys.GetString(Keys.ConnectionServiceListDbErrorNotConnected, uri);
|
||||
@@ -6111,6 +6279,69 @@ namespace Microsoft.SqlTools.ServiceLayer
|
||||
public const string CannotCreateScriptForModifyAlerts = "CannotCreateScriptForModifyAlerts";
|
||||
|
||||
|
||||
public const string CategoryLocal = "CategoryLocal";
|
||||
|
||||
|
||||
public const string CategoryFromMsx = "CategoryFromMsx";
|
||||
|
||||
|
||||
public const string CategoryMultiServer = "CategoryMultiServer";
|
||||
|
||||
|
||||
public const string CategoryDBMaint = "CategoryDBMaint";
|
||||
|
||||
|
||||
public const string CategoryWebAssistant = "CategoryWebAssistant";
|
||||
|
||||
|
||||
public const string CategoryFullText = "CategoryFullText";
|
||||
|
||||
|
||||
public const string CategoryReplDistribution = "CategoryReplDistribution";
|
||||
|
||||
|
||||
public const string CategoryReplDistributionCleanup = "CategoryReplDistributionCleanup";
|
||||
|
||||
|
||||
public const string CategoryReplHistoryCleanup = "CategoryReplHistoryCleanup";
|
||||
|
||||
|
||||
public const string CategoryReplLogReader = "CategoryReplLogReader";
|
||||
|
||||
|
||||
public const string CategoryReplMerge = "CategoryReplMerge";
|
||||
|
||||
|
||||
public const string CategoryReplSnapShot = "CategoryReplSnapShot";
|
||||
|
||||
|
||||
public const string CategoryReplCheckup = "CategoryReplCheckup";
|
||||
|
||||
|
||||
public const string CategoryReplCleanup = "CategoryReplCleanup";
|
||||
|
||||
|
||||
public const string CategoryReplAlert = "CategoryReplAlert";
|
||||
|
||||
|
||||
public const string CategoryReplQReader = "CategoryReplQReader";
|
||||
|
||||
|
||||
public const string CategoryReplication = "CategoryReplication";
|
||||
|
||||
|
||||
public const string CategoryUncategorized = "CategoryUncategorized";
|
||||
|
||||
|
||||
public const string CategoryLogShipping = "CategoryLogShipping";
|
||||
|
||||
|
||||
public const string CategoryDBEngineTuningAdvisor = "CategoryDBEngineTuningAdvisor";
|
||||
|
||||
|
||||
public const string CategoryDataCollector = "CategoryDataCollector";
|
||||
|
||||
|
||||
private Keys()
|
||||
{ }
|
||||
|
||||
|
||||
@@ -2424,4 +2424,88 @@
|
||||
<value>Cannot create script for modify alerts.</value>
|
||||
<comment> Exception thrown when we cannot create script that modify alerts</comment>
|
||||
</data>
|
||||
<data name="CategoryLocal" xml:space="preserve">
|
||||
<value>[Uncategorized (Local)]</value>
|
||||
<comment>job categories</comment>
|
||||
</data>
|
||||
<data name="CategoryFromMsx" xml:space="preserve">
|
||||
<value>Jobs from MSX</value>
|
||||
<comment></comment>
|
||||
</data>
|
||||
<data name="CategoryMultiServer" xml:space="preserve">
|
||||
<value>[Uncategorized (Multi-Server)]</value>
|
||||
<comment></comment>
|
||||
</data>
|
||||
<data name="CategoryDBMaint" xml:space="preserve">
|
||||
<value>Database Maintenance</value>
|
||||
<comment></comment>
|
||||
</data>
|
||||
<data name="CategoryWebAssistant" xml:space="preserve">
|
||||
<value>Web Assistant</value>
|
||||
<comment></comment>
|
||||
</data>
|
||||
<data name="CategoryFullText" xml:space="preserve">
|
||||
<value>Full-Text</value>
|
||||
<comment></comment>
|
||||
</data>
|
||||
<data name="CategoryReplDistribution" xml:space="preserve">
|
||||
<value>REPL-Distribution</value>
|
||||
<comment></comment>
|
||||
</data>
|
||||
<data name="CategoryReplDistributionCleanup" xml:space="preserve">
|
||||
<value>REPL-Distribution Cleanup</value>
|
||||
<comment></comment>
|
||||
</data>
|
||||
<data name="CategoryReplHistoryCleanup" xml:space="preserve">
|
||||
<value>REPL-History Cleanup</value>
|
||||
<comment></comment>
|
||||
</data>
|
||||
<data name="CategoryReplLogReader" xml:space="preserve">
|
||||
<value>REPL-LogReader</value>
|
||||
<comment></comment>
|
||||
</data>
|
||||
<data name="CategoryReplMerge" xml:space="preserve">
|
||||
<value>REPL-Merge</value>
|
||||
<comment></comment>
|
||||
</data>
|
||||
<data name="CategoryReplSnapShot" xml:space="preserve">
|
||||
<value>REPL-Snapshot</value>
|
||||
<comment></comment>
|
||||
</data>
|
||||
<data name="CategoryReplCheckup" xml:space="preserve">
|
||||
<value>REPL-Checkup</value>
|
||||
<comment></comment>
|
||||
</data>
|
||||
<data name="CategoryReplCleanup" xml:space="preserve">
|
||||
<value>REPL-Subscription Cleanup</value>
|
||||
<comment></comment>
|
||||
</data>
|
||||
<data name="CategoryReplAlert" xml:space="preserve">
|
||||
<value>REPL-Alert Response</value>
|
||||
<comment></comment>
|
||||
</data>
|
||||
<data name="CategoryReplQReader" xml:space="preserve">
|
||||
<value>REPL-QueueReader</value>
|
||||
<comment></comment>
|
||||
</data>
|
||||
<data name="CategoryReplication" xml:space="preserve">
|
||||
<value>Replication</value>
|
||||
<comment></comment>
|
||||
</data>
|
||||
<data name="CategoryUncategorized" xml:space="preserve">
|
||||
<value>[Uncategorized]</value>
|
||||
<comment></comment>
|
||||
</data>
|
||||
<data name="CategoryLogShipping" xml:space="preserve">
|
||||
<value>Log Shipping</value>
|
||||
<comment></comment>
|
||||
</data>
|
||||
<data name="CategoryDBEngineTuningAdvisor" xml:space="preserve">
|
||||
<value>Database Engine Tuning Advisor</value>
|
||||
<comment></comment>
|
||||
</data>
|
||||
<data name="CategoryDataCollector" xml:space="preserve">
|
||||
<value>Data Collector</value>
|
||||
<comment></comment>
|
||||
</data>
|
||||
</root>
|
||||
|
||||
@@ -1042,3 +1042,29 @@ OnSuccess = On success
|
||||
CannotModifyAlerts = Cannot modify alerts.
|
||||
; Exception thrown when we cannot create script that modify alerts
|
||||
CannotCreateScriptForModifyAlerts = Cannot create script for modify alerts.
|
||||
|
||||
|
||||
;job categories
|
||||
CategoryLocal = [Uncategorized (Local)]
|
||||
CategoryFromMsx = Jobs from MSX
|
||||
CategoryMultiServer = [Uncategorized (Multi-Server)]
|
||||
CategoryDBMaint = Database Maintenance
|
||||
CategoryWebAssistant = Web Assistant
|
||||
CategoryFullText = Full-Text
|
||||
CategoryReplDistribution = REPL-Distribution
|
||||
CategoryReplDistributionCleanup = REPL-Distribution Cleanup
|
||||
CategoryReplHistoryCleanup = REPL-History Cleanup
|
||||
CategoryReplLogReader = REPL-LogReader
|
||||
CategoryReplMerge = REPL-Merge
|
||||
CategoryReplSnapShot = REPL-Snapshot
|
||||
CategoryReplCheckup = REPL-Checkup
|
||||
CategoryReplCleanup = REPL-Subscription Cleanup
|
||||
CategoryReplAlert = REPL-Alert Response
|
||||
CategoryReplQReader = REPL-QueueReader
|
||||
CategoryReplication = Replication
|
||||
CategoryUncategorized = [Uncategorized]
|
||||
CategoryLogShipping = Log Shipping
|
||||
CategoryDBEngineTuningAdvisor = Database Engine Tuning Advisor
|
||||
CategoryDataCollector = Data Collector
|
||||
|
||||
|
||||
|
||||
@@ -2873,6 +2873,111 @@
|
||||
<target state="new">Cannot create script for modify alerts.</target>
|
||||
<note> Exception thrown when we cannot create script that modify alerts</note>
|
||||
</trans-unit>
|
||||
<trans-unit id="CategoryLocal">
|
||||
<source>[Uncategorized (Local)]</source>
|
||||
<target state="new">[Uncategorized (Local)]</target>
|
||||
<note>job categories</note>
|
||||
</trans-unit>
|
||||
<trans-unit id="CategoryFromMsx">
|
||||
<source>Jobs from MSX</source>
|
||||
<target state="new">Jobs from MSX</target>
|
||||
<note></note>
|
||||
</trans-unit>
|
||||
<trans-unit id="CategoryMultiServer">
|
||||
<source>[Uncategorized (Multi-Server)]</source>
|
||||
<target state="new">[Uncategorized (Multi-Server)]</target>
|
||||
<note></note>
|
||||
</trans-unit>
|
||||
<trans-unit id="CategoryDBMaint">
|
||||
<source>Database Maintenance</source>
|
||||
<target state="new">Database Maintenance</target>
|
||||
<note></note>
|
||||
</trans-unit>
|
||||
<trans-unit id="CategoryWebAssistant">
|
||||
<source>Web Assistant</source>
|
||||
<target state="new">Web Assistant</target>
|
||||
<note></note>
|
||||
</trans-unit>
|
||||
<trans-unit id="CategoryFullText">
|
||||
<source>Full-Text</source>
|
||||
<target state="new">Full-Text</target>
|
||||
<note></note>
|
||||
</trans-unit>
|
||||
<trans-unit id="CategoryReplDistribution">
|
||||
<source>REPL-Distribution</source>
|
||||
<target state="new">REPL-Distribution</target>
|
||||
<note></note>
|
||||
</trans-unit>
|
||||
<trans-unit id="CategoryReplDistributionCleanup">
|
||||
<source>REPL-Distribution Cleanup</source>
|
||||
<target state="new">REPL-Distribution Cleanup</target>
|
||||
<note></note>
|
||||
</trans-unit>
|
||||
<trans-unit id="CategoryReplHistoryCleanup">
|
||||
<source>REPL-History Cleanup</source>
|
||||
<target state="new">REPL-History Cleanup</target>
|
||||
<note></note>
|
||||
</trans-unit>
|
||||
<trans-unit id="CategoryReplLogReader">
|
||||
<source>REPL-LogReader</source>
|
||||
<target state="new">REPL-LogReader</target>
|
||||
<note></note>
|
||||
</trans-unit>
|
||||
<trans-unit id="CategoryReplMerge">
|
||||
<source>REPL-Merge</source>
|
||||
<target state="new">REPL-Merge</target>
|
||||
<note></note>
|
||||
</trans-unit>
|
||||
<trans-unit id="CategoryReplSnapShot">
|
||||
<source>REPL-Snapshot</source>
|
||||
<target state="new">REPL-Snapshot</target>
|
||||
<note></note>
|
||||
</trans-unit>
|
||||
<trans-unit id="CategoryReplCheckup">
|
||||
<source>REPL-Checkup</source>
|
||||
<target state="new">REPL-Checkup</target>
|
||||
<note></note>
|
||||
</trans-unit>
|
||||
<trans-unit id="CategoryReplCleanup">
|
||||
<source>REPL-Subscription Cleanup</source>
|
||||
<target state="new">REPL-Subscription Cleanup</target>
|
||||
<note></note>
|
||||
</trans-unit>
|
||||
<trans-unit id="CategoryReplAlert">
|
||||
<source>REPL-Alert Response</source>
|
||||
<target state="new">REPL-Alert Response</target>
|
||||
<note></note>
|
||||
</trans-unit>
|
||||
<trans-unit id="CategoryReplQReader">
|
||||
<source>REPL-QueueReader</source>
|
||||
<target state="new">REPL-QueueReader</target>
|
||||
<note></note>
|
||||
</trans-unit>
|
||||
<trans-unit id="CategoryReplication">
|
||||
<source>Replication</source>
|
||||
<target state="new">Replication</target>
|
||||
<note></note>
|
||||
</trans-unit>
|
||||
<trans-unit id="CategoryUncategorized">
|
||||
<source>[Uncategorized]</source>
|
||||
<target state="new">[Uncategorized]</target>
|
||||
<note></note>
|
||||
</trans-unit>
|
||||
<trans-unit id="CategoryLogShipping">
|
||||
<source>Log Shipping</source>
|
||||
<target state="new">Log Shipping</target>
|
||||
<note></note>
|
||||
</trans-unit>
|
||||
<trans-unit id="CategoryDBEngineTuningAdvisor">
|
||||
<source>Database Engine Tuning Advisor</source>
|
||||
<target state="new">Database Engine Tuning Advisor</target>
|
||||
<note></note>
|
||||
</trans-unit>
|
||||
<trans-unit id="CategoryDataCollector">
|
||||
<source>Data Collector</source>
|
||||
<target state="new">Data Collector</target>
|
||||
<note></note>
|
||||
</trans-unit>
|
||||
</body>
|
||||
</file>
|
||||
</xliff>
|
||||
@@ -0,0 +1,14 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Management
|
||||
{
|
||||
internal enum ConfigAction
|
||||
{
|
||||
Create,
|
||||
Update,
|
||||
Drop
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,344 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Text;
|
||||
using Microsoft.SqlServer.Management.Diagnostics;
|
||||
using Microsoft.SqlTools.ServiceLayer.Agent;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Management
|
||||
{
|
||||
/// <summary>
|
||||
/// defines mandatory interface that an action must implement
|
||||
/// </summary>
|
||||
public interface IManagementAction
|
||||
{
|
||||
ExecutionMode LastExecutionResult { get; }
|
||||
|
||||
/// <summary>
|
||||
/// performs custom action when user requests to cancel execution.
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
void OnCancel(object sender);
|
||||
|
||||
/// <summary>
|
||||
/// Overridable function that allow a derived class to implement its
|
||||
/// OnScript functionality.
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <returns>text of the generated script</returns>
|
||||
string OnScript(object sender);
|
||||
|
||||
/// <summary>
|
||||
/// Overridable function that allow a derived class to implement its
|
||||
/// OnRunNow functionality
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
void OnRunNow(object sender);
|
||||
|
||||
/// <summary>
|
||||
/// Overridable function that allow a derived class to implement
|
||||
/// a finalizing action after a RunNow or RunNowAndClose were sucesfully executed
|
||||
/// NOTE: same as OnGatherUiInformation, this method is always called from UI thread
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
void OnTaskCompleted(object sender, ExecutionMode executionMode, RunType executionType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This class is responsible for executing panels one by one.
|
||||
/// It is reused by ViewSwitcherControlsManager and treepanelform classes
|
||||
/// </summary>
|
||||
internal class ExecutionHandlerDelegate
|
||||
{
|
||||
private object cancelCriticalSection = new object();
|
||||
private IManagementAction managementAction;
|
||||
|
||||
public ExecutionHandlerDelegate(IManagementAction managementAction)
|
||||
{
|
||||
this.managementAction = managementAction;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="runType"></param>
|
||||
/// <param name="sender"></param>
|
||||
/// <returns>execution result</returns>
|
||||
public ExecutionMode Run(RunType runType, object sender)
|
||||
{
|
||||
//dispatch the call to the right method
|
||||
switch (runType)
|
||||
{
|
||||
case RunType.RunNow:
|
||||
this.managementAction.OnRunNow(sender);
|
||||
break;
|
||||
|
||||
case RunType.ScriptToWindow:
|
||||
this.managementAction.OnScript(sender);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new InvalidOperationException("SRError.UnexpectedRunType");
|
||||
}
|
||||
|
||||
if((this.managementAction.LastExecutionResult == ExecutionMode.Failure) ||
|
||||
(this.managementAction.LastExecutionResult == ExecutionMode.Cancel))
|
||||
{
|
||||
return this.managementAction.LastExecutionResult;
|
||||
}
|
||||
|
||||
// if we're here, everything went fine
|
||||
return ExecutionMode.Success;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// performs custom action wen user requests a cancel
|
||||
/// this is called from the UI thread
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
public void Cancel(object sender)
|
||||
{
|
||||
lock (this.cancelCriticalSection)
|
||||
{
|
||||
this.managementAction.OnCancel(sender);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// manager that hooks up tree view with the individual views
|
||||
/// </summary>
|
||||
internal sealed class ExecutonHandler : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// handler that we delegate execution related tasks to
|
||||
/// </summary>
|
||||
private ExecutionHandlerDelegate panelExecutionHandler;
|
||||
|
||||
/// <summary>
|
||||
/// class that describes available views
|
||||
/// </summary>
|
||||
private ISqlControlCollection viewsHolder;
|
||||
|
||||
/// <summary>
|
||||
/// class that describes available views that is also aware of execution
|
||||
/// </summary>
|
||||
private IExecutionAwareManagementAction managementAction;
|
||||
|
||||
/// <summary>
|
||||
/// result of the last execution
|
||||
/// </summary>
|
||||
private ExecutionMode executionResult;
|
||||
|
||||
/// <summary>
|
||||
/// text of the generated script if RunNow method was called last time with scripting option
|
||||
/// </summary>
|
||||
private StringBuilder script;
|
||||
|
||||
/// <summary>
|
||||
/// index of the panel that is being executed
|
||||
/// </summary>
|
||||
private int currentlyExecutingPanelIndex;
|
||||
|
||||
/// <summary>
|
||||
/// creates instance of the class and returns service provider that aggregates the provider
|
||||
/// provider with extra services
|
||||
/// </summary>
|
||||
/// <param name="serviceProvider">service provider from the host</param>
|
||||
/// <param name="aggregatedProvider">
|
||||
/// aggregates service provider that is derived from the host service provider and
|
||||
/// is extended with extra services and/or overriden services. The host should be
|
||||
/// using this provider whenever it has to specify an IServiceProvider to a component
|
||||
/// that will be managed by this class
|
||||
/// </param>
|
||||
public ExecutonHandler(IExecutionAwareManagementAction managementAction)
|
||||
{
|
||||
this.managementAction = managementAction;
|
||||
this.panelExecutionHandler = new ExecutionHandlerDelegate(managementAction);
|
||||
}
|
||||
|
||||
#region public interface
|
||||
|
||||
public ExecutionMode ExecutionResult
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.executionResult;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// text of the generated script if RunNow method was called last time with scripting option
|
||||
/// </summary>
|
||||
public string ScriptTextFromLastRun
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.script != null)
|
||||
{
|
||||
return this.script.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// we call the run now implementaion of the management action.
|
||||
/// If any exception is generated we stop the execution and we set the execution mode flag to failure.
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
public void RunNow(RunType runType, object sender)
|
||||
{
|
||||
try
|
||||
{
|
||||
// reset some internal vars
|
||||
this.executionResult = ExecutionMode.Failure;
|
||||
this.currentlyExecutingPanelIndex = -1; // will become 0 if we're executing on view by view basis
|
||||
|
||||
// ensure that we have valid StringBulder for scripting
|
||||
if (IsScripting(runType))
|
||||
{
|
||||
EnsureValidScriptBuilder();
|
||||
}
|
||||
|
||||
// do preprocess action. It is possible to do entire execution from inside this method
|
||||
if (this.managementAction != null)
|
||||
{
|
||||
PreProcessExecutionInfo preProcessInfo = new PreProcessExecutionInfo(runType);
|
||||
if (!this.managementAction.PreProcessExecution(preProcessInfo, out this.executionResult))
|
||||
{
|
||||
// In case of scripting preProcessInfo.Script must contain text of the script
|
||||
if (executionResult == ExecutionMode.Success && IsScripting(runType) && preProcessInfo.Script != null)
|
||||
{
|
||||
this.script.Append(preProcessInfo.Script);
|
||||
}
|
||||
|
||||
return; // result of execution is in executionResult
|
||||
}
|
||||
}
|
||||
// NOTE: post process action is done in finally block below
|
||||
|
||||
// start executing
|
||||
this.executionResult = this.panelExecutionHandler.Run(runType, sender);
|
||||
}
|
||||
#region error handling
|
||||
|
||||
catch (OutOfMemoryException)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
catch (System.Threading.ThreadAbortException)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
this.executionResult = ExecutionMode.Cancel;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ProcessExceptionDuringExecution(e, this.currentlyExecutingPanelIndex);
|
||||
|
||||
return;
|
||||
}
|
||||
finally
|
||||
{
|
||||
//do postprocess action
|
||||
if (this.managementAction != null)
|
||||
{
|
||||
this.managementAction.PostProcessExecution(runType, this.executionResult);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Kicks off Cancel operation
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
public void InitiateCancel(object sender)
|
||||
{
|
||||
if (this.managementAction != null)
|
||||
{
|
||||
if (!this.managementAction.Cancel())
|
||||
{
|
||||
//everything was done inside this method
|
||||
this.executionResult = ExecutionMode.Cancel;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//otherwise do cancel ourselves
|
||||
// if everything goes OK, Run() method will return with Cancel result
|
||||
this.panelExecutionHandler.Cancel(sender);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// is called by the host to do post execution actions
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="executionMode"></param>
|
||||
/// <param name="executionType"></param>
|
||||
public void OnTaskCompleted(object sender, ExecutionMode executionResult, RunType executionType)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// enables deterministic cleanup
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
IDisposable managementActionAsDisposable = this.managementAction as IDisposable;
|
||||
if (managementActionAsDisposable != null)
|
||||
{
|
||||
managementActionAsDisposable.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region private helpers
|
||||
|
||||
/// <summary>
|
||||
/// determines whether given run type corresponds to scripting or not
|
||||
/// </summary>
|
||||
/// <param name="runType"></param>
|
||||
/// <returns></returns>
|
||||
private bool IsScripting(RunType runType)
|
||||
{
|
||||
return (runType == RunType.ScriptToClipboard ||
|
||||
runType == RunType.ScriptToFile ||
|
||||
runType == RunType.ScriptToWindow ||
|
||||
runType == RunType.ScriptToJob);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ensure that we have valid StringBulder for scripting
|
||||
/// </summary>
|
||||
private void EnsureValidScriptBuilder()
|
||||
{
|
||||
if (this.script == null)
|
||||
{
|
||||
this.script = new StringBuilder(256);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.script.Length = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// helper function that is called when we caught an exception during execution
|
||||
/// </summary>
|
||||
/// <param name="e"></param>
|
||||
/// <param name="failedViewIndex">-1 indicates that we don't know</param>
|
||||
private void ProcessExceptionDuringExecution(Exception e, int failedViewIndex)
|
||||
{
|
||||
//show the error
|
||||
this.executionResult = ExecutionMode.Failure;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Management
|
||||
{
|
||||
/// <summary>
|
||||
/// Execution mode enumeration Success if execution succeeded of Failure otherwise for now.
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Management
|
||||
{
|
||||
public class PreProcessExecutionInfo
|
||||
{
|
||||
@@ -45,7 +45,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
/// IExecutionAwareSqlControlCollection allows control's container to do pre and post
|
||||
/// processing of the execution commands
|
||||
/// </summary>
|
||||
public interface IExecutionAwareSqlControlCollection : ISqlControlCollection
|
||||
public interface IExecutionAwareManagementAction : ISqlControlCollection, IManagementAction
|
||||
{
|
||||
/// <summary>
|
||||
/// called before dialog's host executes actions on all panels in the dialog one by one.
|
||||
@@ -77,27 +77,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
bool Cancel();
|
||||
|
||||
/// <summary>
|
||||
/// called after dialog's host executes actions on all panels in the dialog one by one
|
||||
/// NOTE: it might be called from worker thread
|
||||
/// called after host executes actions
|
||||
/// </summary>
|
||||
/// <param name="executionMode">result of the execution</param>
|
||||
/// <param name="runType">type of execution</param>
|
||||
void PostProcessExecution(RunType runType, ExecutionMode executionMode);
|
||||
|
||||
/// <summary>
|
||||
/// called before dialog's host executes OnReset method on all panels in the dialog one by one
|
||||
/// NOTE: it might be called from worker thread
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// true if regular execution should take place, false if everything
|
||||
/// has been done by this function
|
||||
/// </returns>
|
||||
bool PreProcessReset();
|
||||
|
||||
/// <summary>
|
||||
/// called after dialog's host executes OnReset method on all panels in the dialog one by one
|
||||
/// NOTE: it might be called from worker thread
|
||||
/// </summary>
|
||||
void PostProcessReset();
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Management
|
||||
{
|
||||
#region interfaces
|
||||
/// <summary>
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Management
|
||||
{
|
||||
/// <summary>
|
||||
/// defines notion of sitable object
|
||||
@@ -4,36 +4,29 @@
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Collections;
|
||||
using System.Text;
|
||||
using System.ComponentModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Data;
|
||||
using System.Xml;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Diagnostics;
|
||||
using System.Collections.Specialized;
|
||||
using Microsoft.SqlServer.Management.Smo;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using Microsoft.SqlServer.Management.Common;
|
||||
using Microsoft.SqlServer.Management.Diagnostics;
|
||||
using Microsoft.SqlServer.Management.Smo;
|
||||
using Microsoft.SqlTools.ServiceLayer.Admin;
|
||||
using Microsoft.SqlTools.ServiceLayer.Agent;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Management
|
||||
{
|
||||
/// <summary>
|
||||
/// base class that can be used to derived from for the main classes [containers] of the dialogs
|
||||
/// base class that can be used to derived from for the main classes
|
||||
/// </summary>
|
||||
public class ManagementActionBase : IDisposable
|
||||
public class ManagementActionBase : IDisposable, IExecutionAwareManagementAction
|
||||
{
|
||||
#region Members
|
||||
|
||||
/// <summary>
|
||||
/// selected node as specified to SelectNode method
|
||||
/// </summary>
|
||||
//private TreeNode selectedNode;
|
||||
|
||||
/// <summary>
|
||||
/// service provider of our host. We should direct all host-specific requests to the services
|
||||
/// implemented by this provider
|
||||
@@ -59,6 +52,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Management
|
||||
//property by the initialization code
|
||||
private ServerConnection serverConnection;
|
||||
|
||||
private ExecutionHandlerDelegate cachedPanelExecutionHandler;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
@@ -141,10 +136,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Management
|
||||
/// </returns>
|
||||
public bool PreProcessExecution(PreProcessExecutionInfo executionInfo, out ExecutionMode executionResult)
|
||||
{
|
||||
//we start from failure
|
||||
// we start from failure
|
||||
executionResult = ExecutionMode.Failure;
|
||||
|
||||
//OK, we do server switching for scripting for SQL/Analysis Server execution here
|
||||
// OK, we do server switching for scripting for SQL Server execution here
|
||||
RunType runType = executionInfo.RunType;
|
||||
if (IsScripting(runType))
|
||||
{
|
||||
@@ -156,19 +151,43 @@ namespace Microsoft.SqlTools.ServiceLayer.Management
|
||||
|
||||
if (DataContainer != null)
|
||||
{
|
||||
//we take over execution here. We substitute the server here for AMO and SQL
|
||||
//dialogs
|
||||
// we take over execution here. We substitute the server here for SQL containers
|
||||
if (DataContainer.ContainerServerType == CDataContainer.ServerType.SQL)
|
||||
{
|
||||
ExecuteForSql(executionInfo, out executionResult);
|
||||
return false;//execution of the entire control was done here
|
||||
return false; // execution of the entire action was done here
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// call virtual function to do regular execution
|
||||
return DoPreProcessExecution(executionInfo.RunType, out executionResult);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// called after dialog's host executes actions on all panels in the dialog one by one
|
||||
/// NOTE: it might be called from worker thread
|
||||
/// </summary>
|
||||
/// <param name="executionMode">result of the execution</param>
|
||||
/// <param name="runType">type of execution</param>
|
||||
public void PostProcessExecution(RunType runType, ExecutionMode executionResult)
|
||||
{
|
||||
//delegate to the protected virtual method
|
||||
DoPostProcessExecution(runType, executionResult);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// called when the host received Cancel request. NOTE: this method can return while
|
||||
/// operation is still being canceled
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// true if the host should do standard cancel for the currently running view or
|
||||
/// false if the Cancel operation was done entirely inside this method and there is nothing
|
||||
/// extra that should be done
|
||||
/// </returns>
|
||||
public bool Cancel()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -185,7 +204,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Management
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// called by IExecutionAwareSqlControlCollection.PreProcessExecution to enable derived
|
||||
/// classes to take over execution of the dialog and do entire execution in this method
|
||||
@@ -207,6 +225,17 @@ namespace Microsoft.SqlTools.ServiceLayer.Management
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// called after dialog's host executes actions on all panels in the dialog one by one
|
||||
/// NOTE: it might be called from worker thread
|
||||
/// </summary>
|
||||
/// <param name="executionMode">result of the execution</param>
|
||||
/// <param name="runType">type of execution</param>
|
||||
protected virtual void DoPostProcessExecution(RunType runType, ExecutionMode executionResult)
|
||||
{
|
||||
//nothing to do in the base class
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// called before dialog's host executes OnReset method on all panels in the dialog one by one
|
||||
/// NOTE: it might be called from worker thread
|
||||
@@ -267,12 +296,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Management
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// /// <summary>
|
||||
// /// SMO Server connection that MUST be used for all enumerator calls
|
||||
// /// We'll get this object out of CDataContainer, that must be initialized
|
||||
// /// property by the initialization code
|
||||
// /// </summary>
|
||||
/// <summary>
|
||||
/// SMO Server connection that MUST be used for all enumerator calls
|
||||
/// We'll get this object out of CDataContainer, that must be initialized
|
||||
/// property by the initialization code
|
||||
/// </summary>
|
||||
protected ServerConnection ServerConnection
|
||||
{
|
||||
get
|
||||
@@ -315,15 +343,15 @@ namespace Microsoft.SqlTools.ServiceLayer.Management
|
||||
ExecutionMode executionResult;
|
||||
if (DoPreProcessExecution(runType, out executionResult))
|
||||
{
|
||||
//true return value means that we need to do execution ourselves
|
||||
//executionResult = PanelExecutionHandler.Run(runType, this);
|
||||
// true return value means that we need to do execution ourselves
|
||||
executionResult = PanelExecutionHandler.Run(runType, this);
|
||||
}
|
||||
|
||||
return executionResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// determines whether we need to substitute SMO/AMO server objects with the
|
||||
/// determines whether we need to substitute SMO server objects with the
|
||||
/// temporary ones while doing scripting
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
@@ -384,25 +412,24 @@ namespace Microsoft.SqlTools.ServiceLayer.Management
|
||||
}
|
||||
catch (System.Exception)
|
||||
{
|
||||
//We may not have a valid dialog subject here (such as if the object hasn't been created yet)
|
||||
//so in that case we'll just ignore it as that's a normal scenario.
|
||||
// We may not have a valid dialog subject here (such as if the object hasn't been created yet)
|
||||
// so in that case we'll just ignore it as that's a normal scenario.
|
||||
}
|
||||
|
||||
StringCollection sc = GetServerConnectionForScript().CapturedSql.Text;
|
||||
//Scripting may happen on either the server ExecutionManager or the
|
||||
//ExecutionManager of the object itself. So we make sure to check
|
||||
//the subject text if the server ExecutionManager didn't have any
|
||||
//scripts after doing the scripting
|
||||
// Scripting may happen on either the server ExecutionManager or the
|
||||
// ExecutionManager of the object itself. So we make sure to check
|
||||
// the subject text if the server ExecutionManager didn't have any
|
||||
// scripts after doing the scripting
|
||||
if (sc.Count == 0 && sqlDialogSubject != null)
|
||||
{
|
||||
sc = sqlDialogSubject.ExecutionManager.ConnectionContext.CapturedSql.Text;
|
||||
}
|
||||
int i;
|
||||
StringBuilder script = new StringBuilder(4096);
|
||||
|
||||
StringBuilder script = new StringBuilder(4096);
|
||||
if (sc != null)
|
||||
{
|
||||
for (i = 0; i < sc.Count; i ++)
|
||||
for (int i = 0; i < sc.Count; i ++)
|
||||
{
|
||||
script.AppendFormat("{0}\r\nGO\r\n", sc[i].ToString());
|
||||
}
|
||||
@@ -411,9 +438,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Management
|
||||
return script.ToString();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// called when we need to script a Sql server dlg.
|
||||
/// called when we need to script a Sql Server action
|
||||
/// </summary>
|
||||
/// <param name="executionInfo"></param>
|
||||
/// <param name="executionResult"></param>
|
||||
@@ -431,13 +457,13 @@ namespace Microsoft.SqlTools.ServiceLayer.Management
|
||||
DataContainer.Server = new Microsoft.SqlServer.Management.Smo.Server(DataContainer.ServerConnection);
|
||||
}
|
||||
|
||||
String szScript = null;
|
||||
string szScript = null;
|
||||
bool isScripting = IsScripting(executionInfo.RunType);
|
||||
var executionModeOriginal = GetServerConnectionForScript().SqlExecutionModes;
|
||||
//For Azure the ExecutionManager is different depending on which ExecutionManager
|
||||
//used - one at the Server level and one at the Database level. So to ensure we
|
||||
//don't use the wrong execution mode we need to set the mode for both (for on-prem
|
||||
//this will essentially be a no-op)
|
||||
// For Azure the ExecutionManager is different depending on which ExecutionManager
|
||||
// used - one at the Server level and one at the Database level. So to ensure we
|
||||
// don't use the wrong execution mode we need to set the mode for both (for on-prem
|
||||
// this will essentially be a no-op)
|
||||
SqlExecutionModes subjectExecutionModeOriginal = executionModeOriginal;
|
||||
SqlSmoObject sqlDialogSubject = null;
|
||||
try
|
||||
@@ -446,8 +472,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Management
|
||||
}
|
||||
catch (System.Exception)
|
||||
{
|
||||
//We may not have a valid dialog subject here (such as if the object hasn't been created yet)
|
||||
//so in that case we'll just ignore it as that's a normal scenario.
|
||||
// We may not have a valid dialog subject here (such as if the object hasn't been created yet)
|
||||
// so in that case we'll just ignore it as that's a normal scenario.
|
||||
}
|
||||
|
||||
if (sqlDialogSubject != null)
|
||||
@@ -459,7 +485,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Management
|
||||
SqlExecutionModes newMode = isScripting
|
||||
? SqlExecutionModes.CaptureSql
|
||||
: SqlExecutionModes.ExecuteSql;
|
||||
//now, do the execution itself
|
||||
|
||||
// now, do the execution itself
|
||||
GetServerConnectionForScript().SqlExecutionModes = newMode;
|
||||
if (sqlDialogSubject != null)
|
||||
{
|
||||
@@ -475,7 +502,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Management
|
||||
szScript = BuildSqlScript();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -508,6 +534,22 @@ namespace Microsoft.SqlTools.ServiceLayer.Management
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// returns internal helper class that we delegate execution of the panels one by one when
|
||||
/// we do it ourselves during scripting
|
||||
/// </summary>
|
||||
private ExecutionHandlerDelegate PanelExecutionHandler
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.cachedPanelExecutionHandler == null)
|
||||
{
|
||||
this.cachedPanelExecutionHandler = new ExecutionHandlerDelegate(this);
|
||||
}
|
||||
return this.cachedPanelExecutionHandler;
|
||||
}
|
||||
}
|
||||
|
||||
// #region ICustomAttributeProvider
|
||||
// object[] System.Reflection.ICustomAttributeProvider.GetCustomAttributes(bool inherit)
|
||||
// {
|
||||
@@ -602,20 +644,18 @@ namespace Microsoft.SqlTools.ServiceLayer.Management
|
||||
// canScriptToWindow = canScriptToFile = canScriptToClipboard = canScriptToJob = true;
|
||||
// }
|
||||
// #endregion
|
||||
// protected IServiceProvider ServiceProvider
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// if (this.serviceProvider == null)
|
||||
// {
|
||||
// STrace.Assert(false, "Cannot work without service provider!");
|
||||
// STrace.LogExThrow();
|
||||
// //BUGBUG - should we have our own exception here?
|
||||
// throw new InvalidOperationException();
|
||||
// }
|
||||
// return this.serviceProvider;
|
||||
// }
|
||||
// }
|
||||
protected IServiceProvider ServiceProvider
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.serviceProvider == null)
|
||||
{
|
||||
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
return this.serviceProvider;
|
||||
}
|
||||
}
|
||||
// /// <summary>
|
||||
// /// returns combination of the given 2 arrays
|
||||
// /// </summary>
|
||||
@@ -640,5 +680,105 @@ namespace Microsoft.SqlTools.ServiceLayer.Management
|
||||
// return finalReturnValue;
|
||||
// }
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// execution mode by default for now is success
|
||||
/// </summary>
|
||||
private ExecutionMode m_executionMode = ExecutionMode.Success;
|
||||
|
||||
/// <summary>
|
||||
/// execution mode accessor
|
||||
/// </summary>
|
||||
protected ExecutionMode ExecutionMode
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_executionMode;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_executionMode = value;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual ExecutionMode LastExecutionResult
|
||||
{
|
||||
get
|
||||
{
|
||||
return ExecutionMode;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overridable function that allow a derived class to implement
|
||||
/// a finalizing action after a RunNow or RunNowAndClose where sucesfully executed
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
public virtual void OnTaskCompleted(object sender, ExecutionMode executionMode, RunType executionType)
|
||||
{
|
||||
//nothing
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Overridable function that allow a derived class to implement its
|
||||
/// OnRunNow functionality
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
public virtual void OnRunNow(object sender)
|
||||
{
|
||||
//nothing
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overridable function that allow a derived class to implement its
|
||||
/// OnScript functionality.
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
public virtual string OnScript(object sender)
|
||||
{
|
||||
//redirect to the single scripting virtual method by default
|
||||
return Script();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// derived class should override this method if it does same action for all types of scripting,
|
||||
/// because all ILaunchFormHostedControl scripting methods implemented in this class simply
|
||||
/// call this method
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected virtual string Script()
|
||||
{
|
||||
// redirect to the RunNow method. Our host should be turning script capture on and off for
|
||||
// OLAP/SQL servers and composing the text of the resulting script by itself
|
||||
OnRunNow(this);
|
||||
|
||||
// null is a special value. It means that we want to indicate that we didn't want to generate
|
||||
// script text
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// performs custom action wen user requests a cancel
|
||||
/// this is called from the UI thread and generally executes
|
||||
/// smoServer.Cancel() or amoServer.Cancel() causing
|
||||
/// the worker thread to inttrerupt its current action
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
public virtual void OnCancel(object sender)
|
||||
{
|
||||
if (this.dataContainer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.dataContainer.Server != null)
|
||||
{
|
||||
// TODO: uncomment next line when SMO server will have support for Cancel
|
||||
// this.dataContainer.Server.Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlTools.ServiceLayer.TaskServices;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Management
|
||||
{
|
||||
/// <summary>
|
||||
/// Utility functions for working with Management classes
|
||||
/// </summary>
|
||||
public static class ManagementUtils
|
||||
{
|
||||
public static RunType asRunType(TaskExecutionMode taskExecutionMode)
|
||||
{
|
||||
if (taskExecutionMode == TaskExecutionMode.Script)
|
||||
{
|
||||
return RunType.ScriptToWindow;
|
||||
}
|
||||
else
|
||||
{
|
||||
return RunType.RunNow;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ using System.Collections;
|
||||
using System.Threading;
|
||||
using System.Text;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Management
|
||||
{
|
||||
/// <summary>
|
||||
/// Allows for the mapping of objects that implement IProgressItem to individual items in the
|
||||
@@ -8,7 +8,7 @@ using System.Drawing;
|
||||
using System.Threading;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Management
|
||||
{
|
||||
/// <summary>
|
||||
/// Enumeration for status of individual actions
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Management
|
||||
{
|
||||
/// <summary>
|
||||
/// what type of actions does the worker know to execute
|
||||
@@ -19,5 +19,4 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
ScriptToClipboard,
|
||||
ScriptToJob
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Management
|
||||
{
|
||||
/// <summary>
|
||||
/// Custom attribute that can be applied on particular DB commander to
|
||||
@@ -0,0 +1,27 @@
|
||||
// //
|
||||
// // Copyright (c) Microsoft. All rights reserved.
|
||||
// // Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
// //
|
||||
|
||||
// using System;
|
||||
|
||||
// /// <summary>
|
||||
// /// Defines static values for both Yukon and Shiloh
|
||||
// /// </summary>
|
||||
// namespace Microsoft.SqlTools.ServiceLayer.Management
|
||||
// {
|
||||
// public class SqlLimits
|
||||
// {
|
||||
// internal SqlLimits()
|
||||
// {
|
||||
// }
|
||||
|
||||
// //Define Version 9 Limits
|
||||
// //Currently MAX is the same for both nVarchar and Varchar.
|
||||
// public static readonly int VarcharMax = 1073741824;
|
||||
// public static readonly int SysName = 128;
|
||||
|
||||
// //Define Pre-Version 9 Limits
|
||||
// public static readonly int CommandDimensionMaxLength=3200;
|
||||
// }
|
||||
// }
|
||||
@@ -42,4 +42,70 @@ namespace Microsoft.SqlTools.ServiceLayer.Security.Contracts
|
||||
RequestType<CreateCredentialParams, CreateCredentialResult> Type =
|
||||
RequestType<CreateCredentialParams, CreateCredentialResult>.Create("security/createcredential");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete Credential params
|
||||
/// </summary>
|
||||
public class DeleteCredentialParams : GeneralRequestDetails
|
||||
{
|
||||
public string OwnerUri { get; set; }
|
||||
|
||||
public CredentialInfo Credential { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete Credential result
|
||||
/// </summary>
|
||||
public class DeleteCredentialResult
|
||||
{
|
||||
public bool Succeeded { get; set; }
|
||||
|
||||
public string ErrorMessage { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete Credential request type
|
||||
/// </summary>
|
||||
public class DeleteCredentialRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Request definition
|
||||
/// </summary>
|
||||
public static readonly
|
||||
RequestType<DeleteCredentialParams, DeleteCredentialResult> Type =
|
||||
RequestType<DeleteCredentialParams, DeleteCredentialResult>.Create("security/deletecredential");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update Credential params
|
||||
/// </summary>
|
||||
public class UpdateCredentialParams : GeneralRequestDetails
|
||||
{
|
||||
public string OwnerUri { get; set; }
|
||||
|
||||
public CredentialInfo Credential { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update Credential result
|
||||
/// </summary>
|
||||
public class UpdateCredentialResult
|
||||
{
|
||||
public bool Succeeded { get; set; }
|
||||
|
||||
public string ErrorMessage { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update Credential request type
|
||||
/// </summary>
|
||||
public class UpdateCredentialRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Request definition
|
||||
/// </summary>
|
||||
public static readonly
|
||||
RequestType<UpdateCredentialParams, UpdateCredentialResult> Type =
|
||||
RequestType<UpdateCredentialParams, UpdateCredentialResult>.Create("security/updatecredential");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,21 +21,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Security
|
||||
internal class Credential : ManagementActionBase
|
||||
{
|
||||
|
||||
// #region Trace support
|
||||
// private const string componentName = "Credential";
|
||||
|
||||
// public string ComponentName
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// return componentName;
|
||||
// }
|
||||
// }
|
||||
// #endregion
|
||||
|
||||
#region Constants
|
||||
private const int MAX_SQL_SYS_NAME_LENGTH = 128; // max sql sys name length
|
||||
private const string PASSWORD_MASK_STRING = "**********";
|
||||
#endregion
|
||||
|
||||
#region Variables
|
||||
@@ -70,19 +57,16 @@ namespace Microsoft.SqlTools.ServiceLayer.Security
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Overrides SqlManagementUserControl
|
||||
/// <summary>
|
||||
/// called on background thread by the framework to execute the action
|
||||
/// </summary>
|
||||
/// <param name="node"></param>
|
||||
public void OnRunNow(object sender)
|
||||
public override void OnRunNow(object sender)
|
||||
{
|
||||
this.credentialData.SendDataToServer();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// update logic layer based on content of user interface
|
||||
/// </summary>
|
||||
|
||||
@@ -75,7 +75,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Security
|
||||
public void InitializeService(ServiceHost serviceHost)
|
||||
{
|
||||
this.ServiceHost = serviceHost;
|
||||
|
||||
// Credential request handlers
|
||||
this.ServiceHost.SetRequestHandler(CreateCredentialRequest.Type, HandleCreateCredentialRequest);
|
||||
this.ServiceHost.SetRequestHandler(UpdateCredentialRequest.Type, HandleUpdateCredentialRequest);
|
||||
this.ServiceHost.SetRequestHandler(DeleteCredentialRequest.Type, HandleDeleteCredentialRequest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -102,6 +106,24 @@ namespace Microsoft.SqlTools.ServiceLayer.Security
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle request to update a credential
|
||||
/// </summary>
|
||||
internal async Task HandleUpdateCredentialRequest(UpdateCredentialParams parameters, RequestContext<UpdateCredentialResult> requestContext)
|
||||
{
|
||||
var result = new UpdateCredentialResult();
|
||||
await requestContext.SendResult(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle request to delete a credential
|
||||
/// </summary>
|
||||
internal async Task HandleDeleteCredentialRequest(DeleteCredentialParams parameters, RequestContext<DeleteCredentialResult> requestContext)
|
||||
{
|
||||
var result = new DeleteCredentialResult();
|
||||
await requestContext.SendResult(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disposes the service
|
||||
/// </summary>
|
||||
|
||||
@@ -13,17 +13,17 @@ namespace Microsoft.SqlTools.ServiceLayer.TaskServices
|
||||
/// <summary>
|
||||
/// Execute task
|
||||
/// </summary>
|
||||
Execute,
|
||||
Execute = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Script task
|
||||
/// </summary>
|
||||
Script,
|
||||
Script = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Execute and script task
|
||||
/// Needed for tasks that will show the script when execution completes
|
||||
/// </summary>
|
||||
ExecuteAndScript
|
||||
ExecuteAndScript = 2
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlTools.Utility;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.TaskServices
|
||||
{
|
||||
public class TaskRequestDetails : GeneralRequestDetails
|
||||
{
|
||||
/// <summary>
|
||||
/// The executation mode for the operation. default is execution
|
||||
/// </summary>
|
||||
public TaskExecutionMode TaskExecutionMode { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user