// // 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.Connection; using Microsoft.SqlTools.ServiceLayer.Utility; namespace Microsoft.SqlTools.ServiceLayer.TaskServices { public class TaskMetadata { /// /// Task Description /// public string Description { get; set; } /// /// Task name to define the type of the task e.g. Create Db, back up /// public string Name { get; set; } /// /// Task execution mode (e.g. execute or script) /// public TaskExecutionMode TaskExecutionMode { get; set; } /// /// The number of seconds to wait before canceling the task. /// This is a optional field and 0 or negative numbers means no timeout /// public int Timeout { get; set; } /// /// Database server name this task is created for /// public string ServerName { get; set; } /// /// Database name this task is created for /// public string DatabaseName { get; set; } /// /// Data required to perform the task /// public ITaskOperation TaskOperation { get; set; } /// /// Creates task metadata given the request parameters /// /// Request parameters /// Task name /// Task operation /// Connection Service /// Task metadata 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; } } }