From ed978fe5b70b9c165111d74b7ba5a0d0bbf8116a Mon Sep 17 00:00:00 2001 From: Karl Burtram Date: Fri, 12 May 2017 07:53:45 -0700 Subject: [PATCH] Fix create db resource strings (#348) * Hook up SMO call into create db handler * Clean-up resource strings * Few additional code clean-ups --- .../Admin/AdminService.cs | 12 +++- .../{Common => Database}/AzureSqlDbHelper.cs | 62 ------------------- .../CreateDatabaseObjects.cs} | 49 +++++++-------- .../{Common => Database}/DatabasePrototype.cs | 54 ++++++++-------- .../DatabasePrototype100.cs | 14 ++--- .../DatabasePrototype110.cs | 0 .../DatabasePrototype80.cs | 27 ++++---- .../DatabasePrototype80SP3.cs | 6 -- .../DatabasePrototype90.cs | 35 +++++------ .../DatabasePrototype90EnterpriseSP2.cs | 4 -- .../DatabasePrototypeAzure.cs | 0 .../DatabaseTaskHelper.cs | 11 ++++ .../Workspace/Workspace.cs | 3 - .../Admin/DatabaseAdminTests.cs | 11 ++-- .../TestConfigPersistenceHelper.cs | 20 ++++++ 15 files changed, 128 insertions(+), 180 deletions(-) rename src/Microsoft.SqlTools.ServiceLayer/Admin/{Common => Database}/AzureSqlDbHelper.cs (83%) rename src/Microsoft.SqlTools.ServiceLayer/Admin/{Common/CreateDatabaseData.cs => Database/CreateDatabaseObjects.cs} (97%) rename src/Microsoft.SqlTools.ServiceLayer/Admin/{Common => Database}/DatabasePrototype.cs (98%) rename src/Microsoft.SqlTools.ServiceLayer/Admin/{Common => Database}/DatabasePrototype100.cs (94%) rename src/Microsoft.SqlTools.ServiceLayer/Admin/{Common => Database}/DatabasePrototype110.cs (100%) rename src/Microsoft.SqlTools.ServiceLayer/Admin/{Common => Database}/DatabasePrototype80.cs (85%) rename src/Microsoft.SqlTools.ServiceLayer/Admin/{Common => Database}/DatabasePrototype80SP3.cs (78%) rename src/Microsoft.SqlTools.ServiceLayer/Admin/{Common => Database}/DatabasePrototype90.cs (82%) rename src/Microsoft.SqlTools.ServiceLayer/Admin/{Common => Database}/DatabasePrototype90EnterpriseSP2.cs (88%) rename src/Microsoft.SqlTools.ServiceLayer/Admin/{Common => Database}/DatabasePrototypeAzure.cs (100%) rename src/Microsoft.SqlTools.ServiceLayer/Admin/{Common => Database}/DatabaseTaskHelper.cs (95%) diff --git a/src/Microsoft.SqlTools.ServiceLayer/Admin/AdminService.cs b/src/Microsoft.SqlTools.ServiceLayer/Admin/AdminService.cs index 673cde00..84c0e978 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Admin/AdminService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Admin/AdminService.cs @@ -11,6 +11,7 @@ using Microsoft.SqlTools.ServiceLayer.SqlContext; using System; using System.Threading.Tasks; using System.Xml; +using Microsoft.SqlServer.Management.Smo; namespace Microsoft.SqlTools.ServiceLayer.Admin { @@ -144,11 +145,16 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin out connInfo); DatabaseTaskHelper taskHelper = CreateDatabaseTaskHelper(connInfo); + DatabasePrototype prototype = taskHelper.Prototype; DatabaseTaskHelper.ApplyToPrototype(databaseParams.DatabaseInfo, taskHelper.Prototype); - response.DefaultDatabaseInfo = DatabaseTaskHelper.DatabasePrototypeToDatabaseInfo(taskHelper.Prototype); - - await requestContext.SendResult(new CreateDatabaseResponse()); + Database db = prototype.ApplyChanges(); + + await requestContext.SendResult(new CreateDatabaseResponse() + { + Result = true, + TaskId = 0 + }); } /// diff --git a/src/Microsoft.SqlTools.ServiceLayer/Admin/Common/AzureSqlDbHelper.cs b/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/AzureSqlDbHelper.cs similarity index 83% rename from src/Microsoft.SqlTools.ServiceLayer/Admin/Common/AzureSqlDbHelper.cs rename to src/Microsoft.SqlTools.ServiceLayer/Admin/Database/AzureSqlDbHelper.cs index d51d9cfe..aaa3a8f2 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Admin/Common/AzureSqlDbHelper.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/AzureSqlDbHelper.cs @@ -198,68 +198,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin /// static AzureSqlDbHelper() { - //foreach (AzureEdition edition in Enum.GetValues(typeof (AzureEdition))) - //{ - // object value; - - // try - // { - // value = Registry.GetValue( - // string.Format(CultureInfo.InvariantCulture, @"{0}\{1}", SSMSAzureRegKey, - // AzureServiceObjectivesRegSubKey), edition.ToString(), null); - // } - // catch (Exception e) - // { - // //We don't really care if we can't read in an override (just fall back to default) so log and move on - // TraceContext.TraceVerbose("Exception reading service objective overrides for {0} - {1}", edition, e.Message); - // continue; - // } - - // if (value != null) - // { - // TraceContext.TraceVerbose("Found ServiceObjective override for {0}, value is {1}", edition, value); - // //Key is in format : - // //e.g. 2:S0,S1,S2 - // //Only split into 2 parts since the service objectives could - // //be changed in the future to have :'s, so only treat the first - // //as special - // string[] values = value.ToString().Split(new[] {':'}, 2); - // if (values.Length != 2) - // { - // //Badly formatted value, ignore this one - // TraceContext.TraceVerbose("ServiceObjective override for {0} is badly formatted - skipping", edition); - // continue; - // } - - // int defaultIndex; - // if (!int.TryParse(values[0], out defaultIndex)) - // { - // //Invalid default index, ignore this one - // TraceContext.TraceVerbose("ServiceObjective override for {0} has non-parseable default index - skipping", edition); - // continue; - // } - - // //Service objectives are in a comma-separated list - // string[] serviceObjectives = values[1].Split(','); - // if (defaultIndex < 0 || defaultIndex >= serviceObjectives.Length) - // { - // //Index out of bounds, ignore this one - // TraceContext.TraceVerbose("ServiceObjective override for {0} has out of bounds default index - skipping"); - // continue; - // } - // if (AzureServiceObjectiveInfo.ContainsKey(edition)) - // { - // //Overwrite our default values if the registry key for this edition exists - // AzureServiceObjectiveInfo[edition] = new KeyValuePair(defaultIndex, - // serviceObjectives); - // } - // else - // { - // AzureServiceObjectiveInfo.Add(edition, - // new KeyValuePair(defaultIndex, serviceObjectives)); - // } - // } - //} } /// diff --git a/src/Microsoft.SqlTools.ServiceLayer/Admin/Common/CreateDatabaseData.cs b/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/CreateDatabaseObjects.cs similarity index 97% rename from src/Microsoft.SqlTools.ServiceLayer/Admin/Common/CreateDatabaseData.cs rename to src/Microsoft.SqlTools.ServiceLayer/Admin/Database/CreateDatabaseObjects.cs index 7dc1e5b4..3572eb0d 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Admin/Common/CreateDatabaseData.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/CreateDatabaseObjects.cs @@ -2033,26 +2033,25 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin if (isAllWhitespace || (0 == fileName.Length) || (-1 != fileName.IndexOfAny(badFileCharacters))) { - ResourceManager resourceManager = - new ResourceManager("Microsoft.SqlServer.Management.SqlManagerUI.CreateDatabaseStrings", - this.GetType().GetAssembly()); + ResourceManager resourceManager = new ResourceManager("Microsoft.SqlTools.ServiceLayer.Localization.SR", typeof(DatabasePrototype).GetAssembly()); + string message = String.Empty; if (0 == fileName.Length) { - message = resourceManager.GetString("error.emptyFileName"); + message = resourceManager.GetString("error_emptyFileName"); } else if (isAllWhitespace) { - message = resourceManager.GetString("error.whitespaceDatabaseName"); + message = resourceManager.GetString("error_whitespaceDatabaseName"); } else { int i = fileName.IndexOfAny(badFileCharacters); message = String.Format(System.Globalization.CultureInfo.CurrentCulture, - resourceManager.GetString("error.fileNameContainsIllegalCharacter"), fileName, fileName[i]); + resourceManager.GetString("error_fileNameContainsIllegalCharacter"), fileName, fileName[i]); } throw new InvalidOperationException(message); @@ -2119,9 +2118,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin /// If logical name is empty, or physical name is invalid. private string MakeDiskFileName(string logicalName, string preferredPhysicalName, string suffix) { - ResourceManager resourceManager = - new ResourceManager("Microsoft.SqlServer.Management.SqlManagerUI.CreateDatabaseStrings", - this.GetType().GetAssembly()); + ResourceManager resourceManager = new ResourceManager("Microsoft.SqlTools.ServiceLayer.Localization.SR", typeof(DatabasePrototype).GetAssembly()); string filePath = String.Empty; // returned to the caller. if (String.IsNullOrEmpty(preferredPhysicalName)) @@ -2140,7 +2137,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin { string message = String.Empty; - message = resourceManager.GetString("error.emptyFileName"); + message = resourceManager.GetString("error_emptyFileName"); throw new InvalidOperationException(message); } @@ -2468,18 +2465,16 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin /// List of Restrict Access Types public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { - ResourceManager manager = - new ResourceManager("Microsoft.SqlServer.Management.SqlManagerUI.CreateDatabaseStrings", - typeof (DatabasePrototype).GetAssembly()); + ResourceManager manager = new ResourceManager("Microsoft.SqlTools.ServiceLayer.Localization.SR", typeof(DatabasePrototype).GetAssembly()); List standardValues = new List(); TypeConverter.StandardValuesCollection result = null; if (string.Compare(context.PropertyDescriptor.Name, "RestrictAccess", StringComparison.OrdinalIgnoreCase) == 0) { - standardValues.Add(manager.GetString("prototype.db.prop.restrictAccess.value.multiple")); - standardValues.Add(manager.GetString("prototype.db.prop.restrictAccess.value.single")); - standardValues.Add(manager.GetString("prototype.db.prop.restrictAccess.value.restricted")); + standardValues.Add(manager.GetString("prototype_db_prop_restrictAccess_value_multiple")); + standardValues.Add(manager.GetString("prototype_db_prop_restrictAccess_value_single")); + standardValues.Add(manager.GetString("prototype_db_prop_restrictAccess_value_restricted")); } if (standardValues.Count > 0) { @@ -2520,17 +2515,17 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin string.Compare(context.PropertyDescriptor.Name, "DatabaseStatusDisplay", StringComparison.OrdinalIgnoreCase) == 0) { - standardValues.Add(manager.GetString("prototype.db.prop.databaseState.value.normal")); - standardValues.Add(manager.GetString("prototype.db.prop.databaseState.value.restoring")); - standardValues.Add(manager.GetString("prototype.db.prop.databaseState.value.recoveryPending")); - standardValues.Add(manager.GetString("prototype.db.prop.databaseState.value.recovering")); - standardValues.Add(manager.GetString("prototype.db.prop.databaseState.value.suspect")); - standardValues.Add(manager.GetString("prototype.db.prop.databaseState.value.offline")); - standardValues.Add(manager.GetString("prototype.db.prop.databaseState.value.inaccessible")); - standardValues.Add(manager.GetString("prototype.db.prop.databaseState.value.standby")); - standardValues.Add(manager.GetString("prototype.db.prop.databaseState.value.shutdown")); - standardValues.Add(manager.GetString("prototype.db.prop.databaseState.value.emergency")); - standardValues.Add(manager.GetString("prototype.db.prop.databaseState.value.autoClosed")); + standardValues.Add(manager.GetString("prototype_db_prop_databaseState_value_normal")); + standardValues.Add(manager.GetString("prototype_db_prop_databaseState_value_restoring")); + standardValues.Add(manager.GetString("prototype_db_prop_databaseState_value_recoveryPending")); + standardValues.Add(manager.GetString("prototype_db_prop_databaseState_value_recovering")); + standardValues.Add(manager.GetString("prototype_db_prop_databaseState_value_suspect")); + standardValues.Add(manager.GetString("prototype_db_prop_databaseState_value_offline")); + standardValues.Add(manager.GetString("prototype_db_prop_databaseState_value_inaccessible")); + standardValues.Add(manager.GetString("prototype_db_prop_databaseState_value_standby")); + standardValues.Add(manager.GetString("prototype_db_prop_databaseState_value_shutdown")); + standardValues.Add(manager.GetString("prototype_db_prop_databaseState_value_emergency")); + standardValues.Add(manager.GetString("prototype_db_prop_databaseState_value_autoClosed")); } if (standardValues.Count > 0) { diff --git a/src/Microsoft.SqlTools.ServiceLayer/Admin/Common/DatabasePrototype.cs b/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabasePrototype.cs similarity index 98% rename from src/Microsoft.SqlTools.ServiceLayer/Admin/Common/DatabasePrototype.cs rename to src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabasePrototype.cs index 963a6b12..49225727 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Admin/Common/DatabasePrototype.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabasePrototype.cs @@ -983,61 +983,61 @@ WHERE do.database_id = @DbID get { string result = null; - ResourceManager manager = new ResourceManager("Microsoft.SqlServer.Management.SqlManagerUI.CreateDatabaseStrings", typeof(DatabasePrototype90).GetAssembly()); - + ResourceManager manager = new ResourceManager("Microsoft.SqlTools.ServiceLayer.Localization.SR", typeof(DatabasePrototype).GetAssembly()); + if ((this.currentState.databaseState & DatabaseStatus.Normal) != 0) { - result = this.AppendState(result, manager.GetString("prototype.db.prop.databaseState.value.normal")); + result = this.AppendState(result, manager.GetString("prototype_db_prop_databaseState_value_normal")); } if ((this.currentState.databaseState & DatabaseStatus.Restoring) != 0) { - result = this.AppendState(result, manager.GetString("prototype.db.prop.databaseState.value.restoring")); + result = this.AppendState(result, manager.GetString("prototype_db_prop_databaseState_value_restoring")); } if ((this.currentState.databaseState & DatabaseStatus.RecoveryPending) != 0) { - result = this.AppendState(result, manager.GetString("prototype.db.prop.databaseState.value.recoveryPending")); + result = this.AppendState(result, manager.GetString("prototype_db_prop_databaseState_value_recoveryPending")); } if ((this.currentState.databaseState & DatabaseStatus.Recovering) != 0) { - result = this.AppendState(result, manager.GetString("prototype.db.prop.databaseState.value.recovering")); + result = this.AppendState(result, manager.GetString("prototype_db_prop_databaseState_value_recovering")); } if ((this.currentState.databaseState & DatabaseStatus.Suspect) != 0) { - result = this.AppendState(result, manager.GetString("prototype.db.prop.databaseState.value.suspect")); + result = this.AppendState(result, manager.GetString("prototype_db_prop_databaseState_value_suspect")); } if ((this.currentState.databaseState & DatabaseStatus.Offline) != 0) { - result = this.AppendState(result, manager.GetString("prototype.db.prop.databaseState.value.offline")); + result = this.AppendState(result, manager.GetString("prototype_db_prop_databaseState_value_offline")); } if ((this.currentState.databaseState & DatabaseStatus.Inaccessible) != 0) { - result = this.AppendState(result, manager.GetString("prototype.db.prop.databaseState.value.inaccessible")); + result = this.AppendState(result, manager.GetString("prototype_db_prop_databaseState_value_inaccessible")); } if ((this.currentState.databaseState & DatabaseStatus.Standby) != 0) { - result = this.AppendState(result, manager.GetString("prototype.db.prop.databaseState.value.standby")); + result = this.AppendState(result, manager.GetString("prototype_db_prop_databaseState_value_standby")); } if ((this.currentState.databaseState & DatabaseStatus.Shutdown) != 0) { - result = this.AppendState(result, manager.GetString("prototype.db.prop.databaseState.value.shutdown")); + result = this.AppendState(result, manager.GetString("prototype_db_prop_databaseState_value_shutdown")); } if ((this.currentState.databaseState & DatabaseStatus.EmergencyMode) != 0) { - result = this.AppendState(result, manager.GetString("prototype.db.prop.databaseState.value.emergency")); + result = this.AppendState(result, manager.GetString("prototype_db_prop_databaseState_value_emergency")); } if ((this.currentState.databaseState & DatabaseStatus.AutoClosed) != 0) { - result = this.AppendState(result, manager.GetString("prototype.db.prop.databaseState.value.autoClosed")); + result = this.AppendState(result, manager.GetString("prototype_db_prop_databaseState_value_autoClosed")); } return result; @@ -1089,19 +1089,19 @@ WHERE do.database_id = @DbID { get { - ResourceManager manager = new ResourceManager("Microsoft.SqlServer.Management.SqlManagerUI.CreateDatabaseStrings", typeof(DatabasePrototype).GetAssembly()); + ResourceManager manager = new ResourceManager("Microsoft.SqlTools.ServiceLayer.Localization.SR", typeof(DatabasePrototype).GetAssembly()); string result = null; switch (this.currentState.defaultCursor) { case DefaultCursor.Local: - result = manager.GetString("prototype.db.prop.defaultCursor.value.local"); + result = manager.GetString("prototype_db_prop_defaultCursor_value_local"); break; case DefaultCursor.Global: - result = manager.GetString("prototype.db.prop.defaultCursor.value.global"); + result = manager.GetString("prototype_db_prop_defaultCursor_value_global"); break; } @@ -1110,9 +1110,9 @@ WHERE do.database_id = @DbID set { - ResourceManager manager = new ResourceManager("Microsoft.SqlServer.Management.SqlManagerUI.CreateDatabaseStrings", typeof(DatabasePrototype).GetAssembly()); - - if (value == manager.GetString("prototype.db.prop.defaultCursor.value.local")) + ResourceManager manager = new ResourceManager("Microsoft.SqlTools.ServiceLayer.Localization.SR", typeof(DatabasePrototype).GetAssembly()); + + if (value == manager.GetString("prototype_db_prop_defaultCursor_value_local")) { this.currentState.defaultCursor = DefaultCursor.Local; } @@ -1547,7 +1547,7 @@ WHERE do.database_id = @DbID } } - // $FUTURE: 6/29/2004-stevetw Make sure version checks use this property, + // Make sure version checks use this property, // not explicit comparisons against the server major version /// /// Whether the server is Yukon or later @@ -1897,9 +1897,7 @@ WHERE do.database_id = @DbID db.Alter(termination); } - // FIXED-SQLBUDefectTracking-20006074-2005/07/11-stevetw // have to explicitly set the default filegroup after the database has been created - // Also bug 97696 foreach (FilegroupPrototype filegroup in Filegroups) { if (filegroup.IsDefault && !(filegroup.Exists && db.FileGroups[filegroup.Name].IsDefault)) @@ -2609,19 +2607,19 @@ WHERE do.database_id = @DbID { TypeConverter.StandardValuesCollection result = null; - ResourceManager manager = new ResourceManager("Microsoft.SqlServer.Management.SqlManagerUI.CreateDatabaseStrings", typeof(DatabasePrototype).GetAssembly()); + ResourceManager manager = new ResourceManager("Microsoft.SqlTools.ServiceLayer.Localization.SR", typeof(DatabasePrototype).GetAssembly()); List standardValues = new List(); if (context.PropertyDescriptor.Name == "DefaultCursorDisplay") { - standardValues.Add(manager.GetString("prototype.db.prop.defaultCursor.value.local")); - standardValues.Add(manager.GetString("prototype.db.prop.defaultCursor.value.global")); + standardValues.Add(manager.GetString("prototype_db_prop_defaultCursor_value_local")); + standardValues.Add(manager.GetString("prototype_db_prop_defaultCursor_value_global")); } else if (context.PropertyDescriptor.Name == "RestrictAccess") { - standardValues.Add(manager.GetString("prototype.db.prop.restrictAccess.value.multiple")); - standardValues.Add(manager.GetString("prototype.db.prop.restrictAccess.value.single")); - standardValues.Add(manager.GetString("prototype.db.prop.restrictAccess.value.restricted")); + standardValues.Add(manager.GetString("prototype_db_prop_restrictAccess_value_multiple")); + standardValues.Add(manager.GetString("prototype_db_prop_restrictAccess_value_single")); + standardValues.Add(manager.GetString("prototype_db_prop_restrictAccess_value_restricted")); } if (standardValues.Count > 0) diff --git a/src/Microsoft.SqlTools.ServiceLayer/Admin/Common/DatabasePrototype100.cs b/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabasePrototype100.cs similarity index 94% rename from src/Microsoft.SqlTools.ServiceLayer/Admin/Common/DatabasePrototype100.cs rename to src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabasePrototype100.cs index 47d9e28b..f5178e72 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Admin/Common/DatabasePrototype100.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabasePrototype100.cs @@ -253,21 +253,21 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin /// A string from the resource manager representing the value. private string GetDatabaseScopedConfigDisplayText(DatabaseScopedConfigurationOnOff onOffValue) { - ResourceManager manager = new ResourceManager("Microsoft.SqlServer.Management.SqlManagerUI.CreateDatabaseStrings", typeof(DatabasePrototype).GetAssembly()); + ResourceManager manager = new ResourceManager("Microsoft.SqlTools.ServiceLayer.Localization.SR", typeof(DatabasePrototype).GetAssembly()); string result = null; switch (onOffValue) { case DatabaseScopedConfigurationOnOff.Off: - result = manager.GetString("prototype.db.prop.databasescopedconfig.value.off"); + result = manager.GetString("prototype_db_prop_databasescopedconfig_value_off"); break; case DatabaseScopedConfigurationOnOff.On: - result = manager.GetString("prototype.db.prop.databasescopedconfig.value.on"); + result = manager.GetString("prototype_db_prop_databasescopedconfig_value_on"); break; case DatabaseScopedConfigurationOnOff.Primary: - result = manager.GetString("prototype.db.prop.databasescopedconfig.value.primary"); + result = manager.GetString("prototype_db_prop_databasescopedconfig_value_primary"); break; } @@ -282,13 +282,13 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin /// The database scoped configuration enum value that matches the display text. private DatabaseScopedConfigurationOnOff SetDatabaseScopedConfigHelper(string displayText, bool forSecondary) { - ResourceManager manager = new ResourceManager("Microsoft.SqlServer.Management.SqlManagerUI.CreateDatabaseStrings", typeof(DatabasePrototype).GetAssembly()); + ResourceManager manager = new ResourceManager("Microsoft.SqlTools.ServiceLayer.Localization.SR", typeof(DatabasePrototype).GetAssembly()); - if (displayText == manager.GetString("prototype.db.prop.databasescopedconfig.value.off")) + if (displayText == manager.GetString("prototype_db_prop_databasescopedconfig_value_off")) { return DatabaseScopedConfigurationOnOff.Off; } - else if (displayText == manager.GetString("prototype.db.prop.databasescopedconfig.value.on") || !forSecondary) + else if (displayText == manager.GetString("prototype_db_prop_databasescopedconfig_value_on") || !forSecondary) { return DatabaseScopedConfigurationOnOff.On; } diff --git a/src/Microsoft.SqlTools.ServiceLayer/Admin/Common/DatabasePrototype110.cs b/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabasePrototype110.cs similarity index 100% rename from src/Microsoft.SqlTools.ServiceLayer/Admin/Common/DatabasePrototype110.cs rename to src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabasePrototype110.cs diff --git a/src/Microsoft.SqlTools.ServiceLayer/Admin/Common/DatabasePrototype80.cs b/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabasePrototype80.cs similarity index 85% rename from src/Microsoft.SqlTools.ServiceLayer/Admin/Common/DatabasePrototype80.cs rename to src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabasePrototype80.cs index 06f5f3f4..7f272827 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Admin/Common/DatabasePrototype80.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabasePrototype80.cs @@ -5,22 +5,17 @@ using System.ComponentModel; using System.Resources; -//using Microsoft.SqlServer.Management.SqlMgmt; using Microsoft.SqlServer.Management.Common; using Microsoft.SqlServer.Management.Smo; using Microsoft.SqlServer.Management.Sdk.Sfc; using Microsoft.SqlServer.Management.Diagnostics; using System.Collections.Generic; -//using DisplayNameAttribute = Microsoft.SqlServer.Management.SqlMgmt.DisplayNameAttribute; - namespace Microsoft.SqlTools.ServiceLayer.Admin { /// /// Database Prototype for SqlServer 2000 and later servers /// - //[TypeConverter(typeof(DynamicValueTypeConverter))] - //[StringResourceClass(typeof(Microsoft.SqlServer.Management.SqlManagerUI.CreateDatabaseOptionsSR))] internal class DatabasePrototype80 : DatabasePrototype, IDynamicValues { /// @@ -53,19 +48,19 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin { get { - ResourceManager manager = new ResourceManager("Microsoft.SqlServer.Management.SqlManagerUI.CreateDatabaseStrings", typeof(DatabasePrototype80).GetAssembly()); + ResourceManager manager = new ResourceManager("Microsoft.SqlTools.ServiceLayer.Localization.SR", typeof(DatabasePrototype).GetAssembly()); string result = null; switch (this.currentState.pageVerify) { case PageVerify.Checksum: - result = manager.GetString("prototype.db.prop.pageVerify.value.checksum"); + result = manager.GetString("prototype_db_prop_pageVerify_value_checksum"); break; case PageVerify.None: - result = manager.GetString("prototype.db.prop.pageVerify.value.none"); + result = manager.GetString("prototype_db_prop_pageVerify_value_none"); break; case PageVerify.TornPageDetection: @@ -79,12 +74,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin set { - ResourceManager manager = new ResourceManager("Microsoft.SqlServer.Management.SqlManagerUI.CreateDatabaseStrings", typeof(DatabasePrototype80).GetAssembly()); - if (value == manager.GetString("prototype.db.prop.pageVerify.value.checksum")) + ResourceManager manager = new ResourceManager("Microsoft.SqlTools.ServiceLayer.Localization.SR", typeof(DatabasePrototype).GetAssembly()); + if (value == manager.GetString("prototype_db_prop_pageVerify_value_checksum")) { this.currentState.pageVerify = PageVerify.Checksum; } - else if (value == manager.GetString("prototype.db.prop.pageVerify.value.none")) + else if (value == manager.GetString("prototype_db_prop_pageVerify_value_none")) { this.currentState.pageVerify = PageVerify.None; } @@ -198,7 +193,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin { base.SaveProperties(db); - ResourceManager manager = new ResourceManager("Microsoft.SqlServer.Management.SqlManagerUI.CreateDatabaseStrings", typeof(DatabasePrototype).GetAssembly()); + ResourceManager manager = new ResourceManager("Microsoft.SqlTools.ServiceLayer.Localization.SR", typeof(DatabasePrototype).GetAssembly()); // never set the real database collation to "" - there is no // real collation with that name. "" is only valid for new @@ -257,16 +252,16 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin if (context.PropertyDescriptor.Name == "PageVerifyDisplay") { - ResourceManager manager = new ResourceManager("Microsoft.SqlServer.Management.SqlManagerUI.CreateDatabaseStrings", typeof(DatabasePrototype80).GetAssembly()); + ResourceManager manager = new ResourceManager("Microsoft.SqlTools.ServiceLayer.Localization.SR", typeof(DatabasePrototype).GetAssembly()); List standardValues = new List(); if (this.IsYukonOrLater) { - standardValues.Add(manager.GetString("prototype.db.prop.pageVerify.value.checksum")); + standardValues.Add(manager.GetString("prototype_db_prop_pageVerify_value_checksum")); } - standardValues.Add(manager.GetString("prototype.db.prop.pageVerify.value.tornPageDetection")); - standardValues.Add(manager.GetString("prototype.db.prop.pageVerify.value.none")); + standardValues.Add(manager.GetString("prototype_db_prop_pageVerify_value_tornPageDetection")); + standardValues.Add(manager.GetString("prototype_db_prop_pageVerify_value_none")); result = new TypeConverter.StandardValuesCollection(standardValues); } diff --git a/src/Microsoft.SqlTools.ServiceLayer/Admin/Common/DatabasePrototype80SP3.cs b/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabasePrototype80SP3.cs similarity index 78% rename from src/Microsoft.SqlTools.ServiceLayer/Admin/Common/DatabasePrototype80SP3.cs rename to src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabasePrototype80SP3.cs index 49121cf4..c1fc9b80 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Admin/Common/DatabasePrototype80SP3.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabasePrototype80SP3.cs @@ -4,18 +4,14 @@ // using System.ComponentModel; -// using Microsoft.SqlServer.Management.SqlMgmt; using Microsoft.SqlServer.Management.Sdk.Sfc; -// using DisplayNameAttribute = Microsoft.SqlServer.Management.SqlMgmt.DisplayNameAttribute; - namespace Microsoft.SqlTools.ServiceLayer.Admin { /// /// Database Prototype for SqlServer 2000 SP3 and later servers /// [TypeConverter(typeof(DynamicValueTypeConverter))] - //[StringResourceClass(typeof(Microsoft.SqlServer.Management.SqlManagerUI.CreateDatabaseOptionsSR))] internal class DatabasePrototype80SP3 : DatabasePrototype80 { /// @@ -35,5 +31,3 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin public DatabasePrototype80SP3(CDataContainer context) : base(context) { } } } - - diff --git a/src/Microsoft.SqlTools.ServiceLayer/Admin/Common/DatabasePrototype90.cs b/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabasePrototype90.cs similarity index 82% rename from src/Microsoft.SqlTools.ServiceLayer/Admin/Common/DatabasePrototype90.cs rename to src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabasePrototype90.cs index 2870ba91..9a2774ab 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Admin/Common/DatabasePrototype90.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabasePrototype90.cs @@ -5,22 +5,17 @@ using System.ComponentModel; using System.Resources; -// using Microsoft.SqlServer.Management.SqlMgmt; using Microsoft.SqlServer.Management.Smo; using Microsoft.SqlServer.Management.Common; using Microsoft.SqlServer.Management.Sdk.Sfc; using Microsoft.SqlServer.Management.Diagnostics; using System.Collections.Generic; -// using DisplayNameAttribute = Microsoft.SqlServer.Management.SqlMgmt.DisplayNameAttribute; - namespace Microsoft.SqlTools.ServiceLayer.Admin { /// /// Database Prototype for SqlServer 2005 and later servers /// - //[TypeConverter(typeof(DynamicValueTypeConverter))] - //[StringResourceClass(typeof(Microsoft.SqlServer.Management.SqlManagerUI.CreateDatabaseOptionsSR))] internal class DatabasePrototype90 : DatabasePrototype80SP3, IDynamicValues { /// @@ -51,24 +46,24 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin { get { - ResourceManager manager = new ResourceManager("Microsoft.SqlServer.Management.SqlManagerUI.CreateDatabaseStrings", typeof(DatabasePrototype80).GetAssembly()); + ResourceManager manager = new ResourceManager("Microsoft.SqlTools.ServiceLayer.Localization.SR", typeof(DatabasePrototype).GetAssembly()); string result = null; switch (this.currentState.pageVerify) { case PageVerify.Checksum: - result = manager.GetString("prototype.db.prop.pageVerify.value.checksum"); + result = manager.GetString("prototype_db_prop_pageVerify_value_checksum"); break; case PageVerify.None: - result = manager.GetString("prototype.db.prop.pageVerify.value.none"); + result = manager.GetString("prototype_db_prop_pageVerify_value_none"); break; case PageVerify.TornPageDetection: - result = manager.GetString("prototype.db.prop.pageVerify.value.tornPageDetection"); + result = manager.GetString("prototype_db_prop_pageVerify_value_tornPageDetection"); break; } @@ -77,12 +72,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin set { - ResourceManager manager = new ResourceManager("Microsoft.SqlServer.Management.SqlManagerUI.CreateDatabaseStrings", typeof(DatabasePrototype80).GetAssembly()); - if (value == manager.GetString("prototype.db.prop.pageVerify.value.checksum")) + ResourceManager manager = new ResourceManager("Microsoft.SqlTools.ServiceLayer.Localization.SR", typeof(DatabasePrototype).GetAssembly()); + if (value == manager.GetString("prototype_db_prop_pageVerify_value_checksum")) { this.currentState.pageVerify = PageVerify.Checksum; } - else if (value == manager.GetString("prototype.db.prop.pageVerify.value.none")) + else if (value == manager.GetString("prototype_db_prop_pageVerify_value_none")) { this.currentState.pageVerify = PageVerify.None; } @@ -192,17 +187,17 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin { get { - ResourceManager manager = new ResourceManager("Microsoft.SqlServer.Management.SqlManagerUI.CreateDatabaseStrings", typeof(DatabasePrototype90).GetAssembly()); + ResourceManager manager = new ResourceManager("Microsoft.SqlTools.ServiceLayer.Localization.SR", typeof(DatabasePrototype).GetAssembly()); string result = this.currentState.parameterization ? - manager.GetString("prototype.db.prop.parameterization.value.forced") : - manager.GetString("prototype.db.prop.parameterization.value.simple"); + manager.GetString("prototype_db_prop_parameterization_value_forced") : + manager.GetString("prototype_db_prop_parameterization_value_simple"); return result; } set { - ResourceManager manager = new ResourceManager("Microsoft.SqlServer.Management.SqlManagerUI.CreateDatabaseStrings", typeof(DatabasePrototype90).GetAssembly()); - this.currentState.parameterization = (value == manager.GetString("prototype.db.prop.parameterization.value.forced")); + ResourceManager manager = new ResourceManager("Microsoft.SqlTools.ServiceLayer.Localization.SR", typeof(DatabasePrototype).GetAssembly()); + this.currentState.parameterization = (value == manager.GetString("prototype_db_prop_parameterization_value_forced")); this.NotifyObservers(); } } @@ -267,10 +262,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin if (context.PropertyDescriptor.Name == "Parameterization") { - ResourceManager manager = new ResourceManager("Microsoft.SqlServer.Management.SqlManagerUI.CreateDatabaseStrings", typeof(DatabasePrototype90).GetAssembly()); + ResourceManager manager = new ResourceManager("Microsoft.SqlTools.ServiceLayer.Localization.SR", typeof(DatabasePrototype).GetAssembly()); List standardValues = new List(); - standardValues.Add(manager.GetString("prototype.db.prop.parameterization.value.forced")); - standardValues.Add(manager.GetString("prototype.db.prop.parameterization.value.simple")); + standardValues.Add(manager.GetString("prototype_db_prop_parameterization_value_forced")); + standardValues.Add(manager.GetString("prototype_db_prop_parameterization_value_simple")); result = new TypeConverter.StandardValuesCollection(standardValues); } else diff --git a/src/Microsoft.SqlTools.ServiceLayer/Admin/Common/DatabasePrototype90EnterpriseSP2.cs b/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabasePrototype90EnterpriseSP2.cs similarity index 88% rename from src/Microsoft.SqlTools.ServiceLayer/Admin/Common/DatabasePrototype90EnterpriseSP2.cs rename to src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabasePrototype90EnterpriseSP2.cs index 9d0ed1a4..23a63f6f 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Admin/Common/DatabasePrototype90EnterpriseSP2.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabasePrototype90EnterpriseSP2.cs @@ -4,19 +4,15 @@ // using System.ComponentModel; -// using Microsoft.SqlServer.Management.SqlMgmt; using Microsoft.SqlServer.Management.Smo; using Microsoft.SqlServer.Management.Sdk.Sfc; -// using DisplayNameAttribute = Microsoft.SqlServer.Management.SqlMgmt.DisplayNameAttribute; - namespace Microsoft.SqlTools.ServiceLayer.Admin { /// /// Database Prototype for SqlServer 2005 Enterprise SP2 and later servers /// [TypeConverter(typeof(DynamicValueTypeConverter))] - //[StringResourceClass(typeof(Microsoft.SqlServer.Management.SqlManagerUI.CreateDatabaseOptionsSR))] internal class DatabasePrototype90EnterpriseSP2 : DatabasePrototype90 { /// diff --git a/src/Microsoft.SqlTools.ServiceLayer/Admin/Common/DatabasePrototypeAzure.cs b/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabasePrototypeAzure.cs similarity index 100% rename from src/Microsoft.SqlTools.ServiceLayer/Admin/Common/DatabasePrototypeAzure.cs rename to src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabasePrototypeAzure.cs diff --git a/src/Microsoft.SqlTools.ServiceLayer/Admin/Common/DatabaseTaskHelper.cs b/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabaseTaskHelper.cs similarity index 95% rename from src/Microsoft.SqlTools.ServiceLayer/Admin/Common/DatabaseTaskHelper.cs rename to src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabaseTaskHelper.cs index 8114dc9f..0d417dd8 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Admin/Common/DatabaseTaskHelper.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabaseTaskHelper.cs @@ -155,11 +155,22 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin return defaultValue; } + private static int logicalNameCount = 0; + public static DatabasePrototype ApplyToPrototype(DatabaseInfo databaseInfo, DatabasePrototype prototype) { if (databaseInfo != null && prototype != null) { prototype.Name = GetValueOrDefault(AdminServicesProviderOptionsHelper.Name, databaseInfo.Options, prototype.Name); + + foreach (var file in prototype.Files) + { + if (string.IsNullOrWhiteSpace(file.Name)) + { + file.Name = prototype.Name + "_" + logicalNameCount; + } + } + } return prototype; } diff --git a/src/Microsoft.SqlTools.ServiceLayer/Workspace/Workspace.cs b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Workspace.cs index 894d0452..279c1b37 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Workspace/Workspace.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Workspace.cs @@ -117,9 +117,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Workspace filePath = fileUri.LocalPath.TrimStart('/'); } - // Some clients send paths with UNIX-style slashes, replace those if necessary - filePath = filePath.Replace('/', '\\'); - // Clients could specify paths with escaped space, [ and ] characters which .NET APIs // will not handle. These paths will get appropriately escaped just before being passed // into the SqlTools engine. diff --git a/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Admin/DatabaseAdminTests.cs b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Admin/DatabaseAdminTests.cs index 0f812f57..6f4a4aba 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Admin/DatabaseAdminTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Admin/DatabaseAdminTests.cs @@ -15,6 +15,7 @@ using Moq; using Microsoft.SqlTools.Hosting.Protocol; using Microsoft.SqlTools.ServiceLayer.Admin.Contracts; using Microsoft.SqlTools.ServiceLayer.Admin; +using System; namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.AdminServices { @@ -43,17 +44,20 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.AdminServices /// /// Validate creating a database with valid input /// - // [Fact] + [Fact] public async void CreateDatabaseWithValidInputTest() { var result = GetLiveAutoCompleteTestObjects(); var requestContext = new Mock>(); requestContext.Setup(x => x.SendResult(It.IsAny())).Returns(Task.FromResult(new object())); + var databaseInfo = new DatabaseInfo(); + databaseInfo.Options.Add("name", "testdb_" + new Random().Next(10000000, 99999999)); + var dbParams = new CreateDatabaseParams { OwnerUri = result.ConnectionInfo.OwnerUri, - DatabaseInfo = new DatabaseInfo() + DatabaseInfo = databaseInfo }; await AdminService.HandleCreateDatabaseRequest(dbParams, requestContext.Object); @@ -61,11 +65,10 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.AdminServices requestContext.VerifyAll(); } - /// /// Get a default database info object /// - // [Fact] + [Fact] public async void GetDefaultDatebaseInfoTest() { var result = GetLiveAutoCompleteTestObjects(); diff --git a/test/Microsoft.SqlTools.ServiceLayer.Test.Common/TestConfigPersistenceHelper.cs b/test/Microsoft.SqlTools.ServiceLayer.Test.Common/TestConfigPersistenceHelper.cs index 074e13a5..a1b89f46 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.Test.Common/TestConfigPersistenceHelper.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.Test.Common/TestConfigPersistenceHelper.cs @@ -11,6 +11,26 @@ using Newtonsoft.Json; namespace Microsoft.SqlTools.ServiceLayer.Test.Common { + /// + /// Class to handle loading test configuration settings + /// + /// Example contents of file at default location ~/sqlConnectionSettings.json + /// + /// { + /// "mssql.connections": [ + /// { + /// "server": "localhost", + /// "database": "master", + /// "authenticationType": "SqlLogin", + /// "user": "sa", + /// "password": "[putvaluehere]", + /// "serverType":"OnPrem", + /// "VersionKey": "defaultSql2016" + /// } + /// ] + /// } + /// + /// public sealed class TestConfigPersistenceHelper { private static string DefaultSettingFileName = Path.Combine(FileUtils.UserRootFolder, "sqlConnectionSettings.json");