mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-07 09:35:37 -05:00
generic way to support scriptable operations (#438)
* implemented a generic way to support scriptable operations
This commit is contained in:
@@ -3,6 +3,9 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||
using Microsoft.SqlTools.ServiceLayer.Utility;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.TaskServices
|
||||
{
|
||||
public class TaskMetadata
|
||||
@@ -28,11 +31,6 @@ namespace Microsoft.SqlTools.ServiceLayer.TaskServices
|
||||
/// </summary>
|
||||
public int Timeout { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Defines if the task can be canceled
|
||||
/// </summary>
|
||||
public bool IsCancelable { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Database server name this task is created for
|
||||
/// </summary>
|
||||
@@ -46,6 +44,52 @@ namespace Microsoft.SqlTools.ServiceLayer.TaskServices
|
||||
/// <summary>
|
||||
/// Data required to perform the task
|
||||
/// </summary>
|
||||
public object Data { get; set; }
|
||||
public ITaskOperation TaskOperation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates task metadata given the request parameters
|
||||
/// </summary>
|
||||
/// <param name="requestParam">Request parameters</param>
|
||||
/// <param name="taskName">Task name</param>
|
||||
/// <param name="taskOperation">Task operation</param>
|
||||
/// <param name="connectionService">Connection Service</param>
|
||||
/// <returns>Task metadata</returns>
|
||||
public static TaskMetadata Create(IRequestParams requestParam, string taskName, ITaskOperation taskOperation, ConnectionService connectionService)
|
||||
{
|
||||
TaskMetadata taskMetadata = new TaskMetadata();
|
||||
ConnectionInfo connInfo;
|
||||
connectionService.TryFindConnection(
|
||||
requestParam.OwnerUri,
|
||||
out connInfo);
|
||||
|
||||
if (connInfo != null)
|
||||
{
|
||||
taskMetadata.ServerName = connInfo.ConnectionDetails.ServerName;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(requestParam.DatabaseName))
|
||||
{
|
||||
taskMetadata.DatabaseName = requestParam.DatabaseName;
|
||||
}
|
||||
else if (connInfo != null)
|
||||
{
|
||||
taskMetadata.DatabaseName = connInfo.ConnectionDetails.DatabaseName;
|
||||
}
|
||||
|
||||
IScriptableRequestParams scriptableRequestParams = requestParam as IScriptableRequestParams;
|
||||
if (scriptableRequestParams != null && scriptableRequestParams.TaskExecutionMode != TaskExecutionMode.Execute)
|
||||
{
|
||||
taskMetadata.Name = string.Format("{0} {1}", taskName, SR.ScriptTaskName);
|
||||
}
|
||||
else
|
||||
{
|
||||
taskMetadata.Name = taskName;
|
||||
}
|
||||
taskMetadata.TaskExecutionMode = scriptableRequestParams.TaskExecutionMode;
|
||||
|
||||
taskMetadata.TaskOperation = taskOperation;
|
||||
return taskMetadata;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user