mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-26 09:35:38 -05:00
Merge create db work in progress (#341)
* Port over initial block of create db implementation * Test case placeholder * In-progress work * Stage changes to other machine * Add database prototype strings * Stage changes to other machine * Stage changes * Hook the database info into capabilities discovery * Stage changes * Update SMO to latest from ssms_main * Various clean-ups * Update localization files
This commit is contained in:
@@ -5,10 +5,12 @@
|
||||
|
||||
using Microsoft.SqlTools.Hosting.Protocol;
|
||||
using Microsoft.SqlTools.ServiceLayer.Admin.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting;
|
||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Admin
|
||||
{
|
||||
@@ -19,6 +21,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
||||
{
|
||||
private static readonly Lazy<AdminService> instance = new Lazy<AdminService>(() => new AdminService());
|
||||
|
||||
private static ConnectionService connectionService = null;
|
||||
|
||||
/// <summary>
|
||||
/// Default, parameterless constructor.
|
||||
/// </summary>
|
||||
@@ -26,6 +30,26 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Internal for testing purposes only
|
||||
/// </summary>
|
||||
internal static ConnectionService ConnectionServiceInstance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (AdminService.connectionService == null)
|
||||
{
|
||||
AdminService.connectionService = ConnectionService.Instance;
|
||||
}
|
||||
return AdminService.connectionService;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
AdminService.connectionService = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the singleton instance object
|
||||
/// </summary>
|
||||
@@ -41,6 +65,62 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
|
||||
{
|
||||
serviceHost.SetRequestHandler(CreateDatabaseRequest.Type, HandleCreateDatabaseRequest);
|
||||
serviceHost.SetRequestHandler(CreateLoginRequest.Type, HandleCreateLoginRequest);
|
||||
serviceHost.SetRequestHandler(DefaultDatabaseInfoRequest.Type, HandleDefaultDatabaseInfoRequest);
|
||||
}
|
||||
|
||||
public static async Task HandleDefaultDatabaseInfoRequest(
|
||||
DefaultDatabaseInfoParams optionsParams,
|
||||
RequestContext<DefaultDatabaseInfoResponse> requestContext)
|
||||
{
|
||||
var response = new DefaultDatabaseInfoResponse();
|
||||
|
||||
ConnectionInfo connInfo;
|
||||
AdminService.ConnectionServiceInstance.TryFindConnection(
|
||||
optionsParams.OwnerUri,
|
||||
out connInfo);
|
||||
|
||||
XmlDocument xmlDoc = CreateDataContainerDocument(connInfo);
|
||||
char[] passwordArray = connInfo.ConnectionDetails.Password.ToCharArray();
|
||||
unsafe
|
||||
{
|
||||
fixed (char* passwordPtr = passwordArray)
|
||||
{
|
||||
var 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();
|
||||
taskHelper.CreateDatabase(dataContainer);
|
||||
|
||||
response.DefaultDatabaseInfo = DatabaseTaskHelper.DatabasePrototypeToDatabaseInfo(taskHelper.Prototype);
|
||||
}
|
||||
}
|
||||
|
||||
await requestContext.SendResult(response);
|
||||
}
|
||||
|
||||
|
||||
private static XmlDocument CreateDataContainerDocument(ConnectionInfo connInfo)
|
||||
{
|
||||
string xml =
|
||||
string.Format(@"<?xml version=""1.0""?>
|
||||
<formdescription><params>
|
||||
<servername>{0}</servername>
|
||||
<connectionmoniker>{0} (SQLServer, user = {1})</connectionmoniker>
|
||||
<servertype>sql</servertype>
|
||||
<urn>Server[@Name='{0}']</urn>
|
||||
<itemtype>Database</itemtype>
|
||||
</params></formdescription> ",
|
||||
connInfo.ConnectionDetails.ServerName.ToUpper(),
|
||||
connInfo.ConnectionDetails.UserName);
|
||||
|
||||
var xmlDoc = new XmlDocument();
|
||||
xmlDoc.LoadXml(xml);
|
||||
return xmlDoc;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user