diff --git a/src/Microsoft.SqlTools.ServiceLayer/Scripting/Contracts/ScriptingOptions.cs b/src/Microsoft.SqlTools.ServiceLayer/Scripting/Contracts/ScriptingOptions.cs index 8e056217..2fcf7074 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Scripting/Contracts/ScriptingOptions.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Scripting/Contracts/ScriptingOptions.cs @@ -13,17 +13,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting.Contracts /// /// Generate ANSI padding statements /// - public bool? ScriptAnsiPadding { get; set; } = false; - - /// - /// Returns Generate ANSI padding statements - /// - public bool? AnsiPadding { get { return ScriptAnsiPadding; } } + public virtual bool? ScriptAnsiPadding { get; set; } = false; /// /// Append the generated script to a file /// - public bool? AppendToFile { get; set; } = false; + public virtual bool? AppendToFile { get; set; } = false; /// /// Continue to script if an error occurs. Otherwise, stop. @@ -31,17 +26,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting.Contracts /// /// The default is true. /// - public bool? ContinueScriptingOnError { get; set; } = true; + public virtual bool? ContinueScriptingOnError { get; set; } = true; /// /// Convert user-defined data types to base types. /// - public bool? ConvertUDDTToBaseType { get; set; } = false; - - /// - /// Returns ConvertUDDTToBaseType - /// - public bool? ConvertUserDefinedDataTypesToBaseType { get { return ConvertUDDTToBaseType; } } + public virtual bool? ConvertUDDTToBaseType { get; set; } = false; /// /// Generate script for dependent objects for each object scripted. @@ -49,7 +39,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting.Contracts /// /// The default is false. /// - public bool? GenerateScriptForDependentObjects { get; set; } = false; + public virtual bool? GenerateScriptForDependentObjects { get; set; } = false; /// /// Include descriptive headers for each object generated. @@ -57,37 +47,27 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting.Contracts /// /// The default is true. /// - public bool? IncludeDescriptiveHeaders { get; set; } = true; - - /// - /// Returns IncludeDescriptiveHeaders - /// - public bool? IncludeHeaders { get { return IncludeDescriptiveHeaders; } } + public virtual bool? IncludeDescriptiveHeaders { get; set; } = true; /// /// Check that an object with the given name exists before dropping or altering or that an object with the given name does not exist before creating. /// - public bool? IncludeIfNotExists { get; set; } = false; + public virtual bool? IncludeIfNotExists { get; set; } = false; /// /// Script options to set vardecimal storage format. /// - public bool? IncludeVarDecimal { get; set; } = true; + public virtual bool? IncludeVarDecimal { get; set; } = true; /// /// Include system generated constraint names to enforce declarative referential integrity. /// - public bool? ScriptDriIncludeSystemNames { get; set; } = false; - - /// - /// Returns ScriptDriIncludeSystemNames - /// - public bool? DriIncludeSystemNames { get { return ScriptDriIncludeSystemNames; } } + public virtual bool? ScriptDriIncludeSystemNames { get; set; } = false; /// /// Include statements in the script that are not supported on the specified SQL Server database engine type. /// - public bool? IncludeUnsupportedStatements { get; set; } = true; + public virtual bool? IncludeUnsupportedStatements { get; set; } = true; /// /// Prefix object names with the object schema. @@ -95,27 +75,17 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting.Contracts /// /// The default is true. /// - public bool? SchemaQualify { get; set; } = true; - - /// - /// Returns SchemaQualify - /// - public bool? SchemaQualifyForeignKeysReferences { get { return SchemaQualify; } } + public virtual bool? SchemaQualify { get; set; } = true; /// /// Script options to set bindings option. /// - public bool? Bindings { get; set; } = false; + public virtual bool? Bindings { get; set; } = false; /// /// Script the objects that use collation. /// - public bool? Collation { get; set; } = false; - - /// - /// Returns false if Collation is true - /// - public bool? NoCollation { get { return !Collation; } } + public virtual bool? Collation { get; set; } = false; /// /// Script the default values. @@ -123,13 +93,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting.Contracts /// /// The default is true. /// - public bool? Default { get; set; } = true; - - /// - /// Returns the value of Default Property - /// - public bool? DriDefaults { get { return Default; } } - + public virtual bool? Default { get; set; } = true; /// /// Script Object CREATE/DROP statements. @@ -142,7 +106,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting.Contracts /// /// The default is ScriptCreate. /// - public string ScriptCreateDrop { get; set; } = "ScriptCreate"; + public virtual string ScriptCreateDrop { get; set; } = "ScriptCreate"; /// /// Script the Extended Properties for each object scripted. @@ -150,13 +114,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting.Contracts /// /// The default is true. /// - public bool? ScriptExtendedProperties { get; set; } = true; - - /// - /// Returns the value of ScriptExtendedProperties Property - /// - public bool? ExtendedProperties { get { return ScriptExtendedProperties; } } - + public virtual bool? ScriptExtendedProperties { get; set; } = true; /// /// Script only features compatible with the specified version of SQL Server. Possible values: @@ -167,11 +125,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting.Contracts /// Script120Compat /// Script130Compat /// Script140Compat + /// Script150Compat /// /// /// The default is Script140Compat. /// - public string ScriptCompatibilityOption { get; set; } = "Script140Compat"; + public virtual string ScriptCompatibilityOption { get; set; } = "Script140Compat"; /// /// Script only features compatible with the specified SQL Server database engine type. @@ -179,8 +138,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting.Contracts /// SingleInstance /// SqlAzure /// - public string TargetDatabaseEngineType { get; set; } = "SingleInstance"; - + public virtual string TargetDatabaseEngineType { get; set; } = "SingleInstance"; + /// /// Script only features compatible with the specified SQL Server database engine edition. /// Possible Values: @@ -191,28 +150,24 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting.Contracts /// SqlAzureDatabaseEdition /// SqlDatawarehouseEdition /// SqlServerStretchEdition + /// SqlManagedInstanceEdition /// - public string TargetDatabaseEngineEdition { get; set; } = "SqlServerEnterpriseEdition"; + public virtual string TargetDatabaseEngineEdition { get; set; } = "SqlServerEnterpriseEdition"; /// /// Script all logins available on the server. Passwords will not be scripted. /// - public bool? ScriptLogins { get; set; } = false; + public virtual bool? ScriptLogins { get; set; } = false; /// /// Generate object-level permissions. /// - public bool? ScriptObjectLevelPermissions { get; set; } = false; - - /// - /// Returns the value of ScriptObjectLevelPermissions Property - /// - public bool? Permissions { get { return ScriptObjectLevelPermissions; } } + public virtual bool? ScriptObjectLevelPermissions { get; set; } = false; /// /// Script owner for the objects. /// - public bool? ScriptOwner { get; set; } = false; + public virtual bool? ScriptOwner { get; set; } = false; /// /// Script statistics, and optionally include histograms, for each selected table or view. @@ -224,18 +179,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting.Contracts /// /// The default value is ScriptStatsNone. /// - public string ScriptStatistics { get; set; } = "ScriptStatsNone"; - - /// - /// Returns the value of ScriptStatistics Property - /// - public string Statistics { get { return ScriptStatistics; } } - + public virtual string ScriptStatistics { get; set; } = "ScriptStatsNone"; /// /// Generate USE DATABASE statement. /// - public bool? ScriptUseDatabase { get; set; } = true; + public virtual bool? ScriptUseDatabase { get; set; } = true; /// /// Generate script that contains schema only or schema and data. @@ -247,18 +196,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting.Contracts /// /// The default value is SchemaOnly. /// - public string TypeOfDataToScript { get; set; } = "SchemaOnly"; + public virtual string TypeOfDataToScript { get; set; } = "SchemaOnly"; /// /// Scripts the change tracking information. /// - public bool? ScriptChangeTracking { get; set; } = false; - - /// - /// Returns the value of ScriptChangeTracking Property - /// - public bool? ChangeTracking { get { return ScriptChangeTracking; } } - + public virtual bool? ScriptChangeTracking { get; set; } = false; /// /// Script the check constraints for each table or view scripted. @@ -266,23 +209,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting.Contracts /// /// The default value is true. /// - public bool? ScriptCheckConstraints { get; set; } = true; - - /// - /// Returns the value of ScriptCheckConstraints Property - /// - public bool? DriChecks { get { return ScriptCheckConstraints; } } + public virtual bool? ScriptCheckConstraints { get; set; } = true; /// /// Scripts the data compression information. /// - public bool? ScriptDataCompressionOptions { get; set; } = false; - - /// - /// Returns the value of ScriptDataCompressionOptions Property - /// - public bool? ScriptDataCompression { get { return ScriptDataCompressionOptions; } } - + public virtual bool? ScriptDataCompressionOptions { get; set; } = false; /// /// Script the foreign keys for each table scripted. @@ -290,24 +222,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting.Contracts /// /// The default value is true. /// - public bool? ScriptForeignKeys { get; set; } = true; - - /// - /// Returns the value of ScriptForeignKeys Property - /// - public bool? DriForeignKeys { get { return ScriptForeignKeys; } } - + public virtual bool? ScriptForeignKeys { get; set; } = true; /// /// Script the full-text indexes for each table or indexed view scripted. /// - public bool? ScriptFullTextIndexes { get; set; } = true; - - /// - /// Returns the value of ScriptFullTextIndexes Property - /// - public bool? FullTextIndexes { get { return ScriptFullTextIndexes; } } - + public virtual bool? ScriptFullTextIndexes { get; set; } = true; /// /// Script the indexes (including XML and clustered indexes) for each table or indexed view scripted. @@ -315,13 +235,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting.Contracts /// /// The default value is true. /// - public bool? ScriptIndexes { get; set; } = true; - - /// - /// Returns the value of ScriptIndexes Property - /// - public bool? DriIndexes { get { return ScriptIndexes; } } - + public virtual bool? ScriptIndexes { get; set; } = true; /// /// Script the primary keys for each table or view scripted @@ -329,24 +243,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting.Contracts /// /// The default value is true. /// - public bool? ScriptPrimaryKeys { get; set; } = true; - - /// - /// Returns the value of ScriptPrimaryKeys Property - /// - public bool? DriPrimaryKey { get { return ScriptPrimaryKeys; } } - + public virtual bool? ScriptPrimaryKeys { get; set; } = true; /// /// Script the triggers for each table or view scripted /// - public bool? ScriptTriggers { get; set; } = true; - - /// - /// Returns the value of ScriptTriggers Property - /// - public bool? Triggers { get { return ScriptTriggers; } } - + public virtual bool? ScriptTriggers { get; set; } = true; /// /// Script the unique keys for each table or view scripted. @@ -354,12 +256,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting.Contracts /// /// The default value is true. /// - public bool? UniqueKeys { get; set; } = true; - - /// - /// Returns the value of UniqueKeys Property - /// - public bool? DriUniqueKeys { get { return UniqueKeys; } } - + public virtual bool? UniqueKeys { get; set; } = true; + } } \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/Scripting/ScriptAsOptions.cs b/src/Microsoft.SqlTools.ServiceLayer/Scripting/ScriptAsOptions.cs new file mode 100644 index 00000000..f1f69088 --- /dev/null +++ b/src/Microsoft.SqlTools.ServiceLayer/Scripting/ScriptAsOptions.cs @@ -0,0 +1,712 @@ +// +// 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.ServiceLayer.Scripting.Contracts; +using Microsoft.SqlTools.Utility; + +namespace Microsoft.SqlTools.ServiceLayer.Scripting +{ + /// + /// A wrpaper of ScriptOptions to map the option name with the oen in SMO.ScriptingOptions + /// + public class ScriptAsOptions : ScriptOptions + { + public ScriptAsOptions(ScriptOptions scriptOptions) + { + Validate.IsNotNull(nameof(scriptOptions), scriptOptions); + ScriptOptions = scriptOptions; + } + + public ScriptOptions ScriptOptions { get; private set; } + + /// + /// Generate ANSI padding statements + /// + public override bool? ScriptAnsiPadding + { + get + { + return ScriptOptions.ScriptAnsiPadding; + } + set + { + ScriptOptions.ScriptAnsiPadding = value; + } + } + + + /// + /// Append the generated script to a file + /// + public override bool? AppendToFile + { + get + { + return ScriptOptions.AppendToFile; + } + set + { + ScriptOptions.AppendToFile = value; + } + } + + /// + /// Continue to script if an error occurs. Otherwise, stop. + /// + /// + /// The default is true. + /// + public override bool? ContinueScriptingOnError + { + get + { + return ScriptOptions.ContinueScriptingOnError; + } + set + { + ScriptOptions.ContinueScriptingOnError = value; + } + } + + /// + /// Convert user-defined data types to base types. + /// + public override bool? ConvertUDDTToBaseType + { + get + { + return ScriptOptions.ConvertUDDTToBaseType; + } + set + { + ScriptOptions.ConvertUDDTToBaseType = value; + } + } + + /// + /// Generate script for dependent objects for each object scripted. + /// + /// + /// The default is false. + /// + public override bool? GenerateScriptForDependentObjects + { + get + { + return ScriptOptions.GenerateScriptForDependentObjects; + } + set + { + ScriptOptions.GenerateScriptForDependentObjects = value; + } + } + + /// + /// Include descriptive headers for each object generated. + /// + /// + /// The default is true. + /// + public override bool? IncludeDescriptiveHeaders + { + get + { + return ScriptOptions.IncludeDescriptiveHeaders; + } + set + { + ScriptOptions.IncludeDescriptiveHeaders = value; + } + } + + /// + /// Check that an object with the given name exists before dropping or altering or that an object with the given name does not exist before creating. + /// + public override bool? IncludeIfNotExists + { + get + { + return ScriptOptions.IncludeIfNotExists; + } + set + { + ScriptOptions.IncludeIfNotExists = value; + } + } + + /// + /// Script options to set vardecimal storage format. + /// + public override bool? IncludeVarDecimal + { + get + { + return ScriptOptions.IncludeVarDecimal; + } + set + { + ScriptOptions.IncludeVarDecimal = value; + } + } + + /// + /// Include system generated constraint names to enforce declarative referential integrity. + /// + public override bool? ScriptDriIncludeSystemNames + { + get + { + return ScriptOptions.ScriptDriIncludeSystemNames; + } + set + { + ScriptOptions.ScriptDriIncludeSystemNames = value; + } + } + + /// + /// Include statements in the script that are not supported on the specified SQL Server database engine type. + /// + public override bool? IncludeUnsupportedStatements + { + get + { + return ScriptOptions.IncludeUnsupportedStatements; + } + set + { + ScriptOptions.IncludeUnsupportedStatements = value; + } + } + + /// + /// Prefix object names with the object schema. + /// + /// + /// The default is true. + /// + public override bool? SchemaQualify + { + get + { + return ScriptOptions.SchemaQualify; + } + set + { + ScriptOptions.SchemaQualify = value; + } + } + + /// + /// Script options to set bindings option. + /// + public override bool? Bindings + { + get + { + return ScriptOptions.Bindings; + } + set + { + ScriptOptions.Bindings = value; + } + } + + /// + /// Script the objects that use collation. + /// + public override bool? Collation + { + get + { + return ScriptOptions.Collation; + } + set + { + ScriptOptions.Collation = value; + } + } + + /// + /// Script the default values. + /// + /// + /// The default is true. + /// + public override bool? Default + { + get + { + return ScriptOptions.Default; + } + set + { + ScriptOptions.Default = value; + } + } + + /// + /// Script Object CREATE/DROP statements. + /// Possible values: + /// ScriptCreate + /// ScriptDrop + /// ScriptCreateDrop + /// ScriptSelect + /// + /// + /// The default is ScriptCreate. + /// + public override string ScriptCreateDrop + { + get + { + return ScriptOptions.ScriptCreateDrop; + } + set + { + ScriptOptions.ScriptCreateDrop = value; + } + } + + /// + /// Script the Extended Properties for each object scripted. + /// + /// + /// The default is true. + /// + public override bool? ScriptExtendedProperties + { + get + { + return ScriptOptions.ScriptExtendedProperties; + } + set + { + ScriptOptions.ScriptExtendedProperties = value; + } + } + + /// + /// Script only features compatible with the specified version of SQL Server. Possible values: + /// Script90Compat + /// Script100Compat + /// Script105Compat + /// Script110Compat + /// Script120Compat + /// Script130Compat + /// Script140Compat + /// + /// + /// The default is Script140Compat. + /// + public override string ScriptCompatibilityOption + { + get + { + return ScriptOptions.ScriptCompatibilityOption; + } + set + { + ScriptOptions.ScriptCompatibilityOption = value; + } + } + + /// + /// Script only features compatible with the specified SQL Server database engine type. + /// Possible Values: + /// SingleInstance + /// SqlAzure + /// + public override string TargetDatabaseEngineType + { + get + { + return ScriptOptions.TargetDatabaseEngineType; + } + set + { + ScriptOptions.TargetDatabaseEngineType = value; + } + } + + /// + /// Script only features compatible with the specified SQL Server database engine edition. + /// Possible Values: + /// SqlServerPersonalEdition + /// SqlServerStandardEdition + /// SqlServerEnterpriseEdition + /// SqlServerExpressEdition + /// SqlAzureDatabaseEdition + /// SqlDatawarehouseEdition + /// SqlServerStretchEdition + /// + public override string TargetDatabaseEngineEdition + { + get + { + return ScriptOptions.TargetDatabaseEngineEdition; + } + set + { + ScriptOptions.TargetDatabaseEngineEdition = value; + } + } + + /// + /// Script all logins available on the server. Passwords will not be scripted. + /// + public override bool? ScriptLogins + { + get + { + return ScriptOptions.ScriptLogins; + } + set + { + ScriptOptions.ScriptLogins = value; + } + } + + /// + /// Generate object-level permissions. + /// + public override bool? ScriptObjectLevelPermissions + { + get + { + return ScriptOptions.ScriptObjectLevelPermissions; + } + set + { + ScriptOptions.ScriptObjectLevelPermissions = value; + } + } + + /// + /// Script owner for the objects. + /// + public override bool? ScriptOwner + { + get + { + return ScriptOptions.ScriptOwner; + } + set + { + ScriptOptions.ScriptOwner = value; + } + } + + /// + /// Script statistics, and optionally include histograms, for each selected table or view. + /// Possible values: + /// ScriptStatsNone + /// ScriptStatsDDL + /// ScriptStatsAll + /// + /// + /// The default value is ScriptStatsNone. + /// + public override string ScriptStatistics + { + get + { + return ScriptOptions.ScriptStatistics; + } + set + { + ScriptOptions.ScriptStatistics = value; + } + } + + /// + /// Generate USE DATABASE statement. + /// + public override bool? ScriptUseDatabase + { + get + { + return ScriptOptions.ScriptUseDatabase; + } + set + { + ScriptOptions.ScriptUseDatabase = value; + } + } + + /// + /// Generate script that contains schema only or schema and data. + /// Possible Values: + /// SchemaAndData + /// DataOnly + /// SchemaOnly + /// + /// + /// The default value is SchemaOnly. + /// + public override string TypeOfDataToScript + { + get + { + return ScriptOptions.TypeOfDataToScript; + } + set + { + ScriptOptions.TypeOfDataToScript = value; + } + } + + /// + /// Scripts the change tracking information. + /// + public override bool? ScriptChangeTracking + { + get + { + return ScriptOptions.ScriptChangeTracking; + } + set + { + ScriptOptions.ScriptChangeTracking = value; + } + } + + /// + /// Script the check constraints for each table or view scripted. + /// + /// + /// The default value is true. + /// + public override bool? ScriptCheckConstraints + { + get + { + return ScriptOptions.ScriptCheckConstraints; + } + set + { + ScriptOptions.ScriptCheckConstraints = value; + } + } + + /// + /// Scripts the data compression information. + /// + public override bool? ScriptDataCompressionOptions + { + get + { + return ScriptOptions.ScriptDataCompressionOptions; + } + set + { + ScriptOptions.ScriptDataCompressionOptions = value; + } + } + + /// + /// Script the foreign keys for each table scripted. + /// + /// + /// The default value is true. + /// + public override bool? ScriptForeignKeys + { + get + { + return ScriptOptions.ScriptForeignKeys; + } + set + { + ScriptOptions.ScriptForeignKeys = value; + } + } + + /// + /// Script the full-text indexes for each table or indexed view scripted. + /// + public override bool? ScriptFullTextIndexes + { + get + { + return ScriptOptions.ScriptFullTextIndexes; + } + set + { + ScriptOptions.ScriptFullTextIndexes = value; + } + } + + /// + /// Script the indexes (including XML and clustered indexes) for each table or indexed view scripted. + /// + /// + /// The default value is true. + /// + public override bool? ScriptIndexes + { + get + { + return ScriptOptions.ScriptIndexes; + } + set + { + ScriptOptions.ScriptIndexes = value; + } + } + + /// + /// Script the primary keys for each table or view scripted + /// + /// + /// The default value is true. + /// + public override bool? ScriptPrimaryKeys + { + get + { + return ScriptOptions.ScriptPrimaryKeys; + } + set + { + ScriptOptions.ScriptPrimaryKeys = value; + } + } + + /// + /// Script the triggers for each table or view scripted + /// + public override bool? ScriptTriggers + { + get + { + return ScriptOptions.ScriptTriggers; + } + set + { + ScriptOptions.ScriptTriggers = value; + } + } + + /// + /// Script the unique keys for each table or view scripted. + /// + /// + /// The default value is true. + /// + public override bool? UniqueKeys + { + get + { + return ScriptOptions.UniqueKeys; + } + set + { + ScriptOptions.UniqueKeys = value; + } + } + + /// + /// Returns Generate ANSI padding statements + /// + public bool? AnsiPadding { get { return ScriptOptions.ScriptAnsiPadding; } } + + /// + /// Returns ConvertUDDTToBaseType + /// + public bool? ConvertUserDefinedDataTypesToBaseType { get { return ScriptOptions.ConvertUDDTToBaseType; } } + + /// + /// Returns IncludeDescriptiveHeaders + /// + public bool? IncludeHeaders { get { return ScriptOptions.IncludeDescriptiveHeaders; } } + + + /// + /// Returns ScriptDriIncludeSystemNames + /// + public bool? DriIncludeSystemNames { get { return ScriptOptions.ScriptDriIncludeSystemNames; } } + + /// + /// Returns SchemaQualify + /// + public bool? SchemaQualifyForeignKeysReferences { get { return ScriptOptions.SchemaQualify; } } + + /// + /// Returns false if Collation is true + /// + public bool? NoCollation { get { return !ScriptOptions.Collation; } } + + /// + /// Returns the value of Default Property + /// + public bool? DriDefaults { get { return ScriptOptions.Default; } } + + /// + /// Returns the value of ScriptExtendedProperties Property + /// + public bool? ExtendedProperties { get { return ScriptOptions.ScriptExtendedProperties; } } + + /// + /// Returns the value of ScriptObjectLevelPermissions Property + /// + public bool? Permissions { get { return ScriptOptions.ScriptObjectLevelPermissions; } } + + /// + /// Returns the value of ScriptStatistics Property + /// + public string Statistics { get { return ScriptOptions.ScriptStatistics; } } + + /// + /// Returns the value of ScriptChangeTracking Property + /// + public bool? ChangeTracking { get { return ScriptOptions.ScriptChangeTracking; } } + + + /// + /// Returns the value of ScriptCheckConstraints Property + /// + public bool? DriChecks { get { return ScriptOptions.ScriptCheckConstraints; } } + + /// + /// Returns the value of ScriptDataCompressionOptions Property + /// + public bool? ScriptDataCompression { get { return ScriptOptions.ScriptDataCompressionOptions; } } + + + /// + /// Returns the value of ScriptForeignKeys Property + /// + public bool? DriForeignKeys { get { return ScriptOptions.ScriptForeignKeys; } } + + + /// + /// Returns the value of ScriptFullTextIndexes Property + /// + public bool? FullTextIndexes { get { return ScriptOptions.ScriptFullTextIndexes; } } + + + /// + /// Returns the value of ScriptIndexes Property + /// + public bool? DriIndexes { get { return ScriptOptions.ScriptIndexes; } } + + + /// + /// Returns the value of ScriptPrimaryKeys Property + /// + public bool? DriPrimaryKey { get { return ScriptOptions.ScriptPrimaryKeys; } } + + /// + /// Returns the value of ScriptTriggers Property + /// + public bool? Triggers { get { return ScriptOptions.ScriptTriggers; } } + + /// + /// Returns the value of UniqueKeys Property + /// + public bool? DriUniqueKeys { get { return ScriptOptions.UniqueKeys; } } + } +} diff --git a/src/Microsoft.SqlTools.ServiceLayer/Scripting/ScriptAsScriptingOperation.cs b/src/Microsoft.SqlTools.ServiceLayer/Scripting/ScriptAsScriptingOperation.cs index 84aaeda2..71367f30 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Scripting/ScriptAsScriptingOperation.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Scripting/ScriptAsScriptingOperation.cs @@ -25,10 +25,17 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting { private static Dictionary scriptCompatabilityMap = LoadScriptCompatabilityMap(); - public ScriptAsScriptingOperation(ScriptingParams parameters): base(parameters) + public ScriptAsScriptingOperation(ScriptingParams parameters, ServerConnection serverConnection): base(parameters) + { + ServerConnection = serverConnection; + } + + public ScriptAsScriptingOperation(ScriptingParams parameters) : base(parameters) { } + internal ServerConnection ServerConnection { get; set; } + public override void Execute() { SqlServer.Management.Smo.Scripter scripter = null; @@ -41,28 +48,30 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting this.CancellationToken.ThrowIfCancellationRequested(); string resultScript = string.Empty; // TODO: try to use one of the existing connections - using (SqlConnection sqlConnection = new SqlConnection(this.Parameters.ConnectionString)) - { - sqlConnection.Open(); - ServerConnection serverConnection = new ServerConnection(sqlConnection); - Server server = new Server(serverConnection); - scripter = new SqlServer.Management.Smo.Scripter(server); - ScriptingOptions options = new ScriptingOptions(); - SetScriptBehavior(options); - PopulateAdvancedScriptOptions(this.Parameters.ScriptOptions, options); - options.WithDependencies = false; - options.ScriptData = false; - SetScriptingOptions(options); - // TODO: Not including the header by default. We have to get this option from client - options.IncludeHeaders = false; - scripter.Options = options; - scripter.Options.ScriptData = false; - scripter.ScriptingError += ScripterScriptingError; - UrnCollection urns = CreateUrns(serverConnection); - var result = scripter.Script(urns); - resultScript = GetScript(options, result); + Server server = new Server(ServerConnection); + if (!ServerConnection.IsOpen) + { + ServerConnection.Connect(); } + scripter = new SqlServer.Management.Smo.Scripter(server); + ScriptingOptions options = new ScriptingOptions(); + SetScriptBehavior(options); + ScriptAsOptions scriptAsOptions = new ScriptAsOptions(this.Parameters.ScriptOptions); + PopulateAdvancedScriptOptions(scriptAsOptions, options); + options.WithDependencies = false; + options.ScriptData = false; + SetScriptingOptions(options); + + // TODO: Not including the header by default. We have to get this option from client + options.IncludeHeaders = false; + scripter.Options = options; + scripter.Options.ScriptData = false; + scripter.ScriptingError += ScripterScriptingError; + UrnCollection urns = CreateUrns(ServerConnection); + var result = scripter.Script(urns); + resultScript = GetScript(options, result); + this.CancellationToken.ThrowIfCancellationRequested(); diff --git a/src/Microsoft.SqlTools.ServiceLayer/Scripting/ScripterCore.cs b/src/Microsoft.SqlTools.ServiceLayer/Scripting/ScripterCore.cs index d212a927..bbe47f6b 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Scripting/ScripterCore.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Scripting/ScripterCore.cs @@ -507,7 +507,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting ScriptDestination = "ToEditor" }; - return new ScriptAsScriptingOperation(parameters); + return new ScriptAsScriptingOperation(parameters, serverConnection); } internal string GetTargetDatabaseEngineEdition() diff --git a/src/Microsoft.SqlTools.ServiceLayer/Scripting/ScriptingService.cs b/src/Microsoft.SqlTools.ServiceLayer/Scripting/ScriptingService.cs index 75253042..5db281a8 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Scripting/ScriptingService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Scripting/ScriptingService.cs @@ -142,11 +142,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting } else { - ScriptAsScriptingOperation operation = new ScriptAsScriptingOperation(parameters); - operation.ProgressNotification += (sender, e) => requestContext.SendEvent(ScriptingProgressNotificationEvent.Type, e); - operation.CompleteNotification += (sender, e) => this.SendScriptingCompleteEvent(requestContext, ScriptingCompleteEvent.Type, e, operation, parameters.ScriptDestination); - - RunTask(requestContext, operation); + RunScriptAsTask(connInfo, parameters, requestContext); } } catch (Exception e) @@ -155,10 +151,34 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting } } - /// - /// Handles request to start the scripting operation - /// - public async Task HandleScriptExecuteRequest(ScriptingParams parameters, RequestContext requestContext) + private void RunScriptAsTask(ConnectionInfo connInfo, ScriptingParams parameters, RequestContext requestContext) + { + ScriptAsScriptingOperation operation = new ScriptAsScriptingOperation(parameters); + ConnectionServiceInstance.ConnectionQueue.QueueBindingOperation( + key: ConnectionServiceInstance.ConnectionQueue.AddConnectionContext(connInfo, "Scripting"), + bindingTimeout: ScriptingOperationTimeout, + bindOperation: (bindingContext, cancelToken) => + { + string script = string.Empty; + operation.ServerConnection = bindingContext.ServerConnection; + operation.ProgressNotification += (sender, e) => requestContext.SendEvent(ScriptingProgressNotificationEvent.Type, e); + operation.CompleteNotification += (sender, e) => this.SendScriptingCompleteEvent(requestContext, ScriptingCompleteEvent.Type, e, operation, parameters.ScriptDestination); + + RunTask(requestContext, operation); + + return null; + }, + timeoutOperation: (bindingContext) => + { + this.SendScriptingCompleteEvent(requestContext, ScriptingCompleteEvent.Type, new ScriptingCompleteParams { Success = false }, operation, parameters.ScriptDestination); + return null; + }); + } + + /// + /// Handles request to start the scripting operation + /// + public async Task HandleScriptExecuteRequest(ScriptingParams parameters, RequestContext requestContext) { try { @@ -314,7 +334,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Scripting } // send script result to client - requestContext.SendResult(new ScriptingResult { Script = script }).Wait(); + requestContext.SendResult(new ScriptingResult { Script = script }).Wait(); } catch (Exception e) {