mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 18:47:57 -05:00
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:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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;
|
||||
@@ -1395,42 +1400,39 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
|
||||
GetConnectionStringParams connStringParams,
|
||||
RequestContext<string> requestContext)
|
||||
{
|
||||
await Task.Run(async () =>
|
||||
string connectionString = string.Empty;
|
||||
ConnectionInfo info;
|
||||
SqlConnectionStringBuilder connStringBuilder;
|
||||
try
|
||||
{
|
||||
string connectionString = string.Empty;
|
||||
ConnectionInfo info;
|
||||
SqlConnectionStringBuilder connStringBuilder;
|
||||
try
|
||||
// set connection string using connection uri if connection details are undefined
|
||||
if (connStringParams.ConnectionDetails == null)
|
||||
{
|
||||
// set connection string using connection uri if connection details are undefined
|
||||
if (connStringParams.ConnectionDetails == null)
|
||||
{
|
||||
TryFindConnection(connStringParams.OwnerUri, out info);
|
||||
connStringBuilder = CreateConnectionStringBuilder(info.ConnectionDetails);
|
||||
}
|
||||
// set connection string using connection details
|
||||
else
|
||||
{
|
||||
connStringBuilder = CreateConnectionStringBuilder(connStringParams.ConnectionDetails as ConnectionDetails);
|
||||
}
|
||||
if (!connStringParams.IncludePassword)
|
||||
{
|
||||
connStringBuilder.Password = ConnectionService.PasswordPlaceholder;
|
||||
}
|
||||
// default connection string application name to always be included unless set to false
|
||||
if (!connStringParams.IncludeApplicationName.HasValue || connStringParams.IncludeApplicationName.Value == true)
|
||||
{
|
||||
connStringBuilder.ApplicationName = "sqlops-connection-string";
|
||||
}
|
||||
connectionString = connStringBuilder.ConnectionString;
|
||||
TryFindConnection(connStringParams.OwnerUri, out info);
|
||||
connStringBuilder = CreateConnectionStringBuilder(info.ConnectionDetails);
|
||||
}
|
||||
catch (Exception e)
|
||||
// set connection string using connection details
|
||||
else
|
||||
{
|
||||
await requestContext.SendError(e.ToString());
|
||||
connStringBuilder = CreateConnectionStringBuilder(connStringParams.ConnectionDetails as ConnectionDetails);
|
||||
}
|
||||
if (!connStringParams.IncludePassword)
|
||||
{
|
||||
connStringBuilder.Password = ConnectionService.PasswordPlaceholder;
|
||||
}
|
||||
// default connection string application name to always be included unless set to false
|
||||
if (!connStringParams.IncludeApplicationName.HasValue || connStringParams.IncludeApplicationName.Value == true)
|
||||
{
|
||||
connStringBuilder.ApplicationName = "sqlops-connection-string";
|
||||
}
|
||||
connectionString = connStringBuilder.ConnectionString;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e.ToString());
|
||||
}
|
||||
|
||||
await requestContext.SendResult(connectionString);
|
||||
});
|
||||
await requestContext.SendResult(connectionString);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1440,19 +1442,16 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
|
||||
string connectionString,
|
||||
RequestContext<ConnectionDetails> requestContext)
|
||||
{
|
||||
await Task.Run(async () =>
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
await requestContext.SendResult(ParseConnectionString(connectionString));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// If theres an error in the parse, it means we just can't parse, so we return undefined
|
||||
// rather than an error.
|
||||
await requestContext.SendResult(null);
|
||||
}
|
||||
});
|
||||
await requestContext.SendResult(ParseConnectionString(connectionString));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// If theres an error in the parse, it means we just can't parse, so we return undefined
|
||||
// rather than an error.
|
||||
await requestContext.SendResult(null);
|
||||
}
|
||||
}
|
||||
|
||||
public ConnectionDetails ParseConnectionString(string connectionString)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -399,33 +399,30 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
/// <returns></returns>
|
||||
internal async Task HandleSyntaxParseRequest(SyntaxParseParams param, RequestContext<SyntaxParseResult> requestContext)
|
||||
{
|
||||
await Task.Run(async () =>
|
||||
try
|
||||
{
|
||||
try
|
||||
ParseResult result = Parser.Parse(param.Query);
|
||||
SyntaxParseResult syntaxResult = new SyntaxParseResult();
|
||||
if (result != null && !result.Errors.Any())
|
||||
{
|
||||
ParseResult result = Parser.Parse(param.Query);
|
||||
SyntaxParseResult syntaxResult = new SyntaxParseResult();
|
||||
if (result != null && result.Errors.Count() == 0)
|
||||
{
|
||||
syntaxResult.Parseable = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
syntaxResult.Parseable = false;
|
||||
string[] errorMessages = new string[result.Errors.Count()];
|
||||
for (int i = 0; i < result.Errors.Count(); i++)
|
||||
{
|
||||
errorMessages[i] = result.Errors.ElementAt(i).Message;
|
||||
}
|
||||
syntaxResult.Errors = errorMessages;
|
||||
}
|
||||
await requestContext.SendResult(syntaxResult);
|
||||
syntaxResult.Parseable = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
else
|
||||
{
|
||||
await requestContext.SendError(ex.ToString());
|
||||
syntaxResult.Parseable = false;
|
||||
string[] errorMessages = new string[result.Errors.Count()];
|
||||
for (int i = 0; i < result.Errors.Count(); i++)
|
||||
{
|
||||
errorMessages[i] = result.Errors.ElementAt(i).Message;
|
||||
}
|
||||
syntaxResult.Errors = errorMessages;
|
||||
}
|
||||
});
|
||||
await requestContext.SendResult(syntaxResult);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
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))
|
||||
{
|
||||
|
||||
@@ -75,49 +75,42 @@ namespace Microsoft.SqlTools.ServiceLayer.NotebookConvert
|
||||
|
||||
internal async Task HandleConvertNotebookToSqlRequest(ConvertNotebookToSqlParams parameters, RequestContext<ConvertNotebookToSqlResult> requestContext)
|
||||
{
|
||||
await Task.Run(async () =>
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
var notebookDoc = JsonConvert.DeserializeObject<NotebookDocument>(parameters.Content);
|
||||
var notebookDoc = JsonConvert.DeserializeObject<NotebookDocument>(parameters.Content);
|
||||
|
||||
var result = new ConvertNotebookToSqlResult
|
||||
{
|
||||
Content = ConvertNotebookDocToSql(notebookDoc)
|
||||
};
|
||||
await requestContext.SendResult(result);
|
||||
}
|
||||
catch (Exception e)
|
||||
var result = new ConvertNotebookToSqlResult
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
});
|
||||
Content = ConvertNotebookDocToSql(notebookDoc)
|
||||
};
|
||||
await requestContext.SendResult(result);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
}
|
||||
|
||||
internal async Task HandleConvertSqlToNotebookRequest(ConvertSqlToNotebookParams parameters, RequestContext<ConvertSqlToNotebookResult> requestContext)
|
||||
{
|
||||
await Task.Run(async () =>
|
||||
try
|
||||
{
|
||||
|
||||
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
|
||||
// what the document events are sent in as.
|
||||
var escapedClientUri = Uri.EscapeUriString(parameters.ClientUri);
|
||||
var file = WorkspaceService<SqlToolsSettings>.Instance.Workspace.GetFile(escapedClientUri);
|
||||
// Temporary notebook that we just fill in with the sql until the parsing logic is added
|
||||
var result = new ConvertSqlToNotebookResult
|
||||
{
|
||||
// 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
|
||||
// what the document events are sent in as.
|
||||
var escapedClientUri = Uri.EscapeUriString(parameters.ClientUri);
|
||||
var file = WorkspaceService<SqlToolsSettings>.Instance.Workspace.GetFile(escapedClientUri);
|
||||
// Temporary notebook that we just fill in with the sql until the parsing logic is added
|
||||
var result = new ConvertSqlToNotebookResult
|
||||
{
|
||||
Content = JsonConvert.SerializeObject(ConvertSqlToNotebook(file.Contents))
|
||||
};
|
||||
await requestContext.SendResult(result);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
});
|
||||
Content = JsonConvert.SerializeObject(ConvertSqlToNotebook(file.Contents))
|
||||
};
|
||||
await requestContext.SendResult(result);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion // Convert Handlers
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -115,59 +115,56 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
|
||||
/// </summary>
|
||||
internal async Task HandleCreateXEventSessionRequest(CreateXEventSessionParams parameters, RequestContext<CreateXEventSessionResult> requestContext)
|
||||
{
|
||||
await Task.Run(async () =>
|
||||
try
|
||||
{
|
||||
try
|
||||
ConnectionInfo connInfo;
|
||||
ConnectionServiceInstance.TryFindConnection(
|
||||
parameters.OwnerUri,
|
||||
out connInfo);
|
||||
if (connInfo == null)
|
||||
{
|
||||
ConnectionInfo connInfo;
|
||||
ConnectionServiceInstance.TryFindConnection(
|
||||
parameters.OwnerUri,
|
||||
out connInfo);
|
||||
if (connInfo == null)
|
||||
{
|
||||
throw new Exception(SR.ProfilerConnectionNotFound);
|
||||
}
|
||||
else if (parameters.SessionName == null)
|
||||
{
|
||||
throw new ArgumentNullException("SessionName");
|
||||
}
|
||||
else if (parameters.Template == null)
|
||||
{
|
||||
throw new ArgumentNullException("Template");
|
||||
}
|
||||
else
|
||||
{
|
||||
IXEventSession xeSession = null;
|
||||
|
||||
// first check whether the session with the given name already exists.
|
||||
// if so skip the creation part. An exception will be thrown if no session with given name can be found,
|
||||
// and it can be ignored.
|
||||
try
|
||||
{
|
||||
xeSession = this.XEventSessionFactory.GetXEventSession(parameters.SessionName, connInfo);
|
||||
}
|
||||
catch { }
|
||||
|
||||
if (xeSession == null)
|
||||
{
|
||||
// create a new XEvent session and Profiler session
|
||||
xeSession = this.XEventSessionFactory.CreateXEventSession(parameters.Template.CreateStatement, parameters.SessionName, connInfo);
|
||||
}
|
||||
|
||||
// start monitoring the profiler session
|
||||
monitor.StartMonitoringSession(parameters.OwnerUri, xeSession);
|
||||
|
||||
var result = new CreateXEventSessionResult();
|
||||
await requestContext.SendResult(result);
|
||||
|
||||
SessionCreatedNotification(parameters.OwnerUri, parameters.SessionName, parameters.Template.Name);
|
||||
}
|
||||
throw new Exception(SR.ProfilerConnectionNotFound);
|
||||
}
|
||||
catch (Exception e)
|
||||
else if (parameters.SessionName == null)
|
||||
{
|
||||
await requestContext.SendError(new Exception(SR.CreateSessionFailed(e.Message)));
|
||||
throw new ArgumentNullException("SessionName");
|
||||
}
|
||||
});
|
||||
else if (parameters.Template == null)
|
||||
{
|
||||
throw new ArgumentNullException("Template");
|
||||
}
|
||||
else
|
||||
{
|
||||
IXEventSession xeSession = null;
|
||||
|
||||
// first check whether the session with the given name already exists.
|
||||
// if so skip the creation part. An exception will be thrown if no session with given name can be found,
|
||||
// and it can be ignored.
|
||||
try
|
||||
{
|
||||
xeSession = this.XEventSessionFactory.GetXEventSession(parameters.SessionName, connInfo);
|
||||
}
|
||||
catch { }
|
||||
|
||||
if (xeSession == null)
|
||||
{
|
||||
// create a new XEvent session and Profiler session
|
||||
xeSession = this.XEventSessionFactory.CreateXEventSession(parameters.Template.CreateStatement, parameters.SessionName, connInfo);
|
||||
}
|
||||
|
||||
// start monitoring the profiler session
|
||||
monitor.StartMonitoringSession(parameters.OwnerUri, xeSession);
|
||||
|
||||
var result = new CreateXEventSessionResult();
|
||||
await requestContext.SendResult(result);
|
||||
|
||||
SessionCreatedNotification(parameters.OwnerUri, parameters.SessionName, parameters.Template.Name);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(new Exception(SR.CreateSessionFailed(e.Message)));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -175,34 +172,31 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
|
||||
/// </summary>
|
||||
internal async Task HandleStartProfilingRequest(StartProfilingParams parameters, RequestContext<StartProfilingResult> requestContext)
|
||||
{
|
||||
await Task.Run(async () =>
|
||||
try
|
||||
{
|
||||
try
|
||||
ConnectionInfo connInfo;
|
||||
ConnectionServiceInstance.TryFindConnection(
|
||||
parameters.OwnerUri,
|
||||
out connInfo);
|
||||
if (connInfo != null)
|
||||
{
|
||||
ConnectionInfo connInfo;
|
||||
ConnectionServiceInstance.TryFindConnection(
|
||||
parameters.OwnerUri,
|
||||
out connInfo);
|
||||
if (connInfo != null)
|
||||
{
|
||||
// create a new XEvent session and Profiler session
|
||||
var xeSession = this.XEventSessionFactory.GetXEventSession(parameters.SessionName, connInfo);
|
||||
// start monitoring the profiler session
|
||||
monitor.StartMonitoringSession(parameters.OwnerUri, xeSession);
|
||||
// create a new XEvent session and Profiler session
|
||||
var xeSession = this.XEventSessionFactory.GetXEventSession(parameters.SessionName, connInfo);
|
||||
// start monitoring the profiler session
|
||||
monitor.StartMonitoringSession(parameters.OwnerUri, xeSession);
|
||||
|
||||
var result = new StartProfilingResult();
|
||||
await requestContext.SendResult(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception(SR.ProfilerConnectionNotFound);
|
||||
}
|
||||
var result = new StartProfilingResult();
|
||||
await requestContext.SendResult(result);
|
||||
}
|
||||
catch (Exception e)
|
||||
else
|
||||
{
|
||||
await requestContext.SendError(new Exception(SR.StartSessionFailed(e.Message)));
|
||||
throw new Exception(SR.ProfilerConnectionNotFound);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(new Exception(SR.StartSessionFailed(e.Message)));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -210,47 +204,44 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
|
||||
/// </summary>
|
||||
internal async Task HandleStopProfilingRequest(StopProfilingParams parameters, RequestContext<StopProfilingResult> requestContext)
|
||||
{
|
||||
await Task.Run(async () =>
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
ProfilerSession session;
|
||||
monitor.StopMonitoringSession(parameters.OwnerUri, out session);
|
||||
ProfilerSession session;
|
||||
monitor.StopMonitoringSession(parameters.OwnerUri, out session);
|
||||
|
||||
if (session != null)
|
||||
if (session != null)
|
||||
{
|
||||
// Occasionally we might see the InvalidOperationException due to a read is
|
||||
// in progress, add the following retry logic will solve the problem.
|
||||
int remainingAttempts = 3;
|
||||
while (true)
|
||||
{
|
||||
// Occasionally we might see the InvalidOperationException due to a read is
|
||||
// in progress, add the following retry logic will solve the problem.
|
||||
int remainingAttempts = 3;
|
||||
while (true)
|
||||
try
|
||||
{
|
||||
try
|
||||
session.XEventSession.Stop();
|
||||
await requestContext.SendResult(new StopProfilingResult { });
|
||||
break;
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
remainingAttempts--;
|
||||
if (remainingAttempts == 0)
|
||||
{
|
||||
session.XEventSession.Stop();
|
||||
await requestContext.SendResult(new StopProfilingResult { });
|
||||
break;
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
remainingAttempts--;
|
||||
if (remainingAttempts == 0)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
Thread.Sleep(500);
|
||||
throw;
|
||||
}
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception(SR.SessionNotFound);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
else
|
||||
{
|
||||
await requestContext.SendError(new Exception(SR.StopSessionFailed(e.Message)));
|
||||
throw new Exception(SR.SessionNotFound);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(new Exception(SR.StopSessionFailed(e.Message)));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -258,19 +249,16 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
|
||||
/// </summary>
|
||||
internal async Task HandlePauseProfilingRequest(PauseProfilingParams parameters, RequestContext<PauseProfilingResult> requestContext)
|
||||
{
|
||||
await Task.Run(async () =>
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
monitor.PauseViewer(parameters.OwnerUri);
|
||||
monitor.PauseViewer(parameters.OwnerUri);
|
||||
|
||||
await requestContext.SendResult(new PauseProfilingResult { });
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(new Exception(SR.PauseSessionFailed(e.Message)));
|
||||
}
|
||||
});
|
||||
await requestContext.SendResult(new PauseProfilingResult { });
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(new Exception(SR.PauseSessionFailed(e.Message)));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -278,31 +266,28 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
|
||||
/// </summary>
|
||||
internal async Task HandleGetXEventSessionsRequest(GetXEventSessionsParams parameters, RequestContext<GetXEventSessionsResult> requestContext)
|
||||
{
|
||||
await Task.Run(async () =>
|
||||
try
|
||||
{
|
||||
try
|
||||
var result = new GetXEventSessionsResult();
|
||||
ConnectionInfo connInfo;
|
||||
ConnectionServiceInstance.TryFindConnection(
|
||||
parameters.OwnerUri,
|
||||
out connInfo);
|
||||
if (connInfo == null)
|
||||
{
|
||||
var result = new GetXEventSessionsResult();
|
||||
ConnectionInfo connInfo;
|
||||
ConnectionServiceInstance.TryFindConnection(
|
||||
parameters.OwnerUri,
|
||||
out connInfo);
|
||||
if (connInfo == null)
|
||||
{
|
||||
await requestContext.SendError(new Exception(SR.ProfilerConnectionNotFound));
|
||||
}
|
||||
else
|
||||
{
|
||||
List<string> sessions = GetXEventSessionList(parameters.OwnerUri, connInfo);
|
||||
result.Sessions = sessions;
|
||||
await requestContext.SendResult(result);
|
||||
}
|
||||
await requestContext.SendError(new Exception(SR.ProfilerConnectionNotFound));
|
||||
}
|
||||
catch (Exception e)
|
||||
else
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
List<string> sessions = GetXEventSessionList(parameters.OwnerUri, connInfo);
|
||||
result.Sessions = sessions;
|
||||
await requestContext.SendResult(result);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -310,18 +295,14 @@ namespace Microsoft.SqlTools.ServiceLayer.Profiler
|
||||
/// </summary>
|
||||
internal async Task HandleDisconnectSessionRequest(DisconnectSessionParams parameters, RequestContext<DisconnectSessionResult> requestContext)
|
||||
{
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
ProfilerSession session;
|
||||
monitor.StopMonitoringSession(parameters.OwnerUri, out session);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
});
|
||||
try
|
||||
{
|
||||
monitor.StopMonitoringSession(parameters.OwnerUri, out _);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -143,43 +143,38 @@ namespace Microsoft.SqlTools.ServiceLayer.Security
|
||||
/// </summary>
|
||||
internal async Task HandleGetCredentialsRequest(GetCredentialsParams parameters, RequestContext<GetCredentialsResult> requestContext)
|
||||
{
|
||||
await Task.Run(async () =>
|
||||
var result = new GetCredentialsResult();
|
||||
try
|
||||
{
|
||||
var result = new GetCredentialsResult();
|
||||
try
|
||||
{
|
||||
ConnectionInfo connInfo;
|
||||
ConnectionServiceInstance.TryFindConnection(parameters.OwnerUri, out connInfo);
|
||||
CDataContainer dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true);
|
||||
ConnectionInfo connInfo;
|
||||
ConnectionServiceInstance.TryFindConnection(parameters.OwnerUri, out connInfo);
|
||||
CDataContainer dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true);
|
||||
|
||||
var credentials = dataContainer.Server.Credentials;
|
||||
int credentialsCount = credentials.Count;
|
||||
CredentialInfo[] credentialsInfos = new CredentialInfo[credentialsCount];
|
||||
for (int i = 0; i < credentialsCount; ++i)
|
||||
{
|
||||
credentialsInfos[i] = new CredentialInfo();
|
||||
credentialsInfos[i].Name = credentials[i].Name;
|
||||
credentialsInfos[i].Identity = credentials[i].Identity;
|
||||
credentialsInfos[i].Id = credentials[i].ID;
|
||||
credentialsInfos[i].DateLastModified = credentials[i].DateLastModified;
|
||||
credentialsInfos[i].CreateDate = credentials[i].CreateDate;
|
||||
credentialsInfos[i].ProviderName = credentials[i].ProviderName;
|
||||
}
|
||||
result.Credentials = credentialsInfos;
|
||||
result.Success = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
var credentials = dataContainer.Server.Credentials;
|
||||
int credentialsCount = credentials.Count;
|
||||
CredentialInfo[] credentialsInfos = new CredentialInfo[credentialsCount];
|
||||
for (int i = 0; i < credentialsCount; ++i)
|
||||
{
|
||||
result.Success = false;
|
||||
result.ErrorMessage = ex.ToString();
|
||||
credentialsInfos[i] = new CredentialInfo();
|
||||
credentialsInfos[i].Name = credentials[i].Name;
|
||||
credentialsInfos[i].Identity = credentials[i].Identity;
|
||||
credentialsInfos[i].Id = credentials[i].ID;
|
||||
credentialsInfos[i].DateLastModified = credentials[i].DateLastModified;
|
||||
credentialsInfos[i].CreateDate = credentials[i].CreateDate;
|
||||
credentialsInfos[i].ProviderName = credentials[i].ProviderName;
|
||||
}
|
||||
result.Credentials = credentialsInfos;
|
||||
result.Success = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result.Success = false;
|
||||
result.ErrorMessage = ex.ToString();
|
||||
}
|
||||
|
||||
await requestContext.SendResult(result);
|
||||
});
|
||||
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
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user