From 2ea5cf345750acbcbdf769144b33a8dc14a775c6 Mon Sep 17 00:00:00 2001 From: Benjamin Russell Date: Wed, 27 Jul 2016 16:45:01 -0700 Subject: [PATCH 1/5] Quick refactor of the connection service Refactoring to match the layout of the other services. --- .../ConnectionService.cs | 0 .../Contracts}/ConnectionMessages.cs | 2 +- .../Contracts}/ISqlConnection.cs | 13 +---------- .../Contracts/ISqlConnectionFactory.cs | 18 +++++++++++++++ .../Contracts}/SqlConnection.cs | 18 +-------------- .../Contracts/SqlConnectionFactory.cs | 23 +++++++++++++++++++ 6 files changed, 44 insertions(+), 30 deletions(-) rename src/ServiceHost/{Connection => ConnectionServices}/ConnectionService.cs (100%) rename src/ServiceHost/{Connection => ConnectionServices/Contracts}/ConnectionMessages.cs (96%) rename src/ServiceHost/{Connection => ConnectionServices/Contracts}/ISqlConnection.cs (64%) create mode 100644 src/ServiceHost/ConnectionServices/Contracts/ISqlConnectionFactory.cs rename src/ServiceHost/{Connection => ConnectionServices/Contracts}/SqlConnection.cs (76%) create mode 100644 src/ServiceHost/ConnectionServices/Contracts/SqlConnectionFactory.cs diff --git a/src/ServiceHost/Connection/ConnectionService.cs b/src/ServiceHost/ConnectionServices/ConnectionService.cs similarity index 100% rename from src/ServiceHost/Connection/ConnectionService.cs rename to src/ServiceHost/ConnectionServices/ConnectionService.cs diff --git a/src/ServiceHost/Connection/ConnectionMessages.cs b/src/ServiceHost/ConnectionServices/Contracts/ConnectionMessages.cs similarity index 96% rename from src/ServiceHost/Connection/ConnectionMessages.cs rename to src/ServiceHost/ConnectionServices/Contracts/ConnectionMessages.cs index a2b506aa..ddbca266 100644 --- a/src/ServiceHost/Connection/ConnectionMessages.cs +++ b/src/ServiceHost/ConnectionServices/Contracts/ConnectionMessages.cs @@ -5,7 +5,7 @@ using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; -namespace Microsoft.SqlTools.ServiceLayer.Connection +namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices.Contracts { /// /// Message format for the initial connection request diff --git a/src/ServiceHost/Connection/ISqlConnection.cs b/src/ServiceHost/ConnectionServices/Contracts/ISqlConnection.cs similarity index 64% rename from src/ServiceHost/Connection/ISqlConnection.cs rename to src/ServiceHost/ConnectionServices/Contracts/ISqlConnection.cs index 3e5fbdfe..a9a255f3 100644 --- a/src/ServiceHost/Connection/ISqlConnection.cs +++ b/src/ServiceHost/ConnectionServices/Contracts/ISqlConnection.cs @@ -5,19 +5,8 @@ using System.Collections.Generic; -namespace Microsoft.SqlTools.ServiceLayer.Connection +namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices.Contracts { - /// - /// Interface for the SQL Connection factory - /// - public interface ISqlConnectionFactory - { - /// - /// Create a new SQL Connection object - /// - ISqlConnection CreateSqlConnection(); - } - /// /// Interface for the SQL Connection wrapper /// diff --git a/src/ServiceHost/ConnectionServices/Contracts/ISqlConnectionFactory.cs b/src/ServiceHost/ConnectionServices/Contracts/ISqlConnectionFactory.cs new file mode 100644 index 00000000..0a79ec0d --- /dev/null +++ b/src/ServiceHost/ConnectionServices/Contracts/ISqlConnectionFactory.cs @@ -0,0 +1,18 @@ +// +// 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.ConnectionServices.Contracts +{ + /// + /// Interface for the SQL Connection factory + /// + public interface ISqlConnectionFactory + { + /// + /// Create a new SQL Connection object + /// + ISqlConnection CreateSqlConnection(); + } +} diff --git a/src/ServiceHost/Connection/SqlConnection.cs b/src/ServiceHost/ConnectionServices/Contracts/SqlConnection.cs similarity index 76% rename from src/ServiceHost/Connection/SqlConnection.cs rename to src/ServiceHost/ConnectionServices/Contracts/SqlConnection.cs index 6ad90b39..937deaa1 100644 --- a/src/ServiceHost/Connection/SqlConnection.cs +++ b/src/ServiceHost/ConnectionServices/Contracts/SqlConnection.cs @@ -7,24 +7,8 @@ using System.Collections.Generic; using System.Data; using System.Data.SqlClient; -namespace Microsoft.SqlTools.ServiceLayer.Connection +namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices.Contracts { - /// - /// Factory class to create SqlClientConnections - /// The purpose of the factory is to make it easier to mock out the database - /// in 'offline' unit test scenarios. - /// - public class SqlConnectionFactory : ISqlConnectionFactory - { - /// - /// Creates a new SqlClientConnection object - /// - public ISqlConnection CreateSqlConnection() - { - return new SqlClientConnection(); - } - } - /// /// Wrapper class that implements ISqlConnection and hosts a SqlConnection. /// This wrapper exists primarily for decoupling to support unit testing. diff --git a/src/ServiceHost/ConnectionServices/Contracts/SqlConnectionFactory.cs b/src/ServiceHost/ConnectionServices/Contracts/SqlConnectionFactory.cs new file mode 100644 index 00000000..79fbae51 --- /dev/null +++ b/src/ServiceHost/ConnectionServices/Contracts/SqlConnectionFactory.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.ConnectionServices.Contracts +{ + /// + /// Factory class to create SqlClientConnections + /// The purpose of the factory is to make it easier to mock out the database + /// in 'offline' unit test scenarios. + /// + public class SqlConnectionFactory : ISqlConnectionFactory + { + /// + /// Creates a new SqlClientConnection object + /// + public ISqlConnection CreateSqlConnection() + { + return new SqlClientConnection(); + } + } +} From bc0383b6e6ad1d6cbf0539e1817bcd7daf36cc8d Mon Sep 17 00:00:00 2001 From: Benjamin Russell Date: Wed, 27 Jul 2016 18:03:55 -0700 Subject: [PATCH 2/5] Expanding SqlConnection to be more like DBConnection Also shifting the Connect operation to be async --- .../ConnectionServices/ConnectionService.cs | 21 ++- .../Contracts/ISqlConnection.cs | 28 ++- .../Contracts/ISqlConnectionFactory.cs | 2 +- .../Contracts/SqlConnection.cs | 175 +++++++++++++++--- .../Contracts/SqlConnectionFactory.cs | 4 +- src/ServiceHost/Program.cs | 2 +- 6 files changed, 186 insertions(+), 46 deletions(-) diff --git a/src/ServiceHost/ConnectionServices/ConnectionService.cs b/src/ServiceHost/ConnectionServices/ConnectionService.cs index afbf4ab4..1b62ab50 100644 --- a/src/ServiceHost/ConnectionServices/ConnectionService.cs +++ b/src/ServiceHost/ConnectionServices/ConnectionService.cs @@ -6,12 +6,14 @@ using System; using System.Collections.Generic; using System.Data.SqlClient; +using System.Linq; using System.Threading.Tasks; using Microsoft.SqlTools.EditorServices.Utility; using Microsoft.SqlTools.ServiceLayer.Hosting; using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol; +using Microsoft.SqlTools.ServiceLayer.ConnectionServices.Contracts; -namespace Microsoft.SqlTools.ServiceLayer.Connection +namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices { /// /// Main class for the Connection Management services @@ -119,25 +121,24 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection /// Open a connection with the specified connection details /// /// - public ConnectionResult Connect(ConnectionDetails connectionDetails) + public async Task Connect(ConnectionDetails connectionDetails) { // build the connection string from the input parameters string connectionString = BuildConnectionString(connectionDetails); // create a sql connection instance - ISqlConnection connection = this.ConnectionFactory.CreateSqlConnection(); + ISqlConnection connection = ConnectionFactory.CreateSqlConnection(connectionString); // open the database - connection.OpenDatabaseConnection(connectionString); + await connection.OpenAsync(); // map the connection id to the connection object for future lookups - this.ActiveConnections.Add(++maxConnectionId, connection); + ActiveConnections.Add(++maxConnectionId, connection); // invoke callback notifications - foreach (var activity in this.onConnectionActivities) - { - activity(connection); - } + var onConnectionCallbackTasks = onConnectionActivities.Select(t => t(connection)); + await Task.WhenAll(onConnectionCallbackTasks); + // TODO: Evaulate if we want to avoid waiting here. We'll need error handling on the other side if we don't wait // return the connection result return new ConnectionResult() @@ -178,7 +179,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection Logger.Write(LogLevel.Verbose, "HandleConnectRequest"); // open connection base on request details - ConnectionResult result = ConnectionService.Instance.Connect(connectionDetails); + ConnectionResult result = await Connect(connectionDetails); await requestContext.SendResult(result); } diff --git a/src/ServiceHost/ConnectionServices/Contracts/ISqlConnection.cs b/src/ServiceHost/ConnectionServices/Contracts/ISqlConnection.cs index a9a255f3..3ee1cb73 100644 --- a/src/ServiceHost/ConnectionServices/Contracts/ISqlConnection.cs +++ b/src/ServiceHost/ConnectionServices/Contracts/ISqlConnection.cs @@ -3,21 +3,33 @@ // 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.Threading; +using System.Threading.Tasks; namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices.Contracts { /// /// Interface for the SQL Connection wrapper /// - public interface ISqlConnection + public interface ISqlConnection : IDbConnection { - /// - /// Open a connection to the provided connection string - /// - /// - void OpenDatabaseConnection(string connectionString); + ///// + ///// Open a connection to the provided connection string + ///// + ///// + //void OpenDatabaseConnection(string connectionString); - IEnumerable GetServerObjects(); + //IEnumerable GetServerObjects(); + + string DataSource { get; } + + string ServerVersion { get; } + + void ClearPool(); + + Task OpenAsync(); + + Task OpenAsync(CancellationToken token); } } diff --git a/src/ServiceHost/ConnectionServices/Contracts/ISqlConnectionFactory.cs b/src/ServiceHost/ConnectionServices/Contracts/ISqlConnectionFactory.cs index 0a79ec0d..664ca374 100644 --- a/src/ServiceHost/ConnectionServices/Contracts/ISqlConnectionFactory.cs +++ b/src/ServiceHost/ConnectionServices/Contracts/ISqlConnectionFactory.cs @@ -13,6 +13,6 @@ namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices.Contracts /// /// Create a new SQL Connection object /// - ISqlConnection CreateSqlConnection(); + ISqlConnection CreateSqlConnection(string connectionString); } } diff --git a/src/ServiceHost/ConnectionServices/Contracts/SqlConnection.cs b/src/ServiceHost/ConnectionServices/Contracts/SqlConnection.cs index 937deaa1..ee08af1a 100644 --- a/src/ServiceHost/ConnectionServices/Contracts/SqlConnection.cs +++ b/src/ServiceHost/ConnectionServices/Contracts/SqlConnection.cs @@ -3,9 +3,11 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -using System.Collections.Generic; +using System; using System.Data; using System.Data.SqlClient; +using System.Threading; +using System.Threading.Tasks; namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices.Contracts { @@ -21,36 +23,161 @@ namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices.Contracts private SqlConnection connection; /// - /// Opens a SqlConnection using provided connection string + /// Creates a new instance of the SqlClientConnection with an underlying connection to the + /// database server provided in . /// - /// - public void OpenDatabaseConnection(string connectionString) + /// Connection string for the database to connect to + public SqlClientConnection(string connectionString) { - this.connection = new SqlConnection(connectionString); - this.connection.Open(); + connection = new SqlConnection(connectionString); } - /// - /// Gets a list of database server schema objects - /// - /// - public IEnumerable GetServerObjects() - { - // Select the values from sys.tables to give a super basic - // autocomplete experience. This will be replaced by SMO. - SqlCommand command = connection.CreateCommand(); - command.CommandText = "SELECT name FROM sys.tables"; - command.CommandTimeout = 15; - command.CommandType = CommandType.Text; - var reader = command.ExecuteReader(); + ///// + ///// Gets a list of database server schema objects + ///// + ///// + //public IEnumerable GetServerObjects() + //{ + // // Select the values from sys.tables to give a super basic + // // autocomplete experience. This will be replaced by SMO. + // SqlCommand command = connection.CreateCommand(); + // command.CommandText = "SELECT name FROM sys.tables"; + // command.CommandTimeout = 15; + // command.CommandType = CommandType.Text; + // var reader = command.ExecuteReader(); - List results = new List(); - while (reader.Read()) + // List results = new List(); + // while (reader.Read()) + // { + // results.Add(reader[0].ToString()); + // } + + // return results; + //} + + #region ISqlConnection Implementation + + #region Properties + + public string ConnectionString + { + get { return connection.ConnectionString; } + set { connection.ConnectionString = value; } + } + + public int ConnectionTimeout + { + get { return connection.ConnectionTimeout; } + } + + public string Database + { + get { return connection.Database; } + } + + public string DataSource + { + get { return connection.DataSource; } + } + + public string ServerVersion + { + get { return connection.ServerVersion; } + } + + public ConnectionState State + { + get { return connection.State; } + } + + #endregion + + #region Public Methods + + public IDbTransaction BeginTransaction() + { + return connection.BeginTransaction(); + } + + public IDbTransaction BeginTransaction(IsolationLevel il) + { + return connection.BeginTransaction(il); + } + + public void ChangeDatabase(string databaseName) + { + connection.ChangeDatabase(databaseName); + } + + public void ClearPool() + { + if (connection != null) { - results.Add(reader[0].ToString()); + SqlConnection.ClearPool(connection); } - - return results; } + + public void Close() + { + connection.Close(); + } + + public IDbCommand CreateCommand() + { + return connection.CreateCommand(); + } + + public void Open() + { + connection.Open(); + } + + public Task OpenAsync() + { + return connection.OpenAsync(); + } + + public Task OpenAsync(CancellationToken token) + { + return connection.OpenAsync(token); + } + + #endregion + + #endregion + + #region IDisposable Implementation + + private bool disposed; + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + private void Dispose(bool disposing) + { + if (!disposed) + { + if (disposing) + { + if (connection.State == ConnectionState.Open) + { + connection.Close(); + } + connection.Dispose(); + } + disposed = true; + } + } + + ~SqlClientConnection() + { + Dispose(false); + } + + #endregion + } } diff --git a/src/ServiceHost/ConnectionServices/Contracts/SqlConnectionFactory.cs b/src/ServiceHost/ConnectionServices/Contracts/SqlConnectionFactory.cs index 79fbae51..9fbe21f0 100644 --- a/src/ServiceHost/ConnectionServices/Contracts/SqlConnectionFactory.cs +++ b/src/ServiceHost/ConnectionServices/Contracts/SqlConnectionFactory.cs @@ -15,9 +15,9 @@ namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices.Contracts /// /// Creates a new SqlClientConnection object /// - public ISqlConnection CreateSqlConnection() + public ISqlConnection CreateSqlConnection(string connectionString) { - return new SqlClientConnection(); + return new SqlClientConnection(connectionString); } } } diff --git a/src/ServiceHost/Program.cs b/src/ServiceHost/Program.cs index a3f9cf8b..aa040bad 100644 --- a/src/ServiceHost/Program.cs +++ b/src/ServiceHost/Program.cs @@ -7,7 +7,7 @@ using Microsoft.SqlTools.ServiceLayer.Hosting; using Microsoft.SqlTools.ServiceLayer.SqlContext; using Microsoft.SqlTools.ServiceLayer.WorkspaceServices; using Microsoft.SqlTools.ServiceLayer.LanguageServices; -using Microsoft.SqlTools.ServiceLayer.Connection; +using Microsoft.SqlTools.ServiceLayer.ConnectionServices; namespace Microsoft.SqlTools.ServiceLayer { From d78c1947e09a04c1b10af5fa40bc2cddb3880fae Mon Sep 17 00:00:00 2001 From: Benjamin Russell Date: Fri, 29 Jul 2016 12:52:24 -0700 Subject: [PATCH 3/5] Stubbing out connectionservice with guid id --- .../ConnectionServices/ConnectionService.cs | 63 +++++++++++++++---- .../Contracts/ConnectionMessages.cs | 3 +- .../Contracts/ISqlConnection.cs | 9 +-- .../Contracts/SqlConnection.cs | 23 ------- .../LanguageServices/AutoCompleteService.cs | 20 +++++- .../LanguageServices/LanguageService.cs | 3 +- 6 files changed, 74 insertions(+), 47 deletions(-) diff --git a/src/ServiceHost/ConnectionServices/ConnectionService.cs b/src/ServiceHost/ConnectionServices/ConnectionService.cs index 1b62ab50..d7f11fe1 100644 --- a/src/ServiceHost/ConnectionServices/ConnectionService.cs +++ b/src/ServiceHost/ConnectionServices/ConnectionService.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; +using System.Data; using System.Data.SqlClient; using System.Linq; using System.Threading.Tasks; @@ -55,17 +56,12 @@ namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices /// private ISqlConnectionFactory connectionFactory; - /// - /// The current connection id that was previously used - /// - private int maxConnectionId = 0; - /// /// Active connections lazy dictionary instance /// - private Lazy> activeConnections - = new Lazy>(() - => new Dictionary()); + private Lazy> activeConnections + = new Lazy>(() + => new Dictionary()); /// /// Callback for onconnection handler @@ -81,7 +77,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices /// /// Gets the active connection map /// - public Dictionary ActiveConnections + public Dictionary ActiveConnections { get { @@ -133,7 +129,8 @@ namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices await connection.OpenAsync(); // map the connection id to the connection object for future lookups - ActiveConnections.Add(++maxConnectionId, connection); + Guid connectionId = Guid.NewGuid(); + ActiveConnections.Add(connectionId, connection); // invoke callback notifications var onConnectionCallbackTasks = onConnectionActivities.Select(t => t(connection)); @@ -141,16 +138,35 @@ namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices // TODO: Evaulate if we want to avoid waiting here. We'll need error handling on the other side if we don't wait // return the connection result - return new ConnectionResult() + return new ConnectionResult { - ConnectionId = maxConnectionId + ConnectionId = connectionId }; } + /// + /// Closes an active connection and removes it from the active connections list + /// + /// ID of the connection to close + public void Disconnect(Guid connectionId) + { + if (!ActiveConnections.ContainsKey(connectionId)) + { + // TODO: Should this possibly be a throw condition? + return; + } + + ActiveConnections[connectionId].Close(); + ActiveConnections.Remove(connectionId); + } + public void Initialize(ServiceHost serviceHost) { // Register request and event handlers with the Service Host serviceHost.SetRequestHandler(ConnectionRequest.Type, HandleConnectRequest); + + // Register the shutdown handler + serviceHost.RegisterShutdownTask(HandleShutdownRequest); } /// @@ -162,6 +178,15 @@ namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices onConnectionActivities.Add(activity); } + public ISqlConnection GetConnection(Guid connectionId) + { + if (!ActiveConnections.ContainsKey(connectionId)) + { + throw new ArgumentException("Connection with provided ID could not be found"); + } + return ActiveConnections[connectionId]; + } + #endregion #region Request Handlers @@ -184,6 +209,20 @@ namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices await requestContext.SendResult(result); } + /// + /// Handles shutdown event by closing out any active connections + /// + protected async Task HandleShutdownRequest(object shutdownObj, RequestContext shutdownContext) + { + // Go through all the existing connections and close them out + foreach (ISqlConnection conn in ActiveConnections.Values) + { + conn.Close(); + } + + await Task.FromResult(0); + } + #endregion #region Private Helpers diff --git a/src/ServiceHost/ConnectionServices/Contracts/ConnectionMessages.cs b/src/ServiceHost/ConnectionServices/Contracts/ConnectionMessages.cs index ddbca266..20463704 100644 --- a/src/ServiceHost/ConnectionServices/Contracts/ConnectionMessages.cs +++ b/src/ServiceHost/ConnectionServices/Contracts/ConnectionMessages.cs @@ -3,6 +3,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // +using System; using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices.Contracts @@ -42,7 +43,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices.Contracts /// /// Gets or sets the connection id /// - public int ConnectionId { get; set; } + public Guid ConnectionId { get; set; } /// /// Gets or sets any connection error messages diff --git a/src/ServiceHost/ConnectionServices/Contracts/ISqlConnection.cs b/src/ServiceHost/ConnectionServices/Contracts/ISqlConnection.cs index 3ee1cb73..026c124f 100644 --- a/src/ServiceHost/ConnectionServices/Contracts/ISqlConnection.cs +++ b/src/ServiceHost/ConnectionServices/Contracts/ISqlConnection.cs @@ -3,6 +3,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // +using System; using System.Data; using System.Threading; using System.Threading.Tasks; @@ -14,14 +15,6 @@ namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices.Contracts /// public interface ISqlConnection : IDbConnection { - ///// - ///// Open a connection to the provided connection string - ///// - ///// - //void OpenDatabaseConnection(string connectionString); - - //IEnumerable GetServerObjects(); - string DataSource { get; } string ServerVersion { get; } diff --git a/src/ServiceHost/ConnectionServices/Contracts/SqlConnection.cs b/src/ServiceHost/ConnectionServices/Contracts/SqlConnection.cs index ee08af1a..8e39f7d4 100644 --- a/src/ServiceHost/ConnectionServices/Contracts/SqlConnection.cs +++ b/src/ServiceHost/ConnectionServices/Contracts/SqlConnection.cs @@ -32,29 +32,6 @@ namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices.Contracts connection = new SqlConnection(connectionString); } - ///// - ///// Gets a list of database server schema objects - ///// - ///// - //public IEnumerable GetServerObjects() - //{ - // // Select the values from sys.tables to give a super basic - // // autocomplete experience. This will be replaced by SMO. - // SqlCommand command = connection.CreateCommand(); - // command.CommandText = "SELECT name FROM sys.tables"; - // command.CommandTimeout = 15; - // command.CommandType = CommandType.Text; - // var reader = command.ExecuteReader(); - - // List results = new List(); - // while (reader.Read()) - // { - // results.Add(reader[0].ToString()); - // } - - // return results; - //} - #region ISqlConnection Implementation #region Properties diff --git a/src/ServiceHost/LanguageServices/AutoCompleteService.cs b/src/ServiceHost/LanguageServices/AutoCompleteService.cs index 67981ae5..5001e1cc 100644 --- a/src/ServiceHost/LanguageServices/AutoCompleteService.cs +++ b/src/ServiceHost/LanguageServices/AutoCompleteService.cs @@ -5,8 +5,11 @@ using System; using System.Collections.Generic; +using System.Data; +using System.Data.SqlClient; using System.Threading.Tasks; -using Microsoft.SqlTools.ServiceLayer.Connection; +using Microsoft.SqlTools.ServiceLayer.ConnectionServices; +using Microsoft.SqlTools.ServiceLayer.ConnectionServices.Contracts; using Microsoft.SqlTools.ServiceLayer.Hosting; using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts; using Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts; @@ -60,11 +63,24 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices /// /// Update the cached autocomplete candidate list when the user connects to a database + /// TODO: Update with refactoring/async /// /// public async Task UpdateAutoCompleteCache(ISqlConnection connection) { - AutoCompleteList = connection.GetServerObjects(); + IDbCommand command = connection.CreateCommand(); + command.CommandText = "SELECT name FROM sys.tables"; + command.CommandTimeout = 15; + command.CommandType = CommandType.Text; + var reader = command.ExecuteReader(); + + List results = new List(); + while (reader.Read()) + { + results.Add(reader[0].ToString()); + } + + AutoCompleteList = results; await Task.FromResult(0); } diff --git a/src/ServiceHost/LanguageServices/LanguageService.cs b/src/ServiceHost/LanguageServices/LanguageService.cs index eb643c0c..e2fb0cb0 100644 --- a/src/ServiceHost/LanguageServices/LanguageService.cs +++ b/src/ServiceHost/LanguageServices/LanguageService.cs @@ -17,7 +17,8 @@ using Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts; using System.Linq; using Microsoft.SqlServer.Management.SqlParser.Parser; using Location = Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts.Location; -using Microsoft.SqlTools.ServiceLayer.Connection; +using Microsoft.SqlTools.ServiceLayer.ConnectionServices; +using Microsoft.SqlTools.ServiceLayer.ConnectionServices.Contracts; namespace Microsoft.SqlTools.ServiceLayer.LanguageServices { From b2f44031b7cd86f51544a4ea5788ab642cca8c73 Mon Sep 17 00:00:00 2001 From: Benjamin Russell Date: Tue, 2 Aug 2016 18:19:51 -0700 Subject: [PATCH 4/5] Switching from ISqlConnection to DbConnection This is a fairly minor change that will save tons of time as we develop this service. The DbConnection and associated Db* abstract classes ask for synchronous versions of the code and allow the addition of async code. The SqlClient implementation already implements Db* abstract classes, so we can piggy back off that for our dependency injection layer. Tests and existing code has been updated to handle the change, as well --- .../ConnectionServices/ConnectionService.cs | 13 +- .../Contracts/ISqlConnection.cs | 28 --- .../Contracts/ISqlConnectionFactory.cs | 4 +- .../Contracts/SqlConnection.cs | 160 ------------ .../Contracts/SqlConnectionFactory.cs | 7 +- .../LanguageServices/AutoCompleteService.cs | 11 +- .../LanguageServices/LanguageService.cs | 3 +- .../Utility/TestObjects.cs | 229 +++++++----------- 8 files changed, 104 insertions(+), 351 deletions(-) delete mode 100644 src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/Contracts/ISqlConnection.cs delete mode 100644 src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/Contracts/SqlConnection.cs diff --git a/src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/ConnectionService.cs b/src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/ConnectionService.cs index 90b7c61f..32ff5720 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/ConnectionService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/ConnectionService.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; +using System.Data.Common; using System.Data.SqlClient; using System.Threading.Tasks; using Microsoft.SqlTools.EditorServices.Utility; @@ -64,15 +65,15 @@ namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices /// /// Active connections lazy dictionary instance /// - private Lazy> activeConnections - = new Lazy>(() - => new Dictionary()); + private readonly Lazy> activeConnections + = new Lazy>(() + => new Dictionary()); /// /// Callback for onconnection handler /// /// - public delegate Task OnConnectionHandler(ISqlConnection sqlConnection); + public delegate Task OnConnectionHandler(DbConnection sqlConnection); /// /// List of onconnection handlers @@ -82,7 +83,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices /// /// Gets the active connection map /// - public Dictionary ActiveConnections + public Dictionary ActiveConnections { get { @@ -128,7 +129,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices string connectionString = BuildConnectionString(connectionDetails); // create a sql connection instance - ISqlConnection connection = this.ConnectionFactory.CreateSqlConnection(connectionString); + DbConnection connection = this.ConnectionFactory.CreateSqlConnection(connectionString); // open the database connection.Open(); diff --git a/src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/Contracts/ISqlConnection.cs b/src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/Contracts/ISqlConnection.cs deleted file mode 100644 index 026c124f..00000000 --- a/src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/Contracts/ISqlConnection.cs +++ /dev/null @@ -1,28 +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 System; -using System.Data; -using System.Threading; -using System.Threading.Tasks; - -namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices.Contracts -{ - /// - /// Interface for the SQL Connection wrapper - /// - public interface ISqlConnection : IDbConnection - { - string DataSource { get; } - - string ServerVersion { get; } - - void ClearPool(); - - Task OpenAsync(); - - Task OpenAsync(CancellationToken token); - } -} diff --git a/src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/Contracts/ISqlConnectionFactory.cs b/src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/Contracts/ISqlConnectionFactory.cs index 664ca374..1edb6501 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/Contracts/ISqlConnectionFactory.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/Contracts/ISqlConnectionFactory.cs @@ -3,6 +3,8 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // +using System.Data.Common; + namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices.Contracts { /// @@ -13,6 +15,6 @@ namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices.Contracts /// /// Create a new SQL Connection object /// - ISqlConnection CreateSqlConnection(string connectionString); + DbConnection CreateSqlConnection(string connectionString); } } diff --git a/src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/Contracts/SqlConnection.cs b/src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/Contracts/SqlConnection.cs deleted file mode 100644 index 8e39f7d4..00000000 --- a/src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/Contracts/SqlConnection.cs +++ /dev/null @@ -1,160 +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 System; -using System.Data; -using System.Data.SqlClient; -using System.Threading; -using System.Threading.Tasks; - -namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices.Contracts -{ - /// - /// Wrapper class that implements ISqlConnection and hosts a SqlConnection. - /// This wrapper exists primarily for decoupling to support unit testing. - /// - public class SqlClientConnection : ISqlConnection - { - /// - /// the underlying SQL connection - /// - private SqlConnection connection; - - /// - /// Creates a new instance of the SqlClientConnection with an underlying connection to the - /// database server provided in . - /// - /// Connection string for the database to connect to - public SqlClientConnection(string connectionString) - { - connection = new SqlConnection(connectionString); - } - - #region ISqlConnection Implementation - - #region Properties - - public string ConnectionString - { - get { return connection.ConnectionString; } - set { connection.ConnectionString = value; } - } - - public int ConnectionTimeout - { - get { return connection.ConnectionTimeout; } - } - - public string Database - { - get { return connection.Database; } - } - - public string DataSource - { - get { return connection.DataSource; } - } - - public string ServerVersion - { - get { return connection.ServerVersion; } - } - - public ConnectionState State - { - get { return connection.State; } - } - - #endregion - - #region Public Methods - - public IDbTransaction BeginTransaction() - { - return connection.BeginTransaction(); - } - - public IDbTransaction BeginTransaction(IsolationLevel il) - { - return connection.BeginTransaction(il); - } - - public void ChangeDatabase(string databaseName) - { - connection.ChangeDatabase(databaseName); - } - - public void ClearPool() - { - if (connection != null) - { - SqlConnection.ClearPool(connection); - } - } - - public void Close() - { - connection.Close(); - } - - public IDbCommand CreateCommand() - { - return connection.CreateCommand(); - } - - public void Open() - { - connection.Open(); - } - - public Task OpenAsync() - { - return connection.OpenAsync(); - } - - public Task OpenAsync(CancellationToken token) - { - return connection.OpenAsync(token); - } - - #endregion - - #endregion - - #region IDisposable Implementation - - private bool disposed; - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - private void Dispose(bool disposing) - { - if (!disposed) - { - if (disposing) - { - if (connection.State == ConnectionState.Open) - { - connection.Close(); - } - connection.Dispose(); - } - disposed = true; - } - } - - ~SqlClientConnection() - { - Dispose(false); - } - - #endregion - - } -} diff --git a/src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/Contracts/SqlConnectionFactory.cs b/src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/Contracts/SqlConnectionFactory.cs index 9fbe21f0..8d7b0dd4 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/Contracts/SqlConnectionFactory.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/Contracts/SqlConnectionFactory.cs @@ -3,6 +3,9 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // +using System.Data.Common; +using System.Data.SqlClient; + namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices.Contracts { /// @@ -15,9 +18,9 @@ namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices.Contracts /// /// Creates a new SqlClientConnection object /// - public ISqlConnection CreateSqlConnection(string connectionString) + public DbConnection CreateSqlConnection(string connectionString) { - return new SqlClientConnection(connectionString); + return new SqlConnection(connectionString); } } } diff --git a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/AutoCompleteService.cs b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/AutoCompleteService.cs index 5001e1cc..9af007a6 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/AutoCompleteService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/AutoCompleteService.cs @@ -6,10 +6,9 @@ using System; using System.Collections.Generic; using System.Data; -using System.Data.SqlClient; +using System.Data.Common; using System.Threading.Tasks; using Microsoft.SqlTools.ServiceLayer.ConnectionServices; -using Microsoft.SqlTools.ServiceLayer.ConnectionServices.Contracts; using Microsoft.SqlTools.ServiceLayer.Hosting; using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts; using Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts; @@ -66,16 +65,16 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices /// TODO: Update with refactoring/async /// /// - public async Task UpdateAutoCompleteCache(ISqlConnection connection) + public async Task UpdateAutoCompleteCache(DbConnection connection) { - IDbCommand command = connection.CreateCommand(); + DbCommand command = connection.CreateCommand(); command.CommandText = "SELECT name FROM sys.tables"; command.CommandTimeout = 15; command.CommandType = CommandType.Text; - var reader = command.ExecuteReader(); + var reader = await command.ExecuteReaderAsync(); List results = new List(); - while (reader.Read()) + while (await reader.ReadAsync()) { results.Add(reader[0].ToString()); } diff --git a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs index e2fb0cb0..77890bef 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; +using System.Data.Common; using System.Threading; using System.Threading.Tasks; using Microsoft.SqlTools.EditorServices.Utility; @@ -309,7 +310,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices /// Callback for when a user connection is done processing /// /// - public async Task OnConnection(ISqlConnection sqlConnection) + public async Task OnConnection(DbConnection sqlConnection) { await AutoCompleteService.Instance.UpdateAutoCompleteCache(sqlConnection); await Task.FromResult(true); diff --git a/test/Microsoft.SqlTools.ServiceLayer.Test/Utility/TestObjects.cs b/test/Microsoft.SqlTools.ServiceLayer.Test/Utility/TestObjects.cs index 02f69532..6bf4d738 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.Test/Utility/TestObjects.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.Test/Utility/TestObjects.cs @@ -9,6 +9,8 @@ using System; using System.Collections; using System.Collections.Generic; using System.Data; +using System.Data.Common; +using System.Data.SqlClient; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -86,7 +88,7 @@ namespace Microsoft.SqlTools.Test.Utility } } - public class TestSqlReader : IDataReader + public class TestDataReader : DbDataReader { #region Test Specific Implementations @@ -105,149 +107,122 @@ namespace Microsoft.SqlTools.Test.Utility #endregion - public bool GetBoolean(int i) + public override bool GetBoolean(int ordinal) { throw new NotImplementedException(); } - public byte GetByte(int i) + public override byte GetByte(int ordinal) { throw new NotImplementedException(); } - public long GetBytes(int i, long fieldOffset, byte[] buffer, int bufferoffset, int length) + public override long GetBytes(int ordinal, long dataOffset, byte[] buffer, int bufferOffset, int length) { throw new NotImplementedException(); } - public char GetChar(int i) + public override char GetChar(int ordinal) { throw new NotImplementedException(); } - public long GetChars(int i, long fieldoffset, char[] buffer, int bufferoffset, int length) + public override long GetChars(int ordinal, long dataOffset, char[] buffer, int bufferOffset, int length) { throw new NotImplementedException(); } - public IDataReader GetData(int i) + public override string GetDataTypeName(int ordinal) { throw new NotImplementedException(); } - public string GetDataTypeName(int i) + public override DateTime GetDateTime(int ordinal) { throw new NotImplementedException(); } - public DateTime GetDateTime(int i) + public override decimal GetDecimal(int ordinal) { throw new NotImplementedException(); } - public decimal GetDecimal(int i) + public override double GetDouble(int ordinal) { throw new NotImplementedException(); } - public double GetDouble(int i) + public override IEnumerator GetEnumerator() { throw new NotImplementedException(); } - public Type GetFieldType(int i) + public override int GetOrdinal(string name) { throw new NotImplementedException(); } - public float GetFloat(int i) + public override string GetName(int ordinal) { throw new NotImplementedException(); } - public Guid GetGuid(int i) + public override long GetInt64(int ordinal) { throw new NotImplementedException(); } - public short GetInt16(int i) + public override int GetInt32(int ordinal) { throw new NotImplementedException(); } - public int GetInt32(int i) + public override short GetInt16(int ordinal) { throw new NotImplementedException(); } - public long GetInt64(int i) + public override Guid GetGuid(int ordinal) { throw new NotImplementedException(); } - public string GetName(int i) + public override float GetFloat(int ordinal) { throw new NotImplementedException(); } - public int GetOrdinal(string name) + public override Type GetFieldType(int ordinal) { throw new NotImplementedException(); } - public string GetString(int i) + public override string GetString(int ordinal) { throw new NotImplementedException(); } - public object GetValue(int i) + public override object GetValue(int ordinal) { throw new NotImplementedException(); } - public int GetValues(object[] values) + public override int GetValues(object[] values) { throw new NotImplementedException(); } - public bool IsDBNull(int i) + public override bool IsDBNull(int ordinal) { throw new NotImplementedException(); } - public int FieldCount { get; } - - object IDataRecord.this[string name] - { - get { return tableEnumerator.Current[name]; } - } - - object IDataRecord.this[int i] - { - get { return tableEnumerator.Current[tableEnumerator.Current.Keys.ToArray()[i]]; } - } - - public void Dispose() + public override bool NextResult() { throw new NotImplementedException(); } - public void Close() - { - throw new NotImplementedException(); - } - - public DataTable GetSchemaTable() - { - throw new NotImplementedException(); - } - - public bool NextResult() - { - throw new NotImplementedException(); - } - - public bool Read() + public override bool Read() { if (tableEnumerator == null) { @@ -263,146 +238,103 @@ namespace Microsoft.SqlTools.Test.Utility return tableEnumerator.MoveNext(); } - public int Depth { get; } - public bool IsClosed { get; } - public int RecordsAffected { get; } + public override int Depth { get; } + public override bool IsClosed { get; } + public override int RecordsAffected { get; } + + public override object this[string name] + { + get { return tableEnumerator.Current[name]; } + } + + public override object this[int ordinal] + { + get { return tableEnumerator.Current[tableEnumerator.Current.Keys.ToArray()[ordinal]]; } + } + + public override int FieldCount { get; } + public override bool HasRows { get; } } /// /// Test mock class for IDbCommand /// - public class TestSqlCommand : IDbCommand + public class TestSqlCommand : DbCommand { - - public string CommandText { get; set; } - - public int CommandTimeout { get; set; } - - public CommandType CommandType { get; set; } - - public IDbConnection Connection { get; set; } - - public IDataParameterCollection Parameters - { - get - { - throw new NotImplementedException(); - } - } - - public IDbTransaction Transaction { get; set; } - - public UpdateRowSource UpdatedRowSource { get; set; } - - public void Cancel() + public override void Cancel() { throw new NotImplementedException(); } - public IDbDataParameter CreateParameter() + public override int ExecuteNonQuery() { throw new NotImplementedException(); } - public void Dispose() - { - } - - public int ExecuteNonQuery() + public override object ExecuteScalar() { throw new NotImplementedException(); } - public IDataReader ExecuteReader() - { - return new TestSqlReader - { - SqlCommandText = CommandText - }; - } - - public IDataReader ExecuteReader(CommandBehavior behavior) + public override void Prepare() { throw new NotImplementedException(); } - public object ExecuteScalar() + public override string CommandText { get; set; } + public override int CommandTimeout { get; set; } + public override CommandType CommandType { get; set; } + public override UpdateRowSource UpdatedRowSource { get; set; } + protected override DbConnection DbConnection { get; set; } + protected override DbParameterCollection DbParameterCollection { get; } + protected override DbTransaction DbTransaction { get; set; } + public override bool DesignTimeVisible { get; set; } + + protected override DbParameter CreateDbParameter() { throw new NotImplementedException(); } - public void Prepare() + protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior) { - throw new NotImplementedException(); + return new TestDataReader {SqlCommandText = CommandText}; } } /// /// Test mock class for SqlConnection wrapper /// - public class TestSqlConnection : ISqlConnection + public class TestSqlConnection : DbConnection { - public TestSqlConnection(string connectionString) + protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLevel) { - + throw new NotImplementedException(); } - public void Dispose() + public override void Close() { - throw new System.NotImplementedException(); + throw new NotImplementedException(); } - public IDbTransaction BeginTransaction() + public override void Open() { - throw new System.NotImplementedException(); + // No Op } - public IDbTransaction BeginTransaction(IsolationLevel il) + public override string ConnectionString { get; set; } + public override string Database { get; } + public override ConnectionState State { get; } + public override string DataSource { get; } + public override string ServerVersion { get; } + + protected override DbCommand CreateDbCommand() { - throw new System.NotImplementedException(); + return new TestSqlCommand(); } - public void Close() + public override void ChangeDatabase(string databaseName) { - throw new System.NotImplementedException(); - } - - public IDbCommand CreateCommand() - { - return new TestSqlCommand {Connection = this}; - } - - public void Open() - { - // No Op. - } - - public string ConnectionString { get; set; } - public int ConnectionTimeout { get; } - public string Database { get; } - public ConnectionState State { get; } - - public void ChangeDatabase(string databaseName) - { - throw new System.NotImplementedException(); - } - - public string DataSource { get; } - public string ServerVersion { get; } - public void ClearPool() - { - throw new System.NotImplementedException(); - } - - public async Task OpenAsync() - { - // No Op. - await Task.FromResult(0); - } - - public Task OpenAsync(CancellationToken token) - { - throw new System.NotImplementedException(); + throw new NotImplementedException(); } } @@ -411,9 +343,12 @@ namespace Microsoft.SqlTools.Test.Utility /// public class TestSqlConnectionFactory : ISqlConnectionFactory { - public ISqlConnection CreateSqlConnection(string connectionString) + public DbConnection CreateSqlConnection(string connectionString) { - return new TestSqlConnection(connectionString); + return new TestSqlConnection() + { + ConnectionString = connectionString + }; } } } From 13fd97ef90db21a458c095583c38687bde03ee80 Mon Sep 17 00:00:00 2001 From: Benjamin Russell Date: Wed, 3 Aug 2016 14:51:17 -0700 Subject: [PATCH 5/5] Fixing issues as per suggestions from @kevcunnane --- .../{ConnectionServices => Connection}/ConnectionService.cs | 4 ++-- .../Contracts/ConnectionMessages.cs | 2 +- .../Contracts => Connection}/ISqlConnectionFactory.cs | 2 +- .../Contracts => Connection}/SqlConnectionFactory.cs | 4 ++-- .../Contracts/BufferPosition.cs | 2 +- .../{WorkspaceServices => Workspace}/Contracts/BufferRange.cs | 2 +- .../Contracts/Configuration.cs | 2 +- .../{WorkspaceServices => Workspace}/Contracts/FileChange.cs | 2 +- .../Contracts/FilePosition.cs | 2 +- .../{WorkspaceServices => Workspace}/Contracts/ScriptFile.cs | 2 +- .../Contracts/ScriptFileMarker.cs | 2 +- .../Contracts/ScriptRegion.cs | 2 +- .../Contracts/TextDocument.cs | 2 +- .../Contracts/WorkspaceSymbols.cs | 2 +- .../{WorkspaceServices => Workspace}/Workspace.cs | 4 ++-- .../{WorkspaceServices => Workspace}/WorkspaceService.cs | 4 ++-- 16 files changed, 20 insertions(+), 20 deletions(-) rename src/Microsoft.SqlTools.ServiceLayer/{ConnectionServices => Connection}/ConnectionService.cs (98%) rename src/Microsoft.SqlTools.ServiceLayer/{ConnectionServices => Connection}/Contracts/ConnectionMessages.cs (96%) rename src/Microsoft.SqlTools.ServiceLayer/{ConnectionServices/Contracts => Connection}/ISqlConnectionFactory.cs (87%) rename src/Microsoft.SqlTools.ServiceLayer/{ConnectionServices/Contracts => Connection}/SqlConnectionFactory.cs (84%) rename src/Microsoft.SqlTools.ServiceLayer/{WorkspaceServices => Workspace}/Contracts/BufferPosition.cs (98%) rename src/Microsoft.SqlTools.ServiceLayer/{WorkspaceServices => Workspace}/Contracts/BufferRange.cs (98%) rename src/Microsoft.SqlTools.ServiceLayer/{WorkspaceServices => Workspace}/Contracts/Configuration.cs (89%) rename src/Microsoft.SqlTools.ServiceLayer/{WorkspaceServices => Workspace}/Contracts/FileChange.cs (93%) rename src/Microsoft.SqlTools.ServiceLayer/{WorkspaceServices => Workspace}/Contracts/FilePosition.cs (98%) rename src/Microsoft.SqlTools.ServiceLayer/{WorkspaceServices => Workspace}/Contracts/ScriptFile.cs (99%) rename src/Microsoft.SqlTools.ServiceLayer/{WorkspaceServices => Workspace}/Contracts/ScriptFileMarker.cs (95%) rename src/Microsoft.SqlTools.ServiceLayer/{WorkspaceServices => Workspace}/Contracts/ScriptRegion.cs (97%) rename src/Microsoft.SqlTools.ServiceLayer/{WorkspaceServices => Workspace}/Contracts/TextDocument.cs (98%) rename src/Microsoft.SqlTools.ServiceLayer/{WorkspaceServices => Workspace}/Contracts/WorkspaceSymbols.cs (95%) rename src/Microsoft.SqlTools.ServiceLayer/{WorkspaceServices => Workspace}/Workspace.cs (98%) rename src/Microsoft.SqlTools.ServiceLayer/{WorkspaceServices => Workspace}/WorkspaceService.cs (98%) diff --git a/src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/ConnectionService.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs similarity index 98% rename from src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/ConnectionService.cs rename to src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs index 32ff5720..dec645d6 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/ConnectionService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/ConnectionService.cs @@ -9,13 +9,13 @@ using System.Data.Common; using System.Data.SqlClient; using System.Threading.Tasks; using Microsoft.SqlTools.EditorServices.Utility; -using Microsoft.SqlTools.ServiceLayer.ConnectionServices.Contracts; +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.WorkspaceServices; -namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices +namespace Microsoft.SqlTools.ServiceLayer.Connection { /// /// Main class for the Connection Management services diff --git a/src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/Contracts/ConnectionMessages.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionMessages.cs similarity index 96% rename from src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/Contracts/ConnectionMessages.cs rename to src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionMessages.cs index 7f5c6492..0ade2b39 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/Contracts/ConnectionMessages.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/Contracts/ConnectionMessages.cs @@ -5,7 +5,7 @@ using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; -namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices +namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts { /// /// Message format for the initial connection request diff --git a/src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/Contracts/ISqlConnectionFactory.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/ISqlConnectionFactory.cs similarity index 87% rename from src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/Contracts/ISqlConnectionFactory.cs rename to src/Microsoft.SqlTools.ServiceLayer/Connection/ISqlConnectionFactory.cs index 1edb6501..ed0cc01b 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/Contracts/ISqlConnectionFactory.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/ISqlConnectionFactory.cs @@ -5,7 +5,7 @@ using System.Data.Common; -namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices.Contracts +namespace Microsoft.SqlTools.ServiceLayer.Connection { /// /// Interface for the SQL Connection factory diff --git a/src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/Contracts/SqlConnectionFactory.cs b/src/Microsoft.SqlTools.ServiceLayer/Connection/SqlConnectionFactory.cs similarity index 84% rename from src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/Contracts/SqlConnectionFactory.cs rename to src/Microsoft.SqlTools.ServiceLayer/Connection/SqlConnectionFactory.cs index 8d7b0dd4..cffb690d 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/ConnectionServices/Contracts/SqlConnectionFactory.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Connection/SqlConnectionFactory.cs @@ -6,7 +6,7 @@ using System.Data.Common; using System.Data.SqlClient; -namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices.Contracts +namespace Microsoft.SqlTools.ServiceLayer.Connection { /// /// Factory class to create SqlClientConnections @@ -16,7 +16,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ConnectionServices.Contracts public class SqlConnectionFactory : ISqlConnectionFactory { /// - /// Creates a new SqlClientConnection object + /// Creates a new SqlConnection object /// public DbConnection CreateSqlConnection(string connectionString) { diff --git a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/BufferPosition.cs b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/BufferPosition.cs similarity index 98% rename from src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/BufferPosition.cs rename to src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/BufferPosition.cs index f74ade68..713736a7 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/BufferPosition.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/BufferPosition.cs @@ -5,7 +5,7 @@ using System.Diagnostics; -namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts +namespace Microsoft.SqlTools.ServiceLayer.Workspace.Contracts { /// /// Provides details about a position in a file buffer. All diff --git a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/BufferRange.cs b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/BufferRange.cs similarity index 98% rename from src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/BufferRange.cs rename to src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/BufferRange.cs index 99316fe5..f8253d02 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/BufferRange.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/BufferRange.cs @@ -6,7 +6,7 @@ using System; using System.Diagnostics; -namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts +namespace Microsoft.SqlTools.ServiceLayer.Workspace.Contracts { /// /// Provides details about a range between two positions in diff --git a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/Configuration.cs b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/Configuration.cs similarity index 89% rename from src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/Configuration.cs rename to src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/Configuration.cs index ff1e5096..af50835f 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/Configuration.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/Configuration.cs @@ -5,7 +5,7 @@ using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; -namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts +namespace Microsoft.SqlTools.ServiceLayer.Workspace.Contracts { public class DidChangeConfigurationNotification { diff --git a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/FileChange.cs b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/FileChange.cs similarity index 93% rename from src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/FileChange.cs rename to src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/FileChange.cs index 7e1af148..e3d49471 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/FileChange.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/FileChange.cs @@ -3,7 +3,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts +namespace Microsoft.SqlTools.ServiceLayer.Workspace.Contracts { /// /// Contains details relating to a content change in an open file. diff --git a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/FilePosition.cs b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/FilePosition.cs similarity index 98% rename from src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/FilePosition.cs rename to src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/FilePosition.cs index 01ed012d..65fe268a 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/FilePosition.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/FilePosition.cs @@ -3,7 +3,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts +namespace Microsoft.SqlTools.ServiceLayer.Workspace.Contracts { /// /// Provides details and operations for a buffer position in a diff --git a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/ScriptFile.cs b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/ScriptFile.cs similarity index 99% rename from src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/ScriptFile.cs rename to src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/ScriptFile.cs index 708bae70..8db022cc 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/ScriptFile.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/ScriptFile.cs @@ -9,7 +9,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; -namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts +namespace Microsoft.SqlTools.ServiceLayer.Workspace.Contracts { /// /// Contains the details and contents of an open script file. diff --git a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/ScriptFileMarker.cs b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/ScriptFileMarker.cs similarity index 95% rename from src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/ScriptFileMarker.cs rename to src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/ScriptFileMarker.cs index 35ba21fa..743ef3d6 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/ScriptFileMarker.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/ScriptFileMarker.cs @@ -3,7 +3,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // -namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts +namespace Microsoft.SqlTools.ServiceLayer.Workspace.Contracts { /// /// Defines the message level of a script file marker. diff --git a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/ScriptRegion.cs b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/ScriptRegion.cs similarity index 97% rename from src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/ScriptRegion.cs rename to src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/ScriptRegion.cs index 1ac56d01..e68400e9 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/ScriptRegion.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/ScriptRegion.cs @@ -5,7 +5,7 @@ //using System.Management.Automation.Language; -namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts +namespace Microsoft.SqlTools.ServiceLayer.Workspace.Contracts { /// /// Contains details about a specific region of text in script file. diff --git a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/TextDocument.cs b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/TextDocument.cs similarity index 98% rename from src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/TextDocument.cs rename to src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/TextDocument.cs index 0708316d..75b542cd 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/TextDocument.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/TextDocument.cs @@ -6,7 +6,7 @@ using System.Diagnostics; using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; -namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts +namespace Microsoft.SqlTools.ServiceLayer.Workspace.Contracts { /// /// Defines a base parameter class for identifying a text document. diff --git a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/WorkspaceSymbols.cs b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/WorkspaceSymbols.cs similarity index 95% rename from src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/WorkspaceSymbols.cs rename to src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/WorkspaceSymbols.cs index 1b7731eb..22445c03 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Contracts/WorkspaceSymbols.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/WorkspaceSymbols.cs @@ -5,7 +5,7 @@ using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts; -namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts +namespace Microsoft.SqlTools.ServiceLayer.Workspace.Contracts { public enum SymbolKind { diff --git a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Workspace.cs b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Workspace.cs similarity index 98% rename from src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Workspace.cs rename to src/Microsoft.SqlTools.ServiceLayer/Workspace/Workspace.cs index 921ecc7c..560805d7 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/Workspace.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Workspace.cs @@ -10,9 +10,9 @@ using System.Text; using System.Text.RegularExpressions; using System.Linq; using Microsoft.SqlTools.EditorServices.Utility; -using Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts; +using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts; -namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices +namespace Microsoft.SqlTools.ServiceLayer.Workspace { /// /// Manages a "workspace" of script files that are open for a particular diff --git a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/WorkspaceService.cs b/src/Microsoft.SqlTools.ServiceLayer/Workspace/WorkspaceService.cs similarity index 98% rename from src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/WorkspaceService.cs rename to src/Microsoft.SqlTools.ServiceLayer/Workspace/WorkspaceService.cs index 96878f45..701fa6f5 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/WorkspaceServices/WorkspaceService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Workspace/WorkspaceService.cs @@ -11,9 +11,9 @@ using System.Threading.Tasks; using Microsoft.SqlTools.EditorServices.Utility; using Microsoft.SqlTools.ServiceLayer.Hosting; using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol; -using Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts; +using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts; -namespace Microsoft.SqlTools.ServiceLayer.WorkspaceServices +namespace Microsoft.SqlTools.ServiceLayer.Workspace { /// /// Class for handling requests/events that deal with the state of the workspace, including the