diff --git a/src/Microsoft.SqlTools.ServiceLayer/SchemaCompare/Contracts/DeploymentOptions.cs b/src/Microsoft.SqlTools.ServiceLayer/DacFx/Contracts/DeploymentOptions.cs similarity index 94% rename from src/Microsoft.SqlTools.ServiceLayer/SchemaCompare/Contracts/DeploymentOptions.cs rename to src/Microsoft.SqlTools.ServiceLayer/DacFx/Contracts/DeploymentOptions.cs index 33f1e89d..da0b65be 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/SchemaCompare/Contracts/DeploymentOptions.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/DacFx/Contracts/DeploymentOptions.cs @@ -2,11 +2,13 @@ // 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.IO; +using System.Linq; using System.Threading.Tasks; using Microsoft.SqlServer.Dac; -namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts +namespace Microsoft.SqlTools.ServiceLayer.DacFx.Contracts { /// /// Class to define deployment options. @@ -15,6 +17,8 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts /// public class DeploymentOptions { + #region Properties + public bool IgnoreTableOptions { get; set; } public bool IgnoreSemicolonBetweenStatements { get; set; } @@ -209,6 +213,8 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts ObjectType.AssemblyFiles, }; + #endregion + public DeploymentOptions() { DacDeployOptions options = new DacDeployOptions(); @@ -297,5 +303,19 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts } } } + + public static DeploymentOptions GetDefaultSchemaCompareOptions() + { + return new DeploymentOptions(); + } + + public static DeploymentOptions GetDefaultPublishOptions() + { + DeploymentOptions result = new DeploymentOptions(); + + result.ExcludeObjectTypes = result.ExcludeObjectTypes.Where(x => x != ObjectType.DatabaseScopedCredentials).ToArray(); // re-include database-scoped credentials + + return result; + } } } diff --git a/src/Microsoft.SqlTools.ServiceLayer/DacFx/Contracts/GetDefaultPublishOptionsRequest.cs b/src/Microsoft.SqlTools.ServiceLayer/DacFx/Contracts/GetDefaultPublishOptionsRequest.cs new file mode 100644 index 00000000..ab68f111 --- /dev/null +++ b/src/Microsoft.SqlTools.ServiceLayer/DacFx/Contracts/GetDefaultPublishOptionsRequest.cs @@ -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.Collections.Generic; +using Microsoft.SqlTools.Hosting.Protocol.Contracts; +using Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts; +using Microsoft.SqlTools.ServiceLayer.Utility; + +namespace Microsoft.SqlTools.ServiceLayer.DacFx.Contracts +{ + /// + /// Parameters for a DacFx get default publish options request. + /// + public class GetDefaultPublishOptionsParams + { + } + + /// + /// Defines the DacFx get default publish options request type + /// + class GetDefaultPublishOptionsRequest + { + public static readonly RequestType Type = + RequestType.Create("dacfx/getDefaultPublishOptions"); + } +} diff --git a/src/Microsoft.SqlTools.ServiceLayer/DacFx/DacFxService.cs b/src/Microsoft.SqlTools.ServiceLayer/DacFx/DacFxService.cs index f24ef689..ca5743fe 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/DacFx/DacFxService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/DacFx/DacFxService.cs @@ -10,7 +10,6 @@ using Microsoft.SqlTools.Hosting.Protocol; using Microsoft.SqlTools.ServiceLayer.Connection; using Microsoft.SqlTools.ServiceLayer.DacFx.Contracts; using Microsoft.SqlTools.ServiceLayer.Hosting; -using Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts; using Microsoft.SqlTools.ServiceLayer.TaskServices; namespace Microsoft.SqlTools.ServiceLayer.DacFx @@ -48,6 +47,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx serviceHost.SetRequestHandler(GenerateDeployPlanRequest.Type, this.HandleGenerateDeployPlanRequest); serviceHost.SetRequestHandler(GetOptionsFromProfileRequest.Type, this.HandleGetOptionsFromProfileRequest); serviceHost.SetRequestHandler(ValidateStreamingJobRequest.Type, this.HandleValidateStreamingJobRequest); + serviceHost.SetRequestHandler(GetDefaultPublishOptionsRequest.Type, this.HandleGetDefaultPublishOptionsRequest); } /// @@ -239,7 +239,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx DacProfile profile = DacProfile.Load(parameters.ProfilePath); if (profile.DeployOptions != null) { - options = new DeploymentOptions(); + options = DeploymentOptions.GetDefaultPublishOptions(); await options.InitializeFromProfile(profile.DeployOptions, parameters.ProfilePath); } } @@ -276,6 +276,35 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx } } + /// + /// Handles request to create default publish options for DacFx + /// + /// + public async Task HandleGetDefaultPublishOptionsRequest(GetDefaultPublishOptionsParams parameters, RequestContext requestContext) + { + try + { + // this does not need to be an async operation since this only creates and returns the default object + DeploymentOptions options = DeploymentOptions.GetDefaultPublishOptions(); + + await requestContext.SendResult(new DacFxOptionsResult() + { + DeploymentOptions = options, + Success = true, + ErrorMessage = null + }); + } + catch (Exception e) + { + await requestContext.SendResult(new DacFxOptionsResult() + { + DeploymentOptions = null, + Success = false, + ErrorMessage = e.Message + }); + } + } + private void ExecuteOperation(DacFxOperation operation, DacFxParams parameters, string taskName, RequestContext requestContext) { Task.Run(async () => diff --git a/src/Microsoft.SqlTools.ServiceLayer/SchemaCompare/Contracts/SchemaCompareOpenScmpRequest.cs b/src/Microsoft.SqlTools.ServiceLayer/SchemaCompare/Contracts/SchemaCompareOpenScmpRequest.cs index 49d01ca2..f5f106bf 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/SchemaCompare/Contracts/SchemaCompareOpenScmpRequest.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/SchemaCompare/Contracts/SchemaCompareOpenScmpRequest.cs @@ -2,10 +2,10 @@ // 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 System.Collections.Generic; +using Microsoft.SqlTools.Hosting.Protocol.Contracts; +using Microsoft.SqlTools.ServiceLayer.DacFx.Contracts; +using Microsoft.SqlTools.ServiceLayer.Utility; namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts { diff --git a/src/Microsoft.SqlTools.ServiceLayer/SchemaCompare/Contracts/SchemaCompareOptionsRequest.cs b/src/Microsoft.SqlTools.ServiceLayer/SchemaCompare/Contracts/SchemaCompareOptionsRequest.cs index d2073596..424eb491 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/SchemaCompare/Contracts/SchemaCompareOptionsRequest.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/SchemaCompare/Contracts/SchemaCompareOptionsRequest.cs @@ -4,6 +4,7 @@ // using Microsoft.SqlTools.Hosting.Protocol.Contracts; +using Microsoft.SqlTools.ServiceLayer.DacFx.Contracts; using Microsoft.SqlTools.ServiceLayer.Utility; namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts diff --git a/src/Microsoft.SqlTools.ServiceLayer/SchemaCompare/Contracts/SchemaCompareRequest.cs b/src/Microsoft.SqlTools.ServiceLayer/SchemaCompare/Contracts/SchemaCompareRequest.cs index 0db7e4f6..13c1b9bf 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/SchemaCompare/Contracts/SchemaCompareRequest.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/SchemaCompare/Contracts/SchemaCompareRequest.cs @@ -2,12 +2,13 @@ // 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.SqlServer.Dac.Compare; using Microsoft.SqlTools.Hosting.Protocol.Contracts; using Microsoft.SqlTools.ServiceLayer.Connection.Contracts; +using Microsoft.SqlTools.ServiceLayer.DacFx.Contracts; using Microsoft.SqlTools.ServiceLayer.TaskServices; using Microsoft.SqlTools.ServiceLayer.Utility; -using System.Collections.Generic; namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts { diff --git a/src/Microsoft.SqlTools.ServiceLayer/SchemaCompare/SchemaCompareOpenScmpOperation.cs b/src/Microsoft.SqlTools.ServiceLayer/SchemaCompare/SchemaCompareOpenScmpOperation.cs index bd087293..b8cf0d27 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/SchemaCompare/SchemaCompareOpenScmpOperation.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/SchemaCompare/SchemaCompareOpenScmpOperation.cs @@ -2,20 +2,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.SqlServer.Dac; -using Microsoft.SqlServer.Dac.Compare; -using Microsoft.SqlTools.ServiceLayer.Connection; -using Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts; -using Microsoft.SqlTools.ServiceLayer.TaskServices; -using Microsoft.SqlTools.Utility; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using System.Text.RegularExpressions; using System.Threading; -using System.Xml; using System.Xml.Linq; +using Microsoft.SqlServer.Dac.Compare; +using Microsoft.SqlTools.ServiceLayer.DacFx.Contracts; +using Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts; +using Microsoft.SqlTools.ServiceLayer.TaskServices; +using Microsoft.SqlTools.Utility; namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare { diff --git a/src/Microsoft.SqlTools.ServiceLayer/SchemaCompare/SchemaCompareService.cs b/src/Microsoft.SqlTools.ServiceLayer/SchemaCompare/SchemaCompareService.cs index dcd9d5ed..2c545a86 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/SchemaCompare/SchemaCompareService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/SchemaCompare/SchemaCompareService.cs @@ -2,19 +2,19 @@ // 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; -using Microsoft.SqlTools.ServiceLayer.Connection; -using Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts; -using Microsoft.SqlTools.ServiceLayer.Hosting; -using Microsoft.SqlTools.ServiceLayer.TaskServices; using System; using System.Collections.Concurrent; +using System.Diagnostics; using System.Threading.Tasks; using Microsoft.SqlServer.Dac.Compare; +using Microsoft.SqlTools.Hosting.Protocol; +using Microsoft.SqlTools.ServiceLayer.Connection; +using Microsoft.SqlTools.ServiceLayer.DacFx.Contracts; +using Microsoft.SqlTools.ServiceLayer.Hosting; +using Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts; +using Microsoft.SqlTools.ServiceLayer.TaskServices; using Microsoft.SqlTools.ServiceLayer.Utility; using Microsoft.SqlTools.Utility; -using System.Diagnostics; -using System.Threading; namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare { @@ -278,8 +278,8 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare { try { - // this does not need to be an async operation since this only creates and resturn the default opbject - DeploymentOptions options = new DeploymentOptions(); + // this does not need to be an async operation since this only creates and returns the default object + DeploymentOptions options = DeploymentOptions.GetDefaultSchemaCompareOptions(); await requestContext.SendResult(new SchemaCompareOptionsResult() { diff --git a/src/Microsoft.SqlTools.ServiceLayer/SchemaCompare/SchemaCompareUtils.cs b/src/Microsoft.SqlTools.ServiceLayer/SchemaCompare/SchemaCompareUtils.cs index e1eb7fcd..6b30cc85 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/SchemaCompare/SchemaCompareUtils.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/SchemaCompare/SchemaCompareUtils.cs @@ -2,16 +2,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.SqlServer.Dac; -using Microsoft.SqlServer.Dac.Compare; -using Microsoft.SqlServer.Dac.Model; -using Microsoft.SqlTools.ServiceLayer.Connection; -using Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts; -using Microsoft.SqlTools.ServiceLayer.Utility; using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; +using Microsoft.SqlServer.Dac; +using Microsoft.SqlServer.Dac.Compare; +using Microsoft.SqlServer.Dac.Model; +using Microsoft.SqlTools.ServiceLayer.Connection; +using Microsoft.SqlTools.ServiceLayer.DacFx.Contracts; +using Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts; +using Microsoft.SqlTools.ServiceLayer.Utility; namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare { diff --git a/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/DacFx/DacFxServiceTests.cs b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/DacFx/DacFxServiceTests.cs index c7cf27c8..c3404e95 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/DacFx/DacFxServiceTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/DacFx/DacFxServiceTests.cs @@ -725,13 +725,12 @@ FROM MissingEdgeHubInputStream'"; [Test] public async Task GetOptionsFromProfile() { - DeploymentOptions expectedResults = new DeploymentOptions() - { - ExcludeObjectTypes = null, - IncludeCompositeObjects = true, - BlockOnPossibleDataLoss = true, - AllowIncompatiblePlatform = true - }; + DeploymentOptions expectedResults = DeploymentOptions.GetDefaultPublishOptions(); + + expectedResults.ExcludeObjectTypes = null; + expectedResults.IncludeCompositeObjects = true; + expectedResults.BlockOnPossibleDataLoss = true; + expectedResults.AllowIncompatiblePlatform = true; var dacfxRequestContext = new Mock>(); dacfxRequestContext.Setup((RequestContext x) => x.SendResult(It.Is((result) => ValidateOptions(expectedResults, result.DeploymentOptions) == true))).Returns(Task.FromResult(new object())); @@ -754,7 +753,7 @@ FROM MissingEdgeHubInputStream'"; [Test] public async Task GetOptionsFromProfileWithoutOptions() { - DeploymentOptions expectedResults = new DeploymentOptions(); + DeploymentOptions expectedResults = DeploymentOptions.GetDefaultPublishOptions(); expectedResults.ExcludeObjectTypes = null; var dacfxRequestContext = new Mock>(); @@ -772,6 +771,23 @@ FROM MissingEdgeHubInputStream'"; dacfxRequestContext.VerifyAll(); } + /// + /// Verify the default dacFx options for publishing + /// + [Test] + public async Task ValidateGetDefaultPublishOptionsCallFromService() + { + DeploymentOptions expectedResults = DeploymentOptions.GetDefaultPublishOptions(); + + var dacfxRequestContext = new Mock>(); + dacfxRequestContext.Setup((RequestContext x) => x.SendResult(It.Is((result) => ValidateOptions(expectedResults, result.DeploymentOptions) == true))).Returns(Task.FromResult(new object())); + + GetDefaultPublishOptionsParams p = new GetDefaultPublishOptionsParams(); + + DacFxService service = new DacFxService(); + await service.HandleGetDefaultPublishOptionsRequest(p, dacfxRequestContext.Object); + } + /// /// Verify that streaming job ///