Removing a lot of redundant async/await wrappers (#1486)

* Removing a lot of redundant async/await wrappers

* Removing kusto changes
This commit is contained in:
Benjamin Russell
2022-06-05 10:26:21 -05:00
committed by GitHub
parent 88a762014d
commit 97a106c575
14 changed files with 899 additions and 1001 deletions

View File

@@ -12,7 +12,7 @@ namespace Microsoft.InsightsGenerator
public class Workflow
{
public async Task<string> ProcessInputData(DataArray rulesData,
public Task<string> ProcessInputData(DataArray rulesData,
CancellationToken cancellationToken = new CancellationToken())
{
// added cancellationToken just in case for future
@@ -21,9 +21,7 @@ namespace Microsoft.InsightsGenerator
//Get the signature result
SignatureGenerator siggen = new SignatureGenerator(rulesData);
string insights = null;
await Task.Run(() =>
return Task.Run(() =>
{
try
{
@@ -31,6 +29,8 @@ namespace Microsoft.InsightsGenerator
transformer.Transform(rulesData);
SignatureGeneratorResult result = siggen.Learn();
// call the rules engine processor
string insights = null;
if (result?.Insights == null)
{
// Console.WriteLine("Failure in generating insights, Input not recognized!");
@@ -42,6 +42,7 @@ namespace Microsoft.InsightsGenerator
// $"Good News! Insights generator has provided you the chart text: \n{insights}\n");
}
return insights;
}
catch (Exception)
{
@@ -50,8 +51,6 @@ namespace Microsoft.InsightsGenerator
}
}, cancellationToken);
return insights;
}
}
}

View File

@@ -102,12 +102,9 @@ namespace Microsoft.SqlTools.Credentials
}
public async Task<Credential> ReadCredentialAsync(Credential credential)
public Task<Credential> ReadCredentialAsync(Credential credential)
{
return await Task.Factory.StartNew(() =>
{
return ReadCredential(credential);
});
return Task.Run(() => ReadCredential(credential));
}
public Credential ReadCredential(Credential credential)
@@ -132,12 +129,9 @@ namespace Microsoft.SqlTools.Credentials
await HandleRequest(doSave, requestContext, "HandleSaveCredentialRequest");
}
public async Task<bool> SaveCredentialAsync(Credential credential)
public Task<bool> SaveCredentialAsync(Credential credential)
{
return await Task.Factory.StartNew(() =>
{
return SaveCredential(credential);
});
return Task.Run(() => SaveCredential(credential));
}
public bool SaveCredential(Credential credential)
@@ -155,9 +149,9 @@ namespace Microsoft.SqlTools.Credentials
await HandleRequest(doDelete, requestContext, "HandleDeleteCredentialRequest");
}
private async Task<bool> DeletePasswordAsync(Credential credential)
private Task<bool> DeletePasswordAsync(Credential credential)
{
return await Task.Factory.StartNew(() =>
return Task.Run(() =>
{
Credential.ValidateForLookup(credential);
return credStore.DeletePassword(credential.CredentialId);

View File

@@ -133,10 +133,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
this.ServiceHost.SetRequestHandler(UpdateAgentNotebookRunNameRequest.Type, HandleUpdateAgentNotebookRunNameRequest);
this.ServiceHost.SetRequestHandler(DeleteNotebookMaterializedRequest.Type, HandleDeleteNotebookMaterializedRequest);
serviceHost.RegisterShutdownTask(async (shutdownParams, shutdownRequestContext) =>
serviceHost.RegisterShutdownTask((_, _) =>
{
DeleteAgentNotebooksTempFiles();
await Task.FromResult(0);
return Task.FromResult(0);
});
}
@@ -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)
{
await Task.Run(async () =>
{
try
{
@@ -182,15 +180,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
{
await requestContext.SendError(e);
}
});
}
/// <summary>
/// Handle request to get Agent Job history
/// </summary>
internal async Task HandleJobHistoryRequest(AgentJobHistoryParams parameters, RequestContext<AgentJobHistoryResult> requestContext)
{
await Task.Run(async () =>
{
try
{
@@ -266,15 +261,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
{
await requestContext.SendError(e);
}
});
}
/// <summary>
/// Handle request to Run a Job
/// </summary>
internal async Task HandleJobActionRequest(AgentJobActionParams parameters, RequestContext<ResultStatus> requestContext)
{
await Task.Run(async () =>
{
var result = new ResultStatus();
try
@@ -324,7 +316,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
}
await requestContext.SendResult(result);
}
});
}
internal async Task HandleCreateAgentJobRequest(CreateAgentJobParams parameters, RequestContext<CreateAgentJobResult> requestContext)
@@ -421,8 +412,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
}
internal async Task HandleAgentJobDefaultsRequest(AgentJobDefaultsParams parameters, RequestContext<AgentJobDefaultsResult> requestContext)
{
await Task.Run(async () =>
{
var result = new AgentJobDefaultsResult();
try
@@ -454,7 +443,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
}
await requestContext.SendResult(result);
});
}
#endregion // "Jobs Handlers"
@@ -465,8 +453,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
/// Handle request to get the alerts list
/// </summary>
internal async Task HandleAgentAlertsRequest(AgentAlertsParams parameters, RequestContext<AgentAlertsResult> requestContext)
{
await Task.Run(async () =>
{
var result = new AgentAlertsResult();
try
@@ -517,7 +503,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
result.ErrorMessage = ex.ToString();
}
await requestContext.SendResult(result);
});
}
/// <summary>
@@ -582,8 +567,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
#region "Operator Handlers"
internal async Task HandleAgentOperatorsRequest(AgentOperatorsParams parameters, RequestContext<AgentOperatorsResult> requestContext)
{
await Task.Run(async () =>
{
var result = new AgentOperatorsResult();
try
@@ -628,7 +611,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
result.ErrorMessage = ex.ToString();
}
await requestContext.SendResult(result);
});
}
internal async Task HandleCreateAgentOperatorRequest(
@@ -690,8 +672,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
#region "Proxy Handlers"
internal async Task HandleAgentProxiesRequest(AgentProxiesParams parameters, RequestContext<AgentProxiesResult> requestContext)
{
await Task.Run(async () =>
{
var result = new AgentProxiesResult();
try
@@ -726,7 +706,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
}
await requestContext.SendResult(result);
});
}
internal async Task HandleCreateAgentProxyRequest(CreateAgentProxyParams parameters, RequestContext<AgentProxyResult> requestContext)
@@ -784,8 +763,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
#region "Schedule Handlers"
internal async Task HandleAgentSchedulesRequest(AgentSchedulesParams parameters, RequestContext<AgentSchedulesResult> requestContext)
{
await Task.Run(async () =>
{
var result = new AgentSchedulesResult();
try
@@ -829,7 +806,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
}
await requestContext.SendResult(result);
});
}
internal async Task HandleCreateAgentScheduleRequest(CreateAgentScheduleParams parameters, RequestContext<AgentScheduleResult> requestContext)
@@ -906,8 +882,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
AgentJobInfo jobInfo,
ConfigAction configAction,
RunType runType)
{
return await Task<Tuple<bool, string>>.Run(async () =>
{
try
{
@@ -976,10 +950,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
{
return new Tuple<bool, string>(false, ex.ToString());
}
});
}
internal async Task<Tuple<bool, string>> ConfigureAgentJobStep(
internal Task<Tuple<bool, string>> ConfigureAgentJobStep(
string ownerUri,
AgentJobStepInfo stepInfo,
ConfigAction configAction,
@@ -987,7 +960,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
JobData jobData = null,
CDataContainer dataContainer = null)
{
return await Task<Tuple<bool, string>>.Run(() =>
return Task.Run(() =>
{
try
{
@@ -1016,7 +989,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
});
}
internal async Task<Tuple<bool, string>> ConfigureAgentAlert(
internal Task<Tuple<bool, string>> ConfigureAgentAlert(
string ownerUri,
string alertName,
AgentAlertInfo alert,
@@ -1025,7 +998,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
JobData jobData = null,
CDataContainer dataContainer = null)
{
return await Task<Tuple<bool, string>>.Run(() =>
return Task<Tuple<bool, string>>.Run(() =>
{
try
{
@@ -1063,13 +1036,13 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
});
}
internal async Task<Tuple<bool, string>> ConfigureAgentOperator(
internal Task<Tuple<bool, string>> ConfigureAgentOperator(
string ownerUri,
AgentOperatorInfo operatorInfo,
ConfigAction configAction,
RunType runType)
{
return await Task<Tuple<bool, string>>.Run(() =>
return Task.Run(() =>
{
try
{
@@ -1093,14 +1066,14 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
});
}
internal async Task<Tuple<bool, string>> ConfigureAgentProxy(
internal Task<Tuple<bool, string>> ConfigureAgentProxy(
string ownerUri,
string accountName,
AgentProxyInfo proxy,
ConfigAction configAction,
RunType runType)
{
return await Task<bool>.Run(() =>
return Task.Run(() =>
{
try
{
@@ -1124,7 +1097,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
});
}
internal async Task<Tuple<bool, string>> ConfigureAgentSchedule(
internal Task<Tuple<bool, string>> ConfigureAgentSchedule(
string ownerUri,
AgentScheduleInfo schedule,
ConfigAction configAction,
@@ -1132,7 +1105,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
JobData jobData = null,
CDataContainer dataContainer = null)
{
return await Task<bool>.Run(() =>
return Task.Run(() =>
{
try
{
@@ -1229,8 +1202,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
}
internal async Task HandleAgentNotebooksRequest(AgentNotebooksParams parameters, RequestContext<AgentNotebooksResult> requestContext)
{
await Task.Run(async () =>
{
var result = new AgentNotebooksResult();
try
@@ -1248,13 +1219,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
result.ErrorMessage = e.ToString();
}
await requestContext.SendResult(result);
});
}
internal async Task HandleAgentNotebookHistoryRequest(
AgentNotebookHistoryParams parameters, RequestContext<AgentNotebookHistoryResult> requestContext)
{
await Task.Run(async () =>
{
var result = new AgentNotebookHistoryResult();
try
@@ -1280,12 +1248,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
result.ErrorMessage = e.ToString();
}
await requestContext.SendResult(result);
});
}
internal async Task HandleAgentNotebookMaterializedRequest(AgentNotebookMaterializedParams parameters, RequestContext<AgentNotebookMaterializedResult> requestContext)
{
await Task.Run(async () =>
{
var result = new AgentNotebookMaterializedResult();
try
@@ -1305,12 +1270,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
}
await requestContext.SendResult(result);
});
}
internal async Task HandleAgentNotebookTemplateRequest(AgentNotebookTemplateParams parameters, RequestContext<AgentNotebookTemplateResult> requestContext)
{
await Task.Run(async () =>
{
var result = new AgentNotebookTemplateResult();
try
@@ -1330,12 +1292,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
}
await requestContext.SendResult(result);
});
}
internal async Task HandleCreateAgentNotebookRequest(CreateAgentNotebookParams parameters, RequestContext<CreateAgentNotebookResult> requestContext)
{
await Task.Run(async () =>
{
var result = new CreateAgentNotebookResult();
try
@@ -1357,12 +1316,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
result.ErrorMessage = e.ToString();
}
await requestContext.SendResult(result);
});
}
internal async Task HandleDeleteAgentNotebooksRequest(DeleteAgentNotebookParams parameters, RequestContext<ResultStatus> requestContext)
{
await Task.Run(async () =>
{
var result = new ResultStatus();
try
@@ -1382,12 +1338,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
result.ErrorMessage = e.ToString();
}
await requestContext.SendResult(result);
});
}
internal async Task HandleUpdateAgentNotebookRequest(UpdateAgentNotebookParams parameters, RequestContext<UpdateAgentNotebookResult> requestContext)
{
await Task.Run(async () =>
{
var result = new UpdateAgentNotebookResult();
try
@@ -1409,12 +1362,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
}
await requestContext.SendResult(result);
});
}
internal async Task HandleUpdateAgentNotebookRunNameRequest(UpdateAgentNotebookRunNameParams parameters, RequestContext<ResultStatus> requestContext)
{
await Task.Run(async () =>
{
var result = new ResultStatus();
try
@@ -1438,12 +1388,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
}
await requestContext.SendResult(result);
});
}
internal async Task HandleUpdateAgentNotebookRunPinRequest(UpdateAgentNotebookRunPinParams parameters, RequestContext<ResultStatus> requestContext)
{
await Task.Run(async () =>
{
var result = new ResultStatus();
try
@@ -1467,12 +1414,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
}
await requestContext.SendResult(result);
});
}
internal async Task HandleDeleteNotebookMaterializedRequest(DeleteMaterializedNotebookParams parameters, RequestContext<ResultStatus> requestContext)
{
await Task.Run(async () =>
{
var result = new ResultStatus();
try
@@ -1495,7 +1439,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Agent
}
await requestContext.SendResult(result);
});
}
public async Task<AgentNotebookHistoryResult> GetAgentNotebookHistories

View File

@@ -238,7 +238,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
/// </summary>
/// <param name="ownerUri">The URI of the connection</param>
/// <returns> True if a refreshed was needed and requested, false otherwise </returns>
internal async Task<bool> TryRequestRefreshAuthToken(string ownerUri)
{
ConnectionInfo connInfo;
@@ -312,6 +311,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
connection.UpdateAuthToken(tokenRefreshedParams.Token, tokenRefreshedParams.ExpiresOn);
}
/// <summary>
/// Validates the given ConnectParams object.
/// </summary>
/// <param name="connectionParams">The params to validate</param>
/// <returns>A ConnectionCompleteParams object upon validation error,
/// null upon validation success</returns>
public ConnectionCompleteParams ValidateConnectParams(ConnectParams connectionParams)
{
string paramValidationErrorMessage;
@@ -1394,8 +1399,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
public async Task HandleGetConnectionStringRequest(
GetConnectionStringParams connStringParams,
RequestContext<string> requestContext)
{
await Task.Run(async () =>
{
string connectionString = string.Empty;
ConnectionInfo info;
@@ -1430,7 +1433,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
}
await requestContext.SendResult(connectionString);
});
}
/// <summary>
@@ -1439,8 +1441,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
public async Task HandleBuildConnectionInfoRequest(
string connectionString,
RequestContext<ConnectionDetails> requestContext)
{
await Task.Run(async () =>
{
try
{
@@ -1452,7 +1452,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
// rather than an error.
await requestContext.SendResult(null);
}
});
}
public ConnectionDetails ParseConnectionString(string connectionString)

View File

@@ -110,9 +110,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Formatter
};
}
private async Task<TextEdit[]> FormatRangeAndReturnEdits(DocumentRangeFormattingParams docFormatParams)
private Task<TextEdit[]> FormatRangeAndReturnEdits(DocumentRangeFormattingParams docFormatParams)
{
return await Task.Factory.StartNew(() =>
return Task.Run(() =>
{
if (ShouldSkipFormatting(docFormatParams))
{
@@ -123,7 +123,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Formatter
ScriptFile scriptFile = GetFile(docFormatParams);
if (scriptFile == null)
{
return new TextEdit[0];
return Array.Empty<TextEdit>();
}
TextEdit textEdit = new TextEdit { Range = range };
string text = scriptFile.GetTextInRange(range.ToBufferRange());
@@ -142,9 +142,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Formatter
return (LanguageService != null && LanguageService.ShouldSkipNonMssqlFile(docFormatParams.TextDocument.Uri));
}
private async Task<TextEdit[]> FormatAndReturnEdits(DocumentFormattingParams docFormatParams)
private Task<TextEdit[]> FormatAndReturnEdits(DocumentFormattingParams docFormatParams)
{
return await Task.Factory.StartNew(() =>
return Task.Factory.StartNew(() =>
{
if (ShouldSkipFormatting(docFormatParams))
{
@@ -155,7 +155,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Formatter
if (scriptFile == null
|| scriptFile.FileLines.Count == 0)
{
return new TextEdit[0];
return Array.Empty<TextEdit>();
}
TextEdit textEdit = PrepareEdit(scriptFile);
string text = scriptFile.Contents;

View File

@@ -201,10 +201,10 @@ namespace Microsoft.SqlTools.ServiceLayer
IDisposable disposable = service as IDisposable;
if (serviceHost != null && disposable != null)
{
serviceHost.RegisterShutdownTask(async (shutdownParams, shutdownRequestContext) =>
serviceHost.RegisterShutdownTask((_, _) =>
{
disposable.Dispose();
await Task.FromResult(0);
return Task.FromResult(0);
});
}
}

View File

@@ -270,12 +270,12 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
serviceHost.SetEventHandler(TokenRefreshedNotification.Type, HandleTokenRefreshedNotification);
// Register a no-op shutdown task for validation of the shutdown logic
serviceHost.RegisterShutdownTask(async (shutdownParams, shutdownRequestContext) =>
serviceHost.RegisterShutdownTask((shutdownParams, shutdownRequestContext) =>
{
Logger.Write(TraceEventType.Verbose, "Shutting down language service");
DeletePeekDefinitionScripts();
this.Dispose();
await Task.FromResult(0);
return Task.FromResult(0);
});
ServiceHostInstance = serviceHost;
@@ -398,14 +398,12 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
/// <param name="requestContext"></param>
/// <returns></returns>
internal async Task HandleSyntaxParseRequest(SyntaxParseParams param, RequestContext<SyntaxParseResult> requestContext)
{
await Task.Run(async () =>
{
try
{
ParseResult result = Parser.Parse(param.Query);
SyntaxParseResult syntaxResult = new SyntaxParseResult();
if (result != null && result.Errors.Count() == 0)
if (result != null && !result.Errors.Any())
{
syntaxResult.Parseable = true;
}
@@ -425,7 +423,6 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
{
await requestContext.SendError(ex.ToString());
}
});
}
/// <summary>
@@ -674,8 +671,6 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
new ScriptFile[] { scriptFile },
eventContext);
}
await Task.FromResult(true);
}
catch (Exception ex)
{
@@ -700,8 +695,6 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
changedFiles.ToArray(),
eventContext);
}
await Task.FromResult(true);
}
catch (Exception ex)
{
@@ -933,13 +926,13 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
/// it is the last URI connected to a particular connection,
/// then remove the cache.
/// </summary>
public async Task RemoveAutoCompleteCacheUriReference(IConnectionSummary summary, string ownerUri)
public Task RemoveAutoCompleteCacheUriReference(IConnectionSummary summary, string ownerUri)
{
RemoveScriptParseInfo(ownerUri);
// currently this method is disabled, but we need to reimplement now that the
// implementation of the 'cache' has changed.
await Task.FromResult(0);
return Task.CompletedTask;
}
/// <summary>
@@ -1049,9 +1042,9 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
/// Update the autocomplete metadata provider when the user connects to a database
/// </summary>
/// <param name="info"></param>
public async Task UpdateLanguageServiceOnConnection(ConnectionInfo info)
public Task UpdateLanguageServiceOnConnection(ConnectionInfo info)
{
await Task.Run(() =>
return Task.Run(() =>
{
if (ConnectionService.IsDedicatedAdminConnection(info.ConnectionDetails))
{

View File

@@ -74,8 +74,6 @@ namespace Microsoft.SqlTools.ServiceLayer.NotebookConvert
#region Convert Handlers
internal async Task HandleConvertNotebookToSqlRequest(ConvertNotebookToSqlParams parameters, RequestContext<ConvertNotebookToSqlResult> requestContext)
{
await Task.Run(async () =>
{
try
{
@@ -91,14 +89,10 @@ namespace Microsoft.SqlTools.ServiceLayer.NotebookConvert
{
await requestContext.SendError(e);
}
});
}
internal async Task HandleConvertSqlToNotebookRequest(ConvertSqlToNotebookParams parameters, RequestContext<ConvertSqlToNotebookResult> requestContext)
{
await Task.Run(async () =>
{
try
{
// This URI doesn't come in escaped - so if it's a file path with reserved characters (such as %)
@@ -117,7 +111,6 @@ namespace Microsoft.SqlTools.ServiceLayer.NotebookConvert
{
await requestContext.SendError(e);
}
});
}
#endregion // Convert Handlers

View File

@@ -171,7 +171,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
{
Validate.IsNotNull(nameof(connectionDetails), connectionDetails);
Validate.IsNotNull(nameof(context), context);
return await Task.Factory.StartNew(() =>
return await Task.Run(() =>
{
string uri = GenerateUri(connectionDetails);
@@ -384,13 +384,11 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
}
internal async Task<ExpandResponse> ExpandNode(ObjectExplorerSession session, string nodePath, bool forceRefresh = false)
internal Task<ExpandResponse> ExpandNode(ObjectExplorerSession session, string nodePath, bool forceRefresh = false)
{
return await Task.Factory.StartNew(() =>
{
return QueueExpandNodeRequest(session, nodePath, forceRefresh);
});
return Task.Run(() => QueueExpandNodeRequest(session, nodePath, forceRefresh));
}
internal ExpandResponse QueueExpandNodeRequest(ObjectExplorerSession session, string nodePath, bool forceRefresh = false)
{
NodeInfo[] nodes = null;

View File

@@ -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)
{
await Task.Run(async () =>
{
try
{
@@ -167,15 +165,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
{
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)
{
await Task.Run(async () =>
{
try
{
@@ -202,15 +197,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
{
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)
{
await Task.Run(async () =>
{
try
{
@@ -250,15 +242,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
{
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)
{
await Task.Run(async () =>
{
try
{
@@ -270,15 +259,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
{
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)
{
await Task.Run(async () =>
{
try
{
@@ -302,26 +288,21 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
{
await requestContext.SendError(e);
}
});
}
/// <summary>
/// Handle request to disconnect a session
/// </summary>
internal async Task HandleDisconnectSessionRequest(DisconnectSessionParams parameters, RequestContext<DisconnectSessionResult> requestContext)
{
await Task.Run(async () =>
{
try
{
ProfilerSession session;
monitor.StopMonitoringSession(parameters.OwnerUri, out session);
monitor.StopMonitoringSession(parameters.OwnerUri, out _);
}
catch (Exception e)
{
await requestContext.SendError(e);
}
});
}
/// <summary>

View File

@@ -707,7 +707,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
/// <param name="scriptFile"></param>
/// <param name="eventContext"></param>
/// <returns></returns>
public async Task HandleDidCloseTextDocumentNotification(
public Task HandleDidCloseTextDocumentNotification(
string uri,
ScriptFile scriptFile,
EventContext eventContext)
@@ -725,7 +725,8 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
{
Logger.Write(TraceEventType.Error, "Unknown error " + ex.ToString());
}
await Task.FromResult(true);
return Task.CompletedTask;
}
#endregion

View File

@@ -142,8 +142,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Security
/// Handle request to get all credentials
/// </summary>
internal async Task HandleGetCredentialsRequest(GetCredentialsParams parameters, RequestContext<GetCredentialsResult> requestContext)
{
await Task.Run(async () =>
{
var result = new GetCredentialsResult();
try
@@ -175,11 +173,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Security
}
await requestContext.SendResult(result);
});
}
/// <summary>
/// Disposes the service
/// </summary>
@@ -193,13 +188,13 @@ namespace Microsoft.SqlTools.ServiceLayer.Security
#region "Helpers"
internal async Task<Tuple<bool, string>> ConfigureCredential(
internal Task<Tuple<bool, string>> ConfigureCredential(
string ownerUri,
CredentialInfo credential,
ConfigAction configAction,
RunType runType)
{
return await Task<Tuple<bool, string>>.Run(() =>
return Task<Tuple<bool, string>>.Run(() =>
{
try
{

View File

@@ -18,7 +18,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TaskServices
/// </summary>
/// <param name="sqlTask">Sql Task</param>
/// <returns>Task Result</returns>
public static async Task<TaskResult> ExecuteTaskAsync(SqlTask sqlTask)
public static Task<TaskResult> ExecuteTaskAsync(SqlTask sqlTask)
{
sqlTask.AddMessage(SR.TaskInProgress, SqlTaskStatus.InProgress, true);
ITaskOperation taskOperation = sqlTask.TaskMetadata.TaskOperation as ITaskOperation;
@@ -28,7 +28,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TaskServices
{
taskOperation.SqlTask = sqlTask;
return await Task.Factory.StartNew(() =>
return Task.Run(() =>
{
TaskResult result = new TaskResult();
try
@@ -66,13 +66,13 @@ namespace Microsoft.SqlTools.ServiceLayer.TaskServices
taskResult.TaskStatus = SqlTaskStatus.Failed;
}
return taskResult;
return Task.FromResult(taskResult);
}
/// <summary>
/// Async method to cancel the operations
/// </summary>
public static async Task<TaskResult> CancelTaskAsync(SqlTask sqlTask)
public static Task<TaskResult> CancelTaskAsync(SqlTask sqlTask)
{
ITaskOperation taskOperation = sqlTask.TaskMetadata.TaskOperation as ITaskOperation;
TaskResult taskResult = null;
@@ -80,7 +80,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TaskServices
if (taskOperation != null)
{
return await Task.Factory.StartNew(() =>
return Task.Run(() =>
{
try
{
@@ -107,7 +107,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TaskServices
taskResult.TaskStatus = SqlTaskStatus.Failed;
}
return taskResult;
return Task.FromResult(taskResult);
}
}
}

View File

@@ -134,7 +134,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Workspace
serviceHost.SetEventHandler(DidChangeConfigurationNotification<TConfig>.Type, HandleDidChangeConfigurationNotification);
// Register an initialization handler that sets the workspace path
serviceHost.RegisterInitializeTask(async (parameters, contect) =>
serviceHost.RegisterInitializeTask((parameters, contect) =>
{
Logger.Write(TraceEventType.Verbose, "Initializing workspace service");
@@ -142,11 +142,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Workspace
{
Workspace.WorkspacePath = parameters.RootPath;
}
await Task.FromResult(0);
return Task.CompletedTask;
});
// Register a shutdown request that disposes the workspace
serviceHost.RegisterShutdownTask(async (parameters, context) =>
serviceHost.RegisterShutdownTask((parameters, context) =>
{
Logger.Write(TraceEventType.Verbose, "Shutting down workspace service");
@@ -155,7 +156,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Workspace
Workspace.Dispose();
Workspace = null;
}
await Task.FromResult(0);
return Task.CompletedTask;
});
}