mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-26 01:25:42 -05:00
Schema compare cancel operation (#826)
* First cut of schema compare cancel (private nuget) * Update Dacfx nuget to a published version
This commit is contained in:
@@ -14,6 +14,7 @@ using Microsoft.SqlServer.Dac.Compare;
|
||||
using Microsoft.SqlTools.ServiceLayer.Utility;
|
||||
using Microsoft.SqlTools.Utility;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
{
|
||||
@@ -27,6 +28,8 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
private static readonly Lazy<SchemaCompareService> instance = new Lazy<SchemaCompareService>(() => new SchemaCompareService());
|
||||
private Lazy<ConcurrentDictionary<string, SchemaComparisonResult>> schemaCompareResults =
|
||||
new Lazy<ConcurrentDictionary<string, SchemaComparisonResult>>(() => new ConcurrentDictionary<string, SchemaComparisonResult>());
|
||||
private Lazy<ConcurrentDictionary<string, Action>> currentComparisonCancellationAction =
|
||||
new Lazy<ConcurrentDictionary<string, Action>>(() => new ConcurrentDictionary<string, Action>());
|
||||
|
||||
// For testability
|
||||
internal Task CurrentSchemaCompareTask;
|
||||
@@ -46,6 +49,7 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
public void InitializeService(ServiceHost serviceHost)
|
||||
{
|
||||
serviceHost.SetRequestHandler(SchemaCompareRequest.Type, this.HandleSchemaCompareRequest);
|
||||
serviceHost.SetRequestHandler(SchemaCompareCancellationRequest.Type, this.HandleSchemaCompareCancelRequest);
|
||||
serviceHost.SetRequestHandler(SchemaCompareGenerateScriptRequest.Type, this.HandleSchemaCompareGenerateScriptRequest);
|
||||
serviceHost.SetRequestHandler(SchemaComparePublishChangesRequest.Type, this.HandleSchemaComparePublishChangesRequest);
|
||||
serviceHost.SetRequestHandler(SchemaCompareIncludeExcludeNodeRequest.Type, this.HandleSchemaCompareIncludeExcludeNodeRequest);
|
||||
@@ -78,6 +82,7 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
try
|
||||
{
|
||||
operation = new SchemaCompareOperation(parameters, sourceConnInfo, targetConnInfo);
|
||||
currentComparisonCancellationAction.Value[operation.OperationId] = operation.Cancel;
|
||||
operation.Execute(parameters.TaskExecutionMode);
|
||||
|
||||
// add result to dictionary of results
|
||||
@@ -110,6 +115,40 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles schema compare cancel request
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task HandleSchemaCompareCancelRequest(SchemaCompareCancelParams parameters, RequestContext<ResultStatus> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
Action cancelAction = null;
|
||||
if (currentComparisonCancellationAction.Value.TryRemove(parameters.OperationId, out cancelAction))
|
||||
{
|
||||
if(cancelAction != null)
|
||||
{
|
||||
cancelAction.Invoke();
|
||||
await requestContext.SendResult(new ResultStatus()
|
||||
{
|
||||
Success = true,
|
||||
ErrorMessage = null
|
||||
});
|
||||
}
|
||||
}
|
||||
await requestContext.SendResult(new ResultStatus()
|
||||
{
|
||||
Success = false,
|
||||
ErrorMessage = SR.SchemaCompareSessionNotFound
|
||||
});
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles request for schema compare generate deploy script
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user