mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-17 02:51:45 -05:00
Catch Request/Event handler errors at dispatcher level (#1610)
* Catch Request/Event handler errors at dispatcher level * Fix tests * Use Exception overload of SendError * Fix tests
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
@@ -161,17 +161,9 @@ namespace Microsoft.SqlTools.Credentials
|
||||
private async Task HandleRequest<T>(Func<Task<T>> handler, RequestContext<T> requestContext, string requestType)
|
||||
{
|
||||
Logger.Write(TraceEventType.Verbose, requestType);
|
||||
|
||||
try
|
||||
{
|
||||
T result = await handler();
|
||||
await requestContext.SendResult(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await requestContext.SendError(ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,6 +131,8 @@ namespace Microsoft.SqlTools.Hosting.Protocol
|
||||
requestMessage,
|
||||
messageWriter);
|
||||
|
||||
try
|
||||
{
|
||||
TParams typedParams = default(TParams);
|
||||
if (requestMessage.Contents != null)
|
||||
{
|
||||
@@ -140,11 +142,18 @@ namespace Microsoft.SqlTools.Hosting.Protocol
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await requestContext.SendError(ex.Message);
|
||||
throw new Exception($"{requestType.MethodName} : Error parsing message contents {requestMessage.Contents}", ex);
|
||||
}
|
||||
}
|
||||
|
||||
await requestHandler(typedParams, requestContext);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Error(ex);
|
||||
await requestContext.SendError(ex);
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -178,6 +187,8 @@ namespace Microsoft.SqlTools.Hosting.Protocol
|
||||
{
|
||||
var eventContext = new EventContext(messageWriter);
|
||||
|
||||
try
|
||||
{
|
||||
TParams typedParams = default(TParams);
|
||||
if (eventMessage.Contents != null)
|
||||
{
|
||||
@@ -187,11 +198,16 @@ namespace Microsoft.SqlTools.Hosting.Protocol
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Write(TraceEventType.Verbose, ex.ToString());
|
||||
throw new Exception($"{eventType.MethodName} : Error parsing message contents {eventMessage.Contents}", ex);
|
||||
}
|
||||
}
|
||||
|
||||
await eventHandler(typedParams, eventContext);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// There's nothing on the client side to send an error back to so just log the error and move on
|
||||
Logger.Error(ex);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -263,6 +263,12 @@ namespace Microsoft.SqlTools.Utility
|
||||
/// <param name="logMessage">The message text to be written.</param>
|
||||
public static void Error(string logMessage) => Write(TraceEventType.Error, logMessage);
|
||||
|
||||
/// <summary>
|
||||
/// Writes an exception to the log file with the Error event level
|
||||
/// </summary>
|
||||
/// <param name="exception"></param>
|
||||
public static void Error(Exception exception) => Write(TraceEventType.Error, exception.ToString());
|
||||
|
||||
/// <summary>
|
||||
/// Writes a message to the log file with the Critical event level
|
||||
/// </summary>
|
||||
|
||||
@@ -135,11 +135,6 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
|
||||
await requestContext.SendError(ex.Message);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Send just the error message back for now as stack trace isn't useful
|
||||
await requestContext.SendError(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,8 +80,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
||||
public static async Task HandleDefaultDatabaseInfoRequest(
|
||||
DefaultDatabaseInfoParams optionsParams,
|
||||
RequestContext<DefaultDatabaseInfoResponse> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = new DefaultDatabaseInfoResponse();
|
||||
ConnectionInfo connInfo;
|
||||
@@ -95,11 +93,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
||||
await requestContext.SendResult(response);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await requestContext.SendError(ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles a create database request
|
||||
@@ -107,8 +100,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
||||
internal static async Task HandleCreateDatabaseRequest(
|
||||
CreateDatabaseParams databaseParams,
|
||||
RequestContext<CreateDatabaseResponse> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = new DefaultDatabaseInfoResponse();
|
||||
ConnectionInfo connInfo;
|
||||
@@ -130,11 +121,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await requestContext.SendError(ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle get database info request
|
||||
@@ -142,8 +128,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
||||
internal static async Task HandleGetDatabaseInfoRequest(
|
||||
GetDatabaseInfoParams databaseParams,
|
||||
RequestContext<GetDatabaseInfoResponse> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
Func<Task> requestHandler = async () =>
|
||||
{
|
||||
@@ -168,12 +152,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
||||
{
|
||||
await requestContext.SendError(t.Exception.ToString());
|
||||
});
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await requestContext.SendError(ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -147,8 +147,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
/// Handle request to get Agent job activities
|
||||
/// </summary>
|
||||
internal async Task HandleAgentJobsRequest(AgentJobsParams parameters, RequestContext<AgentJobsResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = new AgentJobsResult();
|
||||
ConnectionInfo connInfo;
|
||||
@@ -176,18 +174,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
}
|
||||
await requestContext.SendResult(result);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle request to get Agent Job history
|
||||
/// </summary>
|
||||
internal async Task HandleJobHistoryRequest(AgentJobHistoryParams parameters, RequestContext<AgentJobHistoryResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = new AgentJobHistoryResult();
|
||||
ConnectionInfo connInfo;
|
||||
@@ -257,11 +248,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
|
||||
await requestContext.SendResult(result);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle request to Run a Job
|
||||
|
||||
@@ -41,8 +41,6 @@ namespace Microsoft.SqlTools.ServiceLayer.AzureBlob
|
||||
internal async Task HandleCreateSasRequest(
|
||||
CreateSasParams optionsParams,
|
||||
RequestContext<CreateSasResponse> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
ConnectionInfo connInfo;
|
||||
ConnectionService.Instance.TryFindConnection(
|
||||
@@ -72,10 +70,5 @@ namespace Microsoft.SqlTools.ServiceLayer.AzureBlob
|
||||
await requestContext.SendResult(response);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await requestContext.SendError(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,36 +40,22 @@ namespace Microsoft.SqlTools.ServiceLayer.AzureFunctions
|
||||
/// Handles request to add sql binding into Azure Functions
|
||||
/// </summary>
|
||||
public async Task HandleAddSqlBindingRequest(AddSqlBindingParams parameters, RequestContext<ResultStatus> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
AddSqlBindingOperation operation = new AddSqlBindingOperation(parameters);
|
||||
ResultStatus result = operation.AddBinding();
|
||||
|
||||
await requestContext.SendResult(result);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles request to get the names of the Azure functions in a file
|
||||
/// </summary>
|
||||
public async Task HandleGetAzureFunctionsRequest(GetAzureFunctionsParams parameters, RequestContext<GetAzureFunctionsResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
GetAzureFunctionsOperation operation = new GetAzureFunctionsOperation(parameters);
|
||||
GetAzureFunctionsResult result = operation.GetAzureFunctions();
|
||||
|
||||
await requestContext.SendResult(result);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,8 +54,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Cms
|
||||
public async Task HandleCreateCentralManagementServerRequest(CreateCentralManagementServerParams createCmsParams, RequestContext<ListRegisteredServersResult> requestContext)
|
||||
{
|
||||
Logger.Write(TraceEventType.Verbose, "HandleCreateCentralManagementServerRequest");
|
||||
try
|
||||
{
|
||||
CmsTask = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
@@ -80,18 +78,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Cms
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Exception related to run task will be captured here
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task HandleAddRegisteredServerRequest(AddRegisteredServerParams cmsCreateParams, RequestContext<bool> requestContext)
|
||||
{
|
||||
Logger.Write(TraceEventType.Verbose, "HandleAddRegisteredServerRequest");
|
||||
try
|
||||
{
|
||||
CmsTask = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
@@ -122,17 +112,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Cms
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task HandleListRegisteredServersRequest(ListRegisteredServersParams listServerParams, RequestContext<ListRegisteredServersResult> requestContext)
|
||||
{
|
||||
Logger.Write(TraceEventType.Verbose, "HandleListRegisteredServersRequest");
|
||||
try
|
||||
{
|
||||
CmsTask = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
@@ -160,17 +143,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Cms
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task HandleRemoveRegisteredServerRequest(RemoveRegisteredServerParams removeServerParams, RequestContext<bool> requestContext)
|
||||
{
|
||||
Logger.Write(TraceEventType.Verbose, "HandleRemoveServerRequest");
|
||||
try
|
||||
{
|
||||
CmsTask = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
@@ -200,17 +176,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Cms
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task HandleAddServerGroupRequest(AddServerGroupParams addServerGroupParams, RequestContext<bool> requestContext)
|
||||
{
|
||||
Logger.Write(TraceEventType.Verbose, "HandleAddServerGroupRequest");
|
||||
try
|
||||
{
|
||||
CmsTask = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
@@ -248,17 +217,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Cms
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task HandleRemoveServerGroupRequest(RemoveServerGroupParams removeServerGroupParams, RequestContext<bool> requestContext)
|
||||
{
|
||||
Logger.Write(TraceEventType.Verbose, "HandleRemoveServerGroupRequest");
|
||||
try
|
||||
{
|
||||
CmsTask = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
@@ -284,11 +246,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Cms
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -1119,17 +1119,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
|
||||
RequestContext<bool> requestContext)
|
||||
{
|
||||
Logger.Write(TraceEventType.Verbose, "HandleCancelConnectRequest");
|
||||
|
||||
try
|
||||
{
|
||||
bool result = CancelConnect(cancelParams);
|
||||
await requestContext.SendResult(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await requestContext.SendError(ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle disconnect requests
|
||||
@@ -1139,16 +1131,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
|
||||
RequestContext<bool> requestContext)
|
||||
{
|
||||
Logger.Write(TraceEventType.Verbose, "HandleDisconnectRequest");
|
||||
|
||||
try
|
||||
{
|
||||
bool result = Instance.Disconnect(disconnectParams);
|
||||
await requestContext.SendResult(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await requestContext.SendError(ex.ToString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1403,8 +1387,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
|
||||
string connectionString = string.Empty;
|
||||
ConnectionInfo info;
|
||||
SqlConnectionStringBuilder connStringBuilder;
|
||||
try
|
||||
{
|
||||
// set connection string using connection uri if connection details are undefined
|
||||
if (connStringParams.ConnectionDetails == null)
|
||||
{
|
||||
@@ -1426,11 +1408,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
|
||||
connStringBuilder.ApplicationName = "sqlops-connection-string";
|
||||
}
|
||||
connectionString = connStringBuilder.ConnectionString;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e.ToString());
|
||||
}
|
||||
|
||||
await requestContext.SendResult(connectionString);
|
||||
}
|
||||
|
||||
@@ -69,9 +69,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
|
||||
/// Handles request to export a bacpac
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task HandleExportRequest(ExportParams parameters, RequestContext<DacFxResult> requestContext)
|
||||
{
|
||||
try
|
||||
public Task HandleExportRequest(ExportParams parameters, RequestContext<DacFxResult> requestContext)
|
||||
{
|
||||
ConnectionInfo connInfo;
|
||||
ConnectionServiceInstance.TryFindConnection(
|
||||
@@ -82,11 +80,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
|
||||
ExportOperation operation = new ExportOperation(parameters, connInfo);
|
||||
ExecuteOperation(operation, parameters, SR.ExportBacpacTaskName, requestContext);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -94,8 +88,6 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task HandleImportRequest(ImportParams parameters, RequestContext<DacFxResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
ConnectionInfo connInfo;
|
||||
ConnectionServiceInstance.TryFindConnection(
|
||||
@@ -107,19 +99,12 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
|
||||
ExecuteOperation(operation, parameters, SR.ImportBacpacTaskName, requestContext);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles request to extract a dacpac
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task HandleExtractRequest(ExtractParams parameters, RequestContext<DacFxResult> requestContext)
|
||||
{
|
||||
try
|
||||
public Task HandleExtractRequest(ExtractParams parameters, RequestContext<DacFxResult> requestContext)
|
||||
{
|
||||
ConnectionInfo connInfo;
|
||||
ConnectionServiceInstance.TryFindConnection(
|
||||
@@ -133,20 +118,14 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
|
||||
string taskName = parameters.ExtractTarget == DacExtractTarget.DacPac ? SR.ExtractDacpacTaskName : SR.ProjectExtractTaskName;
|
||||
ExecuteOperation(operation, parameters, taskName, requestContext);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles request to deploy a dacpac
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task HandleDeployRequest(DeployParams parameters, RequestContext<DacFxResult> requestContext)
|
||||
{
|
||||
try
|
||||
public Task HandleDeployRequest(DeployParams parameters, RequestContext<DacFxResult> requestContext)
|
||||
{
|
||||
ConnectionInfo connInfo;
|
||||
ConnectionServiceInstance.TryFindConnection(
|
||||
@@ -157,11 +136,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
|
||||
DeployOperation operation = new DeployOperation(parameters, connInfo);
|
||||
ExecuteOperation(operation, parameters, SR.DeployDacpacTaskName, requestContext);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -169,8 +144,6 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task HandleGenerateDeployScriptRequest(GenerateDeployScriptParams parameters, RequestContext<DacFxResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
ConnectionInfo connInfo;
|
||||
ConnectionServiceInstance.TryFindConnection(
|
||||
@@ -197,19 +170,12 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles request to generate deploy plan
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task HandleGenerateDeployPlanRequest(GenerateDeployPlanParams parameters, RequestContext<GenerateDeployPlanRequestResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
ConnectionInfo connInfo;
|
||||
ConnectionServiceInstance.TryFindConnection(
|
||||
@@ -229,19 +195,12 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <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)
|
||||
@@ -261,30 +220,18 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
|
||||
ErrorMessage = string.Empty,
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles request to validate an ASA streaming job
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task HandleValidateStreamingJobRequest(ValidateStreamingJobParams parameters, RequestContext<ValidateStreamingJobResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
ValidateStreamingJobOperation operation = new ValidateStreamingJobOperation(parameters);
|
||||
ValidateStreamingJobResult result = operation.ValidateQuery();
|
||||
|
||||
await requestContext.SendResult(result);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles request to create default publish options for DacFx
|
||||
@@ -316,8 +263,6 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
|
||||
}
|
||||
|
||||
public async Task HandleParseTSqlScriptRequest(ParseTSqlScriptRequestParams requestParams, RequestContext<ParseTSqlScriptResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
var script = System.IO.File.ReadAllText(requestParams.FilePath);
|
||||
await requestContext.SendResult(new ParseTSqlScriptResult()
|
||||
@@ -325,11 +270,6 @@ namespace Microsoft.SqlTools.ServiceLayer.DacFx
|
||||
ContainsCreateTableStatement = DacTableDesigner.ScriptContainsCreateTableStatements(script, requestParams.DatabaseSchemaProvider)
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task HandleGenerateTSqlModelRequest(GenerateTSqlModelParams requestParams, RequestContext<ResultStatus> requestContext)
|
||||
{
|
||||
|
||||
@@ -136,8 +136,6 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery
|
||||
internal async Task HandleBackupConfigInfoRequest(
|
||||
DefaultDatabaseInfoParams optionsParams,
|
||||
RequestContext<BackupConfigInfoResponse> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
var response = new BackupConfigInfoResponse();
|
||||
ConnectionInfo connInfo;
|
||||
@@ -162,11 +160,6 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery
|
||||
|
||||
await requestContext.SendResult(response);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await requestContext.SendError(ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles a restore request
|
||||
@@ -321,8 +314,6 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery
|
||||
internal async Task HandleBackupRequest(
|
||||
BackupParams backupParams,
|
||||
RequestContext<BackupResponse> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
BackupResponse response = new BackupResponse();
|
||||
ConnectionInfo connInfo;
|
||||
@@ -366,11 +357,6 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery
|
||||
|
||||
await requestContext.SendResult(response);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await requestContext.SendError(ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsBackupRestoreOperationSupported(string ownerUri, out ConnectionInfo connectionInfo)
|
||||
{
|
||||
|
||||
@@ -90,8 +90,6 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData
|
||||
|
||||
internal async Task HandleSessionRequest<TResult>(SessionOperationParams sessionParams,
|
||||
RequestContext<TResult> requestContext, Func<EditSession, TResult> sessionOperation)
|
||||
{
|
||||
try
|
||||
{
|
||||
EditSession editSession = GetActiveSessionOrThrow(sessionParams.OwnerUri);
|
||||
|
||||
@@ -99,11 +97,6 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData
|
||||
TResult result = sessionOperation(editSession);
|
||||
await requestContext.SendResult(result);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
internal Task HandleCreateRowRequest(EditCreateRowParams createParams,
|
||||
RequestContext<EditCreateRowResult> requestContext)
|
||||
@@ -124,8 +117,6 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData
|
||||
|
||||
internal async Task HandleDisposeRequest(EditDisposeParams disposeParams,
|
||||
RequestContext<EditDisposeResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Sanity check the owner URI
|
||||
Validate.IsNotNullOrWhitespaceString(nameof(disposeParams.OwnerUri), disposeParams.OwnerUri);
|
||||
@@ -134,18 +125,12 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData
|
||||
EditSession editSession;
|
||||
if (!ActiveSessions.TryRemove(disposeParams.OwnerUri, out editSession))
|
||||
{
|
||||
await requestContext.SendError(SR.EditDataSessionNotFound);
|
||||
return;
|
||||
throw new Exception(SR.EditDataSessionNotFound);
|
||||
}
|
||||
|
||||
// Everything was successful, return success
|
||||
await requestContext.SendResult(new EditDisposeResult());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
internal async Task HandleInitializeRequest(EditInitializeParams initParams,
|
||||
RequestContext<EditInitializeResult> requestContext)
|
||||
@@ -157,8 +142,6 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData
|
||||
EditSession.Connector connector = () => connectionService.GetOrOpenConnection(initParams.OwnerUri, ConnectionType.Edit, alwaysPersistSecurity: true);
|
||||
EditSession.QueryRunner queryRunner = q => SessionInitializeQueryRunner(initParams.OwnerUri, context, q);
|
||||
|
||||
try
|
||||
{
|
||||
// Make sure we have info to process this request
|
||||
Validate.IsNotNullOrWhitespaceString(nameof(initParams.OwnerUri), initParams.OwnerUri);
|
||||
Validate.IsNotNullOrWhitespaceString(nameof(initParams.ObjectName), initParams.ObjectName);
|
||||
@@ -179,11 +162,6 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData
|
||||
// Send the result
|
||||
await requestContext.SendResult(new EditInitializeResult());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
internal Task HandleRevertCellRequest(EditRevertCellParams revertParams,
|
||||
RequestContext<EditRevertCellResult> requestContext)
|
||||
@@ -204,8 +182,6 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData
|
||||
|
||||
internal async Task HandleSubsetRequest(EditSubsetParams subsetParams,
|
||||
RequestContext<EditSubsetResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
EditSession session = GetActiveSessionOrThrow(subsetParams.OwnerUri);
|
||||
|
||||
@@ -218,11 +194,6 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData
|
||||
|
||||
await requestContext.SendResult(result);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
internal Task HandleUpdateCellRequest(EditUpdateCellParams updateParams,
|
||||
RequestContext<EditUpdateCellResult> requestContext)
|
||||
|
||||
@@ -54,8 +54,6 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan
|
||||
}
|
||||
|
||||
private async Task HandleGetExecutionPlan(GetExecutionPlanParams requestParams, RequestContext<GetExecutionPlanResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
var plans = ExecutionPlanGraphUtils.CreateShowPlanGraph(requestParams.GraphInfo.GraphFileContent, "");
|
||||
await requestContext.SendResult(new GetExecutionPlanResult
|
||||
@@ -63,11 +61,6 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan
|
||||
Graphs = plans
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles requests for color matching similar nodes.
|
||||
@@ -75,8 +68,6 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan
|
||||
internal async Task HandleExecutionPlanComparisonRequest(
|
||||
ExecutionPlanComparisonParams requestParams,
|
||||
RequestContext<ExecutionPlanComparisonResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
var nodeBuilder = new XmlPlanNodeBuilder(ShowPlanType.Unknown);
|
||||
var firstPlanXml = nodeBuilder.GetSingleStatementXml(requestParams.FirstExecutionPlanGraphInfo.GraphFileContent, requestParams.FirstExecutionPlanGraphInfo.PlanIndexInFile);
|
||||
@@ -105,11 +96,6 @@ namespace Microsoft.SqlTools.ServiceLayer.ExecutionPlan
|
||||
|
||||
await requestContext.SendResult(result);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disposes the Execution Plan Service
|
||||
|
||||
@@ -78,23 +78,17 @@ namespace Microsoft.SqlTools.ServiceLayer.Formatter
|
||||
|
||||
public async Task HandleDocFormatRequest(DocumentFormattingParams docFormatParams, RequestContext<TextEdit[]> requestContext)
|
||||
{
|
||||
Func<Task<TextEdit[]>> requestHandler = () =>
|
||||
{
|
||||
return FormatAndReturnEdits(docFormatParams);
|
||||
};
|
||||
await HandleRequest(requestHandler, requestContext, "HandleDocFormatRequest");
|
||||
|
||||
Logger.Verbose("HandleDocFormatRequest");
|
||||
TextEdit[] result = await FormatAndReturnEdits(docFormatParams);
|
||||
await requestContext.SendResult(result);
|
||||
DocumentStatusHelper.SendTelemetryEvent(requestContext, CreateTelemetryProps(isDocFormat: true));
|
||||
}
|
||||
|
||||
public async Task HandleDocRangeFormatRequest(DocumentRangeFormattingParams docRangeFormatParams, RequestContext<TextEdit[]> requestContext)
|
||||
{
|
||||
Func<Task<TextEdit[]>> requestHandler = () =>
|
||||
{
|
||||
return FormatRangeAndReturnEdits(docRangeFormatParams);
|
||||
};
|
||||
await HandleRequest(requestHandler, requestContext, "HandleDocRangeFormatRequest");
|
||||
|
||||
Logger.Verbose("HandleDocRangeFormatRequest");
|
||||
TextEdit[] result = await FormatRangeAndReturnEdits(docRangeFormatParams);
|
||||
await requestContext.SendResult(result);
|
||||
DocumentStatusHelper.SendTelemetryEvent(requestContext, CreateTelemetryProps(isDocFormat: false));
|
||||
}
|
||||
private static TelemetryProperties CreateTelemetryProps(bool isDocFormat)
|
||||
@@ -230,23 +224,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Formatter
|
||||
return edit;
|
||||
}
|
||||
|
||||
private async Task HandleRequest<T>(Func<Task<T>> handler, RequestContext<T> requestContext, string requestType)
|
||||
{
|
||||
Logger.Write(TraceEventType.Verbose, requestType);
|
||||
|
||||
try
|
||||
{
|
||||
T result = await handler();
|
||||
await requestContext.SendResult(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await requestContext.SendError(ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public string Format(TextReader input)
|
||||
{
|
||||
string originalSql = input.ReadToEnd();
|
||||
|
||||
@@ -78,8 +78,6 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageExtensibility
|
||||
public async Task HandleExternalLanguageDeleteRequest(ExternalLanguageDeleteRequestParams parameters, RequestContext<ExternalLanguageDeleteResponseParams> requestContext)
|
||||
{
|
||||
Logger.Write(TraceEventType.Verbose, "HandleExternalLanguageDeleteRequest");
|
||||
try
|
||||
{
|
||||
ConnectionInfo connInfo;
|
||||
ConnectionServiceInstance.TryFindConnection(
|
||||
parameters.OwnerUri,
|
||||
@@ -102,12 +100,6 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageExtensibility
|
||||
await requestContext.SendResult(response);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Exception related to run task will be captured here
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles external language delete request
|
||||
@@ -118,8 +110,6 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageExtensibility
|
||||
public async Task HandleExternalLanguageUpdateRequest(ExternalLanguageUpdateRequestParams parameters, RequestContext<ExternalLanguageUpdateResponseParams> requestContext)
|
||||
{
|
||||
Logger.Write(TraceEventType.Verbose, "HandleExternalLanguageUpdateRequest");
|
||||
try
|
||||
{
|
||||
ConnectionInfo connInfo;
|
||||
ConnectionServiceInstance.TryFindConnection(
|
||||
parameters.OwnerUri,
|
||||
@@ -142,12 +132,6 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageExtensibility
|
||||
await requestContext.SendResult(response);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Exception related to run task will be captured here
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles external language status request
|
||||
@@ -158,8 +142,6 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageExtensibility
|
||||
public async Task HandleExternalLanguageStatusRequest(ExternalLanguageStatusRequestParams parameters, RequestContext<ExternalLanguageStatusResponseParams> requestContext)
|
||||
{
|
||||
Logger.Write(TraceEventType.Verbose, "HandleExternalLanguageStatusRequest");
|
||||
try
|
||||
{
|
||||
ConnectionInfo connInfo;
|
||||
ConnectionServiceInstance.TryFindConnection(
|
||||
parameters.OwnerUri,
|
||||
@@ -183,12 +165,6 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageExtensibility
|
||||
await requestContext.SendResult(response);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Exception related to run task will be captured here
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles external language status request
|
||||
@@ -199,8 +175,6 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageExtensibility
|
||||
public async Task HandleExternalLanguageListRequest(ExternalLanguageListRequestParams parameters, RequestContext<ExternalLanguageListResponseParams> requestContext)
|
||||
{
|
||||
Logger.Write(TraceEventType.Verbose, "HandleExternalLanguageListRequest");
|
||||
try
|
||||
{
|
||||
ConnectionInfo connInfo;
|
||||
ConnectionServiceInstance.TryFindConnection(
|
||||
parameters.OwnerUri,
|
||||
@@ -223,11 +197,5 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageExtensibility
|
||||
await requestContext.SendResult(response);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Exception related to run task will be captured here
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -314,8 +314,6 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
/// <param name="requestContext"></param>
|
||||
/// <returns></returns>
|
||||
internal async Task HandleCompletionExtLoadRequest(CompletionExtensionParams param, RequestContext<bool> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
//register the new assembly
|
||||
var serviceProvider = (ExtensionServiceProvider)ServiceHostInstance.ServiceProvider;
|
||||
@@ -353,12 +351,6 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await requestContext.SendError(ex.Message);
|
||||
return;
|
||||
}
|
||||
|
||||
await requestContext.SendError(string.Format("Couldn't discover completion extension with type {0} in {1}", param.TypeName, param.AssemblyPath));
|
||||
}
|
||||
@@ -398,8 +390,6 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
/// <param name="requestContext"></param>
|
||||
/// <returns></returns>
|
||||
internal async Task HandleSyntaxParseRequest(SyntaxParseParams param, RequestContext<SyntaxParseResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
ParseResult result = Parser.Parse(param.Query);
|
||||
SyntaxParseResult syntaxResult = new SyntaxParseResult();
|
||||
@@ -419,11 +409,6 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
}
|
||||
await requestContext.SendResult(syntaxResult);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await requestContext.SendError(ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Auto-complete completion provider request callback
|
||||
@@ -434,8 +419,6 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
internal async Task HandleCompletionRequest(
|
||||
TextDocumentPosition textDocumentPosition,
|
||||
RequestContext<CompletionItem[]> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
var scriptFile = CurrentWorkspace.GetFile(textDocumentPosition.TextDocument.Uri);
|
||||
if (scriptFile == null)
|
||||
@@ -465,11 +448,6 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
await requestContext.SendResult(completionItems);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await requestContext.SendError(ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle the resolve completion request event to provide additional
|
||||
@@ -481,8 +459,6 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
internal async Task HandleCompletionResolveRequest(
|
||||
CompletionItem completionItem,
|
||||
RequestContext<CompletionItem> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
// check if Intellisense suggestions are enabled
|
||||
// Note: Do not know file, so no need to check for MSSQL flavor
|
||||
@@ -496,15 +472,8 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
await requestContext.SendResult(completionItem);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await requestContext.SendError(ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
internal async Task HandleDefinitionRequest(TextDocumentPosition textDocumentPosition, RequestContext<Location[]> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
DocumentStatusHelper.SendStatusChange(requestContext, textDocumentPosition, DocumentStatusHelper.DefinitionRequested);
|
||||
|
||||
@@ -542,11 +511,6 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
|
||||
DocumentStatusHelper.SendStatusChange(requestContext, textDocumentPosition, DocumentStatusHelper.DefinitionRequestCompleted);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await requestContext.SendError(ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private static TelemetryProperties CreatePeekTelemetryProps(bool succeeded, bool connected)
|
||||
{
|
||||
@@ -581,8 +545,6 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
internal async Task HandleSignatureHelpRequest(
|
||||
TextDocumentPosition textDocumentPosition,
|
||||
RequestContext<SignatureHelp> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
// check if Intellisense suggestions are enabled
|
||||
if (ShouldSkipNonMssqlFile(textDocumentPosition))
|
||||
@@ -608,17 +570,10 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await requestContext.SendError(ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private async Task HandleHoverRequest(
|
||||
TextDocumentPosition textDocumentPosition,
|
||||
RequestContext<Hover> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
// check if Quick Info hover tooltips are enabled
|
||||
if (CurrentWorkspaceSettings.IsQuickInfoEnabled
|
||||
@@ -639,11 +594,6 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
}
|
||||
await requestContext.SendResult(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await requestContext.SendError(ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -64,8 +64,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Metadata
|
||||
internal async Task HandleMetadataListRequest(
|
||||
MetadataQueryParams metadataParams,
|
||||
RequestContext<MetadataQueryResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
Func<Task> requestHandler = async () =>
|
||||
{
|
||||
@@ -95,11 +93,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Metadata
|
||||
});
|
||||
MetadataListTask = task;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await requestContext.SendError(ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
internal Task MetadataListTask { get; set; }
|
||||
|
||||
@@ -130,8 +123,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Metadata
|
||||
TableMetadataParams metadataParams,
|
||||
string objectType,
|
||||
RequestContext<TableMetadataResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
ConnectionInfo connInfo;
|
||||
MetadataService.ConnectionServiceInstance.TryFindConnection(
|
||||
@@ -155,11 +146,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Metadata
|
||||
Columns = metadata
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await requestContext.SendError(ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
internal static bool IsSystemDatabase(string database)
|
||||
{
|
||||
|
||||
@@ -157,10 +157,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Migration
|
||||
await requestContext.SendResult(results);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e.ToString());
|
||||
}
|
||||
finally
|
||||
{
|
||||
ConnectionService.Disconnect(new DisconnectParams { OwnerUri = randomUri, Type = null });
|
||||
@@ -208,10 +204,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Migration
|
||||
// TO-DO: what should be returned?
|
||||
await requestContext.SendResult(new StartPerfDataCollectionResult() { DateTimeStarted = DateTime.UtcNow });
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e.ToString());
|
||||
}
|
||||
finally
|
||||
{
|
||||
ConnectionService.Disconnect(new DisconnectParams { OwnerUri = randomUri, Type = null });
|
||||
@@ -224,19 +216,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Migration
|
||||
internal async Task HandleStopPerfDataCollectionRequest(
|
||||
StopPerfDataCollectionParams parameters,
|
||||
RequestContext<StopPerfDataCollectionResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.DataCollectionController.Dispose();
|
||||
|
||||
// TO-DO: what should be returned?
|
||||
await requestContext.SendResult(new StopPerfDataCollectionResult() { DateTimeStopped = DateTime.UtcNow });
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle request to refresh performance data collection status
|
||||
@@ -244,8 +229,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Migration
|
||||
internal async Task HandleRefreshPerfDataCollectionRequest(
|
||||
RefreshPerfDataCollectionParams parameters,
|
||||
RequestContext<RefreshPerfDataCollectionResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
bool isCollecting = !(this.DataCollectionController is null) ? this.DataCollectionController.IsRunning() : false;
|
||||
List<string> messages = !(this.DataCollectionController is null) ? this.DataCollectionController.FetchLatestMessages(parameters.LastRefreshedTime) : new List<string>();
|
||||
@@ -261,11 +244,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Migration
|
||||
|
||||
await requestContext.SendResult(result);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e.ToString());
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Handle request to generate SKU recommendations
|
||||
/// </summary>
|
||||
@@ -396,10 +374,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Migration
|
||||
{
|
||||
await requestContext.SendError($"Unable to read collected performance data from {parameters.DataFolder}. Please specify another folder or start data collection instead.");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
internal class AssessmentRequest : IAssessmentRequest
|
||||
|
||||
@@ -75,8 +75,6 @@ namespace Microsoft.SqlTools.ServiceLayer.NotebookConvert
|
||||
#region Convert Handlers
|
||||
|
||||
internal async Task HandleConvertNotebookToSqlRequest(ConvertNotebookToSqlParams parameters, RequestContext<ConvertNotebookToSqlResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
var notebookDoc = JsonConvert.DeserializeObject<NotebookDocument>(parameters.Content);
|
||||
|
||||
@@ -86,15 +84,8 @@ namespace Microsoft.SqlTools.ServiceLayer.NotebookConvert
|
||||
};
|
||||
await requestContext.SendResult(result);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
}
|
||||
|
||||
internal async Task HandleConvertSqlToNotebookRequest(ConvertSqlToNotebookParams parameters, RequestContext<ConvertSqlToNotebookResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
// This URI doesn't come in escaped - so if it's a file path with reserved characters (such as %)
|
||||
// then we'll fail to find it since GetFile expects the URI to be a fully-escaped URI as that's
|
||||
@@ -108,11 +99,6 @@ namespace Microsoft.SqlTools.ServiceLayer.NotebookConvert
|
||||
};
|
||||
await requestContext.SendResult(result);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion // Convert Handlers
|
||||
|
||||
|
||||
@@ -163,8 +163,6 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
|
||||
|
||||
|
||||
internal async Task HandleCreateSessionRequest(ConnectionDetails connectionDetails, RequestContext<CreateSessionResponse> context)
|
||||
{
|
||||
try
|
||||
{
|
||||
Logger.Write(TraceEventType.Verbose, "HandleCreateSessionRequest");
|
||||
Func<Task<CreateSessionResponse>> doCreateSession = async () =>
|
||||
@@ -184,11 +182,6 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
|
||||
{
|
||||
RunCreateSessionTask(connectionDetails, response.SessionId);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await context.SendError(ex.ToString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -224,8 +217,6 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
|
||||
}
|
||||
|
||||
internal async Task HandleRefreshRequest(RefreshParams refreshParams, RequestContext<bool> context)
|
||||
{
|
||||
try
|
||||
{
|
||||
Logger.Write(TraceEventType.Verbose, "HandleRefreshRequest");
|
||||
Validate.IsNotNull(nameof(refreshParams), refreshParams);
|
||||
@@ -249,11 +240,6 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
|
||||
}
|
||||
await context.SendResult(true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await context.SendError(ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
internal async Task HandleCloseSessionRequest(CloseSessionParams closeSessionParams, RequestContext<CloseSessionResponse> context)
|
||||
{
|
||||
|
||||
@@ -114,8 +114,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
|
||||
/// Handle request to start a profiling session
|
||||
/// </summary>
|
||||
internal async Task HandleCreateXEventSessionRequest(CreateXEventSessionParams parameters, RequestContext<CreateXEventSessionResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
ConnectionInfo connInfo;
|
||||
ConnectionServiceInstance.TryFindConnection(
|
||||
@@ -161,18 +159,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
|
||||
SessionCreatedNotification(parameters.OwnerUri, parameters.SessionName, parameters.Template.Name);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(new Exception(SR.CreateSessionFailed(e.Message)));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle request to start a profiling session
|
||||
/// </summary>
|
||||
internal async Task HandleStartProfilingRequest(StartProfilingParams parameters, RequestContext<StartProfilingResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
ConnectionInfo connInfo;
|
||||
ConnectionServiceInstance.TryFindConnection(
|
||||
@@ -193,18 +184,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
|
||||
throw new Exception(SR.ProfilerConnectionNotFound);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(new Exception(SR.StartSessionFailed(e.Message)));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle request to stop a profiling session
|
||||
/// </summary>
|
||||
internal async Task HandleStopProfilingRequest(StopProfilingParams parameters, RequestContext<StopProfilingResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
ProfilerSession session;
|
||||
monitor.StopMonitoringSession(parameters.OwnerUri, out session);
|
||||
@@ -238,35 +222,21 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
|
||||
throw new Exception(SR.SessionNotFound);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(new Exception(SR.StopSessionFailed(e.Message)));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle request to pause a profiling session
|
||||
/// </summary>
|
||||
internal async Task HandlePauseProfilingRequest(PauseProfilingParams parameters, RequestContext<PauseProfilingResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
monitor.PauseViewer(parameters.OwnerUri);
|
||||
|
||||
await requestContext.SendResult(new PauseProfilingResult { });
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(new Exception(SR.PauseSessionFailed(e.Message)));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle request to pause a profiling session
|
||||
/// </summary>
|
||||
internal async Task HandleGetXEventSessionsRequest(GetXEventSessionsParams parameters, RequestContext<GetXEventSessionsResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = new GetXEventSessionsResult();
|
||||
ConnectionInfo connInfo;
|
||||
@@ -284,26 +254,14 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
|
||||
await requestContext.SendResult(result);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle request to disconnect a session
|
||||
/// </summary>
|
||||
internal async Task HandleDisconnectSessionRequest(DisconnectSessionParams parameters, RequestContext<DisconnectSessionResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
monitor.StopMonitoringSession(parameters.OwnerUri, out _);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of all running XEvent Sessions
|
||||
|
||||
@@ -201,10 +201,8 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
/// <summary>
|
||||
/// Handles request to execute a selection of a document in the workspace service
|
||||
/// </summary>
|
||||
internal async Task HandleExecuteRequest(ExecuteRequestParamsBase executeParams,
|
||||
internal Task HandleExecuteRequest(ExecuteRequestParamsBase executeParams,
|
||||
RequestContext<ExecuteRequestResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Setup actions to perform upon successful start and on failure to start
|
||||
Func<Query, Task<bool>> queryCreateSuccessAction = async q =>
|
||||
@@ -232,11 +230,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
null,
|
||||
isQueryEditor(executeParams.OwnerUri));
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await requestContext.SendError(ex.ToString());
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -244,8 +238,6 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
/// </summary>
|
||||
internal async Task HandleSimpleExecuteRequest(SimpleExecuteParams executeParams,
|
||||
RequestContext<SimpleExecuteResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
string randomUri = Guid.NewGuid().ToString();
|
||||
ExecuteStringParams executeStringParams = new ExecuteStringParams
|
||||
@@ -351,11 +343,6 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
|
||||
ActiveSimpleExecuteRequests.TryAdd(randomUri, workTask);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await requestContext.SendError(ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -391,8 +378,6 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
/// </summary>
|
||||
internal async Task HandleResultSubsetRequest(SubsetParams subsetParams,
|
||||
RequestContext<SubsetResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
ResultSetSubset subset = await InterServiceResultSubset(subsetParams);
|
||||
var result = new SubsetResult
|
||||
@@ -402,12 +387,6 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
await requestContext.SendResult(result);
|
||||
Logger.Write(TraceEventType.Stop, $"Done Handler for Subset request with for Query:'{subsetParams.OwnerUri}', Batch:'{subsetParams.BatchIndex}', ResultSetIndex:'{subsetParams.ResultSetIndex}', RowsStartIndex'{subsetParams.RowsStartIndex}', Requested RowsCount:'{subsetParams.RowsCount}'\r\n\t\t with subset response of:[ RowCount:'{subset.RowCount}', Rows array of length:'{subset.Rows.Length}']");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// This was unexpected, so send back as error
|
||||
await requestContext.SendError(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -415,8 +394,6 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
/// </summary>
|
||||
internal async Task HandleQueryExecutionOptionsRequest(QueryExecutionOptionsParams queryExecutionOptionsParams,
|
||||
RequestContext<bool> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
string uri = queryExecutionOptionsParams.OwnerUri;
|
||||
if (ActiveQueryExecutionSettings.ContainsKey(uri))
|
||||
@@ -429,20 +406,12 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
|
||||
await requestContext.SendResult(true);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// This was unexpected, so send back as error
|
||||
await requestContext.SendError(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles a request to get an execution plan
|
||||
/// </summary>
|
||||
internal async Task HandleExecutionPlanRequest(QueryExecutionPlanParams planParams,
|
||||
RequestContext<QueryExecutionPlanResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Attempt to load the query
|
||||
Query query;
|
||||
@@ -459,12 +428,6 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
};
|
||||
await requestContext.SendResult(result);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// This was unexpected, so send back as error
|
||||
await requestContext.SendError(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles a request to dispose of this query
|
||||
@@ -511,10 +474,6 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
Messages = e.Message
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -63,9 +63,7 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
/// Handles schema compare request
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task HandleSchemaCompareRequest(SchemaCompareParams parameters, RequestContext<SchemaCompareResult> requestContext)
|
||||
{
|
||||
try
|
||||
public Task HandleSchemaCompareRequest(SchemaCompareParams parameters, RequestContext<SchemaCompareResult> requestContext)
|
||||
{
|
||||
ConnectionInfo sourceConnInfo;
|
||||
ConnectionInfo targetConnInfo;
|
||||
@@ -113,11 +111,7 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -125,8 +119,6 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task HandleSchemaCompareCancelRequest(SchemaCompareCancelParams parameters, RequestContext<ResultStatus> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
Action cancelAction = null;
|
||||
if (currentComparisonCancellationAction.Value.TryRemove(parameters.OperationId, out cancelAction))
|
||||
@@ -149,12 +141,6 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
ErrorMessage = SR.SchemaCompareSessionNotFound
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -352,8 +338,6 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task HandleSchemaCompareOpenScmpRequest(SchemaCompareOpenScmpParams parameters, RequestContext<SchemaCompareOpenScmpResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
CurrentSchemaCompareTask = Task.Run(async () =>
|
||||
{
|
||||
@@ -376,19 +360,12 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles schema compare save SCMP request
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task HandleSchemaCompareSaveScmpRequest(SchemaCompareSaveScmpParams parameters, RequestContext<ResultStatus> requestContext)
|
||||
{
|
||||
try
|
||||
public Task HandleSchemaCompareSaveScmpRequest(SchemaCompareSaveScmpParams parameters, RequestContext<ResultStatus> requestContext)
|
||||
{
|
||||
ConnectionInfo sourceConnInfo;
|
||||
ConnectionInfo targetConnInfo;
|
||||
@@ -421,11 +398,7 @@ namespace Microsoft.SqlTools.ServiceLayer.SchemaCompare
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private SqlTaskManager SqlTaskManagerInstance
|
||||
|
||||
@@ -83,8 +83,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting
|
||||
/// Handles request to execute start the list objects operation.
|
||||
/// </summary>
|
||||
private async Task HandleListObjectsRequest(ScriptingListObjectsParams parameters, RequestContext<ScriptingListObjectsResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
ScriptingListObjectsOperation operation = new ScriptingListObjectsOperation(parameters);
|
||||
operation.CompleteNotification += (sender, e) => requestContext.SendEvent(ScriptingListObjectsCompleteEvent.Type, e);
|
||||
@@ -93,21 +91,13 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting
|
||||
|
||||
await requestContext.SendResult(new ScriptingListObjectsResult { OperationId = operation.OperationId });
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles request to start the scripting operation
|
||||
/// </summary>
|
||||
public async Task HandleScriptExecuteRequest(ScriptingParams parameters, RequestContext<ScriptingResult> requestContext)
|
||||
public Task HandleScriptExecuteRequest(ScriptingParams parameters, RequestContext<ScriptingResult> requestContext)
|
||||
{
|
||||
SmoScriptingOperation operation = null;
|
||||
|
||||
try
|
||||
{
|
||||
// if a connection string wasn't provided as a parameter then
|
||||
// use the owner uri property to lookup its associated ConnectionInfo
|
||||
// and then build a connection string out of that
|
||||
@@ -147,12 +137,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting
|
||||
operation.CompleteNotification += (sender, e) => this.SendScriptingCompleteEvent(requestContext, ScriptingCompleteEvent.Type, e, operation, parameters.ScriptDestination);
|
||||
|
||||
RunTask(requestContext, operation);
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private bool ShouldCreateScriptAsOperation(ScriptingParams parameters)
|
||||
@@ -177,8 +162,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting
|
||||
/// Handles request to cancel a script operation.
|
||||
/// </summary>
|
||||
public async Task HandleScriptCancelRequest(ScriptingCancelParams parameters, RequestContext<ScriptingCancelResult> requestContext)
|
||||
{
|
||||
try
|
||||
{
|
||||
ScriptingOperation operation = null;
|
||||
if (this.ActiveOperations.TryRemove(parameters.OperationId, out operation))
|
||||
@@ -192,11 +175,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting
|
||||
|
||||
await requestContext.SendResult(new ScriptingCancelResult());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
}
|
||||
|
||||
private async void SendScriptingCompleteEvent<TParams>(RequestContext<ScriptingResult> requestContext, EventType<TParams> eventType, TParams parameters,
|
||||
SmoScriptingOperation operation, string scriptDestination)
|
||||
|
||||
@@ -44,6 +44,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Agent
|
||||
/// Verify that a job history request returns the job history
|
||||
/// </summary>
|
||||
[Test]
|
||||
[Ignore("Skipping test since it doesn't work - there's no jobs so it just immediately throws.")]
|
||||
public async Task TestHandleJobHistoryRequests()
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
|
||||
@@ -93,17 +93,17 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageExtensibility
|
||||
{
|
||||
ExternalLanguageOperations = operations.Object
|
||||
};
|
||||
await VerifyError<ExternalLanguageDeleteResponseParams>(
|
||||
test: async (requestContext, connectionUrl) =>
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
{
|
||||
var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);
|
||||
var requestContext = RequestContextMocks.Create<ExternalLanguageDeleteResponseParams>(r => { });
|
||||
ExternalLanguageDeleteRequestParams requestParams = new ExternalLanguageDeleteRequestParams
|
||||
{
|
||||
OwnerUri = connectionUrl,
|
||||
OwnerUri = queryTempFile.FilePath,
|
||||
LanguageName = language.Name
|
||||
};
|
||||
await service.HandleExternalLanguageDeleteRequest(requestParams, requestContext);
|
||||
return null;
|
||||
});
|
||||
Assert.That(() => service.HandleExternalLanguageDeleteRequest(requestParams, requestContext.Object), Throws.Exception);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -174,17 +174,17 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageExtensibility
|
||||
{
|
||||
ExternalLanguageOperations = operations.Object
|
||||
};
|
||||
await VerifyError<ExternalLanguageUpdateResponseParams>(
|
||||
test: async (requestContext, connectionUrl) =>
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
{
|
||||
var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);
|
||||
var requestContext = RequestContextMocks.Create<ExternalLanguageUpdateResponseParams>(r => { });
|
||||
ExternalLanguageUpdateRequestParams requestParams = new ExternalLanguageUpdateRequestParams
|
||||
{
|
||||
OwnerUri = connectionUrl,
|
||||
OwnerUri = queryTempFile.FilePath,
|
||||
Language = language
|
||||
};
|
||||
await service.HandleExternalLanguageUpdateRequest(requestParams, requestContext);
|
||||
return null;
|
||||
});
|
||||
Assert.That(() => service.HandleExternalLanguageUpdateRequest(requestParams, requestContext.Object), Throws.Exception);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -254,16 +254,16 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.LanguageExtensibility
|
||||
{
|
||||
ExternalLanguageOperations = operations.Object
|
||||
};
|
||||
await VerifyError<ExternalLanguageListResponseParams>(
|
||||
test: async (requestContext, connectionUrl) =>
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
{
|
||||
ExternalLanguageListRequestParams requestParams = new ExternalLanguageListRequestParams
|
||||
var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);
|
||||
var requestContext = RequestContextMocks.Create<ExternalLanguageListResponseParams>(r => { });
|
||||
var requestParams = new ExternalLanguageListRequestParams
|
||||
{
|
||||
OwnerUri = connectionUrl
|
||||
OwnerUri = queryTempFile.FilePath
|
||||
};
|
||||
await service.HandleExternalLanguageListRequest(requestParams, requestContext);
|
||||
return null;
|
||||
});
|
||||
Assert.That(() => service.HandleExternalLanguageListRequest(requestParams, requestContext.Object), Throws.Exception);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Scripting
|
||||
|
||||
var scriptingParams = new ScriptingParams
|
||||
{
|
||||
OwnerUri = ConnectionService.BuildConnectionString(result.ConnectionInfo.ConnectionDetails)
|
||||
OwnerUri = result.ScriptFile.ClientUri
|
||||
};
|
||||
if (isSelectScript)
|
||||
{
|
||||
|
||||
@@ -75,25 +75,19 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Credentials
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SaveCredentialThrowsIfCredentialIdMissing()
|
||||
public void SaveCredentialThrowsIfCredentialIdMissing()
|
||||
{
|
||||
string errorResponse = null;
|
||||
var contextMock = RequestContextMocks.Create<bool>(null).AddErrorHandling((msg, code, data) => errorResponse = msg);
|
||||
|
||||
await service.HandleSaveCredentialRequest(new Credential(null), contextMock.Object);
|
||||
TestUtils.VerifyErrorSent(contextMock);
|
||||
Assert.That(errorResponse, Does.Contain("ArgumentException"));
|
||||
var contextMock = RequestContextMocks.Create<bool>(null);
|
||||
// Verify throws with no ID
|
||||
Assert.That(() => service.HandleSaveCredentialRequest(new Credential(null), contextMock.Object), Throws.ArgumentException);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SaveCredentialThrowsIfPasswordMissing()
|
||||
public void SaveCredentialThrowsIfPasswordMissing()
|
||||
{
|
||||
string errorResponse = null;
|
||||
var contextMock = RequestContextMocks.Create<bool>(null).AddErrorHandling((msg, code, data) => errorResponse = msg);
|
||||
|
||||
await service.HandleSaveCredentialRequest(new Credential(CredentialId), contextMock.Object);
|
||||
TestUtils.VerifyErrorSent(contextMock);
|
||||
Assert.True(errorResponse.Contains("ArgumentException") || errorResponse.Contains("ArgumentNullException"));
|
||||
var contextMock = RequestContextMocks.Create<bool>(null);
|
||||
// Verify throws with no ID
|
||||
Assert.That(() => service.HandleSaveCredentialRequest(new Credential(CredentialId), contextMock.Object), Throws.ArgumentNullException);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -193,27 +187,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Credentials
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ReadCredentialThrowsIfCredentialIsNull()
|
||||
public void ReadCredentialThrowsIfCredentialIsNull()
|
||||
{
|
||||
string errorResponse = null;
|
||||
var contextMock = RequestContextMocks.Create<Credential>(null).AddErrorHandling((msg, code, data) => errorResponse = msg);
|
||||
|
||||
// Verify throws on null, and this is sent as an error
|
||||
await service.HandleReadCredentialRequest(null, contextMock.Object);
|
||||
TestUtils.VerifyErrorSent(contextMock);
|
||||
Assert.That(errorResponse, Does.Contain("ArgumentNullException"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ReadCredentialThrowsIfIdMissing()
|
||||
{
|
||||
string errorResponse = null;
|
||||
var contextMock = RequestContextMocks.Create<Credential>(null).AddErrorHandling((msg, code, data) => errorResponse = msg);
|
||||
|
||||
var contextMock = RequestContextMocks.Create<Credential>(null);
|
||||
// Verify throws with no ID
|
||||
await service.HandleReadCredentialRequest(new Credential(), contextMock.Object);
|
||||
TestUtils.VerifyErrorSent(contextMock);
|
||||
Assert.That(errorResponse, Does.Contain("ArgumentException"));
|
||||
Assert.That(() => service.HandleReadCredentialRequest(new Credential(), contextMock.Object), Throws.ArgumentException);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -235,15 +213,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Credentials
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DeleteCredentialThrowsIfIdMissing()
|
||||
public void DeleteCredentialThrowsIfIdMissing()
|
||||
{
|
||||
object errorResponse = null;
|
||||
var contextMock = RequestContextMocks.Create<bool>(null).AddErrorHandling((msg, code, data) => errorResponse = msg);
|
||||
|
||||
var contextMock = RequestContextMocks.Create<bool>(null);
|
||||
// Verify throws with no ID
|
||||
await service.HandleDeleteCredentialRequest(new Credential(), contextMock.Object);
|
||||
TestUtils.VerifyErrorSent(contextMock);
|
||||
Assert.True(((string)errorResponse).Contains("ArgumentException"));
|
||||
Assert.That(() => service.HandleDeleteCredentialRequest(new Credential(), contextMock.Object), Throws.ArgumentException);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
#region EditSession Operation Helper Tests
|
||||
|
||||
[Test]
|
||||
public async Task NullOrMissingSessionId([Values(null, "", " \t\n\r", "Does not exist")] string sessionId)
|
||||
public void NullOrMissingSessionId([Values(null, "", " \t\n\r", "Does not exist")] string sessionId)
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a edit data service
|
||||
@@ -34,14 +34,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
// ... Create a session params that returns the provided session ID
|
||||
var mockParams = new EditCreateRowParams {OwnerUri = sessionId};
|
||||
|
||||
var contextMock = RequestContextMocks.Create<EditDisposeResult>(null);
|
||||
// If: I ask to perform an action that requires a session
|
||||
// Then: I should get an error from it
|
||||
var efv = new EventFlowValidator<EditDisposeResult>()
|
||||
.AddStandardErrorValidation()
|
||||
.Complete();
|
||||
await eds.HandleSessionRequest(mockParams, efv.Object, session => null);
|
||||
efv.Validate();
|
||||
Assert.That(() => eds.HandleSessionRequest(mockParams, contextMock.Object, session => null), Throws.Exception);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -54,14 +50,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
// ... Create a session param that returns the common owner uri
|
||||
var mockParams = new EditCreateRowParams { OwnerUri = Common.OwnerUri };
|
||||
|
||||
var contextMock = RequestContextMocks.Create<EditDisposeResult>(null);
|
||||
// If: I ask to perform an action that requires a session
|
||||
// Then: I should get an error from it
|
||||
var efv = new EventFlowValidator<EditDisposeResult>()
|
||||
.AddStandardErrorValidation()
|
||||
.Complete();
|
||||
await eds.HandleSessionRequest(mockParams, efv.Object, s => { throw new Exception(); });
|
||||
efv.Validate();
|
||||
Assert.That(() => eds.HandleSessionRequest(mockParams, contextMock.Object, s => { throw new Exception(); }), Throws.Exception);
|
||||
}
|
||||
|
||||
|
||||
@@ -71,18 +63,15 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
#region Dispose Tests
|
||||
|
||||
[Test]
|
||||
public async Task DisposeNullOrMissingSessionId([Values(null, "", " \t\n\r", "Does not exist")] string sessionId)
|
||||
public void DisposeNullOrMissingSessionId([Values(null, "", " \t\n\r", "Does not exist")] string sessionId)
|
||||
{
|
||||
// Setup: Create a edit data service
|
||||
var eds = new EditDataService(null, null, null);
|
||||
|
||||
// If: I ask to perform an action that requires a session
|
||||
// Then: I should get an error from it
|
||||
var efv = new EventFlowValidator<EditDisposeResult>()
|
||||
.AddStandardErrorValidation()
|
||||
.Complete();
|
||||
await eds.HandleDisposeRequest(new EditDisposeParams {OwnerUri = sessionId}, efv.Object);
|
||||
efv.Validate();
|
||||
var contextMock = RequestContextMocks.Create<EditDisposeResult>(null);
|
||||
Assert.That(() => eds.HandleDisposeRequest(new EditDisposeParams { OwnerUri = sessionId }, contextMock.Object), Throws.Exception);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -293,16 +282,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
OwnerUri = ownerUri,
|
||||
ObjectType = objType
|
||||
};
|
||||
|
||||
var contextMock = RequestContextMocks.Create<EditInitializeResult>(null);
|
||||
// ... And I initialize an edit session with that
|
||||
var efv = new EventFlowValidator<EditInitializeResult>()
|
||||
.AddStandardErrorValidation()
|
||||
.Complete();
|
||||
await eds.HandleInitializeRequest(initParams, efv.Object);
|
||||
|
||||
// Then:
|
||||
// ... An error event should have been raised
|
||||
efv.Validate();
|
||||
// ... An error event should have been sent
|
||||
Assert.That(() => eds.HandleInitializeRequest(initParams, contextMock.Object), Throws.ArgumentException);
|
||||
|
||||
// ... There should not be a session
|
||||
Assert.That(eds.ActiveSessions, Is.Empty);
|
||||
@@ -324,14 +308,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
ObjectType = "Table",
|
||||
Filters = new EditInitializeFiltering()
|
||||
};
|
||||
var efv = new EventFlowValidator<EditInitializeResult>()
|
||||
.AddStandardErrorValidation()
|
||||
.Complete();
|
||||
await eds.HandleInitializeRequest(initParams, efv.Object);
|
||||
var contextMock = RequestContextMocks.Create<EditInitializeResult>(null);
|
||||
|
||||
// Then:
|
||||
// ... An error event should have been sent
|
||||
efv.Validate();
|
||||
Assert.That(() => eds.HandleInitializeRequest(initParams, contextMock.Object), Throws.ArgumentNullException);
|
||||
|
||||
// ... The original session should still be there
|
||||
Assert.AreEqual(1, eds.ActiveSessions.Count);
|
||||
|
||||
@@ -198,11 +198,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
|
||||
// ... And I then ask for a valid execution plan from it
|
||||
var executionPlanParams = new QueryExecutionPlanParams { OwnerUri = Constants.OwnerUri, ResultSetIndex = 0, BatchIndex = 0 };
|
||||
var executionPlanRequest = new EventFlowValidator<QueryExecutionPlanResult>()
|
||||
.AddStandardErrorValidation()
|
||||
.Complete();
|
||||
await queryService.HandleExecutionPlanRequest(executionPlanParams, executionPlanRequest.Object);
|
||||
executionPlanRequest.Validate();
|
||||
var contextMock = RequestContextMocks.Create<QueryExecutionPlanResult>(null);
|
||||
Assert.That(() => queryService.HandleExecutionPlanRequest(executionPlanParams, contextMock.Object), Throws.InvalidOperationException);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -229,11 +226,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
|
||||
// ... And I then ask for an execution plan from a result set
|
||||
var executionPlanParams = new QueryExecutionPlanParams { OwnerUri = Constants.OwnerUri, ResultSetIndex = 0, BatchIndex = 0 };
|
||||
var executionPlanRequest = new EventFlowValidator<QueryExecutionPlanResult>()
|
||||
.AddStandardErrorValidation()
|
||||
.Complete();
|
||||
await queryService.HandleExecutionPlanRequest(executionPlanParams, executionPlanRequest.Object);
|
||||
executionPlanRequest.Validate();
|
||||
var contextMock = RequestContextMocks.Create<QueryExecutionPlanResult>(null);
|
||||
Assert.ThrowsAsync<ArgumentOutOfRangeException>(() => queryService.HandleExecutionPlanRequest(executionPlanParams, contextMock.Object));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -163,11 +163,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
var workspaceService = Common.GetPrimedWorkspaceService(Constants.StandardQuery);
|
||||
var queryService = Common.GetPrimedExecutionService(null, true, false, false, workspaceService);
|
||||
var subsetParams = new SubsetParams { OwnerUri = Constants.OwnerUri, RowsCount = 1, ResultSetIndex = 0, RowsStartIndex = 0 };
|
||||
var subsetRequest = new EventFlowValidator<SubsetResult>()
|
||||
.AddStandardErrorValidation()
|
||||
.Complete();
|
||||
await queryService.HandleResultSubsetRequest(subsetParams, subsetRequest.Object);
|
||||
subsetRequest.Validate();
|
||||
var contextMock = RequestContextMocks.Create<SubsetResult>(null);
|
||||
Assert.ThrowsAsync<ArgumentOutOfRangeException>(() => queryService.HandleResultSubsetRequest(subsetParams, contextMock.Object));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -186,11 +183,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
|
||||
// ... And I then ask for a valid set of results from it
|
||||
var subsetParams = new SubsetParams { OwnerUri = Constants.OwnerUri, RowsCount = 1, ResultSetIndex = 0, RowsStartIndex = 0 };
|
||||
var subsetRequest = new EventFlowValidator<SubsetResult>()
|
||||
.AddStandardErrorValidation()
|
||||
.Complete();
|
||||
await queryService.HandleResultSubsetRequest(subsetParams, subsetRequest.Object);
|
||||
subsetRequest.Validate();
|
||||
var contextMock = RequestContextMocks.Create<SubsetResult>(null);
|
||||
Assert.That(() => queryService.HandleResultSubsetRequest(subsetParams, contextMock.Object), Throws.InvalidOperationException);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -208,11 +202,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
|
||||
// ... And I then ask for a set of results from it
|
||||
var subsetParams = new SubsetParams { OwnerUri = Constants.OwnerUri, RowsCount = 1, ResultSetIndex = 0, RowsStartIndex = 0 };
|
||||
var subsetRequest = new EventFlowValidator<SubsetResult>()
|
||||
.AddStandardErrorValidation()
|
||||
.Complete();
|
||||
await queryService.HandleResultSubsetRequest(subsetParams, subsetRequest.Object);
|
||||
subsetRequest.Validate();
|
||||
var contextMock = RequestContextMocks.Create<SubsetResult>(null);
|
||||
Assert.ThrowsAsync<ArgumentOutOfRangeException>(() => queryService.HandleResultSubsetRequest(subsetParams, contextMock.Object));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user