mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-04 09:35:37 -05:00
Add support to save publish profile (#1844)
* Add support to save publish profile * Address comments * Update dacfx nuget package version * Fix test * Address comments * Resolve package.props conflict * Add content verification in test and use handler methods instead of try-catch * Address comments
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
//
|
||||
// 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.Utility;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.DacFx.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// Parameters for a DacFx save publish profile request.
|
||||
/// </summary>
|
||||
public class SavePublishProfileParams
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the profile path
|
||||
/// </summary>
|
||||
public string ProfilePath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets name for database
|
||||
/// </summary>
|
||||
public string? DatabaseName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets target connection string
|
||||
/// </summary>
|
||||
public string? ConnectionString { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets SQLCMD variables for deployment
|
||||
/// </summary>
|
||||
public IDictionary<string, string>? SqlCommandVariableValues { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the options for deployment
|
||||
/// </summary>
|
||||
public DeploymentOptions? DeploymentOptions { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Defines the DacFx save publish profile request type
|
||||
/// </summary>
|
||||
class SavePublishProfileRequest
|
||||
{
|
||||
public static readonly RequestType<SavePublishProfileParams, ResultStatus> Type =
|
||||
RequestType<SavePublishProfileParams, ResultStatus>.Create("dacfx/savePublishProfile");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ using Microsoft.SqlTools.ServiceLayer.Hosting;
|
||||
using Microsoft.SqlTools.ServiceLayer.TaskServices;
|
||||
using Microsoft.SqlServer.Dac.Model;
|
||||
using DacTableDesigner = Microsoft.Data.Tools.Sql.DesignServices.TableDesigner.TableDesigner;
|
||||
using Microsoft.SqlTools.ServiceLayer.Utility;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.DacFx
|
||||
{
|
||||
@@ -60,6 +61,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
|
||||
serviceHost.SetRequestHandler(ParseTSqlScriptRequest.Type, this.HandleParseTSqlScriptRequest, true);
|
||||
serviceHost.SetRequestHandler(GenerateTSqlModelRequest.Type, this.HandleGenerateTSqlModelRequest, true);
|
||||
serviceHost.SetRequestHandler(GetObjectsFromTSqlModelRequest.Type, this.HandleGetObjectsFromTSqlModelRequest, true);
|
||||
serviceHost.SetRequestHandler(SavePublishProfileRequest.Type, this.HandleSavePublishProfileRequest, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -311,6 +313,36 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
|
||||
return;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles request to save a publish profile
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task HandleSavePublishProfileRequest(SavePublishProfileParams parameters, RequestContext<ResultStatus> requestContext)
|
||||
{
|
||||
await BaseService.RunWithErrorHandling(() =>
|
||||
{
|
||||
if (parameters.ProfilePath != null)
|
||||
{
|
||||
DacProfile profile = new DacProfile();
|
||||
profile.TargetDatabaseName = parameters.DatabaseName;
|
||||
profile.TargetConnectionString = parameters.ConnectionString;
|
||||
//TODO: Set deploy options to pass on to DacFx
|
||||
|
||||
if (parameters.SqlCommandVariableValues != null)
|
||||
{
|
||||
foreach (string key in parameters.SqlCommandVariableValues.Keys)
|
||||
{
|
||||
profile.DeployOptions.SqlCommandVariableValues[key] = parameters.SqlCommandVariableValues[key];
|
||||
}
|
||||
}
|
||||
//TODO: Add return from Save with success/fail status
|
||||
profile.Save(parameters.ProfilePath);
|
||||
}
|
||||
}, requestContext);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
private void ExecuteOperation(DacFxOperation operation, DacFxParams parameters, string taskName, RequestContext<DacFxResult> requestContext)
|
||||
{
|
||||
Task.Run(async () =>
|
||||
|
||||
Reference in New Issue
Block a user