Additional create db options (#342)

* Refactor unsafe block

* Stage changes

* Add additional database prototype metadata

* Fix nullref bug

* Read database info properties
This commit is contained in:
Karl Burtram
2017-05-11 09:44:57 -07:00
committed by GitHub
parent 8a54435a9c
commit c9e2963ca0
4 changed files with 326 additions and 34 deletions

View File

@@ -68,41 +68,49 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
serviceHost.SetRequestHandler(DefaultDatabaseInfoRequest.Type, HandleDefaultDatabaseInfoRequest);
}
public static async Task HandleDefaultDatabaseInfoRequest(
DefaultDatabaseInfoParams optionsParams,
RequestContext<DefaultDatabaseInfoResponse> requestContext)
private static DatabaseTaskHelper CreateDatabaseTaskHelper(ConnectionInfo connInfo)
{
var response = new DefaultDatabaseInfoResponse();
ConnectionInfo connInfo;
AdminService.ConnectionServiceInstance.TryFindConnection(
optionsParams.OwnerUri,
out connInfo);
XmlDocument xmlDoc = CreateDataContainerDocument(connInfo);
char[] passwordArray = connInfo.ConnectionDetails.Password.ToCharArray();
CDataContainer dataContainer;
unsafe
{
fixed (char* passwordPtr = passwordArray)
{
var dataContainer = new CDataContainer(
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);
var taskHelper = new DatabaseTaskHelper();
taskHelper.CreateDatabase(dataContainer);
return taskHelper;
}
/// <summary>
/// Handle a request for the default database prototype info
/// </summary>
public static async Task HandleDefaultDatabaseInfoRequest(
DefaultDatabaseInfoParams optionsParams,
RequestContext<DefaultDatabaseInfoResponse> requestContext)
{
var response = new DefaultDatabaseInfoResponse();
ConnectionInfo connInfo;
AdminService.ConnectionServiceInstance.TryFindConnection(
optionsParams.OwnerUri,
out connInfo);
DatabaseTaskHelper taskHelper = CreateDatabaseTaskHelper(connInfo);
response.DefaultDatabaseInfo = DatabaseTaskHelper.DatabasePrototypeToDatabaseInfo(taskHelper.Prototype);
await requestContext.SendResult(response);
}
private static XmlDocument CreateDataContainerDocument(ConnectionInfo connInfo)
{
@@ -130,6 +138,17 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
CreateDatabaseParams databaseParams,
RequestContext<CreateDatabaseResponse> requestContext)
{
var response = new DefaultDatabaseInfoResponse();
ConnectionInfo connInfo;
AdminService.ConnectionServiceInstance.TryFindConnection(
databaseParams.OwnerUri,
out connInfo);
DatabaseTaskHelper taskHelper = CreateDatabaseTaskHelper(connInfo);
DatabaseTaskHelper.ApplyToPrototype(databaseParams.DatabaseInfo, taskHelper.Prototype);
response.DefaultDatabaseInfo = DatabaseTaskHelper.DatabasePrototypeToDatabaseInfo(taskHelper.Prototype);
await requestContext.SendResult(new CreateDatabaseResponse());
}

View File

@@ -18,6 +18,31 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
internal const string FileGroups = "fileGroups";
internal const string DatabaseFiles = "databaseFiles";
internal const string PhysicalName = "physicalName";
internal const string RecursiveTriggers = "recursiveTriggers";
internal const string Trustworthy = "trustworthy";
internal const string AnsiNullDefault = "ansiNullDefault";
internal const string AnsiNulls = "ansiNulls";
internal const string AnsiPadding = "ansiNulls";
internal const string AnsiWarnings = "ansiNulls";
internal const string IsFilestreamEnabled = "isFilestreamEnabled";
internal const string IsReadCommittedSnapshotOn = "isReadCommittedSnapshotOn";
internal const string IsReadOnly = "isReadOnly";
internal const string IsSystemDB = "isSystemDB";
internal const string MaxDop = "maxDop";
internal const string DatabaseContainmentType = "databaseContainmentType";
internal const string DatabaseState = "databaseState";
internal const string FileGroupType = "fileGroupType";
internal const string IsDefault = "isDefault";
internal const string IsFileStream = "isFileStream";
internal const string IsMemoryOptimized = "isMemoryOptimized";
internal const string Autogrowth = "autogrowth";
internal const string DatabaseFileType = "databaseFileType";
internal const string Folder = "folder";
internal const string Size = "size";
internal const string FileGroup = "fileGroup";
internal const string InitialSize = "initialSize";
internal const string IsPrimaryFile = "isPrimaryFile";
internal static AdminServicesProviderOptions BuildAdminServicesProviderOptions()
{
@@ -53,6 +78,123 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
GroupName = "General"
},
new ServiceOption
{
Name = AdminServicesProviderOptionsHelper.RecursiveTriggers,
DisplayName = "Recursive Triggers",
Description = "Recursive triggers",
ValueType = ServiceOption.ValueTypeBoolean,
IsRequired = false,
GroupName = "Other"
},
new ServiceOption
{
Name = AdminServicesProviderOptionsHelper.Trustworthy,
DisplayName = "Trustworthy",
Description = "Trustworthy",
ValueType = ServiceOption.ValueTypeBoolean,
IsRequired = false,
GroupName = "Other"
},
new ServiceOption
{
Name = AdminServicesProviderOptionsHelper.AnsiNullDefault,
DisplayName = "AnsiNullDefault",
Description = "Ansi null default",
ValueType = ServiceOption.ValueTypeBoolean,
IsRequired = false,
GroupName = "Other"
},
new ServiceOption
{
Name = AdminServicesProviderOptionsHelper.AnsiNulls,
DisplayName = "AnsiNulls",
Description = "AnsiNulls",
ValueType = ServiceOption.ValueTypeBoolean,
IsRequired = false,
GroupName = "Other"
},
new ServiceOption
{
Name = AdminServicesProviderOptionsHelper.AnsiPadding,
DisplayName = "AnsiPadding",
Description = "Ansi padding",
ValueType = ServiceOption.ValueTypeBoolean,
IsRequired = false,
GroupName = "Other"
},
new ServiceOption
{
Name = AdminServicesProviderOptionsHelper.AnsiWarnings,
DisplayName = "AnsiWarnings",
Description = "Ansi warnings",
ValueType = ServiceOption.ValueTypeBoolean,
IsRequired = false,
GroupName = "Other"
},
new ServiceOption
{
Name = AdminServicesProviderOptionsHelper.IsFilestreamEnabled,
DisplayName = "IsFilestreamEnabled",
Description = "Is filestream enabled",
ValueType = ServiceOption.ValueTypeBoolean,
IsRequired = false,
GroupName = "Other"
},
new ServiceOption
{
Name = AdminServicesProviderOptionsHelper.IsReadCommittedSnapshotOn,
DisplayName = "IsReadCommittedSnapshotOn",
Description = "Is read committed snapshot on",
ValueType = ServiceOption.ValueTypeBoolean,
IsRequired = false,
GroupName = "Other"
},
new ServiceOption
{
Name = AdminServicesProviderOptionsHelper.IsReadOnly,
DisplayName = "IsReadOnly",
Description = "Is read only",
ValueType = ServiceOption.ValueTypeBoolean,
IsRequired = false,
GroupName = "Other"
},
new ServiceOption
{
Name = AdminServicesProviderOptionsHelper.IsSystemDB,
DisplayName = "IsSystemDB",
Description = "Is system database",
ValueType = ServiceOption.ValueTypeBoolean,
IsRequired = false,
GroupName = "Other"
},
new ServiceOption
{
Name = AdminServicesProviderOptionsHelper.MaxDop,
DisplayName = "MaxDop",
Description = "Max degree of parallelism",
ValueType = ServiceOption.ValueTypeBoolean,
IsRequired = false,
GroupName = "Other"
},
new ServiceOption
{
Name = AdminServicesProviderOptionsHelper.DatabaseContainmentType,
DisplayName = "DatabaseContainmentType",
Description = "Database containment type",
ValueType = ServiceOption.ValueTypeString,
IsRequired = false,
GroupName = "Other"
},
new ServiceOption
{
Name = AdminServicesProviderOptionsHelper.DatabaseState,
DisplayName = "DatabaseState",
Description = "Database state",
ValueType = ServiceOption.ValueTypeString,
IsRequired = false,
GroupName = "Other"
},
new ServiceOption
{
Name = AdminServicesProviderOptionsHelper.FileGroups,
DisplayName = "File Groups",
@@ -85,8 +227,55 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
ValueType = ServiceOption.ValueTypeString,
IsRequired = true,
GroupName = "General"
}
},
new ServiceOption
{
Name = AdminServicesProviderOptionsHelper.FileGroupType,
DisplayName = "FileGroupType",
Description = "File group type",
ValueType = ServiceOption.ValueTypeString,
IsRequired = true,
GroupName = "General"
},
new ServiceOption
{
Name = AdminServicesProviderOptionsHelper.IsDefault,
DisplayName = "IsDefault",
Description = "Is default",
ValueType = ServiceOption.ValueTypeString,
IsRequired = true,
GroupName = "General"
},
new ServiceOption
{
Name = AdminServicesProviderOptionsHelper.IsFileStream,
DisplayName = "IsFileStream",
Description = "Is file stream",
ValueType = ServiceOption.ValueTypeString,
IsRequired = true,
GroupName = "General"
},
new ServiceOption
{
Name = AdminServicesProviderOptionsHelper.IsMemoryOptimized,
DisplayName = "IsMemoryOptimized",
Description = "Is memory optimized",
ValueType = ServiceOption.ValueTypeString,
IsRequired = true,
GroupName = "General"
},
new ServiceOption
{
Name = AdminServicesProviderOptionsHelper.IsReadOnly,
DisplayName = "IsReadOnly",
Description = "Is read-only",
ValueType = ServiceOption.ValueTypeString,
IsRequired = true,
GroupName = "General"
}
},
DatabaseFileInfoOptions = new ServiceOption[]
{
new ServiceOption
@@ -98,7 +287,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
IsRequired = true,
GroupName = "General"
},
new ServiceOption
new ServiceOption
{
Name = AdminServicesProviderOptionsHelper.PhysicalName,
DisplayName = "Physical Name",
@@ -106,7 +295,71 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
ValueType = ServiceOption.ValueTypeString,
IsRequired = true,
GroupName = "General"
}
},
new ServiceOption
{
Name = AdminServicesProviderOptionsHelper.Autogrowth,
DisplayName = "Autogrowth",
Description = "Autogrowth",
ValueType = ServiceOption.ValueTypeString,
IsRequired = true,
GroupName = "General"
},
new ServiceOption
{
Name = AdminServicesProviderOptionsHelper.DatabaseFileType,
DisplayName = "DatabaseFileType",
Description = "Database file type",
ValueType = ServiceOption.ValueTypeString,
IsRequired = true,
GroupName = "General"
},
new ServiceOption
{
Name = AdminServicesProviderOptionsHelper.Folder,
DisplayName = "Folder",
Description = "Folder",
ValueType = ServiceOption.ValueTypeString,
IsRequired = true,
GroupName = "General"
},
new ServiceOption
{
Name = AdminServicesProviderOptionsHelper.Size,
DisplayName = "Size",
Description = "Size",
ValueType = ServiceOption.ValueTypeString,
IsRequired = true,
GroupName = "General"
},
new ServiceOption
{
Name = AdminServicesProviderOptionsHelper.FileGroup,
DisplayName = "FileGroup",
Description = "File group",
ValueType = ServiceOption.ValueTypeString,
IsRequired = true,
GroupName = "General"
},
new ServiceOption
{
Name = AdminServicesProviderOptionsHelper.InitialSize,
DisplayName = "InitialSize",
Description = "Initial size",
ValueType = ServiceOption.ValueTypeString,
IsRequired = true,
GroupName = "General"
},
new ServiceOption
{
Name = AdminServicesProviderOptionsHelper.IsPrimaryFile,
DisplayName = "IsPrimaryFile",
Description = "Is primary file",
ValueType = ServiceOption.ValueTypeString,
IsRequired = true,
GroupName = "General"
},
}
};
}

View File

@@ -11,20 +11,14 @@ using System.Resources;
using System.Data;
using System.IO;
using System.Text;
//using System.Windows.Forms;
//using System.Drawing.Design;
using Microsoft.SqlServer.Management.Common;
// using Microsoft.SqlServer.Management.SqlMgmt;
using Microsoft.SqlServer.Management.Smo;
using Smo = Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Sdk.Sfc;
using Microsoft.SqlServer.Management.Diagnostics;
//using Microsoft.NetEnterpriseServers;
using System.Globalization;
using System.Data.SqlClient;
using System.Collections.Generic;
// using DisplayNameAttribute = Microsoft.SqlServer.Management.SqlMgmt.DisplayNameAttribute;
using AzureEdition = Microsoft.SqlTools.ServiceLayer.Admin.AzureSqlDbHelper.AzureEdition;
using DataSet = Microsoft.Data.Tools.DataSets.DataSet;
using DataTable = Microsoft.Data.Tools.DataSets.DataTable;
@@ -741,9 +735,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
/// <returns>The string representation</returns>
public override string ToString()
{
ResourceManager manager =
new ResourceManager("Microsoft.SqlServer.Management.SqlManagerUI.CreateDatabaseStrings",
this.GetType().GetAssembly());
ResourceManager manager = new ResourceManager("Microsoft.SqlTools.ServiceLayer.Localization.SR", typeof(DatabasePrototype).GetAssembly());
string result = "";
if (this.IsEnabled)
@@ -760,7 +752,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
else
{
result = String.Format(System.Globalization.CultureInfo.CurrentCulture,
manager.GetString("prototype.autogrowth.restrictedGrowthByMB"),
manager.GetString("prototype_autogrowth_restrictedGrowthByMB"),
this.GrowthInMegabytes,
this.MaximumFileSizeInMegabytes);
}
@@ -770,13 +762,13 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
if (this.IsGrowthInPercent)
{
result = String.Format(System.Globalization.CultureInfo.CurrentCulture,
manager.GetString("prototype.autogrowth.unrestrictedGrowthByPercent"),
manager.GetString("prototype_autogrowth_unrestrictedGrowthByPercent"),
this.GrowthInPercent);
}
else
{
result = String.Format(System.Globalization.CultureInfo.CurrentCulture,
manager.GetString("prototype.autogrowth.unrestrictedGrowthByMB"),
manager.GetString("prototype_autogrowth_unrestrictedGrowthByMB"),
this.GrowthInMegabytes);
}

View File

@@ -107,24 +107,52 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
databaseInfo.Options.Add(AdminServicesProviderOptionsHelper.Name, prototype.Name);
databaseInfo.Options.Add(AdminServicesProviderOptionsHelper.Owner, prototype.Owner);
databaseInfo.Options.Add(AdminServicesProviderOptionsHelper.Collation, prototype.Collation);
databaseInfo.Options.Add(AdminServicesProviderOptionsHelper.DatabaseState, prototype.DatabaseState.ToString());
databaseInfo.Options.Add(AdminServicesProviderOptionsHelper.IsSystemDB, prototype.IsSystemDB.ToString());
databaseInfo.Options.Add(AdminServicesProviderOptionsHelper.AnsiNulls, prototype.AnsiNulls.ToString());
databaseInfo.Options.Add(
AdminServicesProviderOptionsHelper.FileGroups + "Count",
prototype.Filegroups.Count);
for (int i = 0; i < prototype.Filegroups.Count; ++i)
{
var fileGroup = prototype.Filegroups[i];
string itemPrefix = AdminServicesProviderOptionsHelper.FileGroups + "." + i + ".";
databaseInfo.Options.Add(itemPrefix + AdminServicesProviderOptionsHelper.Name, fileGroup.Name);
databaseInfo.Options.Add(itemPrefix + AdminServicesProviderOptionsHelper.IsMemoryOptimized, fileGroup.IsMemoryOptimized);
databaseInfo.Options.Add(itemPrefix + AdminServicesProviderOptionsHelper.IsReadOnly, fileGroup.IsReadOnly);
databaseInfo.Options.Add(itemPrefix + AdminServicesProviderOptionsHelper.IsFileStream, fileGroup.IsFileStream);
databaseInfo.Options.Add(itemPrefix + AdminServicesProviderOptionsHelper.IsDefault, fileGroup.IsDefault);
databaseInfo.Options.Add(itemPrefix + AdminServicesProviderOptionsHelper.FileGroupType, fileGroup.FileGroupType.ToString());
}
databaseInfo.Options.Add(
AdminServicesProviderOptionsHelper.DatabaseFiles + "Count",
prototype.Files.Count);
for (int i = 0; i < prototype.Files.Count; ++i)
{
var file = prototype.Files[i];
string itemPrefix = AdminServicesProviderOptionsHelper.DatabaseFiles + "." + i + ".";
databaseInfo.Options.Add(itemPrefix + AdminServicesProviderOptionsHelper.Name, file.Name);
databaseInfo.Options.Add(itemPrefix + AdminServicesProviderOptionsHelper.PhysicalName, file.PhysicalName);
databaseInfo.Options.Add(itemPrefix + AdminServicesProviderOptionsHelper.Autogrowth, file.DefaultAutogrowth.ToString());
databaseInfo.Options.Add(itemPrefix + AdminServicesProviderOptionsHelper.DatabaseFileType, file.DatabaseFileType.ToString());
databaseInfo.Options.Add(itemPrefix + AdminServicesProviderOptionsHelper.Folder, file.DefaultFolder);
databaseInfo.Options.Add(itemPrefix + AdminServicesProviderOptionsHelper.Size, file.DefaultSize);
databaseInfo.Options.Add(itemPrefix + AdminServicesProviderOptionsHelper.FileGroup, file.FileGroup != null ? file.FileGroup.Name : string.Empty);
databaseInfo.Options.Add(itemPrefix + AdminServicesProviderOptionsHelper.InitialSize, file.InitialSize);
databaseInfo.Options.Add(itemPrefix + AdminServicesProviderOptionsHelper.IsPrimaryFile, file.IsPrimaryFile);
}
return databaseInfo;
}
public static DatabasePrototype ApplyToPrototype(DatabaseInfo databaseInfo, DatabasePrototype prototype)
{
prototype.Name = databaseInfo.Options[AdminServicesProviderOptionsHelper.Name] as string;
return prototype;
}
}
}