Add scripting API implemented by the SqlScriptPublishModel (#316)

Update the ScriptingService to expose new scripting JSON-RPC APIs that use the SqlScriptPublishModel for script generation.

The SqlScriptPublishModel is the model behind the SSMS scripting wizard. To enable scripting for CLI tools, we've ported SqlScriptPublishModel to .NET Core. The SqlScriptPublishModel wraps the SMO scripting APIs for .sql script generation.

1) Added three new requests to the ScriptingService: ScriptingRequest, ScriptingListObjectsRequest, ScriptingCancelRequest.
2) Generating scripts are long running operations, so the ScriptingRequest and ScriptingListObjectsRequest kick off a long running scripting task and return immediately.
3) Long running scripting task reports progress and completion, and can be cancelled by a ScriptingCancelRequest request.
4) Bumped the SMO nuget package to 140.17049.0. This new version contains a signed SSMS_Rel build of SMO with the SqlScriptPublishModel.
5) For testing, adding the Northwind database schema

TODO (in later pull requests)
1) Integrate the new ScriptingService APIs with the ConnectionService
2) Integrate with the metadata support recently added
This commit is contained in:
Brian O'Neill
2017-04-24 16:10:20 -07:00
committed by GitHub
parent e65699ef75
commit 4aac4a4047
42 changed files with 7124 additions and 30 deletions

View File

@@ -8,6 +8,7 @@ using System.Globalization;
using Microsoft.SqlTools.ServiceLayer.Connection;
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
using Xunit;
using System.Data.SqlClient;
namespace Microsoft.SqlTools.ServiceLayer.Test.Common
{
@@ -24,6 +25,31 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Common
public bool DoNotCleanupDb { get; set; }
public string ConnectionString
{
get
{
ConnectParams connectParams = TestConnectionProfileService.Instance.GetConnectionParameters(this.ServerType, this.DatabaseName);
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder
{
DataSource = connectParams.Connection.ServerName,
InitialCatalog = connectParams.Connection.DatabaseName,
};
if (connectParams.Connection.AuthenticationType == "Integrated")
{
builder.IntegratedSecurity = true;
}
else
{
builder.UserID = connectParams.Connection.UserName;
builder.Password = connectParams.Connection.Password;
}
return builder.ToString();
}
}
/// <summary>
/// Create the test db if not already exists
/// </summary>
@@ -63,6 +89,14 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Common
return CreateNew(serverType, false, null, query);
}
/// <summary>
/// Create the test db if not already exists
/// </summary>
public static SqlTestDb CreateNew(TestServerType serverType)
{
return CreateNew(serverType, false, null, null);
}
/// <summary>
/// Returns a mangled name that unique based on Prefix + Machine + Process
/// </summary>
@@ -115,6 +149,16 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Common
return connInfo;
}
/// <summary>
/// Runs the passed query against the test db.
/// </summary>
/// <param name="query">The query to execute.</param>
/// <param name="throwOnError">If true, throw an exception if the query encounters an error executing a batch statement.</param>
public void RunQuery(string query, bool throwOnError = false)
{
TestServiceProvider.Instance.RunQuery(this.ServerType, this.DatabaseName, query, throwOnError);
}
public void Dispose()
{
Cleanup();