From a6cc14d31f3c173bfe8190a43130ad7e858119e2 Mon Sep 17 00:00:00 2001 From: Mitchell Sternke Date: Tue, 16 Aug 2016 13:48:36 -0700 Subject: [PATCH 1/2] Cleaned up connection management code --- .../Connection/ConnectionInfo.cs | 38 +++++ .../Connection/ConnectionService.cs | 26 --- .../Contracts/ConnectMessagesExtensions.cs | 19 +++ .../Contracts/ConnectionSummaryComparer.cs | 53 ++++++ .../LanguageServices/AutoCompleteService.cs | 155 ------------------ .../LanguageServices/IntellisenseCache.cs | 119 ++++++++++++++ 6 files changed, 229 insertions(+), 181 deletions(-) create mode 100644 src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionInfo.cs create mode 100644 src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionSummaryComparer.cs create mode 100644 src/Microsoft.SqlTools.ServiceLayer/LanguageServices/IntellisenseCache.cs diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionInfo.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionInfo.cs new file mode 100644 index 00000000..7490b33c --- /dev/null +++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionInfo.cs @@ -0,0 +1,38 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Data.Common; +using Microsoft.SqlTools.ServiceLayer.Connection.Contracts; + +namespace Microsoft.SqlTools.ServiceLayer.Connection +{ + /// + /// Information pertaining to a unique connection instance. + /// + public class ConnectionInfo + { + public ConnectionInfo(ISqlConnectionFactory factory, string ownerUri, ConnectionDetails details) + { + Factory = factory; + OwnerUri = ownerUri; + ConnectionDetails = details; + ConnectionId = Guid.NewGuid(); + } + + /// + /// Unique Id, helpful to identify a connection info object + /// + public Guid ConnectionId { get; private set; } + + public string OwnerUri { get; private set; } + + public ISqlConnectionFactory Factory {get; private set;} + + public ConnectionDetails ConnectionDetails { get; private set; } + + public DbConnection SqlConnection { get; set; } + } +} diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs index 8f430e29..8905ab92 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs @@ -5,42 +5,16 @@ using System; using System.Collections.Generic; -using System.Data.Common; using System.Data.SqlClient; using System.Threading.Tasks; using Microsoft.SqlTools.EditorServices.Utility; using Microsoft.SqlTools.ServiceLayer.Connection.Contracts; -using Microsoft.SqlTools.ServiceLayer.Hosting; using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol; using Microsoft.SqlTools.ServiceLayer.SqlContext; using Microsoft.SqlTools.ServiceLayer.Workspace; namespace Microsoft.SqlTools.ServiceLayer.Connection { - public class ConnectionInfo - { - public ConnectionInfo(ISqlConnectionFactory factory, string ownerUri, ConnectionDetails details) - { - Factory = factory; - OwnerUri = ownerUri; - ConnectionDetails = details; - ConnectionId = Guid.NewGuid(); - } - - /// - /// Unique Id, helpful to identify a connection info object - /// - public Guid ConnectionId { get; private set; } - - public string OwnerUri { get; private set; } - - public ISqlConnectionFactory Factory {get; private set;} - - public ConnectionDetails ConnectionDetails { get; private set; } - - public DbConnection SqlConnection { get; set; } - } - /// /// Main class for the Connection Management services /// diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectMessagesExtensions.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectMessagesExtensions.cs index b9e73e09..d15adae6 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectMessagesExtensions.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectMessagesExtensions.cs @@ -27,4 +27,23 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts ); } } + + /// + /// Extension methods to ConnectionSummary + /// + public static class ConnectionSummaryExtensions + { + /// + /// Create a copy of a ConnectionSummary object + /// + public static ConnectionSummary Clone(this ConnectionSummary summary) + { + return new ConnectionSummary() + { + ServerName = summary.ServerName, + DatabaseName = summary.DatabaseName, + UserName = summary.UserName + }; + } + } } diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionSummaryComparer.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionSummaryComparer.cs new file mode 100644 index 00000000..dfeb0ab4 --- /dev/null +++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionSummaryComparer.cs @@ -0,0 +1,53 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System; +using System.Collections.Generic; + +namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts +{ + + /// + /// Treats connections as the same if their server, db and usernames all match + /// + public class ConnectionSummaryComparer : IEqualityComparer + { + public bool Equals(ConnectionSummary x, ConnectionSummary y) + { + if(x == y) { return true; } + else if(x != null) + { + if(y == null) { return false; } + + // Compare server, db, username. Note: server is case-insensitive in the driver + return string.Compare(x.ServerName, y.ServerName, StringComparison.OrdinalIgnoreCase) == 0 + && string.Compare(x.DatabaseName, y.DatabaseName, StringComparison.Ordinal) == 0 + && string.Compare(x.UserName, y.UserName, StringComparison.Ordinal) == 0; + } + return false; + } + + public int GetHashCode(ConnectionSummary obj) + { + int hashcode = 31; + if(obj != null) + { + if(obj.ServerName != null) + { + hashcode ^= obj.ServerName.GetHashCode(); + } + if (obj.DatabaseName != null) + { + hashcode ^= obj.DatabaseName.GetHashCode(); + } + if (obj.UserName != null) + { + hashcode ^= obj.UserName.GetHashCode(); + } + } + return hashcode; + } + } +} diff --git a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/AutoCompleteService.cs b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/AutoCompleteService.cs index 14148778..616fc2c6 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/AutoCompleteService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/AutoCompleteService.cs @@ -5,8 +5,6 @@ using System; using System.Collections.Generic; -using System.Data; -using System.Data.Common; using System.Threading.Tasks; using Microsoft.SqlTools.ServiceLayer.Connection; using Microsoft.SqlTools.ServiceLayer.Connection.Contracts; @@ -16,159 +14,6 @@ using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts; namespace Microsoft.SqlTools.ServiceLayer.LanguageServices { - internal class IntellisenseCache - { - // connection used to query for intellisense info - private DbConnection connection; - - // number of documents (URI's) that are using the cache for the same database - // the autocomplete service uses this to remove unreferenced caches - public int ReferenceCount { get; set; } - - public IntellisenseCache(ISqlConnectionFactory connectionFactory, ConnectionDetails connectionDetails) - { - ReferenceCount = 0; - DatabaseInfo = CopySummary(connectionDetails); - - // TODO error handling on this. Intellisense should catch or else the service should handle - connection = connectionFactory.CreateSqlConnection(ConnectionService.BuildConnectionString(connectionDetails)); - connection.Open(); - } - - /// - /// Used to identify a database for which this cache is used - /// - public ConnectionSummary DatabaseInfo - { - get; - private set; - } - /// - /// Gets the current autocomplete candidate list - /// - public IEnumerable AutoCompleteList { get; private set; } - - public async Task UpdateCache() - { - DbCommand command = connection.CreateCommand(); - command.CommandText = "SELECT name FROM sys.tables"; - command.CommandTimeout = 15; - command.CommandType = CommandType.Text; - var reader = await command.ExecuteReaderAsync(); - - List results = new List(); - while (await reader.ReadAsync()) - { - results.Add(reader[0].ToString()); - } - - AutoCompleteList = results; - await Task.FromResult(0); - } - - public List GetAutoCompleteItems(TextDocumentPosition textDocumentPosition) - { - List completions = new List(); - - int i = 0; - - // Take a reference to the list at a point in time in case we update and replace the list - var suggestions = AutoCompleteList; - // the completion list will be null is user not connected to server - if (this.AutoCompleteList != null) - { - - foreach (var autoCompleteItem in suggestions) - { - // convert the completion item candidates into CompletionItems - completions.Add(new CompletionItem() - { - Label = autoCompleteItem, - Kind = CompletionItemKind.Keyword, - Detail = autoCompleteItem + " details", - Documentation = autoCompleteItem + " documentation", - TextEdit = new TextEdit - { - NewText = autoCompleteItem, - Range = new Range - { - Start = new Position - { - Line = textDocumentPosition.Position.Line, - Character = textDocumentPosition.Position.Character - }, - End = new Position - { - Line = textDocumentPosition.Position.Line, - Character = textDocumentPosition.Position.Character + 5 - } - } - } - }); - - // only show 50 items - if (++i == 50) - { - break; - } - } - } - - return completions; - } - - private static ConnectionSummary CopySummary(ConnectionSummary summary) - { - return new ConnectionSummary() - { - ServerName = summary.ServerName, - DatabaseName = summary.DatabaseName, - UserName = summary.UserName - }; - } - } - - /// - /// Treats connections as the same if their server, db and usernames all match - /// - public class ConnectionSummaryComparer : IEqualityComparer - { - public bool Equals(ConnectionSummary x, ConnectionSummary y) - { - if(x == y) { return true; } - else if(x != null) - { - if(y == null) { return false; } - - // Compare server, db, username. Note: server is case-insensitive in the driver - return string.Compare(x.ServerName, y.ServerName, StringComparison.OrdinalIgnoreCase) == 0 - && string.Compare(x.DatabaseName, y.DatabaseName, StringComparison.Ordinal) == 0 - && string.Compare(x.UserName, y.UserName, StringComparison.Ordinal) == 0; - } - return false; - } - - public int GetHashCode(ConnectionSummary obj) - { - int hashcode = 31; - if(obj != null) - { - if(obj.ServerName != null) - { - hashcode ^= obj.ServerName.GetHashCode(); - } - if (obj.DatabaseName != null) - { - hashcode ^= obj.DatabaseName.GetHashCode(); - } - if (obj.UserName != null) - { - hashcode ^= obj.UserName.GetHashCode(); - } - } - return hashcode; - } - } /// /// Main class for Autocomplete functionality /// diff --git a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/IntellisenseCache.cs b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/IntellisenseCache.cs new file mode 100644 index 00000000..ca4c155a --- /dev/null +++ b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/IntellisenseCache.cs @@ -0,0 +1,119 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System.Collections.Generic; +using System.Data; +using System.Data.Common; +using System.Threading.Tasks; +using Microsoft.SqlTools.ServiceLayer.Connection; +using Microsoft.SqlTools.ServiceLayer.Connection.Contracts; +using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts; +using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts; + +namespace Microsoft.SqlTools.ServiceLayer.LanguageServices +{ + + internal class IntellisenseCache + { + // connection used to query for intellisense info + private DbConnection connection; + + // number of documents (URI's) that are using the cache for the same database + // the autocomplete service uses this to remove unreferenced caches + public int ReferenceCount { get; set; } + + public IntellisenseCache(ISqlConnectionFactory connectionFactory, ConnectionDetails connectionDetails) + { + ReferenceCount = 0; + DatabaseInfo = connectionDetails.Clone(); + + // TODO error handling on this. Intellisense should catch or else the service should handle + connection = connectionFactory.CreateSqlConnection(ConnectionService.BuildConnectionString(connectionDetails)); + connection.Open(); + } + + /// + /// Used to identify a database for which this cache is used + /// + public ConnectionSummary DatabaseInfo + { + get; + private set; + } + /// + /// Gets the current autocomplete candidate list + /// + public IEnumerable AutoCompleteList { get; private set; } + + public async Task UpdateCache() + { + DbCommand command = connection.CreateCommand(); + command.CommandText = "SELECT name FROM sys.tables"; + command.CommandTimeout = 15; + command.CommandType = CommandType.Text; + var reader = await command.ExecuteReaderAsync(); + + List results = new List(); + while (await reader.ReadAsync()) + { + results.Add(reader[0].ToString()); + } + + AutoCompleteList = results; + await Task.FromResult(0); + } + + public List GetAutoCompleteItems(TextDocumentPosition textDocumentPosition) + { + List completions = new List(); + + int i = 0; + + // Take a reference to the list at a point in time in case we update and replace the list + var suggestions = AutoCompleteList; + // the completion list will be null is user not connected to server + if (this.AutoCompleteList != null) + { + + foreach (var autoCompleteItem in suggestions) + { + // convert the completion item candidates into CompletionItems + completions.Add(new CompletionItem() + { + Label = autoCompleteItem, + Kind = CompletionItemKind.Keyword, + Detail = autoCompleteItem + " details", + Documentation = autoCompleteItem + " documentation", + TextEdit = new TextEdit + { + NewText = autoCompleteItem, + Range = new Range + { + Start = new Position + { + Line = textDocumentPosition.Position.Line, + Character = textDocumentPosition.Position.Character + }, + End = new Position + { + Line = textDocumentPosition.Position.Line, + Character = textDocumentPosition.Position.Character + 5 + } + } + } + }); + + // only show 50 items + if (++i == 50) + { + break; + } + } + } + + return completions; + } + } +} From 6ffdf644baf6c1a6b4b4fce744506d660f526bc0 Mon Sep 17 00:00:00 2001 From: Mitchell Sternke Date: Tue, 16 Aug 2016 15:27:26 -0700 Subject: [PATCH 2/2] Addressing code review feedback --- .../Connection/ConnectionInfo.cs | 15 ++++ .../Connection/Contracts/ConnectMessages.cs | 89 ------------------- .../Connection/Contracts/ConnectParams.cs | 26 ++++++ ...tensions.cs => ConnectParamsExtensions.cs} | 19 ---- .../Connection/Contracts/ConnectResponse.cs | 23 +++++ .../ConnectionChangedNotification.cs | 19 ++++ ...Messages.cs => ConnectionChangedParams.cs} | 13 --- .../Connection/Contracts/ConnectionDetails.cs | 21 +++++ .../Connection/Contracts/ConnectionRequest.cs | 19 ++++ .../Connection/Contracts/ConnectionSummary.cs | 28 ++++++ .../Contracts/ConnectionSummaryExtensions.cs | 26 ++++++ ...connectMessages.cs => DisconnectParams.cs} | 12 --- .../Connection/Contracts/DisconnectRequest.cs | 19 ++++ .../LanguageServices/IntellisenseCache.cs | 11 ++- 14 files changed, 203 insertions(+), 137 deletions(-) delete mode 100644 src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectMessages.cs create mode 100644 src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectParams.cs rename src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/{ConnectMessagesExtensions.cs => ConnectParamsExtensions.cs} (64%) create mode 100644 src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectResponse.cs create mode 100644 src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionChangedNotification.cs rename src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/{ConnectionChangedMessages.cs => ConnectionChangedParams.cs} (68%) create mode 100644 src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionDetails.cs create mode 100644 src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionRequest.cs create mode 100644 src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionSummary.cs create mode 100644 src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionSummaryExtensions.cs rename src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/{DisconnectMessages.cs => DisconnectParams.cs} (63%) create mode 100644 src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/DisconnectRequest.cs diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionInfo.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionInfo.cs index 7490b33c..31d0026d 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionInfo.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionInfo.cs @@ -14,6 +14,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection /// public class ConnectionInfo { + /// + /// Constructor + /// public ConnectionInfo(ISqlConnectionFactory factory, string ownerUri, ConnectionDetails details) { Factory = factory; @@ -27,12 +30,24 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection /// public Guid ConnectionId { get; private set; } + /// + /// URI identifying the owner/user of the connection. Could be a file, service, resource, etc. + /// public string OwnerUri { get; private set; } + /// + /// Factory used for creating the SQL connection associated with the connection info. + /// public ISqlConnectionFactory Factory {get; private set;} + /// + /// Properties used for creating/opening the SQL connection. + /// public ConnectionDetails ConnectionDetails { get; private set; } + /// + /// The connection to the SQL database that commands will be run against. + /// public DbConnection SqlConnection { get; set; } } } diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectMessages.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectMessages.cs deleted file mode 100644 index 543b18f5..00000000 --- a/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectMessages.cs +++ /dev/null @@ -1,89 +0,0 @@ -// -// Copyright (c) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -// - -using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; - -namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts -{ - /// - /// Parameters for the Connect Request. - /// - public class ConnectParams - { - /// - /// A URI identifying the owner of the connection. This will most commonly be a file in the workspace - /// or a virtual file representing an object in a database. - /// - public string OwnerUri { get; set; } - /// - /// Contains the required parameters to initialize a connection to a database. - /// A connection will identified by its server name, database name and user name. - /// This may be changed in the future to support multiple connections with different - /// connection properties to the same database. - /// - public ConnectionDetails Connection { get; set; } - } - - /// - /// Message format for the connection result response - /// - public class ConnectResponse - { - /// - /// A GUID representing a unique connection ID - /// - public string ConnectionId { get; set; } - - /// - /// Gets or sets any connection error messages - /// - public string Messages { get; set; } - } - - /// - /// Provides high level information about a connection. - /// - public class ConnectionSummary - { - /// - /// Gets or sets the connection server name - /// - public string ServerName { get; set; } - - /// - /// Gets or sets the connection database name - /// - public string DatabaseName { get; set; } - - /// - /// Gets or sets the connection user name - /// - public string UserName { get; set; } - } - - /// - /// Message format for the initial connection request - /// - public class ConnectionDetails : ConnectionSummary - { - /// - /// Gets or sets the connection password - /// - /// - public string Password { get; set; } - - // TODO Handle full set of properties - } - - /// - /// Connect request mapping entry - /// - public class ConnectionRequest - { - public static readonly - RequestType Type = - RequestType.Create("connection/connect"); - } -} diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectParams.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectParams.cs new file mode 100644 index 00000000..31dad8c5 --- /dev/null +++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectParams.cs @@ -0,0 +1,26 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts +{ + /// + /// Parameters for the Connect Request. + /// + public class ConnectParams + { + /// + /// A URI identifying the owner of the connection. This will most commonly be a file in the workspace + /// or a virtual file representing an object in a database. + /// + public string OwnerUri { get; set; } + /// + /// Contains the required parameters to initialize a connection to a database. + /// A connection will identified by its server name, database name and user name. + /// This may be changed in the future to support multiple connections with different + /// connection properties to the same database. + /// + public ConnectionDetails Connection { get; set; } + } +} diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectMessagesExtensions.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectParamsExtensions.cs similarity index 64% rename from src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectMessagesExtensions.cs rename to src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectParamsExtensions.cs index d15adae6..b9e73e09 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectMessagesExtensions.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectParamsExtensions.cs @@ -27,23 +27,4 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts ); } } - - /// - /// Extension methods to ConnectionSummary - /// - public static class ConnectionSummaryExtensions - { - /// - /// Create a copy of a ConnectionSummary object - /// - public static ConnectionSummary Clone(this ConnectionSummary summary) - { - return new ConnectionSummary() - { - ServerName = summary.ServerName, - DatabaseName = summary.DatabaseName, - UserName = summary.UserName - }; - } - } } diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectResponse.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectResponse.cs new file mode 100644 index 00000000..c325c64f --- /dev/null +++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectResponse.cs @@ -0,0 +1,23 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts +{ + /// + /// Message format for the connection result response + /// + public class ConnectResponse + { + /// + /// A GUID representing a unique connection ID + /// + public string ConnectionId { get; set; } + + /// + /// Gets or sets any connection error messages + /// + public string Messages { get; set; } + } +} diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionChangedNotification.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionChangedNotification.cs new file mode 100644 index 00000000..c0daee6d --- /dev/null +++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionChangedNotification.cs @@ -0,0 +1,19 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; + +namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts +{ + /// + /// ConnectionChanged notification mapping entry + /// + public class ConnectionChangedNotification + { + public static readonly + EventType Type = + EventType.Create("connection/connectionchanged"); + } +} diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionChangedMessages.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionChangedParams.cs similarity index 68% rename from src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionChangedMessages.cs rename to src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionChangedParams.cs index 94454bc5..3db86f34 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionChangedMessages.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionChangedParams.cs @@ -3,8 +3,6 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; - namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts { /// @@ -22,15 +20,4 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts /// public ConnectionSummary Connection { get; set; } } - - /// - /// ConnectionChanged notification mapping entry - /// - public class ConnectionChangedNotification - { - public static readonly - EventType Type = - EventType.Create("connection/connectionchanged"); - } - } diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionDetails.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionDetails.cs new file mode 100644 index 00000000..0acac867 --- /dev/null +++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionDetails.cs @@ -0,0 +1,21 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts +{ + /// + /// Message format for the initial connection request + /// + public class ConnectionDetails : ConnectionSummary + { + /// + /// Gets or sets the connection password + /// + /// + public string Password { get; set; } + + // TODO Handle full set of properties + } +} diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionRequest.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionRequest.cs new file mode 100644 index 00000000..50251e12 --- /dev/null +++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionRequest.cs @@ -0,0 +1,19 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; + +namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts +{ + /// + /// Connect request mapping entry + /// + public class ConnectionRequest + { + public static readonly + RequestType Type = + RequestType.Create("connection/connect"); + } +} diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionSummary.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionSummary.cs new file mode 100644 index 00000000..11549e85 --- /dev/null +++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionSummary.cs @@ -0,0 +1,28 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts +{ + /// + /// Provides high level information about a connection. + /// + public class ConnectionSummary + { + /// + /// Gets or sets the connection server name + /// + public string ServerName { get; set; } + + /// + /// Gets or sets the connection database name + /// + public string DatabaseName { get; set; } + + /// + /// Gets or sets the connection user name + /// + public string UserName { get; set; } + } +} diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionSummaryExtensions.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionSummaryExtensions.cs new file mode 100644 index 00000000..02bc7623 --- /dev/null +++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionSummaryExtensions.cs @@ -0,0 +1,26 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts +{ + /// + /// Extension methods to ConnectionSummary + /// + public static class ConnectionSummaryExtensions + { + /// + /// Create a copy of a ConnectionSummary object + /// + public static ConnectionSummary Clone(this ConnectionSummary summary) + { + return new ConnectionSummary() + { + ServerName = summary.ServerName, + DatabaseName = summary.DatabaseName, + UserName = summary.UserName + }; + } + } +} diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/DisconnectMessages.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/DisconnectParams.cs similarity index 63% rename from src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/DisconnectMessages.cs rename to src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/DisconnectParams.cs index c078b308..91bc7faf 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/DisconnectMessages.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/DisconnectParams.cs @@ -3,8 +3,6 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; - namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts { /// @@ -18,14 +16,4 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts /// public string OwnerUri { get; set; } } - - /// - /// Disconnect request mapping entry - /// - public class DisconnectRequest - { - public static readonly - RequestType Type = - RequestType.Create("connection/disconnect"); - } } diff --git a/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/DisconnectRequest.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/DisconnectRequest.cs new file mode 100644 index 00000000..cbf67ef2 --- /dev/null +++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/DisconnectRequest.cs @@ -0,0 +1,19 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; + +namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts +{ + /// + /// Disconnect request mapping entry + /// + public class DisconnectRequest + { + public static readonly + RequestType Type = + RequestType.Create("connection/disconnect"); + } +} diff --git a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/IntellisenseCache.cs b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/IntellisenseCache.cs index ca4c155a..eea72771 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/IntellisenseCache.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/IntellisenseCache.cs @@ -14,14 +14,17 @@ using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts; namespace Microsoft.SqlTools.ServiceLayer.LanguageServices { - internal class IntellisenseCache { - // connection used to query for intellisense info + /// + /// connection used to query for intellisense info + /// private DbConnection connection; - // number of documents (URI's) that are using the cache for the same database - // the autocomplete service uses this to remove unreferenced caches + /// + /// Number of documents (URI's) that are using the cache for the same database. + /// The autocomplete service uses this to remove unreferenced caches. + /// public int ReferenceCount { get; set; } public IntellisenseCache(ISqlConnectionFactory connectionFactory, ConnectionDetails connectionDetails)