mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-13 17:23:02 -05:00
Create DB work in-progress (#350)
* Stage changes to other machine * Stage changes * Update SMO to fix SMO missing Login bug on macOS
This commit is contained in:
Binary file not shown.
BIN
bin/nuget/Microsoft.SqlServer.Smo.140.17053.0.nupkg
Normal file
BIN
bin/nuget/Microsoft.SqlServer.Smo.140.17053.0.nupkg
Normal file
Binary file not shown.
@@ -12,7 +12,7 @@
|
||||
"Newtonsoft.Json": "9.0.1",
|
||||
"System.Data.Common": "4.1.0",
|
||||
"System.Data.SqlClient": "4.4.0-sqltools-24613-04",
|
||||
"Microsoft.SqlServer.Smo": "140.17051.0",
|
||||
"Microsoft.SqlServer.Smo": "140.17053.0",
|
||||
"System.Security.SecureString": "4.0.0",
|
||||
"System.Collections.Specialized": "4.0.1",
|
||||
"System.ComponentModel.TypeConverter": "4.1.0",
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
"emitEntryPoint": true
|
||||
},
|
||||
"dependencies": {
|
||||
"Microsoft.SqlServer.Smo": "140.17051.0"
|
||||
"Microsoft.SqlServer.Smo": "140.17053.0"
|
||||
},
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {
|
||||
|
||||
@@ -12,11 +12,12 @@ using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using Microsoft.SqlServer.Management.Smo;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Admin
|
||||
{
|
||||
/// <summary>
|
||||
/// Datasource admin task service class
|
||||
/// Admin task service class
|
||||
/// </summary>
|
||||
public class AdminService
|
||||
{
|
||||
@@ -24,6 +25,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
||||
|
||||
private static ConnectionService connectionService = null;
|
||||
|
||||
private static readonly ConcurrentDictionary<string, DatabaseTaskHelper> serverTaskHelperMap =
|
||||
new ConcurrentDictionary<string, DatabaseTaskHelper>();
|
||||
|
||||
private static DatabaseTaskHelper taskHelper;
|
||||
|
||||
/// <summary>
|
||||
/// Default, parameterless constructor.
|
||||
/// </summary>
|
||||
@@ -69,30 +75,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
||||
serviceHost.SetRequestHandler(DefaultDatabaseInfoRequest.Type, HandleDefaultDatabaseInfoRequest);
|
||||
}
|
||||
|
||||
private static DatabaseTaskHelper CreateDatabaseTaskHelper(ConnectionInfo connInfo)
|
||||
{
|
||||
XmlDocument xmlDoc = CreateDataContainerDocument(connInfo);
|
||||
char[] passwordArray = connInfo.ConnectionDetails.Password.ToCharArray();
|
||||
CDataContainer dataContainer;
|
||||
|
||||
unsafe
|
||||
{
|
||||
fixed (char* passwordPtr = passwordArray)
|
||||
{
|
||||
dataContainer = new CDataContainer(
|
||||
CDataContainer.ServerType.SQL,
|
||||
connInfo.ConnectionDetails.ServerName,
|
||||
false,
|
||||
connInfo.ConnectionDetails.UserName,
|
||||
new System.Security.SecureString(passwordPtr, passwordArray.Length),
|
||||
xmlDoc.InnerXml);
|
||||
}
|
||||
}
|
||||
|
||||
var taskHelper = new DatabaseTaskHelper(dataContainer);
|
||||
return taskHelper;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle a request for the default database prototype info
|
||||
/// </summary>
|
||||
@@ -106,12 +88,87 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
||||
optionsParams.OwnerUri,
|
||||
out connInfo);
|
||||
|
||||
DatabaseTaskHelper taskHelper = CreateDatabaseTaskHelper(connInfo);
|
||||
if (taskHelper == null)
|
||||
{
|
||||
taskHelper = CreateDatabaseTaskHelper(connInfo);
|
||||
}
|
||||
|
||||
response.DefaultDatabaseInfo = DatabaseTaskHelper.DatabasePrototypeToDatabaseInfo(taskHelper.Prototype);
|
||||
await requestContext.SendResult(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles a create database request
|
||||
/// </summary>
|
||||
internal static async Task HandleCreateDatabaseRequest(
|
||||
CreateDatabaseParams databaseParams,
|
||||
RequestContext<CreateDatabaseResponse> requestContext)
|
||||
{
|
||||
var response = new DefaultDatabaseInfoResponse();
|
||||
ConnectionInfo connInfo;
|
||||
AdminService.ConnectionServiceInstance.TryFindConnection(
|
||||
databaseParams.OwnerUri,
|
||||
out connInfo);
|
||||
|
||||
if (taskHelper == null)
|
||||
{
|
||||
taskHelper = CreateDatabaseTaskHelper(connInfo);
|
||||
}
|
||||
|
||||
DatabasePrototype prototype = taskHelper.Prototype;
|
||||
DatabaseTaskHelper.ApplyToPrototype(databaseParams.DatabaseInfo, taskHelper.Prototype);
|
||||
|
||||
Database db = prototype.ApplyChanges();
|
||||
if (db != null)
|
||||
{
|
||||
taskHelper = null;
|
||||
}
|
||||
|
||||
await requestContext.SendResult(new CreateDatabaseResponse()
|
||||
{
|
||||
Result = true,
|
||||
TaskId = 0
|
||||
});
|
||||
}
|
||||
|
||||
private static DatabaseTaskHelper CreateDatabaseTaskHelper(ConnectionInfo connInfo)
|
||||
{
|
||||
XmlDocument xmlDoc = CreateDataContainerDocument(connInfo);
|
||||
char[] passwordArray = connInfo.ConnectionDetails.Password.ToCharArray();
|
||||
CDataContainer dataContainer;
|
||||
|
||||
// check if the connection is using SQL Auth or Integrated Auth
|
||||
if (string.Equals(connInfo.ConnectionDetails.AuthenticationType, "SqlLogin", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (char* passwordPtr = passwordArray)
|
||||
{
|
||||
dataContainer = new CDataContainer(
|
||||
CDataContainer.ServerType.SQL,
|
||||
connInfo.ConnectionDetails.ServerName,
|
||||
false,
|
||||
connInfo.ConnectionDetails.UserName,
|
||||
new System.Security.SecureString(passwordPtr, passwordArray.Length),
|
||||
xmlDoc.InnerXml);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dataContainer = new CDataContainer(
|
||||
CDataContainer.ServerType.SQL,
|
||||
connInfo.ConnectionDetails.ServerName,
|
||||
true,
|
||||
null,
|
||||
null,
|
||||
xmlDoc.InnerXml);
|
||||
}
|
||||
|
||||
var taskHelper = new DatabaseTaskHelper(dataContainer);
|
||||
return taskHelper;
|
||||
}
|
||||
|
||||
private static XmlDocument CreateDataContainerDocument(ConnectionInfo connInfo)
|
||||
{
|
||||
string xml =
|
||||
@@ -131,32 +188,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
||||
return xmlDoc;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles a create database request
|
||||
/// </summary>
|
||||
internal static async Task HandleCreateDatabaseRequest(
|
||||
CreateDatabaseParams databaseParams,
|
||||
RequestContext<CreateDatabaseResponse> requestContext)
|
||||
{
|
||||
var response = new DefaultDatabaseInfoResponse();
|
||||
ConnectionInfo connInfo;
|
||||
AdminService.ConnectionServiceInstance.TryFindConnection(
|
||||
databaseParams.OwnerUri,
|
||||
out connInfo);
|
||||
|
||||
DatabaseTaskHelper taskHelper = CreateDatabaseTaskHelper(connInfo);
|
||||
DatabasePrototype prototype = taskHelper.Prototype;
|
||||
DatabaseTaskHelper.ApplyToPrototype(databaseParams.DatabaseInfo, taskHelper.Prototype);
|
||||
|
||||
Database db = prototype.ApplyChanges();
|
||||
|
||||
await requestContext.SendResult(new CreateDatabaseResponse()
|
||||
{
|
||||
Result = true,
|
||||
TaskId = 0
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles a create login request
|
||||
/// </summary>
|
||||
|
||||
@@ -169,6 +169,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
||||
{
|
||||
file.Name = prototype.Name + "_" + logicalNameCount;
|
||||
}
|
||||
else
|
||||
{
|
||||
file.Name += prototype.Name + file.Name + "_" + logicalNameCount;
|
||||
}
|
||||
|
||||
++logicalNameCount;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ using System.Text.RegularExpressions;
|
||||
using System.Linq;
|
||||
using Microsoft.SqlTools.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Workspace
|
||||
{
|
||||
@@ -114,7 +115,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Workspace
|
||||
// Client sent the path in URI format, extract the local path and trim
|
||||
// any extraneous slashes
|
||||
Uri fileUri = new Uri(filePath);
|
||||
filePath = fileUri.LocalPath.TrimStart('/');
|
||||
filePath = fileUri.LocalPath;
|
||||
if (filePath.StartsWith("//") || filePath.StartsWith("\\\\"))
|
||||
{
|
||||
filePath = filePath.Substring(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Clients could specify paths with escaped space, [ and ] characters which .NET APIs
|
||||
@@ -122,6 +127,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Workspace
|
||||
// into the SqlTools engine.
|
||||
filePath = UnescapePath(filePath);
|
||||
|
||||
// switch to unix path separators on non-Windows platforms
|
||||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
filePath = filePath.Replace('\\', '/');
|
||||
}
|
||||
|
||||
// Get the absolute file path
|
||||
filePath = Path.GetFullPath(filePath);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
"Newtonsoft.Json": "9.0.1",
|
||||
"System.Data.Common": "4.1.0",
|
||||
"System.Data.SqlClient": "4.4.0-sqltools-24613-04",
|
||||
"Microsoft.SqlServer.Smo": "140.17051.0",
|
||||
"Microsoft.SqlServer.Smo": "140.17053.0",
|
||||
"Microsoft.SqlServer.Management.SqlScriptPublishModel": "140.17049.0",
|
||||
"System.Security.SecureString": "4.0.0",
|
||||
"System.Collections.Specialized": "4.0.1",
|
||||
|
||||
@@ -297,9 +297,9 @@ GO";
|
||||
ServerConnection serverConnection = LiveConnectionHelper.InitLiveServerConnectionForDefinition(connInfo);
|
||||
|
||||
Scripter scripter = new Scripter(serverConnection, connInfo);
|
||||
string objectName = "sp_MSrepl_startup";
|
||||
string objectName = "sp_columns";
|
||||
|
||||
string schemaName = "dbo";
|
||||
string schemaName = "sys";
|
||||
string objectType = "PROCEDURE";
|
||||
|
||||
Location[] locations = scripter.GetSqlObjectDefinition(scripter.GetStoredProcedureScripts, objectName, schemaName, objectType);
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
"System.Runtime.Serialization.Primitives": "4.1.1",
|
||||
"System.Data.Common": "4.1.0",
|
||||
"System.Data.SqlClient": "4.4.0-sqltools-24613-04",
|
||||
"Microsoft.SqlServer.Smo": "140.17051.0",
|
||||
"Microsoft.SqlServer.Smo": "140.17053.0",
|
||||
"System.Security.SecureString": "4.0.0",
|
||||
"System.Collections.Specialized": "4.0.1",
|
||||
"System.ComponentModel.TypeConverter": "4.1.0",
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
"System.Runtime.Serialization.Primitives": "4.1.1",
|
||||
"System.Data.Common": "4.1.0",
|
||||
"System.Data.SqlClient": "4.4.0-sqltools-24613-04",
|
||||
"Microsoft.SqlServer.Smo": "140.17051.0",
|
||||
"Microsoft.SqlServer.Smo": "140.17053.0",
|
||||
"System.Security.SecureString": "4.0.0",
|
||||
"System.Collections.Specialized": "4.0.1",
|
||||
"System.ComponentModel.TypeConverter": "4.1.0",
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
"System.Runtime.Serialization.Primitives": "4.1.1",
|
||||
"System.Data.Common": "4.1.0",
|
||||
"System.Data.SqlClient": "4.4.0-sqltools-24613-04",
|
||||
"Microsoft.SqlServer.Smo": "140.17051.0",
|
||||
"Microsoft.SqlServer.Smo": "140.17053.0",
|
||||
"System.Security.SecureString": "4.0.0",
|
||||
"System.Collections.Specialized": "4.0.1",
|
||||
"System.ComponentModel.TypeConverter": "4.1.0",
|
||||
|
||||
Reference in New Issue
Block a user