mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-09 09:42:35 -05:00
Feature/schemacompare scmp save (#824)
* First cut of scmp Save related changes and some test refactoring * Adding Exclude/Include objects in saving * Add diff entry validation as part of test * Adding PR comments - major change is change to nameparts in place of name hence preserving any "."/"[" in name and avoiding any string operations * One more UT scenario addition for create excluded object
This commit is contained in:
@@ -12,6 +12,8 @@ using System.Collections.Concurrent;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlServer.Dac.Compare;
|
||||
using Microsoft.SqlTools.ServiceLayer.Utility;
|
||||
using Microsoft.SqlTools.Utility;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
{
|
||||
@@ -49,10 +51,9 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
serviceHost.SetRequestHandler(SchemaCompareIncludeExcludeNodeRequest.Type, this.HandleSchemaCompareIncludeExcludeNodeRequest);
|
||||
serviceHost.SetRequestHandler(SchemaCompareGetDefaultOptionsRequest.Type, this.HandleSchemaCompareGetDefaultOptionsRequest);
|
||||
serviceHost.SetRequestHandler(SchemaCompareOpenScmpRequest.Type, this.HandleSchemaCompareOpenScmpRequest);
|
||||
serviceHost.SetRequestHandler(SchemaCompareSaveScmpRequest.Type, this.HandleSchemaCompareSaveScmpRequest);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Handles schema compare request
|
||||
/// </summary>
|
||||
@@ -70,7 +71,7 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
parameters.TargetEndpointInfo.OwnerUri,
|
||||
out targetConnInfo);
|
||||
|
||||
Task schemaCompareTask = Task.Run(async () =>
|
||||
CurrentSchemaCompareTask = Task.Run(async () =>
|
||||
{
|
||||
SchemaCompareOperation operation = null;
|
||||
|
||||
@@ -93,6 +94,7 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Write(TraceEventType.Error, "Failed to compare schema. Error: " + e);
|
||||
await requestContext.SendResult(new SchemaCompareResult()
|
||||
{
|
||||
OperationId = operation != null ? operation.OperationId : null,
|
||||
@@ -137,11 +139,12 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Write(TraceEventType.Error, "Failed to generate schema compare script. Error: " + e);
|
||||
await requestContext.SendResult(new ResultStatus()
|
||||
{
|
||||
Success = false,
|
||||
ErrorMessage = operation == null ? e.Message : operation.ErrorMessage,
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,6 +176,7 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Write(TraceEventType.Error, "Failed to publish schema compare changes. Error: " + e);
|
||||
await requestContext.SendResult(new ResultStatus()
|
||||
{
|
||||
Success = false,
|
||||
@@ -181,6 +185,10 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles request for exclude incude node in Schema compare result
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task HandleSchemaCompareIncludeExcludeNodeRequest(SchemaCompareNodeParams parameters, RequestContext<ResultStatus> requestContext)
|
||||
{
|
||||
SchemaCompareIncludeExcludeNodeOperation operation = null;
|
||||
@@ -199,6 +207,7 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Write(TraceEventType.Error, "Failed to select compare schema result node. Error: " + e);
|
||||
await requestContext.SendResult(new ResultStatus()
|
||||
{
|
||||
Success = false,
|
||||
@@ -207,6 +216,10 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles request to create default deployment options as per DacFx
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task HandleSchemaCompareGetDefaultOptionsRequest(SchemaCompareGetOptionsParams parameters, RequestContext<SchemaCompareOptionsResult> requestContext)
|
||||
{
|
||||
try
|
||||
@@ -267,6 +280,52 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles schema compare save SCMP request
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task HandleSchemaCompareSaveScmpRequest(SchemaCompareSaveScmpParams parameters, RequestContext<ResultStatus> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
ConnectionInfo sourceConnInfo;
|
||||
ConnectionInfo targetConnInfo;
|
||||
ConnectionServiceInstance.TryFindConnection(parameters.SourceEndpointInfo.OwnerUri, out sourceConnInfo);
|
||||
ConnectionServiceInstance.TryFindConnection(parameters.TargetEndpointInfo.OwnerUri, out targetConnInfo);
|
||||
|
||||
CurrentSchemaCompareTask = Task.Run(async () =>
|
||||
{
|
||||
SchemaCompareSaveScmpOperation operation = null;
|
||||
|
||||
try
|
||||
{
|
||||
operation = new SchemaCompareSaveScmpOperation(parameters, sourceConnInfo, targetConnInfo);
|
||||
operation.Execute(parameters.TaskExecutionMode);
|
||||
|
||||
await requestContext.SendResult(new ResultStatus()
|
||||
{
|
||||
Success = true,
|
||||
ErrorMessage = operation.ErrorMessage,
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Write(TraceEventType.Error, "Failed to save scmp file. Error: " + e);
|
||||
await requestContext.SendResult(new SchemaCompareResult()
|
||||
{
|
||||
OperationId = operation != null ? operation.OperationId : null,
|
||||
Success = false,
|
||||
ErrorMessage = operation == null ? e.Message : operation.ErrorMessage,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
}
|
||||
|
||||
private SqlTaskManager SqlTaskManagerInstance
|
||||
{
|
||||
get
|
||||
|
||||
Reference in New Issue
Block a user