mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-17 01:25:40 -05:00
Adds support for checking and updating cross-compatibility for SQL Projects (#1847)
* Adding cross-platform check and update * Checkpoint * checkpoint * Updating for latest nuget package * Correctly typing the result object
This commit is contained in:
@@ -44,6 +44,8 @@ namespace Microsoft.SqlTools.ServiceLayer.SqlProjects
|
||||
serviceHost.SetRequestHandler(OpenSqlProjectRequest.Type, HandleOpenSqlProjectRequest, isParallelProcessingSupported: true);
|
||||
serviceHost.SetRequestHandler(CloseSqlProjectRequest.Type, HandleCloseSqlProjectRequest, isParallelProcessingSupported: true);
|
||||
serviceHost.SetRequestHandler(NewSqlProjectRequest.Type, HandleNewSqlProjectRequest, isParallelProcessingSupported: true);
|
||||
serviceHost.SetRequestHandler(GetCrossPlatformCompatiblityRequest.Type, HandleGetCrossPlatformCompatibilityRequest, isParallelProcessingSupported: true);
|
||||
serviceHost.SetRequestHandler(UpdateProjectForCrossPlatformRequest.Type, HandleUpdateProjectForCrossPlatformRequest, isParallelProcessingSupported: false);
|
||||
|
||||
// SQL object script functions
|
||||
serviceHost.SetRequestHandler(AddSqlObjectScriptRequest.Type, HandleAddSqlObjectScriptRequest, isParallelProcessingSupported: false);
|
||||
@@ -78,12 +80,29 @@ namespace Microsoft.SqlTools.ServiceLayer.SqlProjects
|
||||
{
|
||||
await RunWithErrorHandling(async () =>
|
||||
{
|
||||
await SqlProject.CreateProjectAsync(requestParams.ProjectUri, requestParams.SqlProjectType, requestParams.DatabaseSchemaProvider);
|
||||
await SqlProject.CreateProjectAsync(requestParams.ProjectUri, new CreateSqlProjectParams() { ProjectType = requestParams.SqlProjectType, DspVersion = requestParams.DatabaseSchemaProvider });
|
||||
GetProject(requestParams.ProjectUri); // load into the cache
|
||||
|
||||
}, requestContext);
|
||||
}
|
||||
|
||||
internal async Task HandleGetCrossPlatformCompatibilityRequest(SqlProjectParams requestParams, RequestContext<GetCrossPlatformCompatiblityResult> requestContext)
|
||||
{
|
||||
await RunWithErrorHandling(() =>
|
||||
{
|
||||
return new GetCrossPlatformCompatiblityResult()
|
||||
{
|
||||
Success = true,
|
||||
ErrorMessage = null,
|
||||
IsCrossPlatformCompatible = GetProject(requestParams.ProjectUri).CrossPlatformCompatible
|
||||
};
|
||||
}, requestContext);
|
||||
}
|
||||
|
||||
internal async Task HandleUpdateProjectForCrossPlatformRequest(SqlProjectParams requestParams, RequestContext<ResultStatus> requestContext)
|
||||
{
|
||||
await RunWithErrorHandling(() => GetProject(requestParams.ProjectUri).UpdateForCrossPlatform(), requestContext);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region SQL object script functions
|
||||
@@ -119,25 +138,33 @@ namespace Microsoft.SqlTools.ServiceLayer.SqlProjects
|
||||
|
||||
internal async Task HandleAddDacpacReferenceRequest(AddDacpacReferenceParams requestParams, RequestContext<ResultStatus> requestContext)
|
||||
{
|
||||
await RunWithErrorHandling(() => GetProject(requestParams.ProjectUri).DatabaseReferences.Add(
|
||||
new DacpacReference(
|
||||
requestParams.DacpacPath,
|
||||
requestParams.SuppressMissingDependencies,
|
||||
requestParams.DatabaseVariable,
|
||||
requestParams.ServerVariable)),
|
||||
requestContext);
|
||||
await RunWithErrorHandling(() =>
|
||||
{
|
||||
SqlProject project = GetProject(requestParams.ProjectUri);
|
||||
|
||||
project.DatabaseReferences.Add(
|
||||
new DacpacReference(
|
||||
requestParams.DacpacPath,
|
||||
requestParams.SuppressMissingDependencies,
|
||||
project.SqlCmdVariables.Get(requestParams.DatabaseVariable),
|
||||
project.SqlCmdVariables.Get(requestParams.ServerVariable)));
|
||||
}, requestContext);
|
||||
}
|
||||
|
||||
internal async Task HandleAddSqlProjectReferenceRequest(AddSqlProjectReferenceParams requestParams, RequestContext<ResultStatus> requestContext)
|
||||
{
|
||||
await RunWithErrorHandling(() => GetProject(requestParams.ProjectUri).DatabaseReferences.Add(
|
||||
new SqlProjectReference(
|
||||
requestParams.ProjectPath,
|
||||
requestParams.ProjectGuid,
|
||||
requestParams.SuppressMissingDependencies,
|
||||
requestParams.DatabaseVariable,
|
||||
requestParams.ServerVariable)),
|
||||
requestContext);
|
||||
await RunWithErrorHandling(() =>
|
||||
{
|
||||
SqlProject project = GetProject(requestParams.ProjectUri);
|
||||
|
||||
project.DatabaseReferences.Add(
|
||||
new SqlProjectReference(
|
||||
requestParams.ProjectPath,
|
||||
requestParams.ProjectGuid,
|
||||
requestParams.SuppressMissingDependencies,
|
||||
project.SqlCmdVariables.Get(requestParams.DatabaseVariable),
|
||||
project.SqlCmdVariables.Get(requestParams.ServerVariable)));
|
||||
}, requestContext);
|
||||
}
|
||||
|
||||
internal async Task HandleDeleteDatabaseReferenceRequest(DeleteDatabaseReferenceParams requestParams, RequestContext<ResultStatus> requestContext)
|
||||
@@ -189,26 +216,67 @@ namespace Microsoft.SqlTools.ServiceLayer.SqlProjects
|
||||
|
||||
#region Helper methods
|
||||
|
||||
/// <summary>
|
||||
/// Synchronous action with standard ResultStatus
|
||||
/// </summary>
|
||||
/// <param name="action"></param>
|
||||
/// <param name="requestContext"></param>
|
||||
/// <returns></returns>
|
||||
private async Task RunWithErrorHandling(Action action, RequestContext<ResultStatus> requestContext)
|
||||
{
|
||||
await RunWithErrorHandling(async () => await Task.Run(action), requestContext);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronous action with standard ResultStatus
|
||||
/// </summary>
|
||||
/// <param name="action"></param>
|
||||
/// <param name="requestContext"></param>
|
||||
/// <returns></returns>
|
||||
private async Task RunWithErrorHandling(Func<Task> action, RequestContext<ResultStatus> requestContext)
|
||||
{
|
||||
try
|
||||
await RunWithErrorHandling<ResultStatus>(async () =>
|
||||
{
|
||||
await action();
|
||||
|
||||
await requestContext.SendResult(new ResultStatus()
|
||||
return new ResultStatus()
|
||||
{
|
||||
Success = true,
|
||||
ErrorMessage = null
|
||||
});
|
||||
};
|
||||
}, requestContext);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Synchronous action with custom result
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="action"></param>
|
||||
/// <param name="requestContext"></param>
|
||||
/// <returns></returns>
|
||||
private async Task RunWithErrorHandling<T>(Func<T> action, RequestContext<T> requestContext) where T : ResultStatus, new()
|
||||
{
|
||||
await RunWithErrorHandling<T>(async () => await Task.Run(action), requestContext);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronous action with custom result
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="action"></param>
|
||||
/// <param name="requestContext"></param>
|
||||
/// <returns></returns>
|
||||
private async Task RunWithErrorHandling<T>(Func<Task<T>> action, RequestContext<T> requestContext) where T : ResultStatus, new()
|
||||
{
|
||||
try
|
||||
{
|
||||
T result = await action();
|
||||
await requestContext.SendResult(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await requestContext.SendResult(new ResultStatus()
|
||||
await requestContext.SendResult(new T()
|
||||
{
|
||||
Success = false,
|
||||
ErrorMessage = ex.Message
|
||||
|
||||
Reference in New Issue
Block a user