mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 18:47:57 -05:00
modified the default value for OE session (#394)
This commit is contained in:
@@ -268,6 +268,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
|
|||||||
|
|
||||||
private void RunCreateSessionTask(ConnectionDetails connectionDetails, string uri)
|
private void RunCreateSessionTask(ConnectionDetails connectionDetails, string uri)
|
||||||
{
|
{
|
||||||
|
Logger.Write(LogLevel.Normal, "Creating OE session");
|
||||||
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
|
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
|
||||||
if (connectionDetails != null && !string.IsNullOrEmpty(uri))
|
if (connectionDetails != null && !string.IsNullOrEmpty(uri))
|
||||||
{
|
{
|
||||||
@@ -278,7 +279,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
|
|||||||
ObjectExplorerTaskResult result = await RunTaskWithTimeout(task,
|
ObjectExplorerTaskResult result = await RunTaskWithTimeout(task,
|
||||||
settings?.CreateSessionTimeout ?? ObjectExplorerSettings.DefaultCreateSessionTimeout);
|
settings?.CreateSessionTimeout ?? ObjectExplorerSettings.DefaultCreateSessionTimeout);
|
||||||
|
|
||||||
if (result != null && !result.IsComplete)
|
if (result != null && !result.IsCompleted)
|
||||||
{
|
{
|
||||||
cancellationTokenSource.Cancel();
|
cancellationTokenSource.Cancel();
|
||||||
SessionCreatedParameters response = new SessionCreatedParameters
|
SessionCreatedParameters response = new SessionCreatedParameters
|
||||||
@@ -359,20 +360,28 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
|
|||||||
/// <returns><see cref="ObjectExplorerSession"/> object if successful, null if unsuccessful</returns>
|
/// <returns><see cref="ObjectExplorerSession"/> object if successful, null if unsuccessful</returns>
|
||||||
internal async Task<ObjectExplorerSession> DoCreateSession(ConnectionDetails connectionDetails, string uri)
|
internal async Task<ObjectExplorerSession> DoCreateSession(ConnectionDetails connectionDetails, string uri)
|
||||||
{
|
{
|
||||||
ObjectExplorerSession session;
|
try
|
||||||
connectionDetails.PersistSecurityInfo = true;
|
|
||||||
ConnectParams connectParams = new ConnectParams() { OwnerUri = uri, Connection = connectionDetails };
|
|
||||||
|
|
||||||
ConnectionCompleteParams connectionResult = await Connect(connectParams, uri);
|
|
||||||
if (connectionResult == null)
|
|
||||||
{
|
{
|
||||||
// Connection failed and notification is already sent
|
ObjectExplorerSession session;
|
||||||
|
connectionDetails.PersistSecurityInfo = true;
|
||||||
|
ConnectParams connectParams = new ConnectParams() { OwnerUri = uri, Connection = connectionDetails };
|
||||||
|
|
||||||
|
ConnectionCompleteParams connectionResult = await Connect(connectParams, uri);
|
||||||
|
if (connectionResult == null)
|
||||||
|
{
|
||||||
|
// Connection failed and notification is already sent
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
session = ObjectExplorerSession.CreateSession(connectionResult, serviceProvider);
|
||||||
|
sessionMap.AddOrUpdate(uri, session, (key, oldSession) => session);
|
||||||
|
return session;
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
await SendSessionFailedNotification(uri, ex.Message);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
session = ObjectExplorerSession.CreateSession(connectionResult, serviceProvider);
|
|
||||||
sessionMap.AddOrUpdate(uri, session, (key, oldSession) => session);
|
|
||||||
return session;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -390,30 +399,30 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Logger.Write(LogLevel.Warning, $"Connection Failed for OE. connection error: {connectionErrorMessage}");
|
await SendSessionFailedNotification(uri, result.ErrorMessage);
|
||||||
await serviceHost.SendEvent(CreateSessionCompleteNotification.Type, new SessionCreatedParameters
|
|
||||||
{
|
|
||||||
ErrorMessage = result.ErrorMessage,
|
|
||||||
SessionId = uri
|
|
||||||
});
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Logger.Write(LogLevel.Warning, $"Connection Failed for OE. connection error:{connectionErrorMessage} error: {ex.Message}");
|
await SendSessionFailedNotification(uri, ex.ToString());
|
||||||
// Send a connection failed error message in this case.
|
|
||||||
SessionCreatedParameters result = new SessionCreatedParameters()
|
|
||||||
{
|
|
||||||
ErrorMessage = ex.ToString(),
|
|
||||||
SessionId = uri
|
|
||||||
};
|
|
||||||
await serviceHost.SendEvent(CreateSessionCompleteNotification.Type, result);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task SendSessionFailedNotification(string uri, string errorMessage)
|
||||||
|
{
|
||||||
|
Logger.Write(LogLevel.Warning, $"Failed To create OE session: {errorMessage}");
|
||||||
|
SessionCreatedParameters result = new SessionCreatedParameters()
|
||||||
|
{
|
||||||
|
Success = false,
|
||||||
|
ErrorMessage = errorMessage,
|
||||||
|
SessionId = uri
|
||||||
|
};
|
||||||
|
await serviceHost.SendEvent(CreateSessionCompleteNotification.Type, result);
|
||||||
|
}
|
||||||
|
|
||||||
private void RunExpandTask(ObjectExplorerSession session, ExpandParams expandParams, bool forceRefresh = false)
|
private void RunExpandTask(ObjectExplorerSession session, ExpandParams expandParams, bool forceRefresh = false)
|
||||||
{
|
{
|
||||||
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
|
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
|
||||||
@@ -424,7 +433,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
|
|||||||
ObjectExplorerTaskResult result = await RunTaskWithTimeout(task,
|
ObjectExplorerTaskResult result = await RunTaskWithTimeout(task,
|
||||||
settings?.ExpandTimeout ?? ObjectExplorerSettings.DefaultExpandTimeout);
|
settings?.ExpandTimeout ?? ObjectExplorerSettings.DefaultExpandTimeout);
|
||||||
|
|
||||||
if (result != null && !result.IsComplete)
|
if (result != null && !result.IsCompleted)
|
||||||
{
|
{
|
||||||
cancellationTokenSource.Cancel();
|
cancellationTokenSource.Cancel();
|
||||||
ExpandResponse response = CreateExpandResponse(session, expandParams);
|
ExpandResponse response = CreateExpandResponse(session, expandParams);
|
||||||
@@ -440,7 +449,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
|
|||||||
ObjectExplorerTaskResult result = new ObjectExplorerTaskResult();
|
ObjectExplorerTaskResult result = new ObjectExplorerTaskResult();
|
||||||
TimeSpan timeout = TimeSpan.FromSeconds(timeoutInSec);
|
TimeSpan timeout = TimeSpan.FromSeconds(timeoutInSec);
|
||||||
await Task.WhenAny(task, Task.Delay(timeout));
|
await Task.WhenAny(task, Task.Delay(timeout));
|
||||||
result.IsComplete = task.IsCompleted;
|
result.IsCompleted = task.IsCompleted;
|
||||||
if(task.Exception != null)
|
if(task.Exception != null)
|
||||||
{
|
{
|
||||||
result.Exception = task.Exception;
|
result.Exception = task.Exception;
|
||||||
@@ -563,7 +572,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
|
|||||||
|
|
||||||
internal class ObjectExplorerTaskResult
|
internal class ObjectExplorerTaskResult
|
||||||
{
|
{
|
||||||
public bool IsComplete { get; set; }
|
public bool IsCompleted { get; set; }
|
||||||
public Exception Exception { get; set; }
|
public Exception Exception { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -601,7 +610,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
|
|||||||
DatabaseTreeNode databaseNode = new DatabaseTreeNode(rootNode, response.ConnectionSummary.DatabaseName);
|
DatabaseTreeNode databaseNode = new DatabaseTreeNode(rootNode, response.ConnectionSummary.DatabaseName);
|
||||||
session.Root = databaseNode;
|
session.Root = databaseNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using Microsoft.SqlServer.Management.Smo;
|
using Microsoft.SqlServer.Management.Smo;
|
||||||
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes;
|
|
||||||
using Microsoft.SqlTools.Utility;
|
using Microsoft.SqlTools.Utility;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
|
namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
|
||||||
|
|||||||
@@ -4,14 +4,10 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using Microsoft.SqlServer.Management.Common;
|
|
||||||
using Microsoft.SqlServer.Management.Smo;
|
using Microsoft.SqlServer.Management.Smo;
|
||||||
using Microsoft.SqlTools.Extensibility;
|
using Microsoft.SqlTools.Extensibility;
|
||||||
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes;
|
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes;
|
||||||
using Microsoft.SqlTools.Utility;
|
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
|
namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,20 +3,9 @@
|
|||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
//
|
//
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Data.Common;
|
|
||||||
using System.Data.SqlClient;
|
using System.Data.SqlClient;
|
||||||
using System.Globalization;
|
|
||||||
using System.Linq;
|
|
||||||
using Microsoft.SqlServer.Management.Common;
|
using Microsoft.SqlServer.Management.Common;
|
||||||
using Microsoft.SqlServer.Management.Smo;
|
using Microsoft.SqlServer.Management.Smo;
|
||||||
using Microsoft.SqlTools.Extensibility;
|
|
||||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
|
||||||
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
|
||||||
using Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection;
|
|
||||||
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes;
|
|
||||||
using Microsoft.SqlTools.ServiceLayer.Utility;
|
|
||||||
using Microsoft.SqlTools.Utility;
|
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
|
namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ namespace Microsoft.SqlTools.ServiceLayer.SqlContext
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ObjectExplorerSettings
|
public class ObjectExplorerSettings
|
||||||
{
|
{
|
||||||
public static int DefaultCreateSessionTimeout = 300;
|
public static int DefaultCreateSessionTimeout = 30;
|
||||||
public static int DefaultExpandTimeout = 300;
|
public static int DefaultExpandTimeout = 30;
|
||||||
|
|
||||||
public ObjectExplorerSettings()
|
public ObjectExplorerSettings()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user