Add support for getting DacFx deploy options from a publish profile (#995)

* add support for getting options from a publish profile

* update comments

* set values for default options if they aren't specified in the publish profile

* addressing comments
This commit is contained in:
Kim Santiago
2020-07-27 17:52:15 -07:00
committed by GitHub
parent 0014687343
commit 1a93404e54
6 changed files with 234 additions and 9 deletions

View File

@@ -0,0 +1,39 @@
//
// 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
{
/// <summary>
/// Parameters for a DacFx get options from profile request.
/// </summary>
public class GetOptionsFromProfileParams
{
/// <summary>
/// Gets or sets the profile path
/// </summary>
public string ProfilePath { get; set; }
}
/// <summary>
/// Parameters returned from a DacFx get options from profile request.
/// </summary>
public class DacFxOptionsResult : ResultStatus
{
public DeploymentOptions DeploymentOptions { get; set; }
}
/// <summary>
/// Defines the DacFx get options from profile request type
/// </summary>
class GetOptionsFromProfileRequest
{
public static readonly RequestType<GetOptionsFromProfileParams, DacFxOptionsResult> Type =
RequestType<GetOptionsFromProfileParams, DacFxOptionsResult>.Create("dacfx/getOptionsFromProfile");
}
}

View File

@@ -2,16 +2,16 @@
// 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.Collections.Concurrent;
using System.Threading.Tasks;
using Microsoft.SqlServer.Dac;
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 System;
using System.Collections.Concurrent;
using Microsoft.Data.SqlClient;
using System.Threading.Tasks;
namespace Microsoft.SqlTools.ServiceLayer.DacFx
{
@@ -46,6 +46,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
serviceHost.SetRequestHandler(DeployRequest.Type, this.HandleDeployRequest);
serviceHost.SetRequestHandler(GenerateDeployScriptRequest.Type, this.HandleGenerateDeployScriptRequest);
serviceHost.SetRequestHandler(GenerateDeployPlanRequest.Type, this.HandleGenerateDeployPlanRequest);
serviceHost.SetRequestHandler(GetOptionsFromProfileRequest.Type, this.HandleGetOptionsFromProfileRequest);
}
/// <summary>
@@ -223,6 +224,38 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
}
}
/// <summary>
/// Handles request to get the options from a publish profile
/// </summary>
/// <returns></returns>
public async Task HandleGetOptionsFromProfileRequest(GetOptionsFromProfileParams parameters, RequestContext<DacFxOptionsResult> requestContext)
{
try
{
DeploymentOptions options = null;
if (parameters.ProfilePath != null)
{
DacProfile profile = DacProfile.Load(parameters.ProfilePath);
if (profile.DeployOptions != null)
{
options = new DeploymentOptions();
await options.InitializeFromProfile(profile.DeployOptions, parameters.ProfilePath);
}
}
await requestContext.SendResult(new DacFxOptionsResult()
{
DeploymentOptions = options,
Success = true,
ErrorMessage = string.Empty,
});
}
catch (Exception e)
{
await requestContext.SendError(e);
}
}
private void ExecuteOperation(DacFxOperation operation, DacFxParams parameters, string taskName, RequestContext<DacFxResult> requestContext)
{
Task.Run(async () =>