modified the default value for OE session (#394)

This commit is contained in:
Leila Lali
2017-06-23 15:37:04 -07:00
committed by GitHub
parent 81d031d5eb
commit 276f70ab3b
5 changed files with 41 additions and 48 deletions

View File

@@ -268,6 +268,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
private void RunCreateSessionTask(ConnectionDetails connectionDetails, string uri)
{
Logger.Write(LogLevel.Normal, "Creating OE session");
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
if (connectionDetails != null && !string.IsNullOrEmpty(uri))
{
@@ -278,7 +279,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
ObjectExplorerTaskResult result = await RunTaskWithTimeout(task,
settings?.CreateSessionTimeout ?? ObjectExplorerSettings.DefaultCreateSessionTimeout);
if (result != null && !result.IsComplete)
if (result != null && !result.IsCompleted)
{
cancellationTokenSource.Cancel();
SessionCreatedParameters response = new SessionCreatedParameters
@@ -358,6 +359,8 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
/// </summary>
/// <returns><see cref="ObjectExplorerSession"/> object if successful, null if unsuccessful</returns>
internal async Task<ObjectExplorerSession> DoCreateSession(ConnectionDetails connectionDetails, string uri)
{
try
{
ObjectExplorerSession session;
connectionDetails.PersistSecurityInfo = true;
@@ -374,6 +377,12 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
sessionMap.AddOrUpdate(uri, session, (key, oldSession) => session);
return session;
}
catch(Exception ex)
{
await SendSessionFailedNotification(uri, ex.Message);
return null;
}
}
private async Task<ConnectionCompleteParams> Connect(ConnectParams connectParams, string uri)
@@ -390,28 +399,28 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
}
else
{
Logger.Write(LogLevel.Warning, $"Connection Failed for OE. connection error: {connectionErrorMessage}");
await serviceHost.SendEvent(CreateSessionCompleteNotification.Type, new SessionCreatedParameters
{
ErrorMessage = result.ErrorMessage,
SessionId = uri
});
await SendSessionFailedNotification(uri, result.ErrorMessage);
return null;
}
}
catch (Exception ex)
{
Logger.Write(LogLevel.Warning, $"Connection Failed for OE. connection error:{connectionErrorMessage} error: {ex.Message}");
// Send a connection failed error message in this case.
await SendSessionFailedNotification(uri, ex.ToString());
return null;
}
}
private async Task SendSessionFailedNotification(string uri, string errorMessage)
{
Logger.Write(LogLevel.Warning, $"Failed To create OE session: {errorMessage}");
SessionCreatedParameters result = new SessionCreatedParameters()
{
ErrorMessage = ex.ToString(),
Success = false,
ErrorMessage = errorMessage,
SessionId = uri
};
await serviceHost.SendEvent(CreateSessionCompleteNotification.Type, result);
return null;
}
}
private void RunExpandTask(ObjectExplorerSession session, ExpandParams expandParams, bool forceRefresh = false)
@@ -424,7 +433,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
ObjectExplorerTaskResult result = await RunTaskWithTimeout(task,
settings?.ExpandTimeout ?? ObjectExplorerSettings.DefaultExpandTimeout);
if (result != null && !result.IsComplete)
if (result != null && !result.IsCompleted)
{
cancellationTokenSource.Cancel();
ExpandResponse response = CreateExpandResponse(session, expandParams);
@@ -440,7 +449,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
ObjectExplorerTaskResult result = new ObjectExplorerTaskResult();
TimeSpan timeout = TimeSpan.FromSeconds(timeoutInSec);
await Task.WhenAny(task, Task.Delay(timeout));
result.IsComplete = task.IsCompleted;
result.IsCompleted = task.IsCompleted;
if(task.Exception != null)
{
result.Exception = task.Exception;
@@ -563,7 +572,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
internal class ObjectExplorerTaskResult
{
public bool IsComplete { get; set; }
public bool IsCompleted { get; set; }
public Exception Exception { get; set; }
}

View File

@@ -7,7 +7,6 @@
using System;
using System.Globalization;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes;
using Microsoft.SqlTools.Utility;
namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel

View File

@@ -4,14 +4,10 @@
//
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlTools.Extensibility;
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes;
using Microsoft.SqlTools.Utility;
namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
{

View File

@@ -3,20 +3,9 @@
// 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.Globalization;
using System.Linq;
using Microsoft.SqlServer.Management.Common;
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
{

View File

@@ -10,8 +10,8 @@ namespace Microsoft.SqlTools.ServiceLayer.SqlContext
/// </summary>
public class ObjectExplorerSettings
{
public static int DefaultCreateSessionTimeout = 300;
public static int DefaultExpandTimeout = 300;
public static int DefaultCreateSessionTimeout = 30;
public static int DefaultExpandTimeout = 30;
public ObjectExplorerSettings()
{