forked from microsoft/sqltoolsservice
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add v2 of the Hosting Service and build nuget packages for it (micros…
…oft#675) * Port v2 of Hosting service to SqlToolsService - Renamed project to .v2 so that existing hosted service isn't impacted - Copied over the CoreServices project which contains ConnectionServiceCore and other reusable services for anything interacting with MSSQL - Ported unit test project across and verified tests run. * Nuget package support for reusable DLLs * Use 1.1 version per Karl's suggestion * Use correct license URL and project URL * Use new SMO packages
- Loading branch information
1 parent
4ac02ea
commit 7119586
Showing
224 changed files
with
63,367 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/Microsoft.SqlTools.CoreServices/Connection/CancelTokenKey.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.SqlTools.DataProtocol.Contracts.Connection; | ||
|
||
namespace Microsoft.SqlTools.CoreServices.Connection | ||
{ | ||
/// <summary> | ||
/// Used to uniquely identify a CancellationTokenSource associated with both | ||
/// a string URI and a string connection type. | ||
/// </summary> | ||
public class CancelTokenKey : CancelConnectParams, IEquatable<CancelTokenKey> | ||
{ | ||
public override bool Equals(object obj) | ||
{ | ||
CancelTokenKey other = obj as CancelTokenKey; | ||
if (other == null) | ||
{ | ||
return false; | ||
} | ||
|
||
return other.OwnerUri == OwnerUri && other.Type == Type; | ||
} | ||
|
||
public bool Equals(CancelTokenKey obj) | ||
{ | ||
return obj.OwnerUri == OwnerUri && obj.Type == Type; | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return OwnerUri.GetHashCode() ^ Type.GetHashCode(); | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/Microsoft.SqlTools.CoreServices/Connection/ConnectParamsExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// 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.DataProtocol.Contracts.Connection; | ||
|
||
namespace Microsoft.SqlTools.CoreServices.Connection | ||
{ | ||
/// <summary> | ||
/// Extension methods to ConnectParams | ||
/// </summary> | ||
public static class ConnectParamsExtensions | ||
{ | ||
/// <summary> | ||
/// Check that the fields in ConnectParams are all valid | ||
/// </summary> | ||
public static bool IsValid(this ConnectParams parameters, out string errorMessage) | ||
{ | ||
errorMessage = string.Empty; | ||
if (string.IsNullOrEmpty(parameters.OwnerUri)) | ||
{ | ||
errorMessage = SR.ConnectionParamsValidateNullOwnerUri; | ||
} | ||
else if (parameters.Connection == null) | ||
{ | ||
errorMessage = SR.ConnectionParamsValidateNullConnection; | ||
} | ||
else if (!string.IsNullOrEmpty(parameters.Connection.ConnectionString)) | ||
{ | ||
// Do not check other connection parameters if a connection string is present | ||
return string.IsNullOrEmpty(errorMessage); | ||
} | ||
else if (string.IsNullOrEmpty(parameters.Connection.ServerName)) | ||
{ | ||
errorMessage = SR.ConnectionParamsValidateNullServerName; | ||
} | ||
else if (string.IsNullOrEmpty(parameters.Connection.AuthenticationType) || parameters.Connection.AuthenticationType == "SqlLogin") | ||
{ | ||
// For SqlLogin, username cannot be empty | ||
if (string.IsNullOrEmpty(parameters.Connection.UserName)) | ||
{ | ||
errorMessage = SR.ConnectionParamsValidateNullSqlAuth("UserName"); | ||
} | ||
} | ||
|
||
return string.IsNullOrEmpty(errorMessage); | ||
} | ||
} | ||
} |
171 changes: 171 additions & 0 deletions
171
src/Microsoft.SqlTools.CoreServices/Connection/ConnectionInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
// | ||
// 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.Concurrent; | ||
using System.Collections.Generic; | ||
using System.Data.Common; | ||
using Microsoft.SqlTools.DataProtocol.Contracts.Connection; | ||
using Microsoft.SqlTools.Hosting.Utility; | ||
|
||
namespace Microsoft.SqlTools.CoreServices.Connection | ||
{ | ||
/// <summary> | ||
/// Information pertaining to a unique connection instance. | ||
/// </summary> | ||
public class ConnectionInfo | ||
{ | ||
/// <summary> | ||
/// Constructor | ||
/// </summary> | ||
public ConnectionInfo(ISqlConnectionFactory factory, string ownerUri, ConnectionDetails details) | ||
{ | ||
Factory = factory; | ||
OwnerUri = ownerUri; | ||
ConnectionDetails = details; | ||
ConnectionId = Guid.NewGuid(); | ||
IntellisenseMetrics = new InteractionMetrics<double>(new int[] {50, 100, 200, 500, 1000, 2000}); | ||
} | ||
|
||
/// <summary> | ||
/// Unique Id, helpful to identify a connection info object | ||
/// </summary> | ||
public Guid ConnectionId { get; private set; } | ||
|
||
/// <summary> | ||
/// URI identifying the owner/user of the connection. Could be a file, service, resource, etc. | ||
/// </summary> | ||
public string OwnerUri { get; private set; } | ||
|
||
/// <summary> | ||
/// Factory used for creating the SQL connection associated with the connection info. | ||
/// </summary> | ||
public ISqlConnectionFactory Factory { get; private set; } | ||
|
||
/// <summary> | ||
/// Properties used for creating/opening the SQL connection. | ||
/// </summary> | ||
public ConnectionDetails ConnectionDetails { get; private set; } | ||
|
||
/// <summary> | ||
/// A map containing all connections to the database that are associated with | ||
/// this ConnectionInfo's OwnerUri. | ||
/// This is internal for testing access only | ||
/// </summary> | ||
internal readonly ConcurrentDictionary<string, DbConnection> ConnectionTypeToConnectionMap = | ||
new ConcurrentDictionary<string, DbConnection>(); | ||
|
||
/// <summary> | ||
/// Intellisense Metrics | ||
/// </summary> | ||
public InteractionMetrics<double> IntellisenseMetrics { get; private set; } | ||
|
||
/// <summary> | ||
/// Returns true if the db connection is to any cloud instance | ||
/// </summary> | ||
public bool IsCloud { get; set; } | ||
|
||
/// <summary> | ||
/// Returns true if the db connection is to a SQL db instance | ||
/// </summary> | ||
public bool IsSqlDb { get; set; } | ||
|
||
/// Returns true if the sql connection is to a DW instance | ||
/// </summary> | ||
public bool IsSqlDW { get; set; } | ||
|
||
/// <summary> | ||
/// Returns the major version number of the db we are connected to | ||
/// </summary> | ||
public int MajorVersion { get; set; } | ||
|
||
/// <summary> | ||
/// All DbConnection instances held by this ConnectionInfo | ||
/// </summary> | ||
public ICollection<DbConnection> AllConnections | ||
{ | ||
get | ||
{ | ||
return ConnectionTypeToConnectionMap.Values; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// All connection type strings held by this ConnectionInfo | ||
/// </summary> | ||
/// <returns></returns> | ||
public ICollection<string> AllConnectionTypes | ||
{ | ||
get | ||
{ | ||
return ConnectionTypeToConnectionMap.Keys; | ||
} | ||
} | ||
|
||
public bool HasConnectionType(string connectionType) | ||
{ | ||
connectionType = connectionType ?? ConnectionType.Default; | ||
return ConnectionTypeToConnectionMap.ContainsKey(connectionType); | ||
} | ||
|
||
/// <summary> | ||
/// The count of DbConnectioninstances held by this ConnectionInfo | ||
/// </summary> | ||
public int CountConnections | ||
{ | ||
get | ||
{ | ||
return ConnectionTypeToConnectionMap.Count; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Try to get the DbConnection associated with the given connection type string. | ||
/// </summary> | ||
/// <returns>true if a connection with type connectionType was located and out connection was set, | ||
/// false otherwise </returns> | ||
/// <exception cref="ArgumentException">Thrown when connectionType is null or empty</exception> | ||
public bool TryGetConnection(string connectionType, out DbConnection connection) | ||
{ | ||
Validate.IsNotNullOrEmptyString("Connection Type", connectionType); | ||
return ConnectionTypeToConnectionMap.TryGetValue(connectionType, out connection); | ||
} | ||
|
||
/// <summary> | ||
/// Adds a DbConnection to this object and associates it with the given | ||
/// connection type string. If a connection already exists with an identical | ||
/// connection type string, it is not overwritten. Ignores calls where connectionType = null | ||
/// </summary> | ||
/// <exception cref="ArgumentException">Thrown when connectionType is null or empty</exception> | ||
public void AddConnection(string connectionType, DbConnection connection) | ||
{ | ||
Validate.IsNotNullOrEmptyString("Connection Type", connectionType); | ||
ConnectionTypeToConnectionMap.TryAdd(connectionType, connection); | ||
} | ||
|
||
/// <summary> | ||
/// Removes the single DbConnection instance associated with string connectionType | ||
/// </summary> | ||
/// <exception cref="ArgumentException">Thrown when connectionType is null or empty</exception> | ||
public void RemoveConnection(string connectionType) | ||
{ | ||
Validate.IsNotNullOrEmptyString("Connection Type", connectionType); | ||
DbConnection connection; | ||
ConnectionTypeToConnectionMap.TryRemove(connectionType, out connection); | ||
} | ||
|
||
/// <summary> | ||
/// Removes all DbConnection instances held by this object | ||
/// </summary> | ||
public void RemoveAllConnections() | ||
{ | ||
foreach (var type in AllConnectionTypes) | ||
{ | ||
DbConnection connection; | ||
ConnectionTypeToConnectionMap.TryRemove(type, out connection); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.