diff --git a/Packages.props b/Packages.props index 7d16678a..6eb33c57 100644 --- a/Packages.props +++ b/Packages.props @@ -22,7 +22,7 @@ - + diff --git a/src/Microsoft.SqlTools.ServiceLayer/DacFx/Contracts/ParseTSqlScriptRequest.cs b/src/Microsoft.SqlTools.ServiceLayer/DacFx/Contracts/ParseTSqlScriptRequest.cs new file mode 100644 index 00000000..246bb0d2 --- /dev/null +++ b/src/Microsoft.SqlTools.ServiceLayer/DacFx/Contracts/ParseTSqlScriptRequest.cs @@ -0,0 +1,42 @@ +// +// 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; + +namespace Microsoft.SqlTools.ServiceLayer.DacFx.Contracts +{ + /// + /// Parameters for a parse T-SQL script request. + /// + public class ParseTSqlScriptRequestParams + { + /// + /// Gets or sets the script content + /// + public string Script { get; set; } + + /// + /// Gets or sets the DSP. + /// + public string DatabaseSchemaProvider { get; set;} + } + + /// + /// Result for the ParseTSqlScript Request. + /// + public class ParseTSqlScriptResult : ResultStatus + { + public bool ContainsCreateTableStatement { get; set; } + } + + /// + /// Defines the parse T-SQL script request type + /// + class ParseTSqlScriptRequest + { + public static readonly RequestType Type = + RequestType.Create("dacfx/parseTSqlScript"); + } +} diff --git a/src/Microsoft.SqlTools.ServiceLayer/DacFx/DacFxService.cs b/src/Microsoft.SqlTools.ServiceLayer/DacFx/DacFxService.cs index ca5743fe..13deda58 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/DacFx/DacFxService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/DacFx/DacFxService.cs @@ -11,6 +11,7 @@ using Microsoft.SqlTools.ServiceLayer.Connection; using Microsoft.SqlTools.ServiceLayer.DacFx.Contracts; using Microsoft.SqlTools.ServiceLayer.Hosting; using Microsoft.SqlTools.ServiceLayer.TaskServices; +using DacTableDesigner = Microsoft.Data.Tools.Sql.DesignServices.TableDesigner.TableDesigner; namespace Microsoft.SqlTools.ServiceLayer.DacFx { @@ -48,6 +49,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx serviceHost.SetRequestHandler(GetOptionsFromProfileRequest.Type, this.HandleGetOptionsFromProfileRequest); serviceHost.SetRequestHandler(ValidateStreamingJobRequest.Type, this.HandleValidateStreamingJobRequest); serviceHost.SetRequestHandler(GetDefaultPublishOptionsRequest.Type, this.HandleGetDefaultPublishOptionsRequest); + serviceHost.SetRequestHandler(ParseTSqlScriptRequest.Type, this.HandleParseTSqlScriptRequest); } /// @@ -305,6 +307,21 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx } } + public async Task HandleParseTSqlScriptRequest(ParseTSqlScriptRequestParams requestParams, RequestContext requestContext) + { + try + { + await requestContext.SendResult(new ParseTSqlScriptResult() + { + ContainsCreateTableStatement = DacTableDesigner.ScriptContainsCreateTableStatements(requestParams.Script, requestParams.DatabaseSchemaProvider) + }); + } + catch (Exception e) + { + await requestContext.SendError(e); + } + } + private void ExecuteOperation(DacFxOperation operation, DacFxParams parameters, string taskName, RequestContext requestContext) { Task.Run(async () =>