diff --git a/CHANGELOG.md b/CHANGELOG.md index f647a475..ba9b4de8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,8 +3,16 @@ Update this document for externally visible changes. Put most recent changes first. Once we push a new version to nuget.org add a double hash header for that version. +## 180.10.0 + +- Change SMO collections to implement IEnumerator +- Create a C# source generator to emit SMO collection class implementations +- Create a C# source generator to emit code that replaces reflection calls for finding collection and single properties on SqlSmoObject implementations +- Increment package major version to 180 + ## 172.87.0 +- Add Json index support - Add Vector index support - Use vector_dimensions instead of max_length for Vector columns - Support Order Clause for NonClustered Columnstore Indexes @@ -71,14 +79,12 @@ Once we push a new version to nuget.org add a double hash header for that versio - Add `OwnerLoginName` property to `JobSchedule` per [issue 120](https://github.com/microsoft/sqlmanagementobjects/issues/120) - Fixed the `Database.AvailabilityDatabaseSynchronizationState` property to reflect the correct synchronization state of MI databases in Managed Instance Link -## 170.18.0 +## 170.18.0, 161.48044.0 - Add `SearchPropertyList` support for Azure SQL Database - -## 170.17.0, 161.48044.0 - - Fix issue where `Table.Create` and `View.Create` were querying the server for indexes -- Add option to generate scripts exclusively for Data Classification, Create a new SMO object `SensitivityClassification` under `Database` +- Add option to generate scripts exclusively for Data Classification +- Create a new SMO object `SensitivityClassification` under `Database` - Add support for creating Certificate objects using binary-encoded certificate bytes (https://github.com/microsoft/sqlmanagementobjects/issues/132) - Fix for incorrect scripting of Database objects targeting SQL Managed Instances diff --git a/Directory.Packages.props b/Directory.Packages.props index 8c1c2c83..fa6c40bc 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -22,6 +22,8 @@ + + diff --git a/SmoBuild/Version.props b/SmoBuild/Version.props index 1a7fa260..7181f87d 100644 --- a/SmoBuild/Version.props +++ b/SmoBuild/Version.props @@ -1,7 +1,7 @@ $(MSBuildAllProjects);$(MSBuildThisFileFullPath) - 17 + 18 0 100 $(LocalBuildVersion) @@ -13,7 +13,7 @@ $(AssemblyFileVersion) $(AssemblyFileVersion) $(AssemblyFileVersion) - 2 + 0 $(AssemblyMajorVersion)$(PackageMajorVersionIncrement).$(AssemblyBuildVersion).$(AssemblyBuildRevision) $(AssemblyMajorVersion).$(AssemblyMinorVersion).0.0 diff --git a/global.json b/global.json index 552d5ce2..a7cb916c 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "8.0.414", + "version": "8.0.415", "rollForward": "latestMinor" }, "msbuild-sdks": { diff --git a/src/Codegen/CodeGen.cs b/src/Codegen/CodeGen.cs index a7bd94c9..895c60f2 100644 --- a/src/Codegen/CodeGen.cs +++ b/src/Codegen/CodeGen.cs @@ -214,6 +214,7 @@ private enum CloudSupportedVersionFlags v10_0 = 1, v11_0 = 2, v12_0 = 4, + // VBUMP - Note: Cloud versions have different versioning than on-prem } private static KeyValuePair[] m_CloudSupportedVersion = @@ -221,6 +222,7 @@ private enum CloudSupportedVersionFlags new KeyValuePair(new ServerVersion(10,0), (int)CloudSupportedVersionFlags.v10_0), new KeyValuePair(new ServerVersion(11,0), (int)CloudSupportedVersionFlags.v11_0), new KeyValuePair(new ServerVersion(12,0), (int)CloudSupportedVersionFlags.v12_0) + // VBUMP }; //Note - Datawarehouse is a special case since it doesn't currently actually have diff --git a/src/Codegen/cfg.xml b/src/Codegen/cfg.xml index 0457a152..3aff87c4 100644 --- a/src/Codegen/cfg.xml +++ b/src/Codegen/cfg.xml @@ -1063,6 +1063,7 @@ + @@ -1120,6 +1121,9 @@ + + + @@ -1171,6 +1175,12 @@ + + + + + + diff --git a/src/CollectionGenerator/AnalyzerReleases.Shipped.md b/src/CollectionGenerator/AnalyzerReleases.Shipped.md new file mode 100644 index 00000000..91ab1fc1 --- /dev/null +++ b/src/CollectionGenerator/AnalyzerReleases.Shipped.md @@ -0,0 +1,7 @@ +; Shipped analyzer releases +; https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md + +## Release 1.0 + +### New Rules + diff --git a/src/CollectionGenerator/AnalyzerReleases.Unshipped.md b/src/CollectionGenerator/AnalyzerReleases.Unshipped.md new file mode 100644 index 00000000..101fcc3e --- /dev/null +++ b/src/CollectionGenerator/AnalyzerReleases.Unshipped.md @@ -0,0 +1,9 @@ +; Unshipped analyzer release +; https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md + + +### New Rules + +Rule ID | Category | Severity | Notes +--------|----------|----------|-------------------- +SMOCOLL001 | SmoCollection | Error | \ No newline at end of file diff --git a/src/CollectionGenerator/CollectionGenerator.csproj b/src/CollectionGenerator/CollectionGenerator.csproj new file mode 100644 index 00000000..9cdc5f01 --- /dev/null +++ b/src/CollectionGenerator/CollectionGenerator.csproj @@ -0,0 +1,17 @@ + + + + netstandard2.0 + true + $(DefineConstants);DEBUGCOLLECTIONGENERATOR + + + + + + + + + + + diff --git a/src/CollectionGenerator/README.md b/src/CollectionGenerator/README.md new file mode 100644 index 00000000..3debe294 --- /dev/null +++ b/src/CollectionGenerator/README.md @@ -0,0 +1,112 @@ +# Source Generators for SMO + +We have two source generators in this project. + +## SmoCollectionGenerator + +To simplify adding new object types and their corresponding collections to SMO, we have strongly typed base collection classes and a code generator that emits the body of the collection classes. +To add a new collection, a code author can simply declare the new collection class and specify which of the base classes it uses. + +The source generator looks at the `UrnSuffix` and other properties of the generic type arguments to emit the body of the new collection class at build time. There are 4 base classes to choose from: + +- `SimpleObjectCollectionBase` is the base of the other collections and should be used if your object type doesn't match the criteria for one of the other base classes. +- `RemovableCollectionBase` derives from `SimpleObjectCollectionBase` and can be used when your collection allows removal of elements when the parent of the collection is in `Creating` state. For example, an app can add or remove elements to `Database.FileGroups` before calling `Database.Create`, but afterward it can only call `Database.FileGroups.Add`. +- `SchemaCollectionBase` contains objects that are part of a database schema. +- `ParameterCollectionBase` contains elements whose enumeration order is based on their `ID` instead of on their `Name` + +### Examples + +Input: + +```C# +public sealed partial class FileGroupCollection : RemovableCollectionBase +{ +} +``` + +Output: + +```C# +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. +namespace Microsoft.SqlServer.Management.Smo +{ + /// + ///Collection of FileGroup objects associated with an instance of Database + /// + public partial class FileGroupCollection + { + internal FileGroupCollection(SqlSmoObject parentInstance) : base((Database)parentInstance) + { + } + + protected override string UrnSuffix => FileGroup.UrnSuffix; + + internal override FileGroup GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) => new FileGroup(this, key, state); + } +} +``` + + + +## SqlSmoObjectGenerator + +This source generator uses `SfcObject` attributes in the declaration of a `SqlSmoObject`-derived class to build switch statements that enable the scripting engine to map URN components to child property names without using reflection. Attributes using `SfcContainerRelationship` arguments identify child collections, while attributes using `SfcObjectRelationship` arguments identify child singletons. + +### Examples: + +Input: + +```C# + +[SfcObject(SfcContainerRelationship.ChildContainer, SfcContainerCardinality.ZeroToAny, typeof(Index), SfcObjectFlags.Design | SfcObjectFlags.Deploy)] +public override IndexCollection Indexes +{ + get { return base.Indexes; } +} + +[SfcObject(SfcObjectRelationship.ChildObject, SfcObjectCardinality.One)] +public DatabaseOptions DatabaseOptions +{ + get + { + CheckObjectStateImpl(false); + if (null == m_DatabaseOptions) + { + m_DatabaseOptions = new DatabaseOptions(this, new ObjectKeyBase(), this.State/*SqlSmoState.Existing*/); + } + return m_DatabaseOptions; + } +} +``` + +Output: + +```C# +namespace Microsoft.SqlServer.Management.Smo +{ + public partial class Database + { + protected override SqlSmoObject GetSingletonInstance(string childTypeName) + { + switch (childTypeName) + { + case "Option": + case "DatabaseOptions": + return DatabaseOptions; + case "QueryStoreOptions": + return QueryStoreOptions; + case "DatabaseEncryptionKey": + return DatabaseEncryptionKey; + case "MasterKey": + return MasterKey; + case "ServiceBroker": + return ServiceBroker; + + default: + return base.GetSingletonInstance(childTypeName); + } + } + } +} +``` \ No newline at end of file diff --git a/src/CollectionGenerator/SmoCollectionGenerator.cs b/src/CollectionGenerator/SmoCollectionGenerator.cs new file mode 100644 index 00000000..8171fa2a --- /dev/null +++ b/src/CollectionGenerator/SmoCollectionGenerator.cs @@ -0,0 +1,173 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp.Syntax; + +namespace CollectionGenerator +{ + [Generator] + public class SmoCollectionGenerator : ISourceGenerator, ISyntaxContextReceiver + { + private static readonly DiagnosticDescriptor InvalidCollectionTypeArgument = new DiagnosticDescriptor(id: "SMOCOLL001", + title: "Invalid collection type argument", + messageFormat: "Unable to process collection {0}. {1} or {2} is an invalid type argument.", + category: "SmoCollection", + DiagnosticSeverity.Error, + isEnabledByDefault: true); +#if DEBUGCOLLECTIONGENERATOR + static SmoCollectionGenerator() + { + Debugger.Launch(); + } +#endif + + public class CollectionInfo + { + public string BaseClass { get; set; } + public string Name { get; } + public string TParent { get; } + public string TObject { get; } + public string Namespace { get; } + public string Visibility { get; } + public CollectionInfo(string baseClass, string name, string tObject, string tParent, string @namespace, string visibility) + { + BaseClass = baseClass; + Name = name; + TParent = tParent; + TObject = tObject; + Namespace = @namespace; + Visibility = visibility; + } + public override string ToString() + { + return $"{Namespace}.{Name} : {BaseClass}<{TObject}, {TParent}>"; + } + } + + private class CollectionFactoryInfo + { + public List Collections { get; } = new List(); + public Func CollectionClassGenerator { get; } + public CollectionFactoryInfo(Func collectionClassGenerator) + { + CollectionClassGenerator = collectionClassGenerator; + } + } + + private readonly Dictionary allCollections = new Dictionary() + { + // Currently all collections use the same generator template but we'll keep the capability to vary them in the future + {"SimpleObjectCollectionBase", new CollectionFactoryInfo(CreateSimpleObjectCollection) }, + {"ParameterCollectionBase", new CollectionFactoryInfo(CreateSimpleObjectCollection)}, + {"SchemaCollectionBase",new CollectionFactoryInfo(CreateSimpleObjectCollection) }, + {"RemovableCollectionBase", new CollectionFactoryInfo(CreateSimpleObjectCollection) }, + }; + public List SimpleCollections => allCollections["SimpleObjectCollectionBase"].Collections; + //public readonly List SchemaCollections = new List(); + public List ParameterCollections => allCollections["ParameterCollectionBase"].Collections; + + private static string CreateSimpleObjectCollection(CollectionInfo collection) => $@" +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. +namespace {collection.Namespace} +{{ + /// + ///Collection of {collection.TObject} objects associated with an instance of {collection.TParent} + /// + {collection.Visibility} partial class {collection.Name} + {{ + internal {collection.Name}(SqlSmoObject parentInstance) : base(({collection.TParent})parentInstance) + {{ + }} + + protected override string UrnSuffix => {collection.TObject}.UrnSuffix; + + internal override {collection.TObject} GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) => new {collection.TObject}(this, key, state); + }} +}} +"; + + public void Execute(GeneratorExecutionContext context) + { + _ = context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.targetframework", out var targetFramework); + if (!(context.SyntaxContextReceiver is SmoCollectionGenerator generator)) + { + return; + } + foreach (var collectionFactory in generator.allCollections) + { + foreach (var collectionInfo in collectionFactory.Value.Collections) + { + var source = collectionFactory.Value.CollectionClassGenerator(collectionInfo); + if (collectionInfo.TObject.Contains("global") || collectionInfo.TParent.Contains("global")) + { + context.ReportDiagnostic(Diagnostic.Create(InvalidCollectionTypeArgument, Location.None, collectionInfo.Name, collectionInfo.TObject, collectionInfo.TParent)); + } + Trace.TraceInformation(source); + try + { + context.AddSource($"{collectionInfo.Name}.{targetFramework ?? "default"}.generated.cs", source); + } + catch + { } + } + } + } + + public void Initialize(GeneratorInitializationContext context) + { + context.RegisterForSyntaxNotifications(() => new SmoCollectionGenerator()); + } + + public void OnVisitSyntaxNode(GeneratorSyntaxContext context) + { + if (!(context.Node is ClassDeclarationSyntax cds)) + { + return; + } + if (!cds.Identifier.ValueText.EndsWith("Collection")) + { + return; + } + Trace.TraceInformation($"Found collection candidate {cds.Identifier.Value}"); + + if (!(context.SemanticModel.GetDeclaredSymbol(cds) is INamedTypeSymbol classSymbol)) + { + return; + } + if (!allCollections.ContainsKey(classSymbol.BaseType?.Name)) + { + return; + } + + Trace.TraceInformation($"{cds.Identifier.Value} implements {classSymbol.BaseType.Name}"); + if (classSymbol.BaseType.TypeArguments.Length != 2) + { + return; + } + var tObject = classSymbol.BaseType.TypeArguments[0]; + var tParent = classSymbol.BaseType.TypeArguments[1]; + var collectionInfo = new CollectionInfo(classSymbol.BaseType.Name, + cds.Identifier.ValueText, + tObject.NameForDeclaration(), + tParent.NameForDeclaration(), + classSymbol.ContainingNamespace.ToDisplayString(), + classSymbol.DeclaredAccessibility == Accessibility.Internal ? "internal" : "public"); + allCollections[collectionInfo.BaseClass].Collections.Add(collectionInfo); + } + } + + internal static class SyntaxExtensions + { + public static string NameForDeclaration(this ITypeSymbol typeSymbol) + { + var ns = typeSymbol.ContainingNamespace.ToDisplayString(); + return ns == "Microsoft.SqlServer.Management.Smo" ? typeSymbol.Name : $"{ns}.{typeSymbol.Name}"; + } + } + +} \ No newline at end of file diff --git a/src/CollectionGenerator/SqlSmoObjectGenerator.cs b/src/CollectionGenerator/SqlSmoObjectGenerator.cs new file mode 100644 index 00000000..95bee2a6 --- /dev/null +++ b/src/CollectionGenerator/SqlSmoObjectGenerator.cs @@ -0,0 +1,236 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +using System; +using System.Collections.Generic; +using System.Data.Common; +using System.Diagnostics; +using System.Text; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp.Syntax; + +namespace CollectionGenerator +{ + /// + /// This class builds a switch statement that maps {[Parent type],[Urn Suffix]} tuples to + /// a func<SqlSmoObject,AbstractCollectionBase> that returns the appropriate collection + /// instance without using reflection + /// + [Generator] + public class SqlSmoObjectGenerator : ISourceGenerator, ISyntaxContextReceiver + { + public Dictionary> CollectionsMap = new Dictionary>(); + public Dictionary> SingletonsMap = new Dictionary>(); + public Dictionary TypeAliases = new Dictionary(); + private string GetSingletonFactoryMethod(string className, SqlSmoObjectGenerator generator) + { + var lastDot = className.LastIndexOf('.'); + var cname = className.Substring(lastDot + 1); + var ns = className.Substring(0, lastDot); + var builder = new StringBuilder( +$@"// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. +namespace {ns} +{{ + public partial class {cname} + {{ + protected override SqlSmoObject GetSingletonInstance(string childTypeName) + {{ + switch (childTypeName) + {{ +"); + foreach (var typename in generator.SingletonsMap[className].Keys) + { + if (generator.TypeAliases.ContainsKey(typename)) + { + _ = builder.AppendLine($" case \"{generator.TypeAliases[typename]}\":"); + } + _ = builder.AppendLine($" case \"{typename}\":"); + _ = builder.AppendLine($" return {generator.SingletonsMap[className][typename]};"); + } + _ = builder.Append( +$@" + default: + return base.GetSingletonInstance(childTypeName); + }} + }} + }} +}} +"); + return builder.ToString(); + } + + private string GetCollectionFactoryMethod(string className, SqlSmoObjectGenerator generator) + { + var lastDot = className.LastIndexOf('.'); + var cname = className.Substring(lastDot + 1); + var ns = className.Substring(0, lastDot); + var builder = new StringBuilder( +$@"// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. +namespace {ns} +{{ + public partial class {cname} + {{ + protected override AbstractCollectionBase GetCollectionInstance(string childTypeName) + {{ + switch (childTypeName) + {{ +"); + foreach (var typename in generator.CollectionsMap[className].Keys) + { + if (generator.TypeAliases.ContainsKey(typename)) + { + _ = builder.AppendLine($" case \"{generator.TypeAliases[typename]}\":"); + } + _ = builder.AppendLine($" case \"{typename}\":"); + _ = builder.AppendLine($" return {generator.CollectionsMap[className][typename]};"); + } + _ = builder.Append( +$@" + default: + return base.GetCollectionInstance(childTypeName); + }} + }} + }} +}} +"); + return builder.ToString(); + } + + public void Execute(GeneratorExecutionContext context) + { + _ = context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.targetframework", out var targetFramework); + if (!(context.SyntaxContextReceiver is SqlSmoObjectGenerator generator)) + { + return; + } + Trace.TraceInformation("*** Printing collection references"); + foreach (var className in generator.CollectionsMap.Keys) + { + Trace.TraceInformation($"Class name: {className}"); + foreach (var collectionType in generator.CollectionsMap[className].Keys) + { + Trace.TraceInformation($"\tChild type: {collectionType}\tProperty name: {generator.CollectionsMap[className][collectionType]}"); + } + var collectionsMethod = GetCollectionFactoryMethod(className, generator); + try + { + context.AddSource($"{className}.{targetFramework ?? "default"}.collections.g.cs", collectionsMethod); + } + catch { } + + } + Trace.TraceInformation("+++ Printing singleton references"); + foreach (var className in generator.SingletonsMap.Keys) + { + Console.Write($"Class name: {className}\r\n\t"); + foreach (var propertyType in generator.SingletonsMap[className].Keys) + { + Trace.TraceInformation($"Child type: {propertyType}\tProperty name: {generator.SingletonsMap[className][propertyType]}"); + } + var singletonMethod = GetSingletonFactoryMethod(className, generator); + try + { + context.AddSource($"{className}.{targetFramework ?? "default"}.singles.g.cs", singletonMethod); + } + catch { } + + } + } + + public void Initialize(GeneratorInitializationContext context) + { + context.RegisterForSyntaxNotifications(() => new SqlSmoObjectGenerator()); + } + + public void OnVisitSyntaxNode(GeneratorSyntaxContext context) + { + if (!(context.Node is AttributeSyntax attributeSyntax)) + { + return; + } + if (attributeSyntax.Name.ToString() == "SfcElementType") + { + OnVisitSfcElement(attributeSyntax); + return; + } + if (!attributeSyntax.Name.ToString().Equals("SfcObject")) + { + return; + } + if (!(attributeSyntax.Parent.Parent is PropertyDeclarationSyntax propertyDeclaration)) + { + Trace.TraceInformation($"Skipping SfcObject attribute at {context.Node.GetLocation()} because it's not part of a property declaration"); + return; + } + if (!(propertyDeclaration.Parent is ClassDeclarationSyntax classDeclaration)) + { + Trace.TraceInformation($"Skipping SfcObject attribute at {context.Node.GetLocation()} because it's not part of a class"); + return; + } + if (!(classDeclaration.Parent is NamespaceDeclarationSyntax namespaceDeclaration)) + { + Trace.TraceInformation($"Skipping SfcObject attribute at {context.Node.GetLocation()} because it's part of a nest class"); + return; + } + + if (attributeSyntax.ArgumentList == null || attributeSyntax.ArgumentList.Arguments.Count < 2) + { + Trace.TraceInformation($"Skipping SfcObject attribute at {context.Node.GetLocation()} because it is the wrong constructor"); + return; + } + + var className = $"{namespaceDeclaration.Name}.{classDeclaration.Identifier}"; + var arguments = attributeSyntax.ArgumentList.Arguments.ToString(); + var propertyName = propertyDeclaration.Identifier.ToString(); + if (arguments.Contains("SfcContainerRelationship.ChildContainer") || arguments.Contains("SfcContainerRelationship.ObjectContainer")) + { + var collectionType = attributeSyntax.ArgumentList.Arguments[2].ToString().TrimEnd(')', ' '); + collectionType = collectionType.Substring(collectionType.IndexOf('(') + 1); + + if (!CollectionsMap.ContainsKey(className)) + { + CollectionsMap[className] = new Dictionary(); + } + CollectionsMap[className][collectionType] = propertyName; + } + else if (arguments.Contains("SfcObjectRelationship.ChildObject")|| arguments.Contains("SfcObjectRelationship.Object")) + { + var typeInfo = context.SemanticModel.GetTypeInfo(propertyDeclaration.Type).Type; + var isSmoObject = typeInfo.Name.EndsWith("SqlSmoObject"); + while (!isSmoObject && typeInfo.BaseType != null) + { + typeInfo = typeInfo.BaseType; + isSmoObject = typeInfo.Name.EndsWith("SqlSmoObject"); + } + if (!isSmoObject) + { + Trace.TraceInformation($"Skipping SfcObject attribute at {context.Node.GetLocation()} because the property isn't a SqlSmoObject"); + return; + } + if (!SingletonsMap.ContainsKey(className)) + { + SingletonsMap[className] = new Dictionary(); + } + SingletonsMap[className][propertyDeclaration.Type.ToString()] = propertyName; + } + else + { + Trace.TraceInformation($"Skipping SfcObject attribute at {context.Node.GetLocation()} because it's not a ChildContainer or ChildObject. {arguments}"); + } + } + + private void OnVisitSfcElement(AttributeSyntax attributeSyntax) + { + var classDeclaration = (ClassDeclarationSyntax)attributeSyntax.Parent.Parent; + var className = classDeclaration.Identifier.ToString(); + var arguments = attributeSyntax.ArgumentList.Arguments.ToString().Trim('"', ' '); + if (TypeAliases.ContainsKey(className)) + { + throw new InvalidOperationException("Multiple identical class names use SfcElement"); + } + TypeAliases[className] = arguments; + } + } +} diff --git a/src/FunctionalTest/Framework/Helpers/DatabaseObjectHelpers.cs b/src/FunctionalTest/Framework/Helpers/DatabaseObjectHelpers.cs index 0f2ffde8..ecf58a47 100644 --- a/src/FunctionalTest/Framework/Helpers/DatabaseObjectHelpers.cs +++ b/src/FunctionalTest/Framework/Helpers/DatabaseObjectHelpers.cs @@ -801,7 +801,7 @@ public static void DropAllObjects(this Database database) /// /// /// Optional predicate to filter items to drop. Return true for droppable items - public static void DropAll(this SqlSmoObject parent, Func collection, Func predicate = null) where T : SqlSmoObject, IDroppable + public static void DropAll(this SqlSmoObject parent, Func collection, Func predicate = null) where T : SqlSmoObject, IDroppable { if (parent.IsSupportedObject()) { diff --git a/src/FunctionalTest/Framework/TestFramework/FabricDatabaseHandler.cs b/src/FunctionalTest/Framework/TestFramework/FabricDatabaseHandler.cs index 4b5c16f3..d08e320c 100644 --- a/src/FunctionalTest/Framework/TestFramework/FabricDatabaseHandler.cs +++ b/src/FunctionalTest/Framework/TestFramework/FabricDatabaseHandler.cs @@ -57,6 +57,11 @@ public override Database HandleDatabaseCreation(DatabaseParameters dbParameters) var dbName = string.IsNullOrEmpty(sqlConnectionStringBuilder.InitialCatalog) ? fabricDbName : sqlConnectionStringBuilder.InitialCatalog; db = ServerContext.Databases[dbName]; DatabaseDisplayName = fabricDbName; + if (!string.IsNullOrEmpty(dbParameters?.BackupFile)) + { + // Restore DB from the specified backup file + db = ServerContext.RestoreDatabaseFromBackup(dbParameters.BackupFile, dbName, ConnectionHelpers.GetAzureKeyVaultHelper().StorageHelper); + } } catch { diff --git a/src/FunctionalTest/Smo/GeneralFunctionality/AuditSmoTests.cs b/src/FunctionalTest/Smo/GeneralFunctionality/AuditSmoTests.cs index bcd7dffd..89067e98 100644 --- a/src/FunctionalTest/Smo/GeneralFunctionality/AuditSmoTests.cs +++ b/src/FunctionalTest/Smo/GeneralFunctionality/AuditSmoTests.cs @@ -90,13 +90,14 @@ public void ServerAudit_VerifyAuditObjectIsNotSupportedInAzure() { Audit serverAudit = new Audit(server, auditName); }); - Assert.IsInstanceOf(exception.InnerException, "Unexpected inner exception"); - Assert.IsInstanceOf(exception.InnerException.InnerException, "Unexpected inner exception"); + + var unsupportedException = exception.FirstInstanceOf(); + Assert.That(unsupportedException, Is.Not.Null, $"Unexpected exception: {exception.BuildRecursiveExceptionMessage()}"); string errorMsg = server.DatabaseEngineEdition == DatabaseEngineEdition.SqlOnDemand ? ExceptionTemplates.NotSupportedOnOnDemandWithDetails(typeof(Audit).Name) : ExceptionTemplates.NotSupportedOnCloudWithDetails(typeof(Audit).Name); - Assert.That(exception.InnerException.InnerException.Message, Is.EqualTo(errorMsg), "Unexpected exception message"); + Assert.That(unsupportedException.Message, Is.EqualTo(errorMsg), "Unexpected exception message"); }); } @@ -128,10 +129,9 @@ public void ServerAudit_TestUrlTargetOnlyAvailableInManagedInstance() if (server.DatabaseEngineEdition == DatabaseEngineEdition.SqlOnDemand || server.DatabaseEngineType == DatabaseEngineType.SqlAzureDatabase) { - Assert.IsInstanceOf(exception.InnerException, "Unexpected inner exception for SqlOnDemand"); - Exception sqlOnDemandError = exception.InnerException.InnerException; - Assert.IsInstanceOf(sqlOnDemandError, "Unexpected error for SqlOnDemand"); + var sqlOnDemandError = exception.FirstInstanceOf(); + Assert.That(sqlOnDemandError, Is.Not.Null, $"Unexpected error for SqlOnDemand: {exception.BuildRecursiveExceptionMessage()}"); string errorMsg = server.DatabaseEngineEdition == DatabaseEngineEdition.SqlOnDemand ? ExceptionTemplates.NotSupportedOnOnDemandWithDetails(typeof(Audit).Name) : ExceptionTemplates.NotSupportedOnCloudWithDetails(typeof(Audit).Name); @@ -175,10 +175,8 @@ public void ServerAudit_TestExternalMonitorTargetOnlyAvailableInManagedInstance( if (server.DatabaseEngineEdition == DatabaseEngineEdition.SqlOnDemand || server.DatabaseEngineType == DatabaseEngineType.SqlAzureDatabase) { - Assert.IsInstanceOf(exception.InnerException, "Unexpected inner exception for SqlOnDemand"); - - Exception sqlOnDemandError = exception.InnerException.InnerException; - Assert.IsInstanceOf(sqlOnDemandError, "Unexpected error for SqlOnDemand"); + var sqlOnDemandError = exception.FirstInstanceOf(); + Assert.That(sqlOnDemandError, Is.Not.Null, $"Unexpected error for SqlOnDemand: {exception.BuildRecursiveExceptionMessage()}"); string errorMsg = server.DatabaseEngineEdition == DatabaseEngineEdition.SqlOnDemand ? ExceptionTemplates.NotSupportedOnOnDemandWithDetails(typeof(Audit).Name) : ExceptionTemplates.NotSupportedOnCloudWithDetails(typeof(Audit).Name); diff --git a/src/FunctionalTest/Smo/GeneralFunctionality/LanguageTests.cs b/src/FunctionalTest/Smo/GeneralFunctionality/LanguageTests.cs new file mode 100644 index 00000000..7c707032 --- /dev/null +++ b/src/FunctionalTest/Smo/GeneralFunctionality/LanguageTests.cs @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +using Microsoft.SqlServer.Management.Common; +using Microsoft.SqlServer.Test.Manageability.Utils.TestFramework; +using Microsoft.SqlServer.Test.SMO.ScriptingTests; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using NUnit.Framework; +using Assert=NUnit.Framework.Assert; + +namespace Microsoft.SqlServer.Test.SMO.GeneralFunctionality +{ + [TestClass] + public class LanguageTests : SmoTestBase + { + [TestMethod] + [UnsupportedDatabaseEngineEdition(DatabaseEngineEdition.SqlDataWarehouse)] + public void Languages_ItemById_uses_LocaleId() + { + ExecuteTest(() => + { + var nullLanguage = ServerContext.Languages.ItemById(0); + var english = ServerContext.Languages.ItemById(0x409); + Assert.Multiple(() => + { + Assert.That(nullLanguage, Is.Null, "0 as item id"); + Assert.That(english, Is.Not.Null, "0x409 as item id"); + Assert.That(english.LocaleID, Is.EqualTo(0x409), "LocaleID of English"); + }); + }); + } + } +} diff --git a/src/FunctionalTest/Smo/GeneralFunctionality/SmoInitializingTests.cs b/src/FunctionalTest/Smo/GeneralFunctionality/SmoInitializingTests.cs index 91121927..1f58cda2 100644 --- a/src/FunctionalTest/Smo/GeneralFunctionality/SmoInitializingTests.cs +++ b/src/FunctionalTest/Smo/GeneralFunctionality/SmoInitializingTests.cs @@ -66,9 +66,9 @@ public void ClearAndInitializeTestInitializesTheTablesUsingTheFilter() } } - static class CollectionExtensions + internal static class CollectionExtensions { - public static IList GetNames(this SchemaCollectionBase collection) + public static IList GetNames(this IEnumerable collection) { return collection.Cast().Select(o => o.Name).ToList(); } diff --git a/src/FunctionalTest/Smo/ScriptingTests/Certificate_SmoTestSuite.cs b/src/FunctionalTest/Smo/ScriptingTests/Certificate_SmoTestSuite.cs index 6917b6c3..80826b03 100644 --- a/src/FunctionalTest/Smo/ScriptingTests/Certificate_SmoTestSuite.cs +++ b/src/FunctionalTest/Smo/ScriptingTests/Certificate_SmoTestSuite.cs @@ -25,9 +25,10 @@ namespace Microsoft.SqlServer.Test.SMO.ScriptingTests public class Certificate_SmoTestSuite : SmoObjectTestBase { /// - /// Valid binary data for a test certificate + /// Valid binary data for a test certificate. This was generated from a self-signed cert as the content doesn't actually matter for the purposes of this test. /// - private const string certificateBinaryStream = "0x308205A830820390A00302010202101ED397095FD8B4B347701EAABE7F45B3300D06092A864886F70D01010C05003065310B3009060355040613025553311E301C060355040A13154D6963726F736F667420436F72706F726174696F6E313630340603550403132D4D6963726F736F66742052534120526F6F7420436572746966696361746520417574686F726974792032303137301E170D3139313231383232353132325A170D3432303731383233303032335A3065310B3009060355040613025553311E301C060355040A13154D6963726F736F667420436F72706F726174696F6E313630340603550403132D4D6963726F736F66742052534120526F6F7420436572746966696361746520417574686F72697479203230313730820222300D06092A864886F70D01010105000382020F003082020A0282020100CA5BBE94338C299591160A95BD4762C189F39936DF4690C9A5ED786A6F479168F8276750331DA1A6FBE0E543A3840257015D9C4840825310BCBFC73B6890B6822DE5F465D0CC6D19CC95F97BAC4A94AD0EDE4B431D8707921390808364353904FCE5E96CB3B61F50943865505C1746B9B685B51CB517E8D6459DD8B226B0CAC4704AAE60A4DDB3D9ECFC3BD55772BC3FC8C9B2DE4B6BF8236C03C005BD95C7CD733B668064E31AAC2EF94705F206B69B73F578335BC7A1FB272AA1B49A918C91D33A823E7640B4CD52615170283FC5C55AF2C98C49BB145B4DC8FF674D4C1296ADF5FE78A89787D7FD5E2080DCA14B22FBD489ADBACE479747557B8F45C8672884951C6830EFEF49E0357B64E798B094DA4D853B3E55C428AF57F39E13DB46279F1EA25E4483A4A5CAD513B34B3FC4E3C2E68661A45230B97A204F6F0F3853CB330C132B8FD69ABD2AC82DB11C7D4B51CA47D14827725D87EBD545E648659DAF5290BA5BA2186557129F68B9D4156B94C4692298F433E0EDF9518E4150C9344F7690ACFC38C1D8E17BB9E3E394E14669CB0E0A506B13BAAC0F375AB712B590811E56AE572286D9C9D2D1D751E3AB3BC655FD1E0ED3740AD1DAAAEA69B897288F48C407F852433AF4CA55352CB0A66AC09CF9F281E1126AC045D967B3CEFF23A2890A54D414B92AA8D7ECF9ABCD255832798F905B9839C40806C1AC7F0E3D00A50203010001A3543052300E0603551D0F0101FF040403020186300F0603551D130101FF040530030101FF301D0603551D0E0416041409CB597F86B2708F1AC339E3C0D9E9BFBB4DB223301006092B06010401823715010403020100300D06092A864886F70D01010C05000382020100ACAF3E5DC21196898EA3E792D69715B813A2A6422E02CD16055927CA20E8BAB8E81AEC4DA89756AE6543B18F009B52CD55CD53396D624C8B0D5B7C2E44BF83108FF3538280C34F3AC76E113FE6E3169184FB6D847F3474AD89A7CEB9D7D79F846492BE95A1AD095333DDEE0AEA4A518E6F55ABBAB59446AE8C7FD8A2502565608046DB3304AE6CB598745425DC93E4F8E355153DB86DC30AA412C169856EDF64F15399E14A75209D950FE4D6DC03F15918E84789B2575A94B6A9D8172B1749E576CBC156993A37B1FF692C919193E1DF4CA337764DA19FF86D1E1DD3FAECFBF4451D136DCFF759E52227722B86F357BB30ED244DDC7D56BBA3B3F8347989C1E0F20261F7A6FC0FBB1C170BAE41D97CBD27A3FD2E3AD19394B1731D248BAF5B2089ADB7676679F53AC6A69633FE5392C846B11191C6997F8FC9D66631204110872D0CD6C1AF3498CA6483FB1357D1C1F03C7A8CA5C1FD9521A071C193677112EA8F880A691964992356FBAC2A2E70BE66C40C84EFE58BF39301F86A9093674BB268A3B5628FE93F8C7A3B5E0FE78CB8C67CEF37FD74E2C84F3372E194396DBD12AFBE0C4E707C1B6F8DB332937344166DE8F4F7E095808F965D38A4F4ABDE0A308793D84D00716245274B3A42845B7F65B76734522D9C166BAAA8D87BA3424C71C70CCA3E83E4A6EFB701305E51A379F57069A641440F86B02C91C63DEAAE0F84"; + /// Do NOT use a valid Microsoft cert for this if updating in the future, or the security team gets unhappy about hardcoded certs in code (even test code) + private const string certificateBinaryStream = "0x308202FC308201E4A0030201020210386647026609F186460FC38993A4BCB4300D06092A864886F70D01010B05003011310F300D06035504030C064D7943657274301E170D3235303832383230353932395A170D3236303832383231313932395A3011310F300D06035504030C064D794365727430820122300D06092A864886F70D01010105000382010F003082010A0282010100D0E818D323B886D921342F189E026F0D014869507788BC2AB61126F4CABDA275427E02B60E5C856BE9BAA06D9D67D84950040198F87663ADD6E3EB58D29E41C473B9887E58A133F3804073E4C4AFAB1E28600A1C33BAD4041BD597232DFC343CDDDA007816172F139B4BDC395177C49C609E3BE55EA8BFB07EEC8D1F400DEC6CBCA175C2ACA3246615FBB5F9676B89B435ADC2A31F46A245B923E9FDE688779CB1489112D7E1F3B08A05611AF6D0AC1B108C177C56F4198CF500C4FB7A61FE75DB87842E9DF09EDB23B3EC09B49BF88C9CB4573EBBC342861D9919187D0CAFE894112567001442D2F444D2314A08E70088943DBBD6BBC0F1C05DE69E1E3CE72D0203010001A350304E300E0603551D0F0101FF0404030205A0301D0603551D250416301406082B0601050507030206082B06010505070301301D0603551D0E041604148F0B8A94BB8FC4688035707D3A517D73675A4B86300D06092A864886F70D01010B05000382010100BFDA24C14E2E629F56CEC159667C0A19F553C23C59DBAFA3AE060AD142D21289FAADFCBC3F180B22142A1B050C8F999AC5E2D70A2C13D448C81B51AFBF1DF475CA71E312D637DBD0DE4463490078250C29E04B14E54A603973ECA5644E1E440D7C80FC5A863E6605046CAD8B35986074C5361433420DE45EAA3CA6CB85D5A9AB7D8B6F795DCECEC795A32AAA62CB4D457D97F3AAADB6565C75CB484F8F67735027321432FF09172F2A8E1F1285B8DF719E0C42CD9E40D45361008414275FB89C853B0C2AB7353D8B75E49820A75753FF2BA95E4B41F14D7C934A2E0E8D214298004572E0C7804DEB22BB43642833E4AAA978BDB05ED3D425D53108BB9CEBC2F6"; #region Scripting Tests diff --git a/src/FunctionalTest/Smo/ScriptingTests/Database_SmoTestSuite.cs b/src/FunctionalTest/Smo/ScriptingTests/Database_SmoTestSuite.cs index 1c4e610f..904b0f34 100644 --- a/src/FunctionalTest/Smo/ScriptingTests/Database_SmoTestSuite.cs +++ b/src/FunctionalTest/Smo/ScriptingTests/Database_SmoTestSuite.cs @@ -1002,7 +1002,8 @@ public void SmoDatabase_Alter_DataFile_Property_Growth() /// %BASEDIR%\src\Microsoft\SqlServer\Management\Smo\files.cs /// [TestMethod] - [SupportedServerVersionRange(Edition = DatabaseEngineEdition.Enterprise | DatabaseEngineEdition.SqlManagedInstance)] + [SupportedServerVersionRange(Edition = DatabaseEngineEdition.Enterprise)] + [SupportedServerVersionRange(Edition = DatabaseEngineEdition.SqlManagedInstance)] [UnsupportedDatabaseEngineEdition(DatabaseEngineEdition.SqlOnDemand)] public void SmoDatabase_AddFilesAndFilegroups() { @@ -1021,9 +1022,13 @@ public void SmoDatabase_AddFilesAndFilegroups() // Add new filegroup FileGroup newFileGroup = new FileGroup(database, "NewFileGroup", isFileStream: false); database.FileGroups.Add(newFileGroup); + // testing that the filegroup can be removed from the collection because it doesn't exist yet + database.FileGroups.Remove(newFileGroup); + Assert.That(database.FileGroups.Select(fg => fg.Name), Has.No.Member("NewFileGroup"), "Filegroup should not be in the collection after calling Remove"); + database.FileGroups.Add(newFileGroup); database.Alter(); Assert.That(database.FileGroups["NewFileGroup"], Is.Not.Null, "Filegroup not properly created"); - + Assert.Throws(() => database.FileGroups.Remove("NewFileGroup"), "Filegroup should not be removable after being created"); // Add new file with a couple of properties set var fileWithProperties = new DataFile(database.FileGroups["NewFileGroup"], "FileWithProperties", filenameFileWithProperties) { diff --git a/src/FunctionalTest/Smo/ScriptingTests/Index_SmoTestSuite.cs b/src/FunctionalTest/Smo/ScriptingTests/Index_SmoTestSuite.cs index 63480e38..7034e4d4 100644 --- a/src/FunctionalTest/Smo/ScriptingTests/Index_SmoTestSuite.cs +++ b/src/FunctionalTest/Smo/ScriptingTests/Index_SmoTestSuite.cs @@ -16,9 +16,11 @@ using Microsoft.SqlServer.Test.Manageability.Utils.Helpers; using Microsoft.SqlServer.Test.Manageability.Utils.TestFramework; using NUnit.Framework; +using Assert = NUnit.Framework.Assert; using System.Linq; using Microsoft.SqlServer.Management.Smo; using SFC = Microsoft.SqlServer.Management.Sdk.Sfc; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Microsoft.SqlServer.Test.SMO.ScriptingTests { @@ -510,6 +512,312 @@ private void Verify_Create_Vector_Index(string metric, string type, int? m = nul }); } + /// + /// Verify JSON index create script without optimized_for_array_search option + /// + [DataRow(true)] + [DataRow(false)] + [_VSUT.TestMethod] + [SupportedServerVersionRange(DatabaseEngineType = DatabaseEngineType.Standalone, MinMajor = 17)] + [UnsupportedDatabaseEngineEdition(DatabaseEngineEdition.SqlDataWarehouse, DatabaseEngineEdition.SqlDatabaseEdge, DatabaseEngineEdition.SqlManagedInstance)] + [UnsupportedFeature(SqlFeature.Fabric)] + public void Verify_CreateJsonIndex(bool optimizeForArraySearch) + { + this.ExecuteFromDbPool( + database => + { + _SMO.Table table = null; + + // Create our table with JSON column + table = new _SMO.Table(database, "JsonIndexTable_" + Guid.NewGuid()); + table.Columns.Add(new _SMO.Column(table, "id", _SMO.DataType.Int) { Nullable = false }); + table.Columns.Add(new _SMO.Column(table, "jsonCol", _SMO.DataType.Json) { Nullable = true }); + table.Columns.Add(new _SMO.Column(table, "name", _SMO.DataType.NVarChar(100)) { Nullable = true }); + + _SMO.Index pkIdx = new _SMO.Index(table, "PK_" + table.Name) + { + IndexKeyType = _SMO.IndexKeyType.DriPrimaryKey, + IndexType = _SMO.IndexType.ClusteredIndex + }; + pkIdx.IndexedColumns.Add(new _SMO.IndexedColumn(pkIdx, "id")); + table.Indexes.Add(pkIdx); + table.Create(); + + // Create the JSON index + _SMO.Index index = new _SMO.Index(table, "JsonIndex_" + table.Name) + { + IndexType = _SMO.IndexType.JsonIndex + }; + _SMO.IndexedColumn jsonColumn = new _SMO.IndexedColumn(index, "jsonCol"); + index.IndexedColumns.Add(jsonColumn); + + if (optimizeForArraySearch) + { + index.OptimizeForArraySearch = true; + } + + try + { + index.Create(); + + // Refresh to get a clean copy of the object from the server + table.Indexes.ClearAndInitialize($"[@Name='{SFC.Urn.EscapeString(index.Name)}']", + new string[] { nameof(_SMO.Index.OptimizeForArraySearch) }); + var newIndex = table.Indexes[index.Name]; + Assert.That(newIndex.IndexType, Is.EqualTo(IndexType.JsonIndex)); + + Assert.That(newIndex.OptimizeForArraySearch, Is.EqualTo(optimizeForArraySearch), + "optimizeForArraySearch should be true"); + + // Verify the script contains expected options + string script = ScriptSmoObject(newIndex); + Assert.That(script, Does.Contain("CREATE JSON INDEX"), + "Script should contain CREATE JSON INDEX"); + Assert.That(script, Does.Contain("[jsonCol]"), + "Script should contain the JSON column"); + + if (optimizeForArraySearch) + { + Assert.That(script, Does.Contain("OPTIMIZE_FOR_ARRAY_SEARCH = ON"), + "Script should contain OPTIMIZE_FOR_ARRAY_SEARCH = ON"); + } + else + { + Assert.That(script, Does.Not.Contain("OPTIMIZE_FOR_ARRAY_SEARCH"), + "Script should not contain OPTIMIZE_FOR_ARRAY_SEARCH"); + } + } + finally + { + table?.Drop(); + } + }); + } + + /// + /// Verify JSON index create script with JSON paths + /// + [_VSUT.TestMethod] + [SupportedServerVersionRange(DatabaseEngineType = DatabaseEngineType.Standalone, MinMajor = 17)] + [UnsupportedDatabaseEngineEdition(DatabaseEngineEdition.SqlDataWarehouse, DatabaseEngineEdition.SqlDatabaseEdge, DatabaseEngineEdition.SqlManagedInstance)] + [UnsupportedFeature(SqlFeature.Fabric)] + public void Verify_CreateJsonIndex_With_Paths() + { + this.ExecuteFromDbPool( + database => + { + _SMO.Table table = null; + + // Create our table with JSON column + table = new _SMO.Table(database, "JsonIndexPathTable_" + Guid.NewGuid()); + table.Columns.Add(new _SMO.Column(table, "id", _SMO.DataType.Int) { Nullable = false }); + table.Columns.Add(new _SMO.Column(table, "jsonCol", _SMO.DataType.Json) { Nullable = true }); + + _SMO.Index pkIdx = new _SMO.Index(table, "PK_" + table.Name) + { + IndexKeyType = _SMO.IndexKeyType.DriPrimaryKey, + IndexType = _SMO.IndexType.ClusteredIndex + }; + pkIdx.IndexedColumns.Add(new _SMO.IndexedColumn(pkIdx, "id")); + table.Indexes.Add(pkIdx); + table.Create(); + + // Create the JSON index with paths using INCLUDING clause + _SMO.Index index = new _SMO.Index(table, "JsonIndex_" + table.Name) + { + IndexType = _SMO.IndexType.JsonIndex, + OptimizeForArraySearch = true + }; + _SMO.IndexedColumn jsonColumn = new _SMO.IndexedColumn(index, "jsonCol"); + index.IndexedColumns.Add(jsonColumn); + + // Add multiple JSON paths to the index + var jsonPath1 = new _SMO.IndexedJsonPath(index, "$.customer.name"); + var jsonPath2 = new _SMO.IndexedJsonPath(index, "$.order.items"); + var jsonPath3 = new _SMO.IndexedJsonPath(index, "$.\"믱吨굮뿁霋\""); + index.IndexedJsonPaths.Add(jsonPath1); + index.IndexedJsonPaths.Add(jsonPath2); + index.IndexedJsonPaths.Add(jsonPath3); + + try + { + index.Create(); + table.Indexes.ClearAndInitialize($"[@Name='{SFC.Urn.EscapeString(index.Name)}']", + new string[] { nameof(_SMO.Index.OptimizeForArraySearch) }); + var newIndex = table.Indexes[index.Name]; + Assert.That(newIndex.IndexType, Is.EqualTo(IndexType.JsonIndex)); + Assert.That(newIndex.OptimizeForArraySearch, Is.EqualTo(true)); + + // Verify the script + string script = ScriptSmoObject(newIndex); + Assert.That(script, Does.Contain("CREATE JSON INDEX")); + Assert.That(script, Does.Contain("OPTIMIZE_FOR_ARRAY_SEARCH = ON")); + + // Verify that all paths are included in the script + Assert.That(script, Does.Contain("'$.customer.name'")); + Assert.That(script, Does.Contain("'$.order.items'")); + Assert.That(script, Does.Contain("'$.\"믱吨굮뿁霋\"'")); + + } + finally + { + table?.Drop(); + } + }); + } + + /// + /// Verify JSON index create script with multiple options combined + /// + [_VSUT.TestMethod] + [SupportedServerVersionRange(DatabaseEngineType = DatabaseEngineType.Standalone, MinMajor = 17)] + [UnsupportedDatabaseEngineEdition(DatabaseEngineEdition.SqlDataWarehouse, DatabaseEngineEdition.SqlDatabaseEdge, DatabaseEngineEdition.SqlManagedInstance)] + [UnsupportedFeature(SqlFeature.Fabric)] + public void Verify_CreateJsonIndex_WithMultipleOptions() + { + this.ExecuteFromDbPool( + database => + { + _SMO.Table table = null; + + // Create our table with JSON column + table = new _SMO.Table(database, "JsonIndexTable_" + Guid.NewGuid()); + table.Columns.Add(new _SMO.Column(table, "id", _SMO.DataType.Int) { Nullable = false }); + table.Columns.Add(new _SMO.Column(table, "jsonCol", _SMO.DataType.Json) { Nullable = true }); + + _SMO.Index pkIdx = new _SMO.Index(table, "PK_" + table.Name) + { + IndexKeyType = _SMO.IndexKeyType.DriPrimaryKey, + IndexType = _SMO.IndexType.ClusteredIndex + }; + pkIdx.IndexedColumns.Add(new _SMO.IndexedColumn(pkIdx, "id")); + table.Indexes.Add(pkIdx); + table.Create(); + + // Create the JSON index with multiple options + _SMO.Index index = new _SMO.Index(table, "JsonIndex_" + table.Name) + { + IndexType = _SMO.IndexType.JsonIndex, + OptimizeForArraySearch = true, + FillFactor = 75, + DisallowPageLocks = false, + DisallowRowLocks = false + }; + _SMO.IndexedColumn jsonColumn = new _SMO.IndexedColumn(index, "jsonCol"); + index.IndexedColumns.Add(jsonColumn); + + try + { + index.Create(); + + // Refresh and verify + table.Indexes.ClearAndInitialize($"[@Name='{SFC.Urn.EscapeString(index.Name)}']", + new string[] { + nameof(_SMO.Index.OptimizeForArraySearch), + nameof(_SMO.Index.PadIndex), + nameof(_SMO.Index.DisallowPageLocks), + nameof(_SMO.Index.DisallowRowLocks) + }); + var newIndex = table.Indexes[index.Name]; + Assert.That(newIndex.IndexType, Is.EqualTo(IndexType.JsonIndex)); + Assert.That(newIndex.OptimizeForArraySearch, Is.EqualTo(true), "OptimizeForArraySearch should be true"); + //Assert.That(newIndex.PadIndex, Is.EqualTo(true), "PadIndex should be true"); + Assert.That(newIndex.FillFactor, Is.EqualTo(75), "FillFactor should be 75"); + + // Verify the script contains expected options + string script = ScriptSmoObject(newIndex); + Assert.That(script, Does.Contain("CREATE JSON INDEX"), + "Script should contain CREATE JSON INDEX"); + Assert.That(script, Does.Contain("OPTIMIZE_FOR_ARRAY_SEARCH = ON"), + "Script should contain OPTIMIZE_FOR_ARRAY_SEARCH = ON"); + Assert.That(script, Does.Contain("FILLFACTOR = 75"), + "Script should contain FILLFACTOR = 75"); + Assert.That(script, Does.Contain("ALLOW_PAGE_LOCKS = ON"), + "Script should contain ALLOW_PAGE_LOCKS = ON"); + Assert.That(script, Does.Contain("ALLOW_ROW_LOCKS = ON"), + "Script should contain ALLOW_ROW_LOCKS = ON"); + } + finally + { + table?.Drop(); + } + }); + } + + /// + /// Verify that attempting to alter a JSON index throws an exception. + /// Tests Alter(), Alter(IndexOperation), and scripting ALTER operations. + /// + [_VSUT.TestMethod] + [SupportedServerVersionRange(DatabaseEngineType = DatabaseEngineType.Standalone, MinMajor = 17)] + [UnsupportedDatabaseEngineEdition(DatabaseEngineEdition.SqlDataWarehouse, DatabaseEngineEdition.SqlDatabaseEdge, DatabaseEngineEdition.SqlManagedInstance)] + [UnsupportedFeature(SqlFeature.Fabric)] + public void Verify_JsonIndex_Alter_ThrowsException() + { + this.ExecuteFromDbPool( + database => + { + _SMO.Table table = null; + + try + { + // Create table with JSON column + table = new _SMO.Table(database, "JsonIndexTable_" + Guid.NewGuid()); + table.Columns.Add(new _SMO.Column(table, "id", _SMO.DataType.Int) { Nullable = false }); + table.Columns.Add(new _SMO.Column(table, "jsonCol", _SMO.DataType.Json) { Nullable = true }); + + _SMO.Index pkIdx = new _SMO.Index(table, "PK_" + table.Name) + { + IndexKeyType = _SMO.IndexKeyType.DriPrimaryKey, + IndexType = _SMO.IndexType.ClusteredIndex + }; + pkIdx.IndexedColumns.Add(new _SMO.IndexedColumn(pkIdx, "id")); + table.Indexes.Add(pkIdx); + table.Create(); + + // Create the JSON index + _SMO.Index index = new _SMO.Index(table, "JsonIndex_" + table.Name) + { + IndexType = _SMO.IndexType.JsonIndex + }; + _SMO.IndexedColumn jsonColumn = new _SMO.IndexedColumn(index, "jsonCol"); + index.IndexedColumns.Add(jsonColumn); + index.Create(); + + // Refresh the index to simulate it being loaded from the database + table.Indexes.Refresh(); + var createdIndex = table.Indexes[index.Name]; + + // Test 1: Try to alter the index via Alter() - should throw FailedOperationException + createdIndex.FillFactor = 80; + var ex1 = Assert.Throws<_SMO.FailedOperationException>(() => createdIndex.Alter(), + "Altering a JSON index should throw FailedOperationException"); + + Assert.That(ex1.Message, Does.Contain("Altering JSON indexes is not currently supported").IgnoreCase, + "Exception message should mention Altering JSON indexes is not currently supported"); + + // Test 2: Try to alter with Rebuild operation - should throw FailedOperationException + var ex2 = Assert.Throws<_SMO.FailedOperationException>(() => createdIndex.Alter(_SMO.IndexOperation.Rebuild), + "Altering a JSON index with Rebuild operation should throw FailedOperationException"); + + Assert.That(ex2.Message, Does.Contain("Altering JSON indexes is not currently supported").IgnoreCase, + "Exception message should mention Altering JSON indexes is not currently supported"); + + // Test 3: Try to script alter for the index - should throw FailedOperationException + var scripter = new _SMO.Scripter(database.Parent); + scripter.Options.ScriptForAlter = true; + var ex3 = Assert.Throws<_SMO.FailedOperationException>(() => scripter.Script(new _SMO.SqlSmoObject[] { createdIndex }), + "Scripting ALTER for a JSON index should throw FailedOperationException"); + + Assert.That(ex3.Message, Does.Contain("Script failed for Index").IgnoreCase, + "Exception message should mention script failed"); + } + finally + { + table?.Drop(); + } + }); + } #endregion #region Resumable Operations Tests @@ -1627,7 +1935,7 @@ public void Index_CreateClusteredColumnstoreIndex() index.Create(); table.Indexes.ClearAndInitialize(string.Empty, new string[0]); - Assert.That(table.Indexes.Cast<_SMO.Index>().Select(i => i.Name), Has.Exactly(1).EqualTo("CCS_Idx")); + Assert.That(table.Indexes.Select(i => i.Name), Has.Exactly(1).EqualTo("CCS_Idx")); index.Drop(); table.Drop(); @@ -1672,7 +1980,7 @@ public void Index_CreateClusteredColumnstoreIndex_WithOrderClause_ColumnStoreOrd index.Create(); table.Indexes.ClearAndInitialize(string.Empty, new string[0]); - Assert.That(table.Indexes.Cast<_SMO.Index>().Select(i => i.Name), Has.Exactly(1).EqualTo("CCI_Ordered_Idx")); + Assert.That(table.Indexes.Select(i => i.Name), Has.Exactly(1).EqualTo("CCI_Ordered_Idx")); index.Drop(); table.Drop(); @@ -1721,7 +2029,7 @@ public void Index_CreateNonClusteredColumnstoreIndex_WithOrderClause_ASC() index.Create(); table.Indexes.ClearAndInitialize(string.Empty, new string[0]); - Assert.That(table.Indexes.Cast<_SMO.Index>().Select(i => i.Name), Has.Exactly(1).EqualTo("NCCS_Ordered_Idx")); + Assert.That(table.Indexes.Select(i => i.Name), Has.Exactly(1).EqualTo("NCCS_Ordered_Idx")); index.Drop(); table.Drop(); @@ -1770,7 +2078,7 @@ public void Index_CreateNonClusteredColumnstoreIndex_WithOrderClause_DES() index.Create(); table.Indexes.ClearAndInitialize(string.Empty, new string[0]); - Assert.That(table.Indexes.Cast<_SMO.Index>().Select(i => i.Name), Has.Exactly(1).EqualTo("NCCS_Ordered_Idx")); + Assert.That(table.Indexes.Select(i => i.Name), Has.Exactly(1).EqualTo("NCCS_Ordered_Idx")); index.Drop(); table.Drop(); @@ -1811,7 +2119,7 @@ public void Index_CreateClusteredColumnstoreIndex_WithCompressionDelay() index.Create(); table.Indexes.ClearAndInitialize(string.Empty, new string[0]); - Assert.That(table.Indexes.Cast<_SMO.Index>().Select(i => i.Name), Has.Exactly(1).EqualTo("SmoBaselineVerification_CompressedColumnstoreIndexWithCompressionDelay")); + Assert.That(table.Indexes.Select(i => i.Name), Has.Exactly(1).EqualTo("SmoBaselineVerification_CompressedColumnstoreIndexWithCompressionDelay")); index.Drop(); table.Drop(); @@ -1857,7 +2165,7 @@ public void Index_CreateClusteredColumnstoreIndex_WithInclude_NoClauseGenerate() index.Create(); table.Indexes.ClearAndInitialize(string.Empty, new string[0]); - Assert.That(table.Indexes.Cast<_SMO.Index>().Select(i => i.Name), Has.Exactly(1).EqualTo("CCS_Idx")); + Assert.That(table.Indexes.Select(i => i.Name), Has.Exactly(1).EqualTo("CCS_Idx")); index.Drop(); table.Drop(); @@ -1904,7 +2212,7 @@ public void Index_CreateNonClusteredColumnstoreIndex_WithInclude_NoClauseGenerat index.Create(); table.Indexes.ClearAndInitialize(string.Empty, new string[0]); - Assert.That(table.Indexes.Cast<_SMO.Index>().Select(i => i.Name), Has.Exactly(1).EqualTo("CCS_Idx")); + Assert.That(table.Indexes.Select(i => i.Name), Has.Exactly(1).EqualTo("CCS_Idx")); index.Drop(); table.Drop(); diff --git a/src/FunctionalTest/Smo/ScriptingTests/TestHelpers/SmoObjectTestBase.cs b/src/FunctionalTest/Smo/ScriptingTests/TestHelpers/SmoObjectTestBase.cs index 0144f0c3..1455f629 100644 --- a/src/FunctionalTest/Smo/ScriptingTests/TestHelpers/SmoObjectTestBase.cs +++ b/src/FunctionalTest/Smo/ScriptingTests/TestHelpers/SmoObjectTestBase.cs @@ -220,7 +220,7 @@ protected void VerifySmoObjectCreateOrAlterForAlter(_SMO.Database database, _SMO /// The collection to verify. /// The expected count. /// Additional test related comments. - protected void VerifySmoCollectionCount(_SMO.SmoCollectionBase collection, int expectedCount, params string[] additionalComments) + protected void VerifySmoCollectionCount(_SMO.ISmoCollection collection, int expectedCount, params string[] additionalComments) { if (collection == null) { diff --git a/src/Microsoft/SqlServer/Management/ConnectionInfo/ServerInformation.cs b/src/Microsoft/SqlServer/Management/ConnectionInfo/ServerInformation.cs index fdf2f0cd..f25974b2 100644 --- a/src/Microsoft/SqlServer/Management/ConnectionInfo/ServerInformation.cs +++ b/src/Microsoft/SqlServer/Management/ConnectionInfo/ServerInformation.cs @@ -165,12 +165,22 @@ static public ServerInformation GetServerInformation(IDbConnection sqlConnection dataAdapter.SelectCommand = sqlCommand; dataAdapter.Fill(dataSet); + + // NOTE: Dynamics CRM databases have unique restrictions (master not accessible, CREATE TABLE not permitted) that make + // neither SqlDatabase or Unknown editions usable. Because adding it as a defined DatabaseEngineEdition would result in + // cascading changes elsewhere (query construction for SMO types, designer exemptions) and the previous behavior + // (where this went unconverted) was functioning correctly for MSSQL and Azure Data Studio, we treat it as a special case here. + const DatabaseEngineEdition dynamicsCrmEdition = (DatabaseEngineEdition)1000; + var engineType = (DatabaseEngineType)dataSet.Tables[0].Rows[0]["DatabaseEngineType"]; var edition = (DatabaseEngineEdition)dataSet.Tables[0].Rows[0]["DatabaseEngineEdition"]; // Treat unknown editions from Azure the same as Azure SQL database if (engineType == DatabaseEngineType.SqlAzureDatabase && !validEditions.Contains(edition)) { - edition = DatabaseEngineEdition.SqlDatabase; + if (edition != dynamicsCrmEdition) // Dynamics CRM databases have additional restrictions; don't treat them as Azure SQL DB. See note above. + { + edition = DatabaseEngineEdition.SqlDatabase; + } } // If we're on Managed Instance, don't treat it as a "Sql Azure", but as "Standalone" // Also, determine the underlying engine version. diff --git a/src/Microsoft/SqlServer/Management/Sdk/Sfc/Enumerator/xml/Config.xml b/src/Microsoft/SqlServer/Management/Sdk/Sfc/Enumerator/xml/Config.xml index 4e43d22f..b1eba786 100644 --- a/src/Microsoft/SqlServer/Management/Sdk/Sfc/Enumerator/xml/Config.xml +++ b/src/Microsoft/SqlServer/Management/Sdk/Sfc/Enumerator/xml/Config.xml @@ -537,6 +537,7 @@ + @@ -599,6 +600,7 @@ + diff --git a/src/Microsoft/SqlServer/Management/Sdk/Sfc/SfcMetadata.cs b/src/Microsoft/SqlServer/Management/Sdk/Sfc/SfcMetadata.cs index 88af5ae7..4302b487 100644 --- a/src/Microsoft/SqlServer/Management/Sdk/Sfc/SfcMetadata.cs +++ b/src/Microsoft/SqlServer/Management/Sdk/Sfc/SfcMetadata.cs @@ -771,13 +771,12 @@ private static List InternalLoadTypeRelationsInformationThr if (obj is Attribute) { Type t = obj.GetType(); - if (t == typeof(SfcObjectAttribute)) + if (obj is SfcObjectAttribute o) { if (relationship != SfcRelationship.None || flags != SfcPropertyFlags.None || isReference || isReferenceCollection) { ConflictReporting(customAttributes, sfcType.Name, property.Name); } - SfcObjectAttribute o = obj as SfcObjectAttribute; relationship = o.Relationship; if (relationship == SfcRelationship.ChildContainer || relationship == SfcRelationship.ObjectContainer) { diff --git a/src/Microsoft/SqlServer/Management/Smo.Extended/TransferBase.cs b/src/Microsoft/SqlServer/Management/Smo.Extended/TransferBase.cs index c689ba2b..7f224859 100644 --- a/src/Microsoft/SqlServer/Management/Smo.Extended/TransferBase.cs +++ b/src/Microsoft/SqlServer/Management/Smo.Extended/TransferBase.cs @@ -1151,7 +1151,7 @@ private void AddDiscoverableObjects(HashSet depDiscInputList, Dictionary(ICollection List, SmoCollectionBase collection) + private void AddAllObjects(ICollection List, IEnumerable collection) where T : SqlSmoObject { #if DEBUG @@ -1163,7 +1163,7 @@ private void AddAllObjects(ICollection List, SmoCollectionBase collectio } } - private void AddAllObjects(ICollection List, SmoCollectionBase collection, bool copyAll, + private void AddAllObjects(ICollection List, IEnumerable collection, bool copyAll, Action prefetch, Dictionary originalDefaultFields, params string[] fields) where T : SqlSmoObject { @@ -1185,7 +1185,7 @@ private void AddAllObjects(ICollection List, SmoCollectionBase collectio } } - private void AddAllNonSystemObjects(ICollection List, SmoCollectionBase collection, Func filterLedgerObjects) + private void AddAllNonSystemObjects(ICollection List, IEnumerable collection, Func filterLedgerObjects) where T : SqlSmoObject { #if DEBUG @@ -1200,7 +1200,7 @@ private void AddAllNonSystemObjects(ICollection List, SmoCollectionBase } } - private void AddAllNonSystemObjects(ICollection List, SmoCollectionBase collection, bool copyAll, + private void AddAllNonSystemObjects(ICollection List, IEnumerable collection, bool copyAll, Action prefetch, Dictionary originalDefaultFields, Func filterLedgerObjects = null, params string[] fields) where T : SqlSmoObject { @@ -1514,7 +1514,7 @@ private bool IsUnsupportedType(SqlDataType type, SqlServerVersion targetVersion) } - private bool ContainsUnsupportedType(ParameterCollectionBase parms, SqlServerVersion targetVersion) + private bool ContainsUnsupportedType(IEnumerable parms, SqlServerVersion targetVersion) { foreach (Parameter p in parms) { diff --git a/src/Microsoft/SqlServer/Management/Smo/AbstractCollectionBase.cs b/src/Microsoft/SqlServer/Management/Smo/AbstractCollectionBase.cs index 24164c27..9124f6b8 100644 --- a/src/Microsoft/SqlServer/Management/Smo/AbstractCollectionBase.cs +++ b/src/Microsoft/SqlServer/Management/Smo/AbstractCollectionBase.cs @@ -1,57 +1,45 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -using System; -using System.Diagnostics.CodeAnalysis; using Microsoft.SqlServer.Management.Sdk.Sfc; - -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 namespace Microsoft.SqlServer.Management.Smo { /// /// Base class for all SMO collections /// - public abstract class AbstractCollectionBase + public abstract class AbstractCollectionBase { - // the object that holds this collection - private SqlSmoObject parentInstance; - internal AbstractCollectionBase(SqlSmoObject parentInstance) { - this.parentInstance = parentInstance; + ParentInstance = parentInstance; initialized = false; - m_bIsDirty = false; - } - - // we have this so that contained objects can ask for their parent object - public SqlSmoObject ParentInstance - { - get - { - return parentInstance; - } + IsDirty = false; } - [SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")] - internal protected bool initialized; + /// + /// Returns the parent of the collection instance + /// + public SqlSmoObject ParentInstance { get; private set; } + + protected internal bool initialized; internal void MarkOutOfSync() { initialized = false; } - virtual internal StringComparer StringComparer + internal virtual StringComparer StringComparer { get { - return parentInstance.StringComparer; + return ParentInstance.StringComparer; } } - // we need this abstract method in order to support childred collection + // we need this abstract method in order to support children collection // enumeration automatically - internal protected void AddExisting(SqlSmoObject smoObj) + protected internal void AddExisting(SqlSmoObject smoObj) { ImplAddExisting(smoObj); } @@ -65,14 +53,9 @@ internal void RemoveObject(ObjectKeyBase key) internal abstract void ImplRemove(ObjectKeyBase key); internal abstract SqlSmoObject NoFaultLookup(ObjectKeyBase key); - internal abstract Int32 NoFaultCount { get; } - - bool m_bIsDirty; + internal abstract int NoFaultCount { get; } internal bool IsDirty // is collection dirty. ex: a Remove() has been performed - { - get { return m_bIsDirty; } - set { m_bIsDirty = value; } - } + { get; set; } internal abstract ObjectKeyBase CreateKeyFromUrn(Urn urn); } diff --git a/src/Microsoft/SqlServer/Management/Smo/AvailabilityGroupBase.cs b/src/Microsoft/SqlServer/Management/Smo/AvailabilityGroupBase.cs index 3c84b89e..c753cc8b 100644 --- a/src/Microsoft/SqlServer/Management/Smo/AvailabilityGroupBase.cs +++ b/src/Microsoft/SqlServer/Management/Smo/AvailabilityGroupBase.cs @@ -709,7 +709,7 @@ internal override void ScriptAlter(StringCollection alterQuery, ScriptingPrefere var propertyNames = IsSupportedProperty("BasicAvailabilityGroup") && BasicAvailabilityGroup - ? BasicAlterableGroupPropertyNames + ? BasicAlterableGroupPropertyNames.Where(propertyName => IsSupportedProperty(propertyName)) : AlterableGroupPropertyNames.Where(propertyName => IsSupportedProperty(propertyName)); foreach (var propertyName in propertyNames) @@ -898,7 +898,10 @@ protected override void PostCreate() DatabaseHealthTriggerPropertyName, FailureConditionLevelPropertyName, HealthCheckTimeoutPropertyName, - DtcSupportEnabledPropertyName + DtcSupportEnabledPropertyName, + + // SQL 2025+ + ClusterConnectionOptionsPropertyName }; /// diff --git a/src/Microsoft/SqlServer/Management/Smo/AvailabilityGroupListenerIPAddressCollectionBase.cs b/src/Microsoft/SqlServer/Management/Smo/AvailabilityGroupListenerIPAddressCollectionBase.cs index d3c7d113..fb795a8a 100644 --- a/src/Microsoft/SqlServer/Management/Smo/AvailabilityGroupListenerIPAddressCollectionBase.cs +++ b/src/Microsoft/SqlServer/Management/Smo/AvailabilityGroupListenerIPAddressCollectionBase.cs @@ -9,32 +9,34 @@ #pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 namespace Microsoft.SqlServer.Management.Smo { - // this is the class that contains common features of all schema collection classes - public class AvailabilityGroupListenerIPAddressCollectionBase : SortedListCollectionBase + /// + /// Collection of AvailabilityGroupListenerIPAddress objects associated with an AvailabilityGroupListener + /// + public class AvailabilityGroupListenerIPAddressCollectionBase : SortedListCollectionBase { internal AvailabilityGroupListenerIPAddressCollectionBase(SqlSmoObject parent) - : base(parent) + : base((AvailabilityGroupListener)parent) { } + protected override string UrnSuffix => AvailabilityGroupListenerIPAddress.UrnSuffix; + protected override void InitInnerCollection() { - InternalStorage = new SmoSortedList(new AvailabilityGroupListenerIPAddressObjectComparer(this.StringComparer)); + InternalStorage = new SmoSortedList(new AvailabilityGroupListenerIPAddressObjectComparer(StringComparer)); } - protected override Type GetCollectionElementType() - { - return typeof(AvailabilityGroupListenerIPAddress); - } internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) { - string ipAddress = urn.GetAttribute("IPAddress"); - string subnetMask = urn.GetAttribute("SubnetMask"); - string subnetIP = urn.GetAttribute("SubnetIP"); + var ipAddress = urn.GetAttribute("IPAddress"); + var subnetMask = urn.GetAttribute("SubnetMask"); + var subnetIP = urn.GetAttribute("SubnetIP"); return new AvailabilityGroupListenerIPAddressObjectKey(ipAddress, subnetMask, subnetIP); } + + internal override AvailabilityGroupListenerIPAddress GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) => new AvailabilityGroupListenerIPAddress(this, key, state); } internal class AvailabilityGroupListenerIPAddressObjectComparer : ObjectComparerBase @@ -46,8 +48,8 @@ public AvailabilityGroupListenerIPAddressObjectComparer(IComparer stringComparer public override int Compare(object obj1, object obj2) { - AvailabilityGroupListenerIPAddressObjectKey dbr1 = obj1 as AvailabilityGroupListenerIPAddressObjectKey; - AvailabilityGroupListenerIPAddressObjectKey dbr2 = obj2 as AvailabilityGroupListenerIPAddressObjectKey; + var dbr1 = obj1 as AvailabilityGroupListenerIPAddressObjectKey; + var dbr2 = obj2 as AvailabilityGroupListenerIPAddressObjectKey; if (dbr1 == null && dbr2 == null) { @@ -63,13 +65,13 @@ public override int Compare(object obj1, object obj2) } // We order first by IP address, SubnetIP and then SubnetMask. - int ipAddressComparison = this.stringComparer.Compare(dbr1.IPAddress, dbr2.IPAddress); + var ipAddressComparison = stringComparer.Compare(dbr1.IPAddress, dbr2.IPAddress); if (ipAddressComparison == 0) { - int subnetMaskComparison = this.stringComparer.Compare(dbr1.SubnetMask, dbr2.SubnetMask); + var subnetMaskComparison = stringComparer.Compare(dbr1.SubnetMask, dbr2.SubnetMask); if (subnetMaskComparison == 0) { - return this.stringComparer.Compare(dbr1.SubnetIP, dbr2.SubnetIP); + return stringComparer.Compare(dbr1.SubnetIP, dbr2.SubnetIP); } return subnetMaskComparison; @@ -93,9 +95,9 @@ public AvailabilityGroupListenerIPAddressObjectKey() public AvailabilityGroupListenerIPAddressObjectKey(string ipAddress, string subnetMask, string subnetIP) { - this.IPAddress = ipAddress; - this.SubnetMask = subnetMask; - this.SubnetIP = subnetIP; + IPAddress = ipAddress; + SubnetMask = subnetMask; + SubnetIP = subnetIP; } static AvailabilityGroupListenerIPAddressObjectKey() @@ -129,7 +131,7 @@ public override string UrnFilter get { return string.Format(SmoApplication.DefaultCulture, "@IPAddress='{0}' and @SubnetMask='{1}' and @SubnetIP='{2}'", - SqlSmoObject.SqlString(this.IPAddress), SqlSmoObject.SqlString(this.SubnetMask), SqlSmoObject.SqlString(this.SubnetIP)); + SqlSmoObject.SqlString(IPAddress), SqlSmoObject.SqlString(SubnetMask), SqlSmoObject.SqlString(SubnetIP)); } } @@ -146,18 +148,18 @@ public override bool IsNull { get { - return null == this.IPAddress || null == this.SubnetMask || null == this.SubnetIP; + return null == IPAddress || null == SubnetMask || null == SubnetIP; } } public override string GetExceptionName() { - return string.Format(SmoApplication.DefaultCulture, "IPaddress {0} of Subnet mask {1} and SubnetIP {2}", this.IPAddress, this.SubnetMask, this.SubnetIP); + return string.Format(SmoApplication.DefaultCulture, "IPaddress {0} of Subnet mask {1} and SubnetIP {2}", IPAddress, SubnetMask, SubnetIP); } public override ObjectKeyBase Clone() { - return new AvailabilityGroupListenerIPAddressObjectKey(this.IPAddress, this.SubnetMask, this.SubnetIP); + return new AvailabilityGroupListenerIPAddressObjectKey(IPAddress, SubnetMask, SubnetIP); } public override ObjectComparerBase GetComparer(IComparer stringComparer) @@ -167,7 +169,7 @@ public override ObjectComparerBase GetComparer(IComparer stringComparer) public override string ToString() { - return string.Format(SmoApplication.DefaultCulture, "{0}/{1}/{2}", this.IPAddress, this.SubnetMask, this.SubnetIP); + return string.Format(SmoApplication.DefaultCulture, "{0}/{1}/{2}", IPAddress, SubnetMask, SubnetIP); } } } diff --git a/src/Microsoft/SqlServer/Management/Smo/CollectionBase.cs b/src/Microsoft/SqlServer/Management/Smo/CollectionBase.cs index e128c6b4..8796c4bf 100644 --- a/src/Microsoft/SqlServer/Management/Smo/CollectionBase.cs +++ b/src/Microsoft/SqlServer/Management/Smo/CollectionBase.cs @@ -6,173 +6,190 @@ using System.Collections.Specialized; using Microsoft.SqlServer.Management.Sdk.Sfc; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 namespace Microsoft.SqlServer.Management.Smo { /// /// base class for all generic collections /// - public abstract class SimpleObjectCollectionBase : SortedListCollectionBase - { - internal SimpleObjectCollectionBase(SqlSmoObject parent) : base(parent) - { - } - - /// - /// Initializes the storage - /// - protected override void InitInnerCollection() - { - InternalStorage = new SmoSortedList(new SimpleObjectComparer(this.StringComparer)); - } - - /// - /// Contains - /// - /// - /// - public bool Contains(String name) - { - if (null == name) + public abstract class SimpleObjectCollectionBase : SortedListCollectionBase, INamedObjectCollection + where TObject : SqlSmoObject + where TParent : SqlSmoObject + { + internal SimpleObjectCollectionBase(TParent parent) : base(parent) + { + } + + /// + /// Initializes the storage + /// + protected override void InitInnerCollection() => InternalStorage = new SmoSortedList(new SimpleObjectComparer(StringComparer)); + + /// + /// Returns the parent of the collection + /// + public TParent Parent => ParentInstance as TParent; + + /// + /// Adds the given object to the collection + /// + /// + public void Add(TObject obj) => AddImpl(obj); + + /// + /// Contains + /// + /// + /// + public bool Contains(string name) => null == name + ? throw new FailedOperationException(ExceptionTemplates.Contains, this, new ArgumentNullException(nameof(name))) + : Contains(KeyFromName(name)); + + /// + /// Returns the object identified by the given name after ensuring the collection is initialized + /// + /// + /// + public TObject this[string name] => GetObjectByName(name) as TObject; + + internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) + { + var name = urn.GetAttribute("Name"); + if (null == name || (name.Length == 0 && !CanHaveEmptyName(urn))) { - throw new FailedOperationException(ExceptionTemplates.Contains, this, new ArgumentNullException("name")); + throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); } - return this.Contains(new SimpleObjectKey(name)); - } - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - if( null == name || (name.Length == 0 && !CanHaveEmptyName(urn))) - { - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - } - - return new SimpleObjectKey(name); - } - } - - internal class SimpleObjectComparer : ObjectComparerBase - { - internal SimpleObjectComparer(IComparer stringComparer) : base(stringComparer) - { - } - - public override int Compare(object obj1, object obj2) - { - return stringComparer.Compare((obj1 as SimpleObjectKey).Name, (obj2 as SimpleObjectKey).Name); - } - } - - internal class SimpleObjectKey : ObjectKeyBase - { - protected String name; - - - /// - /// .ctor - /// - /// - public SimpleObjectKey(String name) : base() - { - this.name = name; - } - - static SimpleObjectKey() - { - fields.Add("Name"); - } - - internal static readonly StringCollection fields = new StringCollection(); - - /// - /// Name of the object - /// - /// - public string Name - { - get { return name; } - set { name = value; } - } - - /// - /// ToString - /// - /// - public override string ToString() - { - return string.Format(SmoApplication.DefaultCulture, "[{0}]", - SqlSmoObject.SqlBraket(name)); - } - - /// - /// GetExceptionName - /// - /// - public override string GetExceptionName() - { - return name; - } - - /// - /// Urn suffix that identifies this object - /// - /// - public override string UrnFilter - { - get { return string.Format(SmoApplication.DefaultCulture, "@Name='{0}'", Urn.EscapeString(name)); } - } - - /// - /// Return all fields that are used by this key. - /// - /// - public override StringCollection GetFieldNames() - { - return fields; - } - - /// - /// Clone the object. - /// - /// - public override ObjectKeyBase Clone() - { - return new SimpleObjectKey(this.Name); - } - - internal override void Validate(Type objectType) - { - bool acceptEmptyName = (objectType.Equals(typeof(UserDefinedAggregateParameter)) || - objectType.Equals(typeof(UserDefinedFunctionParameter))); - if( null == this.Name || (this.Name.Length == 0 && !acceptEmptyName)) - { - throw new UnsupportedObjectNameException(ExceptionTemplates.UnsupportedObjectNameExceptionText(objectType.ToString())).SetHelpContext("UnsupportedObjectNameExceptionText"); - } - } - - /// - /// True if the key is null. - /// - /// - public override bool IsNull - { - get { return (null == name);} - } - - /// - /// Returns string comparer needed to compare the string portion of this key. - /// - /// - /// - public override ObjectComparerBase GetComparer(IComparer stringComparer) - { - return new SimpleObjectComparer(stringComparer); - } - - } + return KeyFromName(name); + } + + internal virtual ObjectKeyBase KeyFromName(string name) => new SimpleObjectKey(name); + } + /// + /// Base class for collections that can have items removed + /// + /// + /// + public abstract class RemovableCollectionBase : SimpleObjectCollectionBase + where TObject : NamedSmoObject + where TParent : SqlSmoObject + { + internal RemovableCollectionBase(TParent parent) : base(parent) + { + } + + /// + /// Removes an item with the given name from the collection. If no item with that name is in the collection, the collection remains unchanged. + /// + /// + public void Remove(string name) => Remove(KeyFromName(name)); + + /// + /// Removes the given object from the collection + /// + /// + public void Remove(TObject obj) + { + if (obj == null) + { + throw new ArgumentNullException(nameof(obj)); + } + RemoveObj(obj, KeyFromName(obj.Name)); + } + } + + internal class SimpleObjectComparer : ObjectComparerBase + { + internal SimpleObjectComparer(IComparer stringComparer) : base(stringComparer) + { + } + + public override int Compare(object obj1, object obj2) => stringComparer.Compare((obj1 as SimpleObjectKey).Name, (obj2 as SimpleObjectKey).Name); + } + + internal class SimpleObjectKey : ObjectKeyBase + { + + /// + /// .ctor + /// + /// + public SimpleObjectKey(string name) : base() + { + Name = name; + } + + static SimpleObjectKey() + { + _ = fields.Add(nameof(Name)); + } + + internal static readonly StringCollection fields = new StringCollection(); + + /// + /// Name of the object + /// + /// + public string Name + { + get; + set; + } + + /// + /// ToString + /// + /// + public override string ToString() => $"[{SqlSmoObject.SqlBraket(Name)}]"; + + /// + /// GetExceptionName + /// + /// + public override string GetExceptionName() => Name; + + /// + /// Urn suffix that identifies this object + /// + /// + public override string UrnFilter => $"@Name='{Urn.EscapeString(Name)}'"; + + /// + /// Return all fields that are used by this key. + /// + /// + public override StringCollection GetFieldNames() => fields; + + /// + /// Clone the object. + /// + /// + public override ObjectKeyBase Clone() => new SimpleObjectKey(Name); + + internal override void Validate(Type objectType) + { + var acceptEmptyName = objectType.Equals(typeof(UserDefinedAggregateParameter)) || + objectType.Equals(typeof(UserDefinedFunctionParameter)); + if( null == Name || (Name.Length == 0 && !acceptEmptyName)) + { + throw new UnsupportedObjectNameException(ExceptionTemplates.UnsupportedObjectNameExceptionText(objectType.ToString())).SetHelpContext("UnsupportedObjectNameExceptionText"); + } + } + + /// + /// True if the key is null. + /// + /// + public override bool IsNull => null == Name; + + /// + /// Returns string comparer needed to compare the string portion of this key. + /// + /// + /// + public override ObjectComparerBase GetComparer(IComparer stringComparer) => new SimpleObjectComparer(stringComparer); + + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/CollectionInterfaces.cs b/src/Microsoft/SqlServer/Management/Smo/CollectionInterfaces.cs new file mode 100644 index 00000000..c7a3534d --- /dev/null +++ b/src/Microsoft/SqlServer/Management/Smo/CollectionInterfaces.cs @@ -0,0 +1,101 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Microsoft.SqlServer.Management.Smo +{ + /// + /// Base interface for SMO collections + /// + public interface ISmoCollection : System.Collections.ICollection + { + /// + /// Refreshes the content of the collection without refreshing existing objects in the collection + /// + void Refresh(); + + /// + /// Refreshes the contents of the collection and refreshes the properties of existing objects in the collection + /// + /// + void Refresh(bool refreshChildObjects); + + /// + /// Clears old objects and initializes the collection. Unlike Refresh(), any objects already listed in the collection will be replaced with new versions. + /// Use this method to assure all the objects in the collection have the complete set of properties you want. + /// + /// the xpath to filter the objects by properties + /// (e.g. setting the filter to [(@IsSystemObject = 0)] will exclude the system objects from the result. + /// By setting the parameter to null or empty string, no filter will be applied to the result + /// the list of fields to be loaded in each object. + /// (e.g. setting the extraFields to "new string[] { "IsSystemVersioned" })" when calling this method for TableCollection + /// will include "IsSystemVersioned" property for each table object. + /// By setting the parameter to null or empty array, only the default fields will be included in the result + void ClearAndInitialize(string filterQuery, IEnumerable extraFields); + + /// + /// Empties the collection but doesn't attempt to retrieve any data + /// + void ResetCollection(); + } + + /// + /// Base interface for SMO collections of named objects + /// + public interface INamedObjectCollection : ISmoCollection + { + /// + /// Returns whether the collection contains an object with the given name + /// + /// + /// + bool Contains(string name); + } + + /// + /// Interface with methods that describe characteristics of schema objects in a collection + /// + public interface ISchemaObjectCollection : INamedObjectCollection + { + /// + /// Returns the default schema of the database associated with this collection + /// + /// + string GetDefaultSchema(); + /// + /// Returns whether the collection contains an object with the given name and schema + /// + /// + /// + /// + bool Contains(string name, string schema); + } + + /// + /// Implemented by collections whose sort order is by ID + /// + public interface IOrderedCollection : INamedObjectCollection + { + } + + /// + /// Provides methods to lock and unlock the contents of a collection + /// + public interface ILockableCollection + { + void LockCollection(string lockReason); + + void UnlockCollection(); + + bool IsCollectionLocked { get; } + + void CheckCollectionLock(); + + } +} + diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/AlertCategoryCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/AlertCategoryCollection.cs index 3e3c78e4..5d647cab 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/AlertCategoryCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/AlertCategoryCollection.cs @@ -1,249 +1,13 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo.Agent { /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class + /// A collection of AlertCategory objects associated with a JobServer /// - public sealed class AlertCategoryCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal AlertCategoryCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public JobServer Parent - { - get - { - return this.ParentInstance as JobServer; - } - } - - - public AlertCategory this[Int32 index] - { - get - { - return GetObjectByIndex(index) as AlertCategory; - } - } - - - // returns wrapper class - public AlertCategory this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as AlertCategory; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(AlertCategory[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public AlertCategory ItemById(int id) - { - return (AlertCategory)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(AlertCategory); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new AlertCategory(this, key, state); - } - - - - - public void Remove(AlertCategory alertCategory) - { - if( null == alertCategory ) - throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException("alertCategory")); - - RemoveObj(alertCategory, new SimpleObjectKey(alertCategory.Name)); - } - - public void Remove(string name) - { - this.Remove(new SimpleObjectKey(name)); - } - - - - public void Add(AlertCategory alertCategory) - { - AddImpl(alertCategory); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public partial class AlertCategoryCollection : RemovableCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/AlertCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/AlertCollection.cs index 93fab856..f5b84a54 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/AlertCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/AlertCollection.cs @@ -1,250 +1,42 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; using System.Collections.Specialized; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo.Agent { - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class AlertCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal AlertCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public JobServer Parent - { - get - { - return this.ParentInstance as JobServer; - } - } - - - public Alert this[Int32 index] - { - get - { - return GetObjectByIndex(index) as Alert; - } - } - - - // returns wrapper class - public Alert this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as Alert; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(Alert[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public Alert ItemById(int id) - { - return (Alert)GetItemById(id); - } - - - - - - - - - - - public StringCollection Script() - { - return this.Script(new ScriptingOptions()); - } - - public StringCollection Script(ScriptingOptions scriptingOptions) - { - if( this.Count <= 0 ) - { - return new StringCollection(); - } - - SqlSmoObject [] scriptList = new SqlSmoObject[this.Count]; - int i = 0; - foreach(SqlSmoObject o in this) - { - scriptList[i++] = o; - } - Scripter scr = new Scripter(scriptList[0].GetServerObject()); - scr.Options = scriptingOptions; - return scr.Script(scriptList); - } - - - protected override Type GetCollectionElementType() - { - return typeof(Alert); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new Alert(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(Alert alert) - { - AddImpl(alert); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); + public sealed partial class AlertCollection : SimpleObjectCollectionBase + { + /// + /// Returns the set of TSQL statements needed to create the Alerts, using default ScriptingOptions + /// + /// + public StringCollection Script() => Script(new ScriptingOptions()); + + /// + /// Returns the set of TSQL statements needed to create the Alerts, using the provided ScriptingOptions + /// + /// + /// + public StringCollection Script(ScriptingOptions scriptingOptions) + { + if (Count <= 0) + { + return new StringCollection(); + } + + var scriptList = new SqlSmoObject[Count]; + var i = 0; + foreach (SqlSmoObject o in this) + { + scriptList[i++] = o; + } + var scr = new Scripter(scriptList[0].GetServerObject()) + { + Options = scriptingOptions + }; + return scr.Script(scriptList); } - - - - - - - - - - - - - - - - - - } + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/ApplicationRoleCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/ApplicationRoleCollection.cs index 5568c600..7c734e49 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/ApplicationRoleCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/ApplicationRoleCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class ApplicationRoleCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal ApplicationRoleCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public ApplicationRole this[Int32 index] - { - get - { - return GetObjectByIndex(index) as ApplicationRole; - } - } - - - // returns wrapper class - public ApplicationRole this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as ApplicationRole; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(ApplicationRole[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public ApplicationRole ItemById(int id) - { - return (ApplicationRole)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(ApplicationRole); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new ApplicationRole(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(ApplicationRole applicationRole) - { - AddImpl(applicationRole); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class ApplicationRoleCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/AsymmetricKeyCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/AsymmetricKeyCollection.cs index 3266c815..d74348fe 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/AsymmetricKeyCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/AsymmetricKeyCollection.cs @@ -1,249 +1,12 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class + /// Collection of AsymmetricKey objects /// - public sealed class AsymmetricKeyCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal AsymmetricKeyCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public AsymmetricKey this[Int32 index] - { - get - { - return GetObjectByIndex(index) as AsymmetricKey; - } - } - - - // returns wrapper class - public AsymmetricKey this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as AsymmetricKey; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(AsymmetricKey[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public AsymmetricKey ItemById(int id) - { - return (AsymmetricKey)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(AsymmetricKey); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new AsymmetricKey(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(AsymmetricKey asymmetricKey) - { - AddImpl(asymmetricKey); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class AsymmetricKeyCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/AuditCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/AuditCollection.cs index bf1b6769..26bb7f5f 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/AuditCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/AuditCollection.cs @@ -1,249 +1,12 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class + /// Collection of Audit objects on a Server /// - public sealed class AuditCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal AuditCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Server Parent - { - get - { - return this.ParentInstance as Server; - } - } - - - public Audit this[Int32 index] - { - get - { - return GetObjectByIndex(index) as Audit; - } - } - - - // returns wrapper class - public Audit this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as Audit; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(Audit[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public Audit ItemById(int id) - { - return (Audit)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(Audit); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new Audit(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(Audit audit) - { - AddImpl(audit); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class AuditCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/AvailabilityDatabaseCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/AvailabilityDatabaseCollection.cs index 225a3b1a..7ecf898d 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/AvailabilityDatabaseCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/AvailabilityDatabaseCollection.cs @@ -2,248 +2,10 @@ // Licensed under the MIT license. using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class AvailabilityDatabaseCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal AvailabilityDatabaseCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public AvailabilityGroup Parent - { - get - { - return this.ParentInstance as AvailabilityGroup; - } - } - - - public AvailabilityDatabase this[Int32 index] - { - get - { - return GetObjectByIndex(index) as AvailabilityDatabase; - } - } - - - // returns wrapper class - public AvailabilityDatabase this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as AvailabilityDatabase; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(AvailabilityDatabase[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public AvailabilityDatabase ItemById(int id) - { - return (AvailabilityDatabase)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(AvailabilityDatabase); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new AvailabilityDatabase(this, key, state); - } - - - - - public void Remove(AvailabilityDatabase AvailabilityDatabase) - { - if( null == AvailabilityDatabase ) - throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException("AvailabilityDatabase")); - - RemoveObj(AvailabilityDatabase, new SimpleObjectKey(AvailabilityDatabase.Name)); - } - - public void Remove(string name) - { - this.Remove(new SimpleObjectKey(name)); - } - - - - public void Add(AvailabilityDatabase AvailabilityDatabase) - { - AddImpl(AvailabilityDatabase); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class AvailabilityDatabaseCollection : RemovableCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/AvailabilityGroupCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/AvailabilityGroupCollection.cs index bfdd7660..61d2385a 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/AvailabilityGroupCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/AvailabilityGroupCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class AvailabilityGroupCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal AvailabilityGroupCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Server Parent - { - get - { - return this.ParentInstance as Server; - } - } - - - public AvailabilityGroup this[Int32 index] - { - get - { - return GetObjectByIndex(index) as AvailabilityGroup; - } - } - - - // returns wrapper class - public AvailabilityGroup this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as AvailabilityGroup; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(AvailabilityGroup[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public AvailabilityGroup ItemById(int id) - { - return (AvailabilityGroup)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(AvailabilityGroup); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new AvailabilityGroup(this, key, state); - } - - - - - public void Remove(AvailabilityGroup availabilityGroup) - { - if( null == availabilityGroup ) - throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException("availabilityGroup")); - - RemoveObj(availabilityGroup, new SimpleObjectKey(availabilityGroup.Name)); - } - - public void Remove(string name) - { - this.Remove(new SimpleObjectKey(name)); - } - - - - public void Add(AvailabilityGroup availabilityGroup) - { - AddImpl(availabilityGroup); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class AvailabilityGroupCollection : RemovableCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/AvailabilityGroupListenerCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/AvailabilityGroupListenerCollection.cs index 0c12a319..5209f2f0 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/AvailabilityGroupListenerCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/AvailabilityGroupListenerCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class AvailabilityGroupListenerCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal AvailabilityGroupListenerCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public AvailabilityGroup Parent - { - get - { - return this.ParentInstance as AvailabilityGroup; - } - } - - - public AvailabilityGroupListener this[Int32 index] - { - get - { - return GetObjectByIndex(index) as AvailabilityGroupListener; - } - } - - - // returns wrapper class - public AvailabilityGroupListener this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as AvailabilityGroupListener; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(AvailabilityGroupListener[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public AvailabilityGroupListener ItemById(int id) - { - return (AvailabilityGroupListener)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(AvailabilityGroupListener); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new AvailabilityGroupListener(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(AvailabilityGroupListener AvailabilityGroupListener) - { - AddImpl(AvailabilityGroupListener); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class AvailabilityGroupListenerCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/AvailabilityGroupListenerIPAddressCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/AvailabilityGroupListenerIPAddressCollection.cs index 9226e812..3bf4b6b8 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/AvailabilityGroupListenerIPAddressCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/AvailabilityGroupListenerIPAddressCollection.cs @@ -2,44 +2,18 @@ // Licensed under the MIT license. using System; -using System.Collections; -#pragma warning disable 1590, 1591, 1592, 1573, 1571, 1570, 1572, 1587 - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { /// - /// Strongly typed collection of MAPPED_TYPE objects + /// Strongly typed collection of AvailabilityGroupListenerIPAddress objects /// Supports indexing objects by their IPAddress and SubnetMask and SubnetIP properties /// public sealed class AvailabilityGroupListenerIPAddressCollection : AvailabilityGroupListenerIPAddressCollectionBase { - internal AvailabilityGroupListenerIPAddressCollection(SqlSmoObject parentInstance) : base(parentInstance) + internal AvailabilityGroupListenerIPAddressCollection(SqlSmoObject parentInstance) : base(parentInstance) { } @@ -53,14 +27,6 @@ public AvailabilityGroupListener Parent } - public AvailabilityGroupListenerIPAddress this[Int32 index] - { - get - { - return GetObjectByIndex(index) as AvailabilityGroupListenerIPAddress; - } - } - public AvailabilityGroupListenerIPAddress this[string ipAddress, string subnetMask, string subnetIP] { get @@ -70,51 +36,12 @@ public AvailabilityGroupListenerIPAddress this[Int32 index] } } - public void CopyTo(AvailabilityGroupListenerIPAddress[] array, int index) + public void Add(AvailabilityGroupListenerIPAddress availabilityGroupListenerIPAddress) { - ((ICollection)this).CopyTo(array, index); - } + if (null == availabilityGroupListenerIPAddress) + throw new FailedOperationException(ExceptionTemplates.AddCollection, this, new ArgumentNullException(nameof(availabilityGroupListenerIPAddress))); - - public AvailabilityGroupListenerIPAddress ItemById(int id) - { - return (AvailabilityGroupListenerIPAddress)GetItemById(id); - } - - - protected override Type GetCollectionElementType() - { - return typeof(AvailabilityGroupListenerIPAddress); + AddImpl(availabilityGroupListenerIPAddress); } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new AvailabilityGroupListenerIPAddress(this, key, state); - } - - - - - - - - - - - - - - - - - - - public void Add(AvailabilityGroupListenerIPAddress AvailabilityGroupListenerIPAddress) - { - if( null == AvailabilityGroupListenerIPAddress ) - throw new FailedOperationException(ExceptionTemplates.AddCollection, this, new ArgumentNullException("AvailabilityGroupListenerIPAddress")); - - AddImpl(AvailabilityGroupListenerIPAddress); - } } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/AvailabilityReplicaCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/AvailabilityReplicaCollection.cs index 8e51c217..c5f86b29 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/AvailabilityReplicaCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/AvailabilityReplicaCollection.cs @@ -1,249 +1,26 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { + public sealed partial class AvailabilityReplicaCollection : RemovableCollectionBase + { - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class AvailabilityReplicaCollection : SimpleObjectCollectionBase - { - - //has custom string comparer - StringComparer m_comparer; - - //must initialize in constructor - internal AvailabilityReplicaCollection(SqlSmoObject parentInstance, StringComparer comparer) : base(parentInstance) - { - m_comparer = comparer; - } - - override internal StringComparer StringComparer - { - get - { - return m_comparer; - } - } - - - - - - - - public AvailabilityGroup Parent - { - get - { - return this.ParentInstance as AvailabilityGroup; - } - } - - - public AvailabilityReplica this[Int32 index] - { - get - { - return GetObjectByIndex(index) as AvailabilityReplica; - } - } - - - // returns wrapper class - public AvailabilityReplica this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as AvailabilityReplica; - - - - - - - - - - - - - - - - - - - + //has custom string comparer + private readonly StringComparer m_comparer; - - } - } - - - public void CopyTo(AvailabilityReplica[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public AvailabilityReplica ItemById(int id) - { - return (AvailabilityReplica)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(AvailabilityReplica); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new AvailabilityReplica(this, key, state); - } - - - - - public void Remove(AvailabilityReplica availabilityReplica) - { - if( null == availabilityReplica ) - throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException("availabilityReplica")); - - RemoveObj(availabilityReplica, new SimpleObjectKey(availabilityReplica.Name)); - } - - public void Remove(string name) - { - this.Remove(new SimpleObjectKey(name)); - } - - - - public void Add(AvailabilityReplica availabilityReplica) - { - AddImpl(availabilityReplica); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); + //must initialize in constructor + internal AvailabilityReplicaCollection(SqlSmoObject parentInstance, StringComparer comparer) : base((AvailabilityGroup)parentInstance) + { + m_comparer = comparer; } - - - - - - - - - - - - - - - - - - } + internal override StringComparer StringComparer + { + get + { + return m_comparer; + } + } + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/BackupDeviceCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/BackupDeviceCollection.cs index ed4bf957..e49721d0 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/BackupDeviceCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/BackupDeviceCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class BackupDeviceCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal BackupDeviceCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Server Parent - { - get - { - return this.ParentInstance as Server; - } - } - - - public BackupDevice this[Int32 index] - { - get - { - return GetObjectByIndex(index) as BackupDevice; - } - } - - - // returns wrapper class - public BackupDevice this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as BackupDevice; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(BackupDevice[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(BackupDevice); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new BackupDevice(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(BackupDevice backupDevice) - { - AddImpl(backupDevice); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class BackupDeviceCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/BrokerPriorityCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/BrokerPriorityCollection.cs index 1ecfd030..b9480d82 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/BrokerPriorityCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/BrokerPriorityCollection.cs @@ -1,249 +1,26 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo.Broker { + public sealed partial class BrokerPriorityCollection : SimpleObjectCollectionBase + { - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class BrokerPriorityCollection : SimpleObjectCollectionBase - { - - //has custom string comparer - StringComparer m_comparer; - - //must initialize in constructor - internal BrokerPriorityCollection(SqlSmoObject parentInstance, StringComparer comparer) : base(parentInstance) - { - m_comparer = comparer; - } - - override internal StringComparer StringComparer - { - get - { - return m_comparer; - } - } - - - - - - - - public ServiceBroker Parent - { - get - { - return this.ParentInstance as ServiceBroker; - } - } - - - public BrokerPriority this[Int32 index] - { - get - { - return GetObjectByIndex(index) as BrokerPriority; - } - } - - - // returns wrapper class - public BrokerPriority this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as BrokerPriority; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(BrokerPriority[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public BrokerPriority ItemById(int id) - { - return (BrokerPriority)GetItemById(id); - } - + //has custom string comparer + private readonly StringComparer m_comparer; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(BrokerPriority); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new BrokerPriority(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(BrokerPriority brokerPriority) - { - AddImpl(brokerPriority); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); + //must initialize in constructor + internal BrokerPriorityCollection(SqlSmoObject parentInstance, StringComparer comparer) : base((ServiceBroker)parentInstance) + { + m_comparer = comparer; } - - - - - - - - - - - - - - - - - - } + internal override StringComparer StringComparer + { + get + { + return m_comparer; + } + } + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/BrokerServiceCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/BrokerServiceCollection.cs index e95a2978..916015f7 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/BrokerServiceCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/BrokerServiceCollection.cs @@ -1,249 +1,26 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo.Broker { + public sealed partial class BrokerServiceCollection : SimpleObjectCollectionBase + { - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class BrokerServiceCollection : SimpleObjectCollectionBase - { - - //has custom string comparer - StringComparer m_comparer; - - //must initialize in constructor - internal BrokerServiceCollection(SqlSmoObject parentInstance, StringComparer comparer) : base(parentInstance) - { - m_comparer = comparer; - } - - override internal StringComparer StringComparer - { - get - { - return m_comparer; - } - } - - - - - - - - public ServiceBroker Parent - { - get - { - return this.ParentInstance as ServiceBroker; - } - } - - - public BrokerService this[Int32 index] - { - get - { - return GetObjectByIndex(index) as BrokerService; - } - } - - - // returns wrapper class - public BrokerService this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as BrokerService; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(BrokerService[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public BrokerService ItemById(int id) - { - return (BrokerService)GetItemById(id); - } - + //has custom string comparer + StringComparer m_comparer; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(BrokerService); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new BrokerService(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(BrokerService brokerService) - { - AddImpl(brokerService); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); + //must initialize in constructor + internal BrokerServiceCollection(SqlSmoObject parentInstance, StringComparer comparer) : base((ServiceBroker)parentInstance) + { + m_comparer = comparer; } - - - - - - - - - - - - - - - - - - } + override internal StringComparer StringComparer + { + get + { + return m_comparer; + } + } + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/CertificateCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/CertificateCollection.cs index fc8f51e3..0b387ce1 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/CertificateCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/CertificateCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class CertificateCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal CertificateCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public Certificate this[Int32 index] - { - get - { - return GetObjectByIndex(index) as Certificate; - } - } - - - // returns wrapper class - public Certificate this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as Certificate; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(Certificate[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public Certificate ItemById(int id) - { - return (Certificate)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(Certificate); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new Certificate(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(Certificate certificate) - { - AddImpl(certificate); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class CertificateCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/CheckCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/CheckCollection.cs index f615d490..73d3c909 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/CheckCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/CheckCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class CheckCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal CheckCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public SqlSmoObject Parent - { - get - { - return this.ParentInstance as SqlSmoObject; - } - } - - - public Check this[Int32 index] - { - get - { - return GetObjectByIndex(index) as Check; - } - } - - - // returns wrapper class - public Check this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as Check; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(Check[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public Check ItemById(int id) - { - return (Check)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(Check); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new Check(this, key, state); - } - - - - - public void Remove(Check check) - { - if( null == check ) - throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException("check")); - - RemoveObj(check, new SimpleObjectKey(check.Name)); - } - - public void Remove(string name) - { - this.Remove(new SimpleObjectKey(name)); - } - - - - public void Add(Check check) - { - AddImpl(check); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class CheckCollection : RemovableCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/ColumnCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/ColumnCollection.cs index 4e7f8d6f..6d9c4064 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/ColumnCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/ColumnCollection.cs @@ -1,148 +1,10 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590, 1591, 1592, 1573, 1571, 1570, 1572, 1587 - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class ColumnCollection : ParameterCollectionBase - { - internal ColumnCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - public SqlSmoObject Parent - { - get - { - return this.ParentInstance as SqlSmoObject; - } - } - - - public Column this[Int32 index] - { - get - { - return GetObjectByIndex(index) as Column; - } - } - - public void CopyTo(Column[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - // returns wrapper class - public Column this[string name] - { - get - { - return GetObjectByKey( new SimpleObjectKey(name)) as Column; - } - } - - - protected override Type GetCollectionElementType() - { - return typeof(Column); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new Column(this, key, state); - } - - - public void Add(Column column) - { - AddImpl(column); - } - - public void Add(Column column, string insertAtColumnName) - { - AddImpl(column, new SimpleObjectKey(insertAtColumnName)); - } - - public void Add(Column column, int insertAtPosition) - { - AddImpl(column, insertAtPosition); - } - - - public void Remove(Column column) - { - if( null == column ) - throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException("column")); - - RemoveObj(column, column.key); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - public Column ItemById(int id) - { - return (Column)GetItemById(id); - } - - - } + public sealed partial class ColumnCollection : ParameterCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/ColumnEncryptionKeyCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/ColumnEncryptionKeyCollection.cs index 261b9109..23880cda 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/ColumnEncryptionKeyCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/ColumnEncryptionKeyCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class ColumnEncryptionKeyCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal ColumnEncryptionKeyCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public ColumnEncryptionKey this[Int32 index] - { - get - { - return GetObjectByIndex(index) as ColumnEncryptionKey; - } - } - - - // returns wrapper class - public ColumnEncryptionKey this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as ColumnEncryptionKey; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(ColumnEncryptionKey[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public ColumnEncryptionKey ItemById(int id) - { - return (ColumnEncryptionKey)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(ColumnEncryptionKey); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new ColumnEncryptionKey(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(ColumnEncryptionKey columnEncryptionKey) - { - AddImpl(columnEncryptionKey); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class ColumnEncryptionKeyCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/ColumnEncryptionKeyValueCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/ColumnEncryptionKeyValueCollection.cs index 739d7d7c..2356af64 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/ColumnEncryptionKeyValueCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/ColumnEncryptionKeyValueCollection.cs @@ -6,11 +6,10 @@ namespace Microsoft.SqlServer.Management.Smo { - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class ColumnEncryptionKeyValueCollection : ColumnEncryptionKeyValueCollectionBase + /// + /// Collection of ColumnEncryptionKeyValue objects associated with a ColumnEncryptionKey + /// + public sealed partial class ColumnEncryptionKeyValueCollection : ColumnEncryptionKeyValueCollectionBase { internal ColumnEncryptionKeyValueCollection(SqlSmoObject parentInstance) : base(parentInstance) { @@ -20,68 +19,24 @@ internal ColumnEncryptionKeyValueCollection(SqlSmoObject parentInstance) : base /// /// Returns the parent object /// - public ColumnEncryptionKey Parent - { - get - { - return this.ParentInstance as ColumnEncryptionKey; - } - } + public ColumnEncryptionKey Parent => ParentInstance as ColumnEncryptionKey; + + protected override string UrnSuffix => ColumnEncryptionKeyValue.UrnSuffix; - - /// - /// Returns the column encryption key value for a given index - /// - /// The index in the collection - /// The column encryption key at the given index - public ColumnEncryptionKeyValue this[Int32 index] - { - get - { - return GetObjectByIndex(index) as ColumnEncryptionKeyValue; - } - } /// /// Gets the column encryption key value for a given column master key id /// /// The Column Master Key ID /// The CEK value if found, null otherwise - public ColumnEncryptionKeyValue GetItemByColumnMasterKeyID(int ColumnMasterKeyID) - { - return InternalStorage[new ColumnEncryptionKeyValueObjectKey(ColumnMasterKeyID)] as ColumnEncryptionKeyValue; - } + public ColumnEncryptionKeyValue GetItemByColumnMasterKeyID(int ColumnMasterKeyID) => InternalStorage[new ColumnEncryptionKeyValueObjectKey(ColumnMasterKeyID)]; /// /// Adds the CEK value to the collection. /// - public void Add(ColumnEncryptionKeyValue columnEncryptionKeyValue) - { - InternalStorage.Add(new ColumnEncryptionKeyValueObjectKey(columnEncryptionKeyValue.ColumnMasterKeyID), columnEncryptionKeyValue); - } - - /// - /// Copies the collection to an arryay - /// - /// The array to copy to - /// The zero-based index in array at which copying begins - public void CopyTo(ColumnEncryptionKeyValue[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } + public void Add(ColumnEncryptionKeyValue columnEncryptionKeyValue) => InternalStorage.Add(new ColumnEncryptionKeyValueObjectKey(columnEncryptionKeyValue.ColumnMasterKeyID), columnEncryptionKeyValue); - /// - /// Returns the collection element type - /// - /// The collection element type - protected override Type GetCollectionElementType() - { - return typeof(ColumnEncryptionKeyValue); - } - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new ColumnEncryptionKeyValue(this, key, state); - } + internal override ColumnEncryptionKeyValue GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) => new ColumnEncryptionKeyValue(this, key, state); } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/ColumnMasterKeyCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/ColumnMasterKeyCollection.cs index ee8db192..81809d83 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/ColumnMasterKeyCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/ColumnMasterKeyCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class ColumnMasterKeyCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal ColumnMasterKeyCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public ColumnMasterKey this[Int32 index] - { - get - { - return GetObjectByIndex(index) as ColumnMasterKey; - } - } - - - // returns wrapper class - public ColumnMasterKey this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as ColumnMasterKey; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(ColumnMasterKey[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public ColumnMasterKey ItemById(int id) - { - return (ColumnMasterKey)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(ColumnMasterKey); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new ColumnMasterKey(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(ColumnMasterKey columnMasterKey) - { - AddImpl(columnMasterKey); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class ColumnMasterKeyCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/ConfigurationValueCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/ConfigurationValueCollection.cs index 9d63a34e..4aa1c9a2 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/ConfigurationValueCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/ConfigurationValueCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo.Mail { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class ConfigurationValueCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal ConfigurationValueCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public SqlMail Parent - { - get - { - return this.ParentInstance as SqlMail; - } - } - - - public ConfigurationValue this[Int32 index] - { - get - { - return GetObjectByIndex(index) as ConfigurationValue; - } - } - - - // returns wrapper class - public ConfigurationValue this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as ConfigurationValue; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(ConfigurationValue[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(ConfigurationValue); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new ConfigurationValue(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(ConfigurationValue configurationValue) - { - AddImpl(configurationValue); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class ConfigurationValueCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/CredentialCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/CredentialCollection.cs index cef791f7..57390a72 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/CredentialCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/CredentialCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class CredentialCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal CredentialCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Server Parent - { - get - { - return this.ParentInstance as Server; - } - } - - - public Credential this[Int32 index] - { - get - { - return GetObjectByIndex(index) as Credential; - } - } - - - // returns wrapper class - public Credential this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as Credential; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(Credential[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public Credential ItemById(int id) - { - return (Credential)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(Credential); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new Credential(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(Credential credential) - { - AddImpl(credential); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class CredentialCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/CryptographicProviderCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/CryptographicProviderCollection.cs index c511897c..56b2530b 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/CryptographicProviderCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/CryptographicProviderCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class CryptographicProviderCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal CryptographicProviderCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Server Parent - { - get - { - return this.ParentInstance as Server; - } - } - - - public CryptographicProvider this[Int32 index] - { - get - { - return GetObjectByIndex(index) as CryptographicProvider; - } - } - - - // returns wrapper class - public CryptographicProvider this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as CryptographicProvider; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(CryptographicProvider[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public CryptographicProvider ItemById(int id) - { - return (CryptographicProvider)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(CryptographicProvider); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new CryptographicProvider(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(CryptographicProvider cryptographicProvider) - { - AddImpl(cryptographicProvider); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class CryptographicProviderCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/DataFileCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/DataFileCollection.cs index de41d9ba..e9ca90ad 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/DataFileCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/DataFileCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class DataFileCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal DataFileCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public FileGroup Parent - { - get - { - return this.ParentInstance as FileGroup; - } - } - - - public DataFile this[Int32 index] - { - get - { - return GetObjectByIndex(index) as DataFile; - } - } - - - // returns wrapper class - public DataFile this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as DataFile; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(DataFile[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public DataFile ItemById(int id) - { - return (DataFile)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(DataFile); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new DataFile(this, key, state); - } - - - - - public void Remove(DataFile dataFile) - { - if( null == dataFile ) - throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException("dataFile")); - - RemoveObj(dataFile, new SimpleObjectKey(dataFile.Name)); - } - - public void Remove(string name) - { - this.Remove(new SimpleObjectKey(name)); - } - - - - public void Add(DataFile dataFile) - { - AddImpl(dataFile); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class DataFileCollection : RemovableCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/DatabaseAuditSpecificationCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/DatabaseAuditSpecificationCollection.cs index a22b5061..582b0c9f 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/DatabaseAuditSpecificationCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/DatabaseAuditSpecificationCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class DatabaseAuditSpecificationCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal DatabaseAuditSpecificationCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public DatabaseAuditSpecification this[Int32 index] - { - get - { - return GetObjectByIndex(index) as DatabaseAuditSpecification; - } - } - - - // returns wrapper class - public DatabaseAuditSpecification this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as DatabaseAuditSpecification; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(DatabaseAuditSpecification[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public DatabaseAuditSpecification ItemById(int id) - { - return (DatabaseAuditSpecification)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(DatabaseAuditSpecification); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new DatabaseAuditSpecification(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(DatabaseAuditSpecification databaseAuditSpecification) - { - AddImpl(databaseAuditSpecification); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class DatabaseAuditSpecificationCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/DatabaseCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/DatabaseCollection.cs index f71f24cc..69a33733 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/DatabaseCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/DatabaseCollection.cs @@ -1,240 +1,30 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - #if MICROSOFTDATA using Microsoft.Data.SqlClient; #else using System.Data.SqlClient; #endif - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class DatabaseCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal DatabaseCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Server Parent - { - get - { - return this.ParentInstance as Server; - } - } - - - public Database this[Int32 index] - { - get - { - return GetObjectByIndex(index) as Database; - } - } - - - // returns wrapper class - public Database this[string name] + public sealed partial class DatabaseCollection : SimpleObjectCollectionBase + { + internal override SqlSmoObject GetObjectByName(string name) { - get + try { - - - try - { - - - - return GetObjectByName(name) as Database; - - - - } - catch (Microsoft.SqlServer.Management.Common.ConnectionFailureException cfe) when (cfe.InnerException is SqlException sqlEx && sqlEx.Number == 4060) - { - Microsoft.SqlServer.Management.Diagnostics.TraceHelper.LogExCatch(cfe); - // this exception occurs if the user doesn't have access to - // the database with the input name - // in such a case the expected behavior is to return null - return null; - } - - + return base.GetObjectByName(name); + } + catch (Microsoft.SqlServer.Management.Common.ConnectionFailureException cfe) + when (cfe.InnerException is SqlException ex && ex.Number == 4060) + { + Microsoft.SqlServer.Management.Diagnostics.TraceHelper.LogExCatch(cfe); + // this exception occurs if the user doesn't have access to + // the database with the input name + // in such a case the expected behavior is to return null + return null; } } - - - public void CopyTo(Database[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public Database ItemById(int id) - { - return (Database)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(Database); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new Database(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(Database database) - { - AddImpl(database); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/DatabaseDdlTriggerCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/DatabaseDdlTriggerCollection.cs index 4306297b..ecc082cb 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/DatabaseDdlTriggerCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/DatabaseDdlTriggerCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class DatabaseDdlTriggerCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal DatabaseDdlTriggerCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public DatabaseDdlTrigger this[Int32 index] - { - get - { - return GetObjectByIndex(index) as DatabaseDdlTrigger; - } - } - - - // returns wrapper class - public DatabaseDdlTrigger this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as DatabaseDdlTrigger; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(DatabaseDdlTrigger[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public DatabaseDdlTrigger ItemById(int id) - { - return (DatabaseDdlTrigger)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(DatabaseDdlTrigger); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new DatabaseDdlTrigger(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(DatabaseDdlTrigger databaseDdlTrigger) - { - AddImpl(databaseDdlTrigger); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class DatabaseDdlTriggerCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/DatabaseReplicaStateCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/DatabaseReplicaStateCollection.cs index efc92f8e..be2f8dea 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/DatabaseReplicaStateCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/DatabaseReplicaStateCollection.cs @@ -2,64 +2,21 @@ // Licensed under the MIT license. using System; -using System.Collections; -#pragma warning disable 1590, 1591, 1592, 1573, 1571, 1570, 1572, 1587 - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - /// - /// Strongly typed collection of MAPPED_TYPE objects - /// Supports indexing objects by their AvailabilityReplicaServerName and AvailabilityDatabaseName properties + /// Collection of DatabaseReplicaState objects associated with an AvailabilityGroup /// public sealed class DatabaseReplicaStateCollection : DatabaseReplicaStateCollectionBase { - internal DatabaseReplicaStateCollection(SqlSmoObject parentInstance) : base(parentInstance) + internal DatabaseReplicaStateCollection(SqlSmoObject parentInstance) : base(parentInstance) { } - public AvailabilityGroup Parent - { - get - { - return this.ParentInstance as AvailabilityGroup; - } - } - + public AvailabilityGroup Parent => ParentInstance as AvailabilityGroup; - public DatabaseReplicaState this[Int32 index] - { - get - { - return GetObjectByIndex(index) as DatabaseReplicaState; - } - } public DatabaseReplicaState this[string replicaName, string name] { @@ -78,59 +35,37 @@ public DatabaseReplicaState this[Int32 index] } } - public void CopyTo(DatabaseReplicaState[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - public DatabaseReplicaState ItemById(int id) + public void Remove(string replicaName, string name) { - return (DatabaseReplicaState)GetItemById(id); - } - + if (name == null) + { + throw new ArgumentNullException("name cannot be null"); + } + else if (replicaName == null) + { + throw new ArgumentNullException("replica name cannot be null"); + } - protected override Type GetCollectionElementType() - { - return typeof(DatabaseReplicaState); + Remove(new DatabaseReplicaStateObjectKey(replicaName, name)); } - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) + public void Remove(DatabaseReplicaState DatabaseReplicaState) { - return new DatabaseReplicaState(this, key, state); - } + if (null == DatabaseReplicaState) + throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException("DatabaseReplicaState")); + RemoveObj(DatabaseReplicaState, new DatabaseReplicaStateObjectKey(DatabaseReplicaState.AvailabilityReplicaServerName, DatabaseReplicaState.AvailabilityDatabaseName)); + } - public void Remove(string replicaName, string name) - { - if (name == null) - { - throw new ArgumentNullException("name cannot be null"); - } - else if (replicaName == null) - { - throw new ArgumentNullException("replica name cannot be null"); - } - - this.Remove(new DatabaseReplicaStateObjectKey(replicaName, name)); - } - - public void Remove(DatabaseReplicaState DatabaseReplicaState) - { - if( null == DatabaseReplicaState ) - throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException("DatabaseReplicaState")); - - RemoveObj(DatabaseReplicaState, new DatabaseReplicaStateObjectKey(DatabaseReplicaState.AvailabilityReplicaServerName, DatabaseReplicaState.AvailabilityDatabaseName)); - } - + public void Add(DatabaseReplicaState DatabaseReplicaState) + { + if (null == DatabaseReplicaState) + throw new FailedOperationException(ExceptionTemplates.AddCollection, this, new ArgumentNullException("DatabaseReplicaState")); - public void Add(DatabaseReplicaState DatabaseReplicaState) - { - if( null == DatabaseReplicaState ) - throw new FailedOperationException(ExceptionTemplates.AddCollection, this, new ArgumentNullException("DatabaseReplicaState")); - - AddImpl(DatabaseReplicaState); - } + AddImpl(DatabaseReplicaState); + } } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/DatabaseRoleCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/DatabaseRoleCollection.cs index d6980f31..aa6624aa 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/DatabaseRoleCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/DatabaseRoleCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class DatabaseRoleCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal DatabaseRoleCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public DatabaseRole this[Int32 index] - { - get - { - return GetObjectByIndex(index) as DatabaseRole; - } - } - - - // returns wrapper class - public DatabaseRole this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as DatabaseRole; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(DatabaseRole[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public DatabaseRole ItemById(int id) - { - return (DatabaseRole)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(DatabaseRole); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new DatabaseRole(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(DatabaseRole databaseRole) - { - AddImpl(databaseRole); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class DatabaseRoleCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/DatabaseScopedConfigurationCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/DatabaseScopedConfigurationCollection.cs index 2ce125ad..07f0932f 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/DatabaseScopedConfigurationCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/DatabaseScopedConfigurationCollection.cs @@ -1,113 +1,47 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - - using System; -using System.Collections; - -using Microsoft.SqlServer.Management.Sdk.Sfc; -namespace Microsoft.SqlServer.Management.Smo +namespace Microsoft.SqlServer.Management.Smo { - - /// - /// DatabaseScopedConfigurationCollection - /// - public sealed class DatabaseScopedConfigurationCollection : SimpleObjectCollectionBase + public sealed partial class DatabaseScopedConfigurationCollection : SimpleObjectCollectionBase { - internal DatabaseScopedConfigurationCollection(SqlSmoObject parentInstance) - : base(parentInstance) - { - } - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - public DatabaseScopedConfiguration this[Int32 index] - { - get - { - return GetObjectByIndex(index) as DatabaseScopedConfiguration; - } - } - - public DatabaseScopedConfiguration this[string name] + /// + ///Returns a DatabaseScopedConfiguration identified by the given name. + ///If the parent object is in Creating state and the configuration object is not in the collection, + ///and new configuration with the given name and empty value will be added to the collection and returned. + ///If the parent object is not in Creating state and the named configuration is not found, + ///a SmoException will be thrown. + /// + internal override SqlSmoObject GetObjectByName(string name) { - get + if (!this.ContainsKey(new SimpleObjectKey(name))) { - if (!this.Contains(name)) + // The unknown configuration would be saved first on the offline scenario. + if (Parent.State == SqlSmoState.Creating) { - // The unknown configuration would be saved first on the offline scenario. - if (Parent.State == SqlSmoState.Creating) + DatabaseScopedConfiguration newConfig = new DatabaseScopedConfiguration(Parent, name) { - DatabaseScopedConfiguration newConfig = new DatabaseScopedConfiguration(Parent, name); - newConfig.Value = string.Empty; - newConfig.ValueForSecondary = string.Empty; - this.Add(newConfig); - } - else + Value = string.Empty, + ValueForSecondary = string.Empty + }; + InternalStorage.Add(newConfig.key, newConfig); + } + else + { + if (Parent.State == SqlSmoState.Existing) { - if (Parent.State == SqlSmoState.Existing) - { - this.Refresh(); - } + this.Refresh(); + } - if (!this.Contains(name)) - { - throw new SmoException(ExceptionTemplates.UnsupportedDatabaseScopedConfiguration(name)); - } + if (!this.Contains(name)) + { + throw new SmoException(ExceptionTemplates.UnsupportedDatabaseScopedConfiguration(name)); } } - - return GetObjectByName(name) as DatabaseScopedConfiguration; - } - } - - public void CopyTo(DatabaseScopedConfiguration[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - public DatabaseScopedConfiguration ItemById(int id) - { - return (DatabaseScopedConfiguration)GetItemById(id); - } - - protected override Type GetCollectionElementType() - { - return typeof(DatabaseScopedConfiguration); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new DatabaseScopedConfiguration(this, key, state); - } - - public void Add(DatabaseScopedConfiguration databaseScopedConfiguration) - { - AddImpl(databaseScopedConfiguration); - } - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - if (null == name || name.Length == 0) - { - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); } - return new SimpleObjectKey(name); + return base.GetObjectByName(name) as DatabaseScopedConfiguration; } /// @@ -115,7 +49,7 @@ internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) /// protected override void InitInnerCollection() { - InternalStorage = new SmoSortedList(new DatabaseScopedConfigurationObjectComparer()); + InternalStorage = new SmoSortedList(new DatabaseScopedConfigurationObjectComparer()); } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/DatabaseScopedCredentialCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/DatabaseScopedCredentialCollection.cs index 104232f5..dcfdc4aa 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/DatabaseScopedCredentialCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/DatabaseScopedCredentialCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class DatabaseScopedCredentialCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal DatabaseScopedCredentialCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public DatabaseScopedCredential this[Int32 index] - { - get - { - return GetObjectByIndex(index) as DatabaseScopedCredential; - } - } - - - // returns wrapper class - public DatabaseScopedCredential this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as DatabaseScopedCredential; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(DatabaseScopedCredential[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public DatabaseScopedCredential ItemById(int id) - { - return (DatabaseScopedCredential)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(DatabaseScopedCredential); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new DatabaseScopedCredential(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(DatabaseScopedCredential databaseScopedCredential) - { - AddImpl(databaseScopedCredential); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class DatabaseScopedCredentialCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/DefaultCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/DefaultCollection.cs index 61ad78b0..68ba4685 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/DefaultCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/DefaultCollection.cs @@ -1,170 +1,12 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590, 1591, 1592, 1573, 1571, 1570, 1572, 1587 - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - /// - /// Strongly typed collection of MAPPED_TYPE objects - /// Supports indexing objects by their Name and Schema properties - /// - public sealed class DefaultCollection : SchemaCollectionBase - { - - internal DefaultCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public Default this[Int32 index] - { - get - { - return GetObjectByIndex(index) as Default; - } - } - - public Default this[string name] - { - get - { - if (name == null) - { - throw new ArgumentNullException("name cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, GetDefaultSchema())) as Default; - } - } - - public Default this[string name, string schema] - { - get - { - if (name == null) - { - throw new ArgumentNullException("name cannot be null"); - } - else if (schema == null) - { - throw new ArgumentNullException("schema cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, schema)) as Default; - } - } - - public void CopyTo(Default[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public Default ItemById(int id) - { - return (Default)GetItemById(id); - } - - - protected override Type GetCollectionElementType() - { - return typeof(Default); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new Default(this, key, state); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - public void Add(Default def) - { - if( null == def ) - throw new FailedOperationException(ExceptionTemplates.AddCollection, this, new ArgumentNullException("def")); - - AddImpl(def); - } - - internal SqlSmoObject GetObjectByName(string name) - { - if (name == null) - { - throw new ArgumentNullException("schema cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, GetDefaultSchema())); - } - - } + public sealed partial class DefaultCollection : SchemaCollectionBase + { + + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/EdgeConstraintClauseCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/EdgeConstraintClauseCollection.cs index 6558fae7..8aa11ba3 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/EdgeConstraintClauseCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/EdgeConstraintClauseCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class EdgeConstraintClauseCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal EdgeConstraintClauseCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public SqlSmoObject Parent - { - get - { - return this.ParentInstance as SqlSmoObject; - } - } - - - public EdgeConstraintClause this[Int32 index] - { - get - { - return GetObjectByIndex(index) as EdgeConstraintClause; - } - } - - - // returns wrapper class - public EdgeConstraintClause this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as EdgeConstraintClause; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(EdgeConstraintClause[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public EdgeConstraintClause ItemById(int id) - { - return (EdgeConstraintClause)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(EdgeConstraintClause); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new EdgeConstraintClause(this, key, state); - } - - - - - public void Remove(EdgeConstraintClause edgeconstraintclause) - { - if( null == edgeconstraintclause ) - throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException("edgeconstraintclause")); - - RemoveObj(edgeconstraintclause, new SimpleObjectKey(edgeconstraintclause.Name)); - } - - public void Remove(string name) - { - this.Remove(new SimpleObjectKey(name)); - } - - - - public void Add(EdgeConstraintClause edgeconstraintclause) - { - AddImpl(edgeconstraintclause); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class EdgeConstraintClauseCollection : RemovableCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/EdgeConstraintCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/EdgeConstraintCollection.cs index 881d5dc8..60599b06 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/EdgeConstraintCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/EdgeConstraintCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class EdgeConstraintCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal EdgeConstraintCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public SqlSmoObject Parent - { - get - { - return this.ParentInstance as SqlSmoObject; - } - } - - - public EdgeConstraint this[Int32 index] - { - get - { - return GetObjectByIndex(index) as EdgeConstraint; - } - } - - - // returns wrapper class - public EdgeConstraint this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as EdgeConstraint; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(EdgeConstraint[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public EdgeConstraint ItemById(int id) - { - return (EdgeConstraint)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(EdgeConstraint); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new EdgeConstraint(this, key, state); - } - - - - - public void Remove(EdgeConstraint edgeconstraint) - { - if( null == edgeconstraint ) - throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException("edgeconstraint")); - - RemoveObj(edgeconstraint, new SimpleObjectKey(edgeconstraint.Name)); - } - - public void Remove(string name) - { - this.Remove(new SimpleObjectKey(name)); - } - - - - public void Add(EdgeConstraint edgeconstraint) - { - AddImpl(edgeconstraint); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class EdgeConstraintCollection : RemovableCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/EndpointCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/EndpointCollection.cs index d05367fa..613a354d 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/EndpointCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/EndpointCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed partial class EndpointCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal EndpointCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Server Parent - { - get - { - return this.ParentInstance as Server; - } - } - - - public Endpoint this[Int32 index] - { - get - { - return GetObjectByIndex(index) as Endpoint; - } - } - - - // returns wrapper class - public Endpoint this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as Endpoint; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(Endpoint[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public Endpoint ItemById(int id) - { - return (Endpoint)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(Endpoint); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new Endpoint(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(Endpoint endpoint) - { - AddImpl(endpoint); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class EndpointCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/ExtendedPropertyCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/ExtendedPropertyCollection.cs index b4e3c7a6..d4d7fc66 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/ExtendedPropertyCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/ExtendedPropertyCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class ExtendedPropertyCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal ExtendedPropertyCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public SqlSmoObject Parent - { - get - { - return this.ParentInstance as SqlSmoObject; - } - } - - - public ExtendedProperty this[Int32 index] - { - get - { - return GetObjectByIndex(index) as ExtendedProperty; - } - } - - - // returns wrapper class - public ExtendedProperty this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as ExtendedProperty; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(ExtendedProperty[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(ExtendedProperty); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new ExtendedProperty(this, key, state); - } - - - - - public void Remove(ExtendedProperty extendedProperty) - { - if( null == extendedProperty ) - throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException("extendedProperty")); - - RemoveObj(extendedProperty, new SimpleObjectKey(extendedProperty.Name)); - } - - public void Remove(string name) - { - this.Remove(new SimpleObjectKey(name)); - } - - - - public void Add(ExtendedProperty extendedProperty) - { - AddImpl(extendedProperty); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class ExtendedPropertyCollection : RemovableCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/ExtendedStoredProcedureCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/ExtendedStoredProcedureCollection.cs index 677d566e..d0b50fae 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/ExtendedStoredProcedureCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/ExtendedStoredProcedureCollection.cs @@ -1,170 +1,10 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590, 1591, 1592, 1573, 1571, 1570, 1572, 1587 - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - /// - /// Strongly typed collection of MAPPED_TYPE objects - /// Supports indexing objects by their Name and Schema properties - /// - public sealed class ExtendedStoredProcedureCollection : SchemaCollectionBase - { - - internal ExtendedStoredProcedureCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public ExtendedStoredProcedure this[Int32 index] - { - get - { - return GetObjectByIndex(index) as ExtendedStoredProcedure; - } - } - - public ExtendedStoredProcedure this[string name] - { - get - { - if (name == null) - { - throw new ArgumentNullException("name cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, GetDefaultSchema())) as ExtendedStoredProcedure; - } - } - - public ExtendedStoredProcedure this[string name, string schema] - { - get - { - if (name == null) - { - throw new ArgumentNullException("name cannot be null"); - } - else if (schema == null) - { - throw new ArgumentNullException("schema cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, schema)) as ExtendedStoredProcedure; - } - } - - public void CopyTo(ExtendedStoredProcedure[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public ExtendedStoredProcedure ItemById(int id) - { - return (ExtendedStoredProcedure)GetItemById(id); - } - - - protected override Type GetCollectionElementType() - { - return typeof(ExtendedStoredProcedure); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new ExtendedStoredProcedure(this, key, state); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - public void Add(ExtendedStoredProcedure extendedStoredProcedure) - { - if( null == extendedStoredProcedure ) - throw new FailedOperationException(ExceptionTemplates.AddCollection, this, new ArgumentNullException("extendedStoredProcedure")); - - AddImpl(extendedStoredProcedure); - } - - internal SqlSmoObject GetObjectByName(string name) - { - if (name == null) - { - throw new ArgumentNullException("schema cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, GetDefaultSchema())); - } - - } + public sealed partial class ExtendedStoredProcedureCollection : SchemaCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/ExternalDataSourceCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/ExternalDataSourceCollection.cs index dbedb268..d7e3c395 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/ExternalDataSourceCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/ExternalDataSourceCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class ExternalDataSourceCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal ExternalDataSourceCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public ExternalDataSource this[Int32 index] - { - get - { - return GetObjectByIndex(index) as ExternalDataSource; - } - } - - - // returns wrapper class - public ExternalDataSource this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as ExternalDataSource; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(ExternalDataSource[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public ExternalDataSource ItemById(int id) - { - return (ExternalDataSource)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(ExternalDataSource); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new ExternalDataSource(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(ExternalDataSource externalDataSource) - { - AddImpl(externalDataSource); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class ExternalDataSourceCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/ExternalFileFormatCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/ExternalFileFormatCollection.cs index 3067b221..8651dbba 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/ExternalFileFormatCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/ExternalFileFormatCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class ExternalFileFormatCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal ExternalFileFormatCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public ExternalFileFormat this[Int32 index] - { - get - { - return GetObjectByIndex(index) as ExternalFileFormat; - } - } - - - // returns wrapper class - public ExternalFileFormat this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as ExternalFileFormat; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(ExternalFileFormat[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public ExternalFileFormat ItemById(int id) - { - return (ExternalFileFormat)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(ExternalFileFormat); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new ExternalFileFormat(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(ExternalFileFormat externalFileFormat) - { - AddImpl(externalFileFormat); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class ExternalFileFormatCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/ExternalLanguageCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/ExternalLanguageCollection.cs index 9243c5a3..4733392a 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/ExternalLanguageCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/ExternalLanguageCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class ExternalLanguageCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal ExternalLanguageCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public ExternalLanguage this[Int32 index] - { - get - { - return GetObjectByIndex(index) as ExternalLanguage; - } - } - - - // returns wrapper class - public ExternalLanguage this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as ExternalLanguage; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(ExternalLanguage[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public ExternalLanguage ItemById(int id) - { - return (ExternalLanguage)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(ExternalLanguage); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new ExternalLanguage(this, key, state); - } - - - - - public void Remove(ExternalLanguage externalLanguage) - { - if( null == externalLanguage ) - throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException("externalLanguage")); - - RemoveObj(externalLanguage, new SimpleObjectKey(externalLanguage.Name)); - } - - public void Remove(string name) - { - this.Remove(new SimpleObjectKey(name)); - } - - - - public void Add(ExternalLanguage externalLanguage) - { - AddImpl(externalLanguage); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class ExternalLanguageCollection : RemovableCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/ExternalLanguageFileCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/ExternalLanguageFileCollection.cs index e56e7137..6fa421ed 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/ExternalLanguageFileCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/ExternalLanguageFileCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class ExternalLanguageFileCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal ExternalLanguageFileCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public ExternalLanguage Parent - { - get - { - return this.ParentInstance as ExternalLanguage; - } - } - - - public ExternalLanguageFile this[Int32 index] - { - get - { - return GetObjectByIndex(index) as ExternalLanguageFile; - } - } - - - // returns wrapper class - public ExternalLanguageFile this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as ExternalLanguageFile; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(ExternalLanguageFile[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public ExternalLanguageFile ItemById(int id) - { - return (ExternalLanguageFile)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(ExternalLanguageFile); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new ExternalLanguageFile(this, key, state); - } - - - - - public void Remove(ExternalLanguageFile externalLanguageFile) - { - if( null == externalLanguageFile ) - throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException("externalLanguageFile")); - - RemoveObj(externalLanguageFile, new SimpleObjectKey(externalLanguageFile.Name)); - } - - public void Remove(string name) - { - this.Remove(new SimpleObjectKey(name)); - } - - - - public void Add(ExternalLanguageFile externalLanguageFile) - { - AddImpl(externalLanguageFile); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class ExternalLanguageFileCollection : RemovableCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/ExternalLibraryCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/ExternalLibraryCollection.cs index e5a6467a..b484d553 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/ExternalLibraryCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/ExternalLibraryCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class ExternalLibraryCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal ExternalLibraryCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public ExternalLibrary this[Int32 index] - { - get - { - return GetObjectByIndex(index) as ExternalLibrary; - } - } - - - // returns wrapper class - public ExternalLibrary this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as ExternalLibrary; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(ExternalLibrary[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public ExternalLibrary ItemById(int id) - { - return (ExternalLibrary)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(ExternalLibrary); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new ExternalLibrary(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(ExternalLibrary externalLibrary) - { - AddImpl(externalLibrary); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class ExternalLibraryCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/ExternalResourcePoolCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/ExternalResourcePoolCollection.cs index cc34ab89..1f716166 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/ExternalResourcePoolCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/ExternalResourcePoolCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class ExternalResourcePoolCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal ExternalResourcePoolCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public ResourceGovernor Parent - { - get - { - return this.ParentInstance as ResourceGovernor; - } - } - - - public ExternalResourcePool this[Int32 index] - { - get - { - return GetObjectByIndex(index) as ExternalResourcePool; - } - } - - - // returns wrapper class - public ExternalResourcePool this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as ExternalResourcePool; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(ExternalResourcePool[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public ExternalResourcePool ItemById(int id) - { - return (ExternalResourcePool)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(ExternalResourcePool); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new ExternalResourcePool(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(ExternalResourcePool externalResourcePool) - { - AddImpl(externalResourcePool); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class ExternalResourcePoolCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/ExternalStreamCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/ExternalStreamCollection.cs index 7ce3a78f..7830e44e 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/ExternalStreamCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/ExternalStreamCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class ExternalStreamCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal ExternalStreamCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public ExternalStream this[Int32 index] - { - get - { - return GetObjectByIndex(index) as ExternalStream; - } - } - - - // returns wrapper class - public ExternalStream this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as ExternalStream; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(ExternalStream[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public ExternalStream ItemById(int id) - { - return (ExternalStream)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(ExternalStream); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new ExternalStream(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(ExternalStream externalStream) - { - AddImpl(externalStream); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class ExternalStreamCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/ExternalStreamingJobCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/ExternalStreamingJobCollection.cs index 28de97e9..15a98f12 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/ExternalStreamingJobCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/ExternalStreamingJobCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class ExternalStreamingJobCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal ExternalStreamingJobCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public ExternalStreamingJob this[Int32 index] - { - get - { - return GetObjectByIndex(index) as ExternalStreamingJob; - } - } - - - // returns wrapper class - public ExternalStreamingJob this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as ExternalStreamingJob; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(ExternalStreamingJob[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public ExternalStreamingJob ItemById(int id) - { - return (ExternalStreamingJob)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(ExternalStreamingJob); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new ExternalStreamingJob(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(ExternalStreamingJob externalStreamingJob) - { - AddImpl(externalStreamingJob); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class ExternalStreamingJobCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/FileGroupCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/FileGroupCollection.cs index 13a2e7f1..6f84f33b 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/FileGroupCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/FileGroupCollection.cs @@ -1,249 +1,12 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class FileGroupCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal FileGroupCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public FileGroup this[Int32 index] - { - get - { - return GetObjectByIndex(index) as FileGroup; - } - } - - - // returns wrapper class - public FileGroup this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as FileGroup; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(FileGroup[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public FileGroup ItemById(int id) - { - return (FileGroup)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(FileGroup); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new FileGroup(this, key, state); - } - - - - - public void Remove(FileGroup fileGroup) - { - if( null == fileGroup ) - throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException("fileGroup")); - - RemoveObj(fileGroup, new SimpleObjectKey(fileGroup.Name)); - } - - public void Remove(string name) - { - this.Remove(new SimpleObjectKey(name)); - } - - - - public void Add(FileGroup fileGroup) - { - AddImpl(fileGroup); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + /// + /// A collection of FileGroup objects associated with a Database object. + /// + public sealed partial class FileGroupCollection : RemovableCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/ForeignKeyCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/ForeignKeyCollection.cs index 9bcc13f8..d9dfe0d4 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/ForeignKeyCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/ForeignKeyCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class ForeignKeyCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal ForeignKeyCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Table Parent - { - get - { - return this.ParentInstance as Table; - } - } - - - public ForeignKey this[Int32 index] - { - get - { - return GetObjectByIndex(index) as ForeignKey; - } - } - - - // returns wrapper class - public ForeignKey this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as ForeignKey; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(ForeignKey[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public ForeignKey ItemById(int id) - { - return (ForeignKey)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(ForeignKey); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new ForeignKey(this, key, state); - } - - - - - public void Remove(ForeignKey foreignKey) - { - if( null == foreignKey ) - throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException("foreignKey")); - - RemoveObj(foreignKey, new SimpleObjectKey(foreignKey.Name)); - } - - public void Remove(string name) - { - this.Remove(new SimpleObjectKey(name)); - } - - - - public void Add(ForeignKey foreignKey) - { - AddImpl(foreignKey); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class ForeignKeyCollection : RemovableCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/ForeignKeyColumnCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/ForeignKeyColumnCollection.cs index 84c6fa9c..8765d073 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/ForeignKeyColumnCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/ForeignKeyColumnCollection.cs @@ -1,148 +1,10 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590, 1591, 1592, 1573, 1571, 1570, 1572, 1587 - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class ForeignKeyColumnCollection : ParameterCollectionBase - { - internal ForeignKeyColumnCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - public ForeignKey Parent - { - get - { - return this.ParentInstance as ForeignKey; - } - } - - - public ForeignKeyColumn this[Int32 index] - { - get - { - return GetObjectByIndex(index) as ForeignKeyColumn; - } - } - - public void CopyTo(ForeignKeyColumn[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - // returns wrapper class - public ForeignKeyColumn this[string name] - { - get - { - return GetObjectByKey( new SimpleObjectKey(name)) as ForeignKeyColumn; - } - } - - - protected override Type GetCollectionElementType() - { - return typeof(ForeignKeyColumn); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new ForeignKeyColumn(this, key, state); - } - - - public void Add(ForeignKeyColumn foreignKeyColumn) - { - AddImpl(foreignKeyColumn); - } - - public void Add(ForeignKeyColumn foreignKeyColumn, string insertAtColumnName) - { - AddImpl(foreignKeyColumn, new SimpleObjectKey(insertAtColumnName)); - } - - public void Add(ForeignKeyColumn foreignKeyColumn, int insertAtPosition) - { - AddImpl(foreignKeyColumn, insertAtPosition); - } - - - public void Remove(ForeignKeyColumn foreignKeyColumn) - { - if( null == foreignKeyColumn ) - throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException("foreignKeyColumn")); - - RemoveObj(foreignKeyColumn, foreignKeyColumn.key); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - public ForeignKeyColumn ItemById(int id) - { - return (ForeignKeyColumn)GetItemById(id); - } - - - } + public sealed partial class ForeignKeyColumnCollection : ParameterCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/FullTextCatalogCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/FullTextCatalogCollection.cs index 231662d5..b89852ed 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/FullTextCatalogCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/FullTextCatalogCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class FullTextCatalogCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal FullTextCatalogCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public FullTextCatalog this[Int32 index] - { - get - { - return GetObjectByIndex(index) as FullTextCatalog; - } - } - - - // returns wrapper class - public FullTextCatalog this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as FullTextCatalog; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(FullTextCatalog[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public FullTextCatalog ItemById(int id) - { - return (FullTextCatalog)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(FullTextCatalog); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new FullTextCatalog(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(FullTextCatalog fullTextCatalog) - { - AddImpl(fullTextCatalog); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class FullTextCatalogCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/FullTextIndexColumnCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/FullTextIndexColumnCollection.cs index f62d70e7..a871d22c 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/FullTextIndexColumnCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/FullTextIndexColumnCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class FullTextIndexColumnCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal FullTextIndexColumnCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public FullTextIndex Parent - { - get - { - return this.ParentInstance as FullTextIndex; - } - } - - - public FullTextIndexColumn this[Int32 index] - { - get - { - return GetObjectByIndex(index) as FullTextIndexColumn; - } - } - - - // returns wrapper class - public FullTextIndexColumn this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as FullTextIndexColumn; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(FullTextIndexColumn[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(FullTextIndexColumn); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new FullTextIndexColumn(this, key, state); - } - - - - - public void Remove(FullTextIndexColumn fullTextIndexColumn) - { - if( null == fullTextIndexColumn ) - throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException("fullTextIndexColumn")); - - RemoveObj(fullTextIndexColumn, new SimpleObjectKey(fullTextIndexColumn.Name)); - } - - public void Remove(string name) - { - this.Remove(new SimpleObjectKey(name)); - } - - - - public void Add(FullTextIndexColumn fullTextIndexColumn) - { - AddImpl(fullTextIndexColumn); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class FullTextIndexColumnCollection : RemovableCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/FullTextStopListCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/FullTextStopListCollection.cs index 42edcd56..780a6051 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/FullTextStopListCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/FullTextStopListCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class FullTextStopListCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal FullTextStopListCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public FullTextStopList this[Int32 index] - { - get - { - return GetObjectByIndex(index) as FullTextStopList; - } - } - - - // returns wrapper class - public FullTextStopList this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as FullTextStopList; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(FullTextStopList[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public FullTextStopList ItemById(int id) - { - return (FullTextStopList)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(FullTextStopList); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new FullTextStopList(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(FullTextStopList fullTextStopList) - { - AddImpl(fullTextStopList); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class FullTextStopListCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/IndexCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/IndexCollection.cs index 15fa5d01..5c77ea49 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/IndexCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/IndexCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class IndexCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal IndexCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public SqlSmoObject Parent - { - get - { - return this.ParentInstance as SqlSmoObject; - } - } - - - public Index this[Int32 index] - { - get - { - return GetObjectByIndex(index) as Index; - } - } - - - // returns wrapper class - public Index this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as Index; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(Index[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public Index ItemById(int id) - { - return (Index)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(Index); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new Index(this, key, state); - } - - - - - public void Remove(Index index) - { - if( null == index ) - throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException("index")); - - RemoveObj(index, new SimpleObjectKey(index.Name)); - } - - public void Remove(string name) - { - this.Remove(new SimpleObjectKey(name)); - } - - - - public void Add(Index index) - { - AddImpl(index); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class IndexCollection : RemovableCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/IndexedColumnCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/IndexedColumnCollection.cs index ce8293f2..86dcb5f5 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/IndexedColumnCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/IndexedColumnCollection.cs @@ -1,148 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590, 1591, 1592, 1573, 1571, 1570, 1572, 1587 - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class IndexedColumnCollection : ParameterCollectionBase - { - internal IndexedColumnCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - public Index Parent - { - get - { - return this.ParentInstance as Index; - } - } - - - public IndexedColumn this[Int32 index] - { - get - { - return GetObjectByIndex(index) as IndexedColumn; - } - } - - public void CopyTo(IndexedColumn[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - // returns wrapper class - public IndexedColumn this[string name] - { - get - { - return GetObjectByKey( new SimpleObjectKey(name)) as IndexedColumn; - } - } - - - protected override Type GetCollectionElementType() - { - return typeof(IndexedColumn); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new IndexedColumn(this, key, state); - } - - - public void Add(IndexedColumn indexedColumn) - { - AddImpl(indexedColumn); - } - - public void Add(IndexedColumn indexedColumn, string insertAtColumnName) - { - AddImpl(indexedColumn, new SimpleObjectKey(insertAtColumnName)); - } - - public void Add(IndexedColumn indexedColumn, int insertAtPosition) - { - AddImpl(indexedColumn, insertAtPosition); - } - - - public void Remove(IndexedColumn indexedColumn) - { - if( null == indexedColumn ) - throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException("indexedColumn")); - - RemoveObj(indexedColumn, indexedColumn.key); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - public IndexedColumn ItemById(int id) - { - return (IndexedColumn)GetItemById(id); - } - - - } + public sealed partial class IndexedColumnCollection : ParameterCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/IndexedJsonPathCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/IndexedJsonPathCollection.cs new file mode 100644 index 00000000..dacb51b0 --- /dev/null +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/IndexedJsonPathCollection.cs @@ -0,0 +1,113 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +using System; +using System.Collections; +using System.Collections.Specialized; +using Microsoft.SqlServer.Management.Sdk.Sfc; + +namespace Microsoft.SqlServer.Management.Smo +{ + /// + /// Represents a collection of indexed JSON paths. + /// + public sealed partial class IndexedJsonPathCollection : SortedListCollectionBase + { + internal IndexedJsonPathCollection(SqlSmoObject parentInstance) : base((Index)parentInstance) + { + } + + /// + /// Returns the parent object + /// + public Index Parent => ParentInstance as Index; + + protected override string UrnSuffix => IndexedJsonPath.UrnSuffix; + + /// + /// Internal Storage + /// + protected override void InitInnerCollection() => InternalStorage = new SmoSortedList(new IndexedJsonPathObjectComparer()); + + /// + /// Contains Method + /// + /// The JSON path string + /// Returns if there is an IndexedJsonPath with the given path. + public bool Contains(string path) => Contains(new IndexedJsonPathObjectKey(path)); + + /// + /// Gets the indexed JSON path for a given path string + /// + /// The JSON path + /// The IndexedJsonPath if found, null otherwise + public IndexedJsonPath GetItemByPath(string path) => InternalStorage[new IndexedJsonPathObjectKey(path)]; + + /// + /// Adds an IndexedJsonPath to the collection. + /// + /// The IndexedJsonPath object to add + public void Add(IndexedJsonPath indexedJsonPath) => InternalStorage.Add(new IndexedJsonPathObjectKey(indexedJsonPath.Path), indexedJsonPath); + + /// + /// Removes an IndexedJsonPath from the collection by path. + /// + /// + public void Remove(IndexedJsonPath indexedJsonPath) => InternalStorage.Remove(new IndexedJsonPathObjectKey(indexedJsonPath.Path)); + + internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) + { + var path = urn.GetAttribute(nameof(IndexedJsonPath.Path)); + return new IndexedJsonPathObjectKey(path); + } + + internal override IndexedJsonPath GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) => new IndexedJsonPath(this, key, state); + } + + internal class IndexedJsonPathObjectComparer : ObjectComparerBase + { + internal IndexedJsonPathObjectComparer() + : base(null) + { + } + + public override int Compare(object obj1, object obj2) => + string.Compare( + ((IndexedJsonPathObjectKey)obj1).Path, + ((IndexedJsonPathObjectKey)obj2).Path, + StringComparison.Ordinal); + } + + internal class IndexedJsonPathObjectKey : ObjectKeyBase + { + public string Path; + + public IndexedJsonPathObjectKey(string path) + : base() + { + Path = path; + } + + static IndexedJsonPathObjectKey() + { + _ = fields.Add(nameof(Path)); + } + + internal static readonly StringCollection fields = new StringCollection(); + + public override string ToString() => string.Format(SmoApplication.DefaultCulture, "{0}", Path); + + /// + /// This is the one used for constructing the Urn + /// + public override string UrnFilter => string.Format(SmoApplication.DefaultCulture, "@Path='{0}'", Urn.EscapeString(Path)); + + public override StringCollection GetFieldNames() => fields; + + public override ObjectKeyBase Clone() => new IndexedJsonPathObjectKey(Path); + + public override bool IsNull => string.IsNullOrEmpty(Path); + + public override ObjectComparerBase GetComparer(IComparer stringComparer) => new IndexedJsonPathObjectComparer(); + } +} diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/IndexedXmlPathCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/IndexedXmlPathCollection.cs index c8e8a134..4ad86676 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/IndexedXmlPathCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/IndexedXmlPathCollection.cs @@ -2,147 +2,10 @@ // Licensed under the MIT license. using System; -using System.Collections; -#pragma warning disable 1590, 1591, 1592, 1573, 1571, 1570, 1572, 1587 - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class IndexedXmlPathCollection : ParameterCollectionBase + public sealed partial class IndexedXmlPathCollection : ParameterCollectionBase { - internal IndexedXmlPathCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - public Index Parent - { - get - { - return this.ParentInstance as Index; - } - } - - - public IndexedXmlPath this[Int32 index] - { - get - { - return GetObjectByIndex(index) as IndexedXmlPath; - } - } - - public void CopyTo(IndexedXmlPath[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - // returns wrapper class - public IndexedXmlPath this[string name] - { - get - { - return GetObjectByKey( new SimpleObjectKey(name)) as IndexedXmlPath; - } - } - - - protected override Type GetCollectionElementType() - { - return typeof(IndexedXmlPath); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new IndexedXmlPath(this, key, state); - } - - - public void Add(IndexedXmlPath indexedXmlPath) - { - AddImpl(indexedXmlPath); - } - - public void Add(IndexedXmlPath indexedXmlPath, string insertAtColumnName) - { - AddImpl(indexedXmlPath, new SimpleObjectKey(insertAtColumnName)); - } - - public void Add(IndexedXmlPath indexedXmlPath, int insertAtPosition) - { - AddImpl(indexedXmlPath, insertAtPosition); - } - - - public void Remove(IndexedXmlPath indexedXmlPath) - { - if( null == indexedXmlPath ) - throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException("indexedXmlPath")); - - RemoveObj(indexedXmlPath, indexedXmlPath.key); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - public IndexedXmlPath ItemById(int id) - { - return (IndexedXmlPath)GetItemById(id); - } - - } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/IndexedXmlPathNamespaceCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/IndexedXmlPathNamespaceCollection.cs index fd122a3b..3d85ff80 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/IndexedXmlPathNamespaceCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/IndexedXmlPathNamespaceCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class IndexedXmlPathNamespaceCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal IndexedXmlPathNamespaceCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Index Parent - { - get - { - return this.ParentInstance as Index; - } - } - - - public IndexedXmlPathNamespace this[Int32 index] - { - get - { - return GetObjectByIndex(index) as IndexedXmlPathNamespace; - } - } - - - // returns wrapper class - public IndexedXmlPathNamespace this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as IndexedXmlPathNamespace; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(IndexedXmlPathNamespace[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(IndexedXmlPathNamespace); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new IndexedXmlPathNamespace(this, key, state); - } - - - - - public void Remove(IndexedXmlPathNamespace indexedXmlPathNamespace) - { - if( null == indexedXmlPathNamespace ) - throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException("indexedXmlPathNamespace")); - - RemoveObj(indexedXmlPathNamespace, new SimpleObjectKey(indexedXmlPathNamespace.Name)); - } - - public void Remove(string name) - { - this.Remove(new SimpleObjectKey(name)); - } - - - - public void Add(IndexedXmlPathNamespace indexedXmlPathNamespace) - { - AddImpl(indexedXmlPathNamespace); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class IndexedXmlPathNamespaceCollection : RemovableCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/JobCategoryCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/JobCategoryCollection.cs index a7ce5465..b9bab321 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/JobCategoryCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/JobCategoryCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo.Agent { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class JobCategoryCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal JobCategoryCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public JobServer Parent - { - get - { - return this.ParentInstance as JobServer; - } - } - - - public JobCategory this[Int32 index] - { - get - { - return GetObjectByIndex(index) as JobCategory; - } - } - - - // returns wrapper class - public JobCategory this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as JobCategory; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(JobCategory[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public JobCategory ItemById(int id) - { - return (JobCategory)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(JobCategory); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new JobCategory(this, key, state); - } - - - - - public void Remove(JobCategory jobCategory) - { - if( null == jobCategory ) - throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException("jobCategory")); - - RemoveObj(jobCategory, new SimpleObjectKey(jobCategory.Name)); - } - - public void Remove(string name) - { - this.Remove(new SimpleObjectKey(name)); - } - - - - public void Add(JobCategory jobCategory) - { - AddImpl(jobCategory); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class JobCategoryCollection : RemovableCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/JobScheduleCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/JobScheduleCollection.cs index 396cefe7..8d904fa6 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/JobScheduleCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/JobScheduleCollection.cs @@ -1,130 +1,42 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590, 1591, 1592, 1573, 1571, 1570, 1572, 1587 - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo.Agent { - - /// - /// Strongly typed collection of MAPPED_TYPE objects - /// Supports indexing objects by their Name and Schema properties - /// - public sealed class JobScheduleCollection : JobScheduleCollectionBase - { - - internal JobScheduleCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - public SqlSmoObject Parent - { - get - { - return this.ParentInstance as SqlSmoObject; - } - } - - - public JobSchedule this[Int32 index] - { - get - { - return GetObjectByIndex(index) as JobSchedule; - } - } - + /// + /// A collection of JobSchedule objects associated with a TParent instance + /// + /// + public sealed class JobScheduleCollection : JobScheduleCollectionBase + where TParent : SqlSmoObject + { + + internal JobScheduleCollection(SqlSmoObject parentInstance) : base((TParent)parentInstance) + { + } + + /// + /// Returns the parent object + /// + public TParent Parent + { + get + { + return ParentInstance as TParent; + } + } + + /// + /// Return the JobSchedule object with the given name, or null if it's not in the collection + /// + /// + /// public JobSchedule this[string name] - { - get - { - return GetObjectByKey(new ScheduleObjectKey(name, GetDefaultID())) as JobSchedule; - } - } - - public void CopyTo(JobSchedule[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - public JobSchedule ItemById(int id) - { - IEnumerator ie = ((IEnumerable)this).GetEnumerator(); - while (ie.MoveNext()) - { - JobSchedule c = (JobSchedule)ie.Current; - - if (c.ID == id) // found object with the right id - return c; - } - return null; - - } - - protected override Type GetCollectionElementType() - { - return typeof(JobSchedule); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new JobSchedule(this, key, state); - } - - - - - - - - - - - - - - - - - - - - - - - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new ScheduleObjectKey(name, GetDefaultID())); - } - - } + { + get + { + return GetObjectByKey(new ScheduleObjectKey(name, GetDefaultID())) as JobSchedule; + } + } + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/JobStepCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/JobStepCollection.cs index d60f3f81..e6f31065 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/JobStepCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/JobStepCollection.cs @@ -1,148 +1,10 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590, 1591, 1592, 1573, 1571, 1570, 1572, 1587 - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo.Agent { - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class JobStepCollection : ParameterCollectionBase - { - internal JobStepCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - public Job Parent - { - get - { - return this.ParentInstance as Job; - } - } - - - public JobStep this[Int32 index] - { - get - { - return GetObjectByIndex(index) as JobStep; - } - } - - public void CopyTo(JobStep[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - // returns wrapper class - public JobStep this[string name] - { - get - { - return GetObjectByKey( new SimpleObjectKey(name)) as JobStep; - } - } - - - protected override Type GetCollectionElementType() - { - return typeof(JobStep); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new JobStep(this, key, state); - } - - - public void Add(JobStep jobStep) - { - AddImpl(jobStep); - } - - public void Add(JobStep jobStep, string insertAtColumnName) - { - AddImpl(jobStep, new SimpleObjectKey(insertAtColumnName)); - } - - public void Add(JobStep jobStep, int insertAtPosition) - { - AddImpl(jobStep, insertAtPosition); - } - - - public void Remove(JobStep jobStep) - { - if( null == jobStep ) - throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException("jobStep")); - - RemoveObj(jobStep, jobStep.key); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - public JobStep ItemById(int id) - { - return (JobStep)GetItemById(id); - } - - - } + public sealed partial class JobStepCollection : ParameterCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/LanguageCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/LanguageCollection.cs index b9d65c19..5c1f3a6d 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/LanguageCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/LanguageCollection.cs @@ -1,249 +1,16 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class LanguageCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal LanguageCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Server Parent - { - get - { - return this.ParentInstance as Server; - } - } - - - public Language this[Int32 index] - { - get - { - return GetObjectByIndex(index) as Language; - } - } - - - // returns wrapper class - public Language this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as Language; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(Language[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - - - - - - - - public Language ItemById(int id) - { - return (Language)GetItemById(id, "LocaleID"); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(Language); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new Language(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(Language language) - { - AddImpl(language); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class LanguageCollection : SimpleObjectCollectionBase + { + + /// + /// Overrides ItemById to use the LocaleID property as the key. + /// + /// + /// + public override Language ItemById(int lcid) => GetItemById(lcid, nameof(Language.LocaleID)); + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/LinkedServerCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/LinkedServerCollection.cs index cad54cdd..676990c8 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/LinkedServerCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/LinkedServerCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class LinkedServerCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal LinkedServerCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Server Parent - { - get - { - return this.ParentInstance as Server; - } - } - - - public LinkedServer this[Int32 index] - { - get - { - return GetObjectByIndex(index) as LinkedServer; - } - } - - - // returns wrapper class - public LinkedServer this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as LinkedServer; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(LinkedServer[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public LinkedServer ItemById(int id) - { - return (LinkedServer)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(LinkedServer); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new LinkedServer(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(LinkedServer linkedServer) - { - AddImpl(linkedServer); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class LinkedServerCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/LinkedServerLoginCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/LinkedServerLoginCollection.cs index 29cea47a..c1b824d3 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/LinkedServerLoginCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/LinkedServerLoginCollection.cs @@ -1,249 +1,12 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class LinkedServerLoginCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal LinkedServerLoginCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public LinkedServer Parent - { - get - { - return this.ParentInstance as LinkedServer; - } - } - - - public LinkedServerLogin this[Int32 index] - { - get - { - return GetObjectByIndex(index) as LinkedServerLogin; - } - } - - - // returns wrapper class - public LinkedServerLogin this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as LinkedServerLogin; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(LinkedServerLogin[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(LinkedServerLogin); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new LinkedServerLogin(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(LinkedServerLogin linkedServerLogin) - { - AddImpl(linkedServerLogin); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - if( null == name) - - - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class LinkedServerLoginCollection : SimpleObjectCollectionBase + { + internal override bool CanHaveEmptyName(Urn urn) => true; + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/LogFileCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/LogFileCollection.cs index 836dcc7e..0babb5e9 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/LogFileCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/LogFileCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class LogFileCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal LogFileCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public LogFile this[Int32 index] - { - get - { - return GetObjectByIndex(index) as LogFile; - } - } - - - // returns wrapper class - public LogFile this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as LogFile; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(LogFile[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public LogFile ItemById(int id) - { - return (LogFile)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(LogFile); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new LogFile(this, key, state); - } - - - - - public void Remove(LogFile logFile) - { - if( null == logFile ) - throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException("logFile")); - - RemoveObj(logFile, new SimpleObjectKey(logFile.Name)); - } - - public void Remove(string name) - { - this.Remove(new SimpleObjectKey(name)); - } - - - - public void Add(LogFile logFile) - { - AddImpl(logFile); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class LogFileCollection : RemovableCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/LoginCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/LoginCollection.cs index 89daca33..dd5e2ab6 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/LoginCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/LoginCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class LoginCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal LoginCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Server Parent - { - get - { - return this.ParentInstance as Server; - } - } - - - public Login this[Int32 index] - { - get - { - return GetObjectByIndex(index) as Login; - } - } - - - // returns wrapper class - public Login this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as Login; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(Login[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public Login ItemById(int id) - { - return (Login)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(Login); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new Login(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(Login login) - { - AddImpl(login); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class LoginCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/MailAccountCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/MailAccountCollection.cs index 904fa469..637cf870 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/MailAccountCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/MailAccountCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo.Mail { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class MailAccountCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal MailAccountCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public SqlMail Parent - { - get - { - return this.ParentInstance as SqlMail; - } - } - - - public MailAccount this[Int32 index] - { - get - { - return GetObjectByIndex(index) as MailAccount; - } - } - - - // returns wrapper class - public MailAccount this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as MailAccount; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(MailAccount[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public MailAccount ItemById(int id) - { - return (MailAccount)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(MailAccount); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new MailAccount(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(MailAccount mailAccount) - { - AddImpl(mailAccount); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class MailAccountCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/MailProfileCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/MailProfileCollection.cs index 6daa7f8d..4efc2912 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/MailProfileCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/MailProfileCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo.Mail { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class MailProfileCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal MailProfileCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public SqlMail Parent - { - get - { - return this.ParentInstance as SqlMail; - } - } - - - public MailProfile this[Int32 index] - { - get - { - return GetObjectByIndex(index) as MailProfile; - } - } - - - // returns wrapper class - public MailProfile this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as MailProfile; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(MailProfile[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public MailProfile ItemById(int id) - { - return (MailProfile)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(MailProfile); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new MailProfile(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(MailProfile mailProfile) - { - AddImpl(mailProfile); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class MailProfileCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/MailServerCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/MailServerCollection.cs index 86d378b9..bce3ab9e 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/MailServerCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/MailServerCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo.Mail { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class MailServerCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal MailServerCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public MailAccount Parent - { - get - { - return this.ParentInstance as MailAccount; - } - } - - - public MailServer this[Int32 index] - { - get - { - return GetObjectByIndex(index) as MailServer; - } - } - - - // returns wrapper class - public MailServer this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as MailServer; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(MailServer[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(MailServer); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new MailServer(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(MailServer mailServer) - { - AddImpl(mailServer); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class MailServerCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/MessageTypeCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/MessageTypeCollection.cs index 8c4c495d..e5b75f97 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/MessageTypeCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/MessageTypeCollection.cs @@ -1,249 +1,25 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo.Broker { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class MessageTypeCollection : SimpleObjectCollectionBase - { - - //has custom string comparer - StringComparer m_comparer; - - //must initialize in constructor - internal MessageTypeCollection(SqlSmoObject parentInstance, StringComparer comparer) : base(parentInstance) - { - m_comparer = comparer; - } - - override internal StringComparer StringComparer - { - get - { - return m_comparer; - } - } - - - - - - - - public ServiceBroker Parent - { - get - { - return this.ParentInstance as ServiceBroker; - } - } - - - public MessageType this[Int32 index] - { - get - { - return GetObjectByIndex(index) as MessageType; - } - } - - - // returns wrapper class - public MessageType this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as MessageType; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(MessageType[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public MessageType ItemById(int id) - { - return (MessageType)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(MessageType); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new MessageType(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(MessageType messageType) - { - AddImpl(messageType); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); + public sealed partial class MessageTypeCollection : SimpleObjectCollectionBase + { + //has custom string comparer + private readonly StringComparer m_comparer; + + //must initialize in constructor + internal MessageTypeCollection(SqlSmoObject parentInstance, StringComparer comparer) : base((ServiceBroker)parentInstance) + { + m_comparer = comparer; } - - - - - - - - - - - - - - - - - - } + internal override StringComparer StringComparer + { + get + { + return m_comparer; + } + } + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/MessageTypeMappingCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/MessageTypeMappingCollection.cs index 9967b540..876d71f0 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/MessageTypeMappingCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/MessageTypeMappingCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo.Broker { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class MessageTypeMappingCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal MessageTypeMappingCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public ServiceContract Parent - { - get - { - return this.ParentInstance as ServiceContract; - } - } - - - public MessageTypeMapping this[Int32 index] - { - get - { - return GetObjectByIndex(index) as MessageTypeMapping; - } - } - - - // returns wrapper class - public MessageTypeMapping this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as MessageTypeMapping; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(MessageTypeMapping[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(MessageTypeMapping); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new MessageTypeMapping(this, key, state); - } - - - - - public void Remove(MessageTypeMapping messageTypeMapping) - { - if( null == messageTypeMapping ) - throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException("messageTypeMapping")); - - RemoveObj(messageTypeMapping, new SimpleObjectKey(messageTypeMapping.Name)); - } - - public void Remove(string name) - { - this.Remove(new SimpleObjectKey(name)); - } - - - - public void Add(MessageTypeMapping messageTypeMapping) - { - AddImpl(messageTypeMapping); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class MessageTypeMappingCollection : RemovableCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/NumberedStoredProcedureCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/NumberedStoredProcedureCollection.cs index a2366cbf..06d8125d 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/NumberedStoredProcedureCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/NumberedStoredProcedureCollection.cs @@ -1,111 +1,35 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590, 1591, 1592, 1573, 1571, 1570, 1572, 1587 - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class NumberedStoredProcedureCollection : - - - - NumberedObjectCollectionBase - - { - - internal NumberedStoredProcedureCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - public StoredProcedure Parent - { - get - { - return this.ParentInstance as StoredProcedure; - } - } - - - - - - - - - - - - - - - - - - - - - - public NumberedStoredProcedure this[Int32 index] - { - get - { - return GetObjectByIndex(index) as NumberedStoredProcedure; - } - } + /// + /// Collection of NumberedStoredProcedure objects associated with a StoredProcedure + /// + public sealed partial class NumberedStoredProcedureCollection : NumberedObjectCollectionBase + { - protected override Type GetCollectionElementType() - { - return typeof(NumberedStoredProcedure); - } + internal NumberedStoredProcedureCollection(SqlSmoObject parentInstance) : base(parentInstance) + { + } - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new NumberedStoredProcedure(this, key, state); - } + /// + /// Returns the parent StoredProcedure + /// + public StoredProcedure Parent => ParentInstance as StoredProcedure; + protected override string UrnSuffix => NumberedStoredProcedure.UrnSuffix; - public NumberedStoredProcedure GetProcedureByNumber(short number) - { - return GetObjectByKey(new NumberedObjectKey(number)) as NumberedStoredProcedure; - } + internal override NumberedStoredProcedure GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) + { + return new NumberedStoredProcedure(this, key, state); + } - public void CopyTo(NumberedStoredProcedure[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - } + public NumberedStoredProcedure GetProcedureByNumber(short number) + { + return GetObjectByKey(new NumberedObjectKey(number)) as NumberedStoredProcedure; + } + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/NumberedStoredProcedureParameterCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/NumberedStoredProcedureParameterCollection.cs index 9e6831f2..1d96bcba 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/NumberedStoredProcedureParameterCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/NumberedStoredProcedureParameterCollection.cs @@ -1,148 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590, 1591, 1592, 1573, 1571, 1570, 1572, 1587 - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class NumberedStoredProcedureParameterCollection : ParameterCollectionBase + public sealed partial class NumberedStoredProcedureParameterCollection : ParameterCollectionBase { - internal NumberedStoredProcedureParameterCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - public NumberedStoredProcedure Parent - { - get - { - return this.ParentInstance as NumberedStoredProcedure; - } - } - - - public NumberedStoredProcedureParameter this[Int32 index] - { - get - { - return GetObjectByIndex(index) as NumberedStoredProcedureParameter; - } - } - - public void CopyTo(NumberedStoredProcedureParameter[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - // returns wrapper class - public NumberedStoredProcedureParameter this[string name] - { - get - { - return GetObjectByKey( new SimpleObjectKey(name)) as NumberedStoredProcedureParameter; - } - } - - - protected override Type GetCollectionElementType() - { - return typeof(NumberedStoredProcedureParameter); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new NumberedStoredProcedureParameter(this, key, state); - } - - - public void Add(NumberedStoredProcedureParameter numberedStoredProcedureParameter) - { - AddImpl(numberedStoredProcedureParameter); - } - - public void Add(NumberedStoredProcedureParameter numberedStoredProcedureParameter, string insertAtColumnName) - { - AddImpl(numberedStoredProcedureParameter, new SimpleObjectKey(insertAtColumnName)); - } - - public void Add(NumberedStoredProcedureParameter numberedStoredProcedureParameter, int insertAtPosition) - { - AddImpl(numberedStoredProcedureParameter, insertAtPosition); - } - - - public void Remove(NumberedStoredProcedureParameter numberedStoredProcedureParameter) - { - if( null == numberedStoredProcedureParameter ) - throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException("numberedStoredProcedureParameter")); - - RemoveObj(numberedStoredProcedureParameter, numberedStoredProcedureParameter.key); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - public NumberedStoredProcedureParameter ItemById(int id) - { - return (NumberedStoredProcedureParameter)GetItemById(id); - } - - } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/OleDbProviderSettingsCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/OleDbProviderSettingsCollection.cs index 5b722a68..f55b02a5 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/OleDbProviderSettingsCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/OleDbProviderSettingsCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public class OleDbProviderSettingsCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal OleDbProviderSettingsCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Settings Parent - { - get - { - return this.ParentInstance as Settings; - } - } - - - public OleDbProviderSettings this[Int32 index] - { - get - { - return GetObjectByIndex(index) as OleDbProviderSettings; - } - } - - - // returns wrapper class - public OleDbProviderSettings this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as OleDbProviderSettings; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(OleDbProviderSettings[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(OleDbProviderSettings); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new OleDbProviderSettings(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(OleDbProviderSettings settings) - { - AddImpl(settings); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class OleDbProviderSettingsCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/OperatorCategoryCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/OperatorCategoryCollection.cs index 7be76c0d..87b91a06 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/OperatorCategoryCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/OperatorCategoryCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo.Agent { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class OperatorCategoryCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal OperatorCategoryCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public JobServer Parent - { - get - { - return this.ParentInstance as JobServer; - } - } - - - public OperatorCategory this[Int32 index] - { - get - { - return GetObjectByIndex(index) as OperatorCategory; - } - } - - - // returns wrapper class - public OperatorCategory this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as OperatorCategory; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(OperatorCategory[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public OperatorCategory ItemById(int id) - { - return (OperatorCategory)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(OperatorCategory); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new OperatorCategory(this, key, state); - } - - - - - public void Remove(OperatorCategory operatorCategory) - { - if( null == operatorCategory ) - throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException("operatorCategory")); - - RemoveObj(operatorCategory, new SimpleObjectKey(operatorCategory.Name)); - } - - public void Remove(string name) - { - this.Remove(new SimpleObjectKey(name)); - } - - - - public void Add(OperatorCategory operatorCategory) - { - AddImpl(operatorCategory); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class OperatorCategoryCollection : RemovableCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/OperatorCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/OperatorCollection.cs index 7ac3c557..cd99cb77 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/OperatorCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/OperatorCollection.cs @@ -1,250 +1,41 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -using System; -using System.Collections; using System.Collections.Specialized; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo.Agent { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class OperatorCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal OperatorCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public JobServer Parent - { - get - { - return this.ParentInstance as JobServer; - } - } - - - public Operator this[Int32 index] - { - get - { - return GetObjectByIndex(index) as Operator; - } - } - - - // returns wrapper class - public Operator this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as Operator; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(Operator[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public Operator ItemById(int id) - { - return (Operator)GetItemById(id); - } - - - - - - - - - - - public StringCollection Script() - { - return this.Script(new ScriptingOptions()); - } - - public StringCollection Script(ScriptingOptions scriptingOptions) - { - if( this.Count <= 0 ) - { - return new StringCollection(); - } - - SqlSmoObject [] scriptList = new SqlSmoObject[this.Count]; - int i = 0; - foreach(SqlSmoObject o in this) - { - scriptList[i++] = o; - } - Scripter scr = new Scripter(scriptList[0].GetServerObject()); - scr.Options = scriptingOptions; - return scr.Script(scriptList); - } - - - protected override Type GetCollectionElementType() - { - return typeof(Operator); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new Operator(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(Operator serverOperator) - { - AddImpl(serverOperator); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); + public sealed partial class OperatorCollection : SimpleObjectCollectionBase + { + + /// + /// Returns a TSQL script for creating the members of the collection, using default scripting options + /// + public StringCollection Script() + { + return Script(new ScriptingOptions()); } + /// + /// Returns a TSQL script for creating the members of the collection, using the provided scripting options + /// + public StringCollection Script(ScriptingOptions scriptingOptions) + { + if( this.Count <= 0 ) + { + return new StringCollection(); + } + + SqlSmoObject [] scriptList = new SqlSmoObject[this.Count]; + int i = 0; + foreach(SqlSmoObject o in this) + { + scriptList[i++] = o; + } + Scripter scr = new Scripter(scriptList[0].GetServerObject()); + scr.Options = scriptingOptions; + return scr.Script(scriptList); + } - - - - - - - - - - - - - - - - - } + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/OrderColumnCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/OrderColumnCollection.cs index 9aca1da5..8c9c963c 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/OrderColumnCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/OrderColumnCollection.cs @@ -1,148 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590, 1591, 1592, 1573, 1571, 1570, 1572, 1587 - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class OrderColumnCollection : ParameterCollectionBase - { - internal OrderColumnCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - public UserDefinedFunction Parent - { - get - { - return this.ParentInstance as UserDefinedFunction; - } - } - - - public OrderColumn this[Int32 index] - { - get - { - return GetObjectByIndex(index) as OrderColumn; - } - } - - public void CopyTo(OrderColumn[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - // returns wrapper class - public OrderColumn this[string name] - { - get - { - return GetObjectByKey( new SimpleObjectKey(name)) as OrderColumn; - } - } - - - protected override Type GetCollectionElementType() - { - return typeof(OrderColumn); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new OrderColumn(this, key, state); - } - - - public void Add(OrderColumn orderColumn) - { - AddImpl(orderColumn); - } - - public void Add(OrderColumn orderColumn, string insertAtColumnName) - { - AddImpl(orderColumn, new SimpleObjectKey(insertAtColumnName)); - } - - public void Add(OrderColumn orderColumn, int insertAtPosition) - { - AddImpl(orderColumn, insertAtPosition); - } - - - public void Remove(OrderColumn orderColumn) - { - if( null == orderColumn ) - throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException("orderColumn")); - - RemoveObj(orderColumn, orderColumn.key); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - public OrderColumn ItemById(int id) - { - return (OrderColumn)GetItemById(id); - } - - - } + public sealed partial class OrderColumnCollection : ParameterCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/PartitionFunctionCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/PartitionFunctionCollection.cs index 11cd6fa8..dbb4390e 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/PartitionFunctionCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/PartitionFunctionCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class PartitionFunctionCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal PartitionFunctionCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public PartitionFunction this[Int32 index] - { - get - { - return GetObjectByIndex(index) as PartitionFunction; - } - } - - - // returns wrapper class - public PartitionFunction this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as PartitionFunction; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(PartitionFunction[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public PartitionFunction ItemById(int id) - { - return (PartitionFunction)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(PartitionFunction); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new PartitionFunction(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(PartitionFunction partitionFunction) - { - AddImpl(partitionFunction); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class PartitionFunctionCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/PartitionFunctionParameterCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/PartitionFunctionParameterCollection.cs index 586d774d..4df1c1ad 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/PartitionFunctionParameterCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/PartitionFunctionParameterCollection.cs @@ -1,148 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590, 1591, 1592, 1573, 1571, 1570, 1572, 1587 - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class PartitionFunctionParameterCollection : ParameterCollectionBase - { - internal PartitionFunctionParameterCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - public PartitionFunction Parent - { - get - { - return this.ParentInstance as PartitionFunction; - } - } - - - public PartitionFunctionParameter this[Int32 index] - { - get - { - return GetObjectByIndex(index) as PartitionFunctionParameter; - } - } - - public void CopyTo(PartitionFunctionParameter[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(PartitionFunctionParameter); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new PartitionFunctionParameter(this, key, state); - } - - - public void Add(PartitionFunctionParameter partitionFunctionParameter) - { - AddImpl(partitionFunctionParameter); - } - - public void Add(PartitionFunctionParameter partitionFunctionParameter, string insertAtColumnName) - { - AddImpl(partitionFunctionParameter, new SimpleObjectKey(insertAtColumnName)); - } - - public void Add(PartitionFunctionParameter partitionFunctionParameter, int insertAtPosition) - { - AddImpl(partitionFunctionParameter, insertAtPosition); - } - - - public void Remove(PartitionFunctionParameter partitionFunctionParameter) - { - if( null == partitionFunctionParameter ) - throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException("partitionFunctionParameter")); - - RemoveObj(partitionFunctionParameter, partitionFunctionParameter.key); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - public PartitionFunctionParameter ItemById(int id) - { - return (PartitionFunctionParameter)GetItemById(id); - } - - - } + public sealed partial class PartitionFunctionParameterCollection : ParameterCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/PartitionSchemeCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/PartitionSchemeCollection.cs index d5d66f0c..a83dfa24 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/PartitionSchemeCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/PartitionSchemeCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class PartitionSchemeCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal PartitionSchemeCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public PartitionScheme this[Int32 index] - { - get - { - return GetObjectByIndex(index) as PartitionScheme; - } - } - - - // returns wrapper class - public PartitionScheme this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as PartitionScheme; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(PartitionScheme[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public PartitionScheme ItemById(int id) - { - return (PartitionScheme)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(PartitionScheme); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new PartitionScheme(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(PartitionScheme partitionScheme) - { - AddImpl(partitionScheme); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class PartitionSchemeCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/PartitionSchemeParameterCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/PartitionSchemeParameterCollection.cs index 86aa4302..f23130c4 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/PartitionSchemeParameterCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/PartitionSchemeParameterCollection.cs @@ -2,147 +2,9 @@ // Licensed under the MIT license. using System; -using System.Collections; -#pragma warning disable 1590, 1591, 1592, 1573, 1571, 1570, 1572, 1587 - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class PartitionSchemeParameterCollection : ParameterCollectionBase - { - internal PartitionSchemeParameterCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - public SqlSmoObject Parent - { - get - { - return this.ParentInstance as SqlSmoObject; - } - } - - - public PartitionSchemeParameter this[Int32 index] - { - get - { - return GetObjectByIndex(index) as PartitionSchemeParameter; - } - } - - public void CopyTo(PartitionSchemeParameter[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - // returns wrapper class - public PartitionSchemeParameter this[string name] - { - get - { - return GetObjectByKey( new SimpleObjectKey(name)) as PartitionSchemeParameter; - } - } - - - protected override Type GetCollectionElementType() - { - return typeof(PartitionSchemeParameter); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new PartitionSchemeParameter(this, key, state); - } - - - public void Add(PartitionSchemeParameter partitionSchemeParameter) - { - AddImpl(partitionSchemeParameter); - } - - public void Add(PartitionSchemeParameter partitionSchemeParameter, string insertAtColumnName) - { - AddImpl(partitionSchemeParameter, new SimpleObjectKey(insertAtColumnName)); - } - - public void Add(PartitionSchemeParameter partitionSchemeParameter, int insertAtPosition) - { - AddImpl(partitionSchemeParameter, insertAtPosition); - } - - - public void Remove(PartitionSchemeParameter partitionSchemeParameter) - { - if( null == partitionSchemeParameter ) - throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException("partitionSchemeParameter")); - - RemoveObj(partitionSchemeParameter, partitionSchemeParameter.key); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - public PartitionSchemeParameter ItemById(int id) - { - return (PartitionSchemeParameter)GetItemById(id); - } - - - } + public sealed partial class PartitionSchemeParameterCollection : ParameterCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/PhysicalPartitionCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/PhysicalPartitionCollection.cs index 070723a0..1a3fbbb2 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/PhysicalPartitionCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/PhysicalPartitionCollection.cs @@ -2,109 +2,31 @@ // Licensed under the MIT license. using System; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed partial class PhysicalPartitionCollection : - - PartitionNumberedObjectCollectionBase - - - + /// + /// Collection of PhysicalPartition objects associated with an index or table + /// + public sealed partial class PhysicalPartitionCollection : PartitionNumberedObjectCollectionBase { internal PhysicalPartitionCollection(SqlSmoObject parentInstance) : base(parentInstance) { } + /// + /// Returns the parent of the collection + /// + public SqlSmoObject Parent => ParentInstance as SqlSmoObject; - public SqlSmoObject Parent - { - get - { - return this.ParentInstance as SqlSmoObject; - } - } - - - - public void Add(PhysicalPartition physicalPartition) - { - InternalStorage.Add(new PartitionNumberedObjectKey((short)physicalPartition.PartitionNumber),physicalPartition); - } - - public void Remove(PhysicalPartition physicalPartition) - { - InternalStorage.Remove(new PartitionNumberedObjectKey((short)physicalPartition.PartitionNumber)); - } - public void Remove(Int32 partitionNumber) - { - InternalStorage.Remove(new PartitionNumberedObjectKey((short)partitionNumber)); - } - - - - - - public PhysicalPartition this[Int32 index] - { - get - { - return GetObjectByIndex(index) as PhysicalPartition; - } - } - - protected override Type GetCollectionElementType() - { - return typeof(PhysicalPartition); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new PhysicalPartition(this, key, state); - } - - - - - - - - - - + protected override string UrnSuffix => PhysicalPartition.UrnSuffix; + public void Add(PhysicalPartition physicalPartition) => InternalStorage.Add(new PartitionNumberedObjectKey((short)physicalPartition.PartitionNumber), physicalPartition); + public void Remove(PhysicalPartition physicalPartition) => InternalStorage.Remove(new PartitionNumberedObjectKey((short)physicalPartition.PartitionNumber)); + public void Remove(int partitionNumber) => InternalStorage.Remove(new PartitionNumberedObjectKey((short)partitionNumber)); - } + internal override PhysicalPartition GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) => new PhysicalPartition(this, key, state); + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/PlanGuideCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/PlanGuideCollection.cs index 67ee33eb..2c7791a9 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/PlanGuideCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/PlanGuideCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class PlanGuideCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal PlanGuideCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public PlanGuide this[Int32 index] - { - get - { - return GetObjectByIndex(index) as PlanGuide; - } - } - - - // returns wrapper class - public PlanGuide this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as PlanGuide; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(PlanGuide[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public PlanGuide ItemById(int id) - { - return (PlanGuide)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(PlanGuide); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new PlanGuide(this, key, state); - } - - - - - public void Remove(PlanGuide planGuide) - { - if( null == planGuide ) - throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException("planGuide")); - - RemoveObj(planGuide, new SimpleObjectKey(planGuide.Name)); - } - - public void Remove(string name) - { - this.Remove(new SimpleObjectKey(name)); - } - - - - public void Add(PlanGuide planGuide) - { - AddImpl(planGuide); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class PlanGuideCollection : RemovableCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/ProxyAccountCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/ProxyAccountCollection.cs index 86360549..8749658e 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/ProxyAccountCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/ProxyAccountCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo.Agent { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class ProxyAccountCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal ProxyAccountCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public JobServer Parent - { - get - { - return this.ParentInstance as JobServer; - } - } - - - public ProxyAccount this[Int32 index] - { - get - { - return GetObjectByIndex(index) as ProxyAccount; - } - } - - - // returns wrapper class - public ProxyAccount this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as ProxyAccount; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(ProxyAccount[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public ProxyAccount ItemById(int id) - { - return (ProxyAccount)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(ProxyAccount); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new ProxyAccount(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(ProxyAccount proxyAccount) - { - AddImpl(proxyAccount); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class ProxyAccountCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/RemoteServiceBindingCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/RemoteServiceBindingCollection.cs index 5ef7579c..cae23ffa 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/RemoteServiceBindingCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/RemoteServiceBindingCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo.Broker { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class RemoteServiceBindingCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal RemoteServiceBindingCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public ServiceBroker Parent - { - get - { - return this.ParentInstance as ServiceBroker; - } - } - - - public RemoteServiceBinding this[Int32 index] - { - get - { - return GetObjectByIndex(index) as RemoteServiceBinding; - } - } - - - // returns wrapper class - public RemoteServiceBinding this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as RemoteServiceBinding; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(RemoteServiceBinding[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public RemoteServiceBinding ItemById(int id) - { - return (RemoteServiceBinding)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(RemoteServiceBinding); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new RemoteServiceBinding(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(RemoteServiceBinding remoteServiceBinding) - { - AddImpl(remoteServiceBinding); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class RemoteServiceBindingCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/ResourcePoolCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/ResourcePoolCollection.cs index 905ea024..7bf5d949 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/ResourcePoolCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/ResourcePoolCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class ResourcePoolCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal ResourcePoolCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public ResourceGovernor Parent - { - get - { - return this.ParentInstance as ResourceGovernor; - } - } - - - public ResourcePool this[Int32 index] - { - get - { - return GetObjectByIndex(index) as ResourcePool; - } - } - - - // returns wrapper class - public ResourcePool this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as ResourcePool; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(ResourcePool[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public ResourcePool ItemById(int id) - { - return (ResourcePool)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(ResourcePool); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new ResourcePool(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(ResourcePool resourcePool) - { - AddImpl(resourcePool); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class ResourcePoolCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/ResumableIndexCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/ResumableIndexCollection.cs index 6d926b41..aca71701 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/ResumableIndexCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/ResumableIndexCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class ResumableIndexCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal ResumableIndexCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public SqlSmoObject Parent - { - get - { - return this.ParentInstance as SqlSmoObject; - } - } - - - public ResumableIndex this[Int32 index] - { - get - { - return GetObjectByIndex(index) as ResumableIndex; - } - } - - - // returns wrapper class - public ResumableIndex this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as ResumableIndex; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(ResumableIndex[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public ResumableIndex ItemById(int id) - { - return (ResumableIndex)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(ResumableIndex); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new ResumableIndex(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(ResumableIndex resumableIndex) - { - AddImpl(resumableIndex); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class ResumableIndexCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/RuleCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/RuleCollection.cs index 079e4b88..4cd90531 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/RuleCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/RuleCollection.cs @@ -1,170 +1,10 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590, 1591, 1592, 1573, 1571, 1570, 1572, 1587 - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - /// - /// Strongly typed collection of MAPPED_TYPE objects - /// Supports indexing objects by their Name and Schema properties - /// - public sealed class RuleCollection : SchemaCollectionBase - { - - internal RuleCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public Rule this[Int32 index] - { - get - { - return GetObjectByIndex(index) as Rule; - } - } - - public Rule this[string name] - { - get - { - if (name == null) - { - throw new ArgumentNullException("name cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, GetDefaultSchema())) as Rule; - } - } - - public Rule this[string name, string schema] - { - get - { - if (name == null) - { - throw new ArgumentNullException("name cannot be null"); - } - else if (schema == null) - { - throw new ArgumentNullException("schema cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, schema)) as Rule; - } - } - - public void CopyTo(Rule[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public Rule ItemById(int id) - { - return (Rule)GetItemById(id); - } - - - protected override Type GetCollectionElementType() - { - return typeof(Rule); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new Rule(this, key, state); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - public void Add(Rule rule) - { - if( null == rule ) - throw new FailedOperationException(ExceptionTemplates.AddCollection, this, new ArgumentNullException("rule")); - - AddImpl(rule); - } - - internal SqlSmoObject GetObjectByName(string name) - { - if (name == null) - { - throw new ArgumentNullException("schema cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, GetDefaultSchema())); - } - - } + public sealed partial class RuleCollection : SchemaCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/SchemaCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/SchemaCollection.cs index 14d7746a..c7bd1b0b 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/SchemaCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/SchemaCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class SchemaCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal SchemaCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public Schema this[Int32 index] - { - get - { - return GetObjectByIndex(index) as Schema; - } - } - - - // returns wrapper class - public Schema this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as Schema; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(Schema[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public Schema ItemById(int id) - { - return (Schema)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(Schema); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new Schema(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(Schema schema) - { - AddImpl(schema); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class SchemaCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/SearchPropertyCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/SearchPropertyCollection.cs index 5e8f10b5..21be3551 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/SearchPropertyCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/SearchPropertyCollection.cs @@ -1,241 +1,17 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -using System; using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class SearchPropertyCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal SearchPropertyCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public SearchPropertyList Parent - { - get - { - return this.ParentInstance as SearchPropertyList; - } - } - - - public SearchProperty this[Int32 index] - { - get - { - return GetObjectByIndex(index) as SearchProperty; - } - } - - - // returns wrapper class - public SearchProperty this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as SearchProperty; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(SearchProperty[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public SearchProperty ItemById(int id) - { - return (SearchProperty)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(SearchProperty); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new SearchProperty(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(SearchProperty searchProperty) - { - AddImpl(searchProperty); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - /// - /// Initializes the storage - /// + public sealed partial class SearchPropertyCollection : SimpleObjectCollectionBase + { protected override void InitInnerCollection() { - InternalStorage = new SmoSortedList(new SimpleObjectCaseSensitiveComparer()); + InternalStorage = new SmoSortedList(new SimpleObjectCaseSensitiveComparer()); } - + internal class SimpleObjectCaseSensitiveComparer : IComparer { int IComparer.Compare(object obj1, object obj2) @@ -243,7 +19,5 @@ int IComparer.Compare(object obj1, object obj2) return string.Compare((obj1 as SimpleObjectKey).Name, (obj2 as SimpleObjectKey).Name, false, SmoApplication.DefaultCulture); } } - - - } + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/SearchPropertyListCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/SearchPropertyListCollection.cs index 8b947099..80ef3eea 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/SearchPropertyListCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/SearchPropertyListCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class SearchPropertyListCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal SearchPropertyListCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public SearchPropertyList this[Int32 index] - { - get - { - return GetObjectByIndex(index) as SearchPropertyList; - } - } - - - // returns wrapper class - public SearchPropertyList this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as SearchPropertyList; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(SearchPropertyList[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public SearchPropertyList ItemById(int id) - { - return (SearchPropertyList)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(SearchPropertyList); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new SearchPropertyList(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(SearchPropertyList searchPropertyList) - { - AddImpl(searchPropertyList); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class SearchPropertyListCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/SecurityPolicyCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/SecurityPolicyCollection.cs index 9fda1f9f..e5ccfb7f 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/SecurityPolicyCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/SecurityPolicyCollection.cs @@ -1,170 +1,10 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590, 1591, 1592, 1573, 1571, 1570, 1572, 1587 - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - /// - /// Strongly typed collection of MAPPED_TYPE objects - /// Supports indexing objects by their Name and Schema properties - /// - public sealed class SecurityPolicyCollection : SchemaCollectionBase - { - - internal SecurityPolicyCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public SecurityPolicy this[Int32 index] - { - get - { - return GetObjectByIndex(index) as SecurityPolicy; - } - } - - public SecurityPolicy this[string name] - { - get - { - if (name == null) - { - throw new ArgumentNullException("name cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, GetDefaultSchema())) as SecurityPolicy; - } - } - - public SecurityPolicy this[string name, string schema] - { - get - { - if (name == null) - { - throw new ArgumentNullException("name cannot be null"); - } - else if (schema == null) - { - throw new ArgumentNullException("schema cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, schema)) as SecurityPolicy; - } - } - - public void CopyTo(SecurityPolicy[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public SecurityPolicy ItemById(int id) - { - return (SecurityPolicy)GetItemById(id); - } - - - protected override Type GetCollectionElementType() - { - return typeof(SecurityPolicy); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new SecurityPolicy(this, key, state); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - public void Add(SecurityPolicy securityPolicy) - { - if( null == securityPolicy ) - throw new FailedOperationException(ExceptionTemplates.AddCollection, this, new ArgumentNullException("securityPolicy")); - - AddImpl(securityPolicy); - } - - internal SqlSmoObject GetObjectByName(string name) - { - if (name == null) - { - throw new ArgumentNullException("schema cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, GetDefaultSchema())); - } - - } + public sealed partial class SecurityPolicyCollection : SchemaCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/SecurityPredicateCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/SecurityPredicateCollection.cs index 6130f13d..bcbd0e3f 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/SecurityPredicateCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/SecurityPredicateCollection.cs @@ -1,46 +1,24 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; namespace Microsoft.SqlServer.Management.Smo { - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class SecurityPredicateCollection : SecurityPredicateCollectionBase + /// + /// Collection of SecurityPredicate objects associated with a SecurityPolicy + /// + public sealed partial class SecurityPredicateCollection : SecurityPredicateCollectionBase { internal SecurityPredicateCollection(SqlSmoObject parentInstance) : base(parentInstance) { } - /// /// Returns the parent object /// - public SecurityPolicy Parent - { - get - { - return this.ParentInstance as SecurityPolicy; - } - } + public SecurityPolicy Parent => ParentInstance as SecurityPolicy; + + protected override string UrnSuffix => SecurityPredicate.UrnSuffix; - - /// - /// Returns the security predicate for a given index - /// - /// The index in the collection - /// The security predicate at the given index - public SecurityPredicate this[Int32 index] - { - get - { - return GetObjectByIndex(index) as SecurityPredicate; - } - } /// /// Adds the security predicate to the collection. /// @@ -52,33 +30,14 @@ public void Add(SecurityPredicate securityPredicate) // if (InternalStorage.Contains(securityPredicate.key)) { - securityPredicate.SecurityPredicateID = this[this.Count - 1].SecurityPredicateID + 1; + securityPredicate.SecurityPredicateID = this[Count - 1].SecurityPredicateID + 1; securityPredicate.key = new SecurityPredicateObjectKey(securityPredicate.SecurityPredicateID); } InternalStorage.Add(securityPredicate.key, securityPredicate); } - /// - /// Copies the collection to an arryay - /// - /// The array to copy to - /// The zero-based index in array at which copying begins - public void CopyTo(SecurityPredicate[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - /// - /// Returns the collection element type - /// - /// The collection element type - protected override Type GetCollectionElementType() - { - return typeof(SecurityPredicate); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) + internal override SecurityPredicate GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) { return new SecurityPredicate(this, key, state); } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/SensitivityClassificationCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/SensitivityClassificationCollection.cs index a7ed2c7e..c76abb0c 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/SensitivityClassificationCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/SensitivityClassificationCollection.cs @@ -1,256 +1,9 @@ - -/////////////////////////////////////////////////////////////// -// -// Copyright (c) Microsoft. -// Licensed under the MIT license. -// WARNING : DO NOT ATTEMPT TO MODIFY THIS FILE MANUALLY -// -// This class is autogenerated from generic_collection.cs -// -/////////////////////////////////////////////////////////////// - -using System; -using System.Collections; - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + // Copyright (c) Microsoft Corporation + // Licensed under the MIT license. namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of SensitivityClassification objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class SensitivityClassificationCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal SensitivityClassificationCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public SqlSmoObject Parent - { - get - { - return this.ParentInstance as SqlSmoObject; - } - } - - - public SensitivityClassification this[Int32 index] - { - get - { - return GetObjectByIndex(index) as SensitivityClassification; - } - } - - - // returns wrapper class - public SensitivityClassification this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as SensitivityClassification; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(SensitivityClassification[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public SensitivityClassification ItemById(int id) - { - return (SensitivityClassification)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(SensitivityClassification); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new SensitivityClassification(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(SensitivityClassification SensitivityClassification) - { - AddImpl(SensitivityClassification); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class SensitivityClassificationCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/SequenceCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/SequenceCollection.cs index 00f44b6c..f08010a6 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/SequenceCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/SequenceCollection.cs @@ -1,170 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590, 1591, 1592, 1573, 1571, 1570, 1572, 1587 - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed collection of MAPPED_TYPE objects - /// Supports indexing objects by their Name and Schema properties - /// - public sealed class SequenceCollection : SchemaCollectionBase - { - - internal SequenceCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public Sequence this[Int32 index] - { - get - { - return GetObjectByIndex(index) as Sequence; - } - } - - public Sequence this[string name] - { - get - { - if (name == null) - { - throw new ArgumentNullException("name cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, GetDefaultSchema())) as Sequence; - } - } - - public Sequence this[string name, string schema] - { - get - { - if (name == null) - { - throw new ArgumentNullException("name cannot be null"); - } - else if (schema == null) - { - throw new ArgumentNullException("schema cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, schema)) as Sequence; - } - } - - public void CopyTo(Sequence[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public Sequence ItemById(int id) - { - return (Sequence)GetItemById(id); - } - - - protected override Type GetCollectionElementType() - { - return typeof(Sequence); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new Sequence(this, key, state); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - public void Add(Sequence sequence) - { - if( null == sequence ) - throw new FailedOperationException(ExceptionTemplates.AddCollection, this, new ArgumentNullException("sequence")); - - AddImpl(sequence); - } - - internal SqlSmoObject GetObjectByName(string name) - { - if (name == null) - { - throw new ArgumentNullException("schema cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, GetDefaultSchema())); - } - - } + public sealed partial class SequenceCollection : SchemaCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/ServerAuditSpecificationCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/ServerAuditSpecificationCollection.cs index 129cf19b..a86cb32e 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/ServerAuditSpecificationCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/ServerAuditSpecificationCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class ServerAuditSpecificationCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal ServerAuditSpecificationCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Server Parent - { - get - { - return this.ParentInstance as Server; - } - } - - - public ServerAuditSpecification this[Int32 index] - { - get - { - return GetObjectByIndex(index) as ServerAuditSpecification; - } - } - - - // returns wrapper class - public ServerAuditSpecification this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as ServerAuditSpecification; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(ServerAuditSpecification[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public ServerAuditSpecification ItemById(int id) - { - return (ServerAuditSpecification)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(ServerAuditSpecification); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new ServerAuditSpecification(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(ServerAuditSpecification serverAuditSpecification) - { - AddImpl(serverAuditSpecification); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class ServerAuditSpecificationCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/ServerDdlTriggerCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/ServerDdlTriggerCollection.cs index 548878b7..b64c2a1e 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/ServerDdlTriggerCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/ServerDdlTriggerCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class ServerDdlTriggerCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal ServerDdlTriggerCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Server Parent - { - get - { - return this.ParentInstance as Server; - } - } - - - public ServerDdlTrigger this[Int32 index] - { - get - { - return GetObjectByIndex(index) as ServerDdlTrigger; - } - } - - - // returns wrapper class - public ServerDdlTrigger this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as ServerDdlTrigger; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(ServerDdlTrigger[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public ServerDdlTrigger ItemById(int id) - { - return (ServerDdlTrigger)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(ServerDdlTrigger); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new ServerDdlTrigger(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(ServerDdlTrigger serverDdlTrigger) - { - AddImpl(serverDdlTrigger); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class ServerDdlTriggerCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/ServerRoleCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/ServerRoleCollection.cs index becf63bf..f49a7e95 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/ServerRoleCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/ServerRoleCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class ServerRoleCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal ServerRoleCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Server Parent - { - get - { - return this.ParentInstance as Server; - } - } - - - public ServerRole this[Int32 index] - { - get - { - return GetObjectByIndex(index) as ServerRole; - } - } - - - // returns wrapper class - public ServerRole this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as ServerRole; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(ServerRole[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public ServerRole ItemById(int id) - { - return (ServerRole)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(ServerRole); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new ServerRole(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(ServerRole serverRole) - { - AddImpl(serverRole); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class ServerRoleCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/ServiceContractCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/ServiceContractCollection.cs index dd48c5b1..af6dd1cf 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/ServiceContractCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/ServiceContractCollection.cs @@ -1,249 +1,25 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo.Broker { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class ServiceContractCollection : SimpleObjectCollectionBase - { - - //has custom string comparer - StringComparer m_comparer; - - //must initialize in constructor - internal ServiceContractCollection(SqlSmoObject parentInstance, StringComparer comparer) : base(parentInstance) - { - m_comparer = comparer; - } - - override internal StringComparer StringComparer - { - get - { - return m_comparer; - } - } - - - - - - - - public ServiceBroker Parent - { - get - { - return this.ParentInstance as ServiceBroker; - } - } - - - public ServiceContract this[Int32 index] - { - get - { - return GetObjectByIndex(index) as ServiceContract; - } - } - - - // returns wrapper class - public ServiceContract this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as ServiceContract; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(ServiceContract[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public ServiceContract ItemById(int id) - { - return (ServiceContract)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(ServiceContract); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new ServiceContract(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(ServiceContract serviceContract) - { - AddImpl(serviceContract); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); + public sealed partial class ServiceContractCollection : SimpleObjectCollectionBase + { + //has custom string comparer + private readonly StringComparer m_comparer; + + //must initialize in constructor + internal ServiceContractCollection(SqlSmoObject parentInstance, StringComparer comparer) : base((ServiceBroker)parentInstance) + { + m_comparer = comparer; } - - - - - - - - - - - - - - - - - - } + override internal StringComparer StringComparer + { + get + { + return m_comparer; + } + } + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/ServiceContractMappingCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/ServiceContractMappingCollection.cs index 03b354ef..1fdcd8e0 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/ServiceContractMappingCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/ServiceContractMappingCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo.Broker { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class ServiceContractMappingCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal ServiceContractMappingCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public BrokerService Parent - { - get - { - return this.ParentInstance as BrokerService; - } - } - - - public ServiceContractMapping this[Int32 index] - { - get - { - return GetObjectByIndex(index) as ServiceContractMapping; - } - } - - - // returns wrapper class - public ServiceContractMapping this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as ServiceContractMapping; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(ServiceContractMapping[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(ServiceContractMapping); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new ServiceContractMapping(this, key, state); - } - - - - - public void Remove(ServiceContractMapping serviceContractMapping) - { - if( null == serviceContractMapping ) - throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException("serviceContractMapping")); - - RemoveObj(serviceContractMapping, new SimpleObjectKey(serviceContractMapping.Name)); - } - - public void Remove(string name) - { - this.Remove(new SimpleObjectKey(name)); - } - - - - public void Add(ServiceContractMapping serviceContractMapping) - { - AddImpl(serviceContractMapping); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class ServiceContractMappingCollection : RemovableCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/ServiceQueueCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/ServiceQueueCollection.cs index a93b765e..417111dc 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/ServiceQueueCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/ServiceQueueCollection.cs @@ -1,170 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590, 1591, 1592, 1573, 1571, 1570, 1572, 1587 - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo.Broker { - - /// - /// Strongly typed collection of MAPPED_TYPE objects - /// Supports indexing objects by their Name and Schema properties - /// - public sealed class ServiceQueueCollection : SchemaCollectionBase - { - - internal ServiceQueueCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - public ServiceBroker Parent - { - get - { - return this.ParentInstance as ServiceBroker; - } - } - - - public ServiceQueue this[Int32 index] - { - get - { - return GetObjectByIndex(index) as ServiceQueue; - } - } - - public ServiceQueue this[string name] - { - get - { - if (name == null) - { - throw new ArgumentNullException("name cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, GetDefaultSchema())) as ServiceQueue; - } - } - - public ServiceQueue this[string name, string schema] - { - get - { - if (name == null) - { - throw new ArgumentNullException("name cannot be null"); - } - else if (schema == null) - { - throw new ArgumentNullException("schema cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, schema)) as ServiceQueue; - } - } - - public void CopyTo(ServiceQueue[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public ServiceQueue ItemById(int id) - { - return (ServiceQueue)GetItemById(id); - } - - - protected override Type GetCollectionElementType() - { - return typeof(ServiceQueue); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new ServiceQueue(this, key, state); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - public void Add(ServiceQueue serviceQueue) - { - if( null == serviceQueue ) - throw new FailedOperationException(ExceptionTemplates.AddCollection, this, new ArgumentNullException("serviceQueue")); - - AddImpl(serviceQueue); - } - - internal SqlSmoObject GetObjectByName(string name) - { - if (name == null) - { - throw new ArgumentNullException("schema cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, GetDefaultSchema())); - } - - } + public sealed partial class ServiceQueueCollection : SchemaCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/ServiceRouteCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/ServiceRouteCollection.cs index c631ffc5..7d1921bf 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/ServiceRouteCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/ServiceRouteCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo.Broker { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class ServiceRouteCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal ServiceRouteCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public ServiceBroker Parent - { - get - { - return this.ParentInstance as ServiceBroker; - } - } - - - public ServiceRoute this[Int32 index] - { - get - { - return GetObjectByIndex(index) as ServiceRoute; - } - } - - - // returns wrapper class - public ServiceRoute this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as ServiceRoute; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(ServiceRoute[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public ServiceRoute ItemById(int id) - { - return (ServiceRoute)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(ServiceRoute); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new ServiceRoute(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(ServiceRoute serviceRoute) - { - AddImpl(serviceRoute); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class ServiceRouteCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/SoapPayloadMethodCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/SoapPayloadMethodCollection.cs index f8e783cd..5689312f 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/SoapPayloadMethodCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/SoapPayloadMethodCollection.cs @@ -2,113 +2,42 @@ // Licensed under the MIT license. using System; -using System.Collections; -#pragma warning disable 1590, 1591, 1592, 1573, 1571, 1570, 1572, 1587 - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class + /// Collection of SoapPayloadMethod objects associated with a SoapPayload /// - public sealed class SoapPayloadMethodCollection : SoapMethodCollectionBase - { - - internal SoapPayloadMethodCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - public SoapPayload Parent - { - get - { - return this.ParentInstance as SoapPayload; - } - } - - - public SoapPayloadMethod this[string name] - { - get - { - return GetObjectByKey(new SoapMethodKey(name, SoapMethodCollectionBase.GetDefaultNamespace())) as SoapPayloadMethod; - } - } - - // returns wrapper class - public SoapPayloadMethod this[string name, string methodNamespace] - { - get - { - return GetObjectByKey(new SoapMethodKey(name, methodNamespace)) as SoapPayloadMethod; - } - } - - public SoapPayloadMethod this[Int32 index] - { - get - { - return GetObjectByIndex(index) as SoapPayloadMethod; - } - } - - protected override Type GetCollectionElementType() - { - return typeof(SoapPayloadMethod); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new SoapPayloadMethod(this, key, state); - } - - public void CopyTo(SoapPayloadMethod[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public void Remove(SoapPayloadMethod soapMethod) - { - if( null == soapMethod ) - throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException("soapMethod")); - - RemoveObj(soapMethod, soapMethod.key); - } - - public void Add(SoapPayloadMethod soapMethod) - { - AddImpl(soapMethod); - } - - - - } + public sealed class SoapPayloadMethodCollection : SoapMethodCollectionBase + { + + internal SoapPayloadMethodCollection(SqlSmoObject parentInstance) : base((SoapPayload)parentInstance) + { + } + + public SoapPayloadMethod this[string name, string methodNamespace] + { + get + { + return GetObjectByKey(new SoapMethodKey(name, methodNamespace)) as SoapPayloadMethod; + } + } + + protected override string UrnSuffix => SoapPayloadMethod.UrnSuffix; + + public void Remove(SoapPayloadMethod soapMethod) + { + if (null == soapMethod) + throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException(nameof(soapMethod))); + + RemoveObj(soapMethod, soapMethod.key); + } + + internal override SoapPayloadMethod GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) + { + return new SoapPayloadMethod(this, key, state); + } + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/SqlAssemblyCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/SqlAssemblyCollection.cs index 1cacd8e9..23307dc5 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/SqlAssemblyCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/SqlAssemblyCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class SqlAssemblyCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal SqlAssemblyCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public SqlAssembly this[Int32 index] - { - get - { - return GetObjectByIndex(index) as SqlAssembly; - } - } - - - // returns wrapper class - public SqlAssembly this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as SqlAssembly; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(SqlAssembly[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public SqlAssembly ItemById(int id) - { - return (SqlAssembly)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(SqlAssembly); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new SqlAssembly(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(SqlAssembly sqlAssembly) - { - AddImpl(sqlAssembly); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class SqlAssemblyCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/SqlAssemblyFileCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/SqlAssemblyFileCollection.cs index 787d5db3..4b9224cb 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/SqlAssemblyFileCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/SqlAssemblyFileCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class SqlAssemblyFileCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal SqlAssemblyFileCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public SqlAssembly Parent - { - get - { - return this.ParentInstance as SqlAssembly; - } - } - - - public SqlAssemblyFile this[Int32 index] - { - get - { - return GetObjectByIndex(index) as SqlAssemblyFile; - } - } - - - // returns wrapper class - public SqlAssemblyFile this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as SqlAssemblyFile; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(SqlAssemblyFile[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public SqlAssemblyFile ItemById(int id) - { - return (SqlAssemblyFile)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(SqlAssemblyFile); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new SqlAssemblyFile(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(SqlAssemblyFile file) - { - AddImpl(file); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class SqlAssemblyFileCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/StatisticCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/StatisticCollection.cs index 115697a3..02e4831d 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/StatisticCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/StatisticCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class StatisticCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal StatisticCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public SqlSmoObject Parent - { - get - { - return this.ParentInstance as SqlSmoObject; - } - } - - - public Statistic this[Int32 index] - { - get - { - return GetObjectByIndex(index) as Statistic; - } - } - - - // returns wrapper class - public Statistic this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as Statistic; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(Statistic[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public Statistic ItemById(int id) - { - return (Statistic)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(Statistic); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new Statistic(this, key, state); - } - - - - - public void Remove(Statistic statistic) - { - if( null == statistic ) - throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException("statistic")); - - RemoveObj(statistic, new SimpleObjectKey(statistic.Name)); - } - - public void Remove(string name) - { - this.Remove(new SimpleObjectKey(name)); - } - - - - public void Add(Statistic statistic) - { - AddImpl(statistic); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class StatisticCollection : RemovableCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/StatisticColumnCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/StatisticColumnCollection.cs index b6d7f905..62148d69 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/StatisticColumnCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/StatisticColumnCollection.cs @@ -1,148 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590, 1591, 1592, 1573, 1571, 1570, 1572, 1587 - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class StatisticColumnCollection : ParameterCollectionBase - { - internal StatisticColumnCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - public Statistic Parent - { - get - { - return this.ParentInstance as Statistic; - } - } - - - public StatisticColumn this[Int32 index] - { - get - { - return GetObjectByIndex(index) as StatisticColumn; - } - } - - public void CopyTo(StatisticColumn[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - // returns wrapper class - public StatisticColumn this[string name] - { - get - { - return GetObjectByKey( new SimpleObjectKey(name)) as StatisticColumn; - } - } - - - protected override Type GetCollectionElementType() - { - return typeof(StatisticColumn); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new StatisticColumn(this, key, state); - } - - - public void Add(StatisticColumn statisticColumn) - { - AddImpl(statisticColumn); - } - - public void Add(StatisticColumn statisticColumn, string insertAtColumnName) - { - AddImpl(statisticColumn, new SimpleObjectKey(insertAtColumnName)); - } - - public void Add(StatisticColumn statisticColumn, int insertAtPosition) - { - AddImpl(statisticColumn, insertAtPosition); - } - - - public void Remove(StatisticColumn statisticColumn) - { - if( null == statisticColumn ) - throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException("statisticColumn")); - - RemoveObj(statisticColumn, statisticColumn.key); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - public StatisticColumn ItemById(int id) - { - return (StatisticColumn)GetItemById(id); - } - - - } + public sealed partial class StatisticColumnCollection : ParameterCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/StoredProcedureCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/StoredProcedureCollection.cs index 2d08566b..60dcf7ce 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/StoredProcedureCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/StoredProcedureCollection.cs @@ -1,170 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590, 1591, 1592, 1573, 1571, 1570, 1572, 1587 - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed collection of MAPPED_TYPE objects - /// Supports indexing objects by their Name and Schema properties - /// - public sealed class StoredProcedureCollection : SchemaCollectionBase - { - - internal StoredProcedureCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public StoredProcedure this[Int32 index] - { - get - { - return GetObjectByIndex(index) as StoredProcedure; - } - } - - public StoredProcedure this[string name] - { - get - { - if (name == null) - { - throw new ArgumentNullException("name cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, GetDefaultSchema())) as StoredProcedure; - } - } - - public StoredProcedure this[string name, string schema] - { - get - { - if (name == null) - { - throw new ArgumentNullException("name cannot be null"); - } - else if (schema == null) - { - throw new ArgumentNullException("schema cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, schema)) as StoredProcedure; - } - } - - public void CopyTo(StoredProcedure[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public StoredProcedure ItemById(int id) - { - return (StoredProcedure)GetItemById(id); - } - - - protected override Type GetCollectionElementType() - { - return typeof(StoredProcedure); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new StoredProcedure(this, key, state); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - public void Add(StoredProcedure storedProcedure) - { - if( null == storedProcedure ) - throw new FailedOperationException(ExceptionTemplates.AddCollection, this, new ArgumentNullException("storedProcedure")); - - AddImpl(storedProcedure); - } - - internal SqlSmoObject GetObjectByName(string name) - { - if (name == null) - { - throw new ArgumentNullException("schema cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, GetDefaultSchema())); - } - - } + public sealed partial class StoredProcedureCollection : SchemaCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/StoredProcedureParameterCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/StoredProcedureParameterCollection.cs index 80849c2d..3e47de27 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/StoredProcedureParameterCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/StoredProcedureParameterCollection.cs @@ -1,148 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590, 1591, 1592, 1573, 1571, 1570, 1572, 1587 - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class StoredProcedureParameterCollection : ParameterCollectionBase - { - internal StoredProcedureParameterCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - public StoredProcedure Parent - { - get - { - return this.ParentInstance as StoredProcedure; - } - } - - - public StoredProcedureParameter this[Int32 index] - { - get - { - return GetObjectByIndex(index) as StoredProcedureParameter; - } - } - - public void CopyTo(StoredProcedureParameter[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - // returns wrapper class - public StoredProcedureParameter this[string name] - { - get - { - return GetObjectByKey( new SimpleObjectKey(name)) as StoredProcedureParameter; - } - } - - - protected override Type GetCollectionElementType() - { - return typeof(StoredProcedureParameter); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new StoredProcedureParameter(this, key, state); - } - - - public void Add(StoredProcedureParameter storedProcedureParameter) - { - AddImpl(storedProcedureParameter); - } - - public void Add(StoredProcedureParameter storedProcedureParameter, string insertAtColumnName) - { - AddImpl(storedProcedureParameter, new SimpleObjectKey(insertAtColumnName)); - } - - public void Add(StoredProcedureParameter storedProcedureParameter, int insertAtPosition) - { - AddImpl(storedProcedureParameter, insertAtPosition); - } - - - public void Remove(StoredProcedureParameter storedProcedureParameter) - { - if( null == storedProcedureParameter ) - throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException("storedProcedureParameter")); - - RemoveObj(storedProcedureParameter, storedProcedureParameter.key); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - public StoredProcedureParameter ItemById(int id) - { - return (StoredProcedureParameter)GetItemById(id); - } - - - } + public sealed partial class StoredProcedureParameterCollection : ParameterCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/SymmetricKeyCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/SymmetricKeyCollection.cs index 3e0ba4f3..1eb7957e 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/SymmetricKeyCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/SymmetricKeyCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class SymmetricKeyCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal SymmetricKeyCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public SymmetricKey this[Int32 index] - { - get - { - return GetObjectByIndex(index) as SymmetricKey; - } - } - - - // returns wrapper class - public SymmetricKey this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as SymmetricKey; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(SymmetricKey[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public SymmetricKey ItemById(int id) - { - return (SymmetricKey)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(SymmetricKey); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new SymmetricKey(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(SymmetricKey symmetricKey) - { - AddImpl(symmetricKey); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class SymmetricKeyCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/SynonymCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/SynonymCollection.cs index 23aa6c49..e617651e 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/SynonymCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/SynonymCollection.cs @@ -1,170 +1,10 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590, 1591, 1592, 1573, 1571, 1570, 1572, 1587 - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - /// - /// Strongly typed collection of MAPPED_TYPE objects - /// Supports indexing objects by their Name and Schema properties - /// - public sealed class SynonymCollection : SchemaCollectionBase - { - - internal SynonymCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public Synonym this[Int32 index] - { - get - { - return GetObjectByIndex(index) as Synonym; - } - } - - public Synonym this[string name] - { - get - { - if (name == null) - { - throw new ArgumentNullException("name cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, GetDefaultSchema())) as Synonym; - } - } - - public Synonym this[string name, string schema] - { - get - { - if (name == null) - { - throw new ArgumentNullException("name cannot be null"); - } - else if (schema == null) - { - throw new ArgumentNullException("schema cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, schema)) as Synonym; - } - } - - public void CopyTo(Synonym[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public Synonym ItemById(int id) - { - return (Synonym)GetItemById(id); - } - - - protected override Type GetCollectionElementType() - { - return typeof(Synonym); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new Synonym(this, key, state); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - public void Add(Synonym synonym) - { - if( null == synonym ) - throw new FailedOperationException(ExceptionTemplates.AddCollection, this, new ArgumentNullException("synonym")); - - AddImpl(synonym); - } - - internal SqlSmoObject GetObjectByName(string name) - { - if (name == null) - { - throw new ArgumentNullException("schema cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, GetDefaultSchema())); - } - - } + public sealed partial class SynonymCollection : SchemaCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/SystemDataTypeCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/SystemDataTypeCollection.cs index 1123dabc..f6341a5c 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/SystemDataTypeCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/SystemDataTypeCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class SystemDataTypeCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal SystemDataTypeCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Server Parent - { - get - { - return this.ParentInstance as Server; - } - } - - - public SystemDataType this[Int32 index] - { - get - { - return GetObjectByIndex(index) as SystemDataType; - } - } - - - // returns wrapper class - public SystemDataType this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as SystemDataType; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(SystemDataType[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public SystemDataType ItemById(int id) - { - return (SystemDataType)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(SystemDataType); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new SystemDataType(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(SystemDataType dataType) - { - AddImpl(dataType); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class SystemDataTypeCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/SystemMessageCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/SystemMessageCollection.cs index 007108bb..7567758d 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/SystemMessageCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/SystemMessageCollection.cs @@ -1,123 +1,21 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590, 1591, 1592, 1573, 1571, 1570, 1572, 1587 - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public class SystemMessageCollection : MessageCollectionBase - { - - internal SystemMessageCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - public Server Parent - { - get - { - return this.ParentInstance as Server; - } - } - - - public SystemMessage this[Int32 index] - { - get - { - return GetObjectByIndex(index) as SystemMessage; - } - } - - // returns wrapper class - public SystemMessage this[Int32 id, string language] - { - get - { - return GetObjectByKey(new MessageObjectKey(id, language)) as SystemMessage; - } - } - - public SystemMessage ItemByIdAndLanguage(Int32 id, string language) - { - return this[id, language]; - } - - public SystemMessage ItemByIdAndLanguageId(Int32 id, Int32 languageId) - { - Language lang = (ParentInstance as Server).Languages.ItemById(languageId); - if(null != lang) - { - return this[id, lang.Name]; - } - else - { - throw new FailedOperationException(ExceptionTemplates.ObjectDoesNotExist("LanguageID", languageId.ToString(SmoApplication.DefaultCulture))); - } - } - - protected override Type GetCollectionElementType() - { - return typeof(SystemMessage); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new SystemMessage(this, key, state); - } - - public void CopyTo(SystemMessage[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - + /// + /// A collection of SystemMessage instances associated with a Server + /// + public sealed class SystemMessageCollection : MessageCollectionBase + { + internal SystemMessageCollection(SqlSmoObject parentInstance) : base(parentInstance) + { + } + protected override string UrnSuffix => SystemMessage.UrnSuffix; - - - - - - - - - - - - } + internal override SystemMessage GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) => new SystemMessage(this, key, state); + } } - diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/TableCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/TableCollection.cs index 25abc145..08588484 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/TableCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/TableCollection.cs @@ -1,170 +1,10 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590, 1591, 1592, 1573, 1571, 1570, 1572, 1587 - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - /// - /// Strongly typed collection of MAPPED_TYPE objects - /// Supports indexing objects by their Name and Schema properties - /// - public sealed class TableCollection : SchemaCollectionBase - { - - internal TableCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public Table this[Int32 index] - { - get - { - return GetObjectByIndex(index) as Table; - } - } - - public Table this[string name] - { - get - { - if (name == null) - { - throw new ArgumentNullException("name cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, GetDefaultSchema())) as Table; - } - } - - public Table this[string name, string schema] - { - get - { - if (name == null) - { - throw new ArgumentNullException("name cannot be null"); - } - else if (schema == null) - { - throw new ArgumentNullException("schema cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, schema)) as Table; - } - } - - public void CopyTo(Table[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public Table ItemById(int id) - { - return (Table)GetItemById(id); - } - - - protected override Type GetCollectionElementType() - { - return typeof(Table); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new Table(this, key, state); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - public void Add(Table table) - { - if( null == table ) - throw new FailedOperationException(ExceptionTemplates.AddCollection, this, new ArgumentNullException("table")); - - AddImpl(table); - } - - internal SqlSmoObject GetObjectByName(string name) - { - if (name == null) - { - throw new ArgumentNullException("schema cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, GetDefaultSchema())); - } - - } + public sealed partial class TableCollection : SchemaCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/TargetServerCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/TargetServerCollection.cs index e0af8caf..d7d0bfbf 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/TargetServerCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/TargetServerCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo.Agent { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class TargetServerCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal TargetServerCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public JobServer Parent - { - get - { - return this.ParentInstance as JobServer; - } - } - - - public TargetServer this[Int32 index] - { - get - { - return GetObjectByIndex(index) as TargetServer; - } - } - - - // returns wrapper class - public TargetServer this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as TargetServer; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(TargetServer[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public TargetServer ItemById(int id) - { - return (TargetServer)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(TargetServer); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new TargetServer(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(TargetServer server) - { - AddImpl(server); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class TargetServerCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/TargetServerGroupCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/TargetServerGroupCollection.cs index 79ead84b..18296d50 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/TargetServerGroupCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/TargetServerGroupCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo.Agent { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class TargetServerGroupCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal TargetServerGroupCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public JobServer Parent - { - get - { - return this.ParentInstance as JobServer; - } - } - - - public TargetServerGroup this[Int32 index] - { - get - { - return GetObjectByIndex(index) as TargetServerGroup; - } - } - - - // returns wrapper class - public TargetServerGroup this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as TargetServerGroup; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(TargetServerGroup[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public TargetServerGroup ItemById(int id) - { - return (TargetServerGroup)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(TargetServerGroup); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new TargetServerGroup(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(TargetServerGroup targetServerGroup) - { - AddImpl(targetServerGroup); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class TargetServerGroupCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/TriggerCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/TriggerCollection.cs index 8f5e7720..743edf5d 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/TriggerCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/TriggerCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public class TriggerCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal TriggerCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public SqlSmoObject Parent - { - get - { - return this.ParentInstance as SqlSmoObject; - } - } - - - public Trigger this[Int32 index] - { - get - { - return GetObjectByIndex(index) as Trigger; - } - } - - - // returns wrapper class - public Trigger this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as Trigger; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(Trigger[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public Trigger ItemById(int id) - { - return (Trigger)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(Trigger); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new Trigger(this, key, state); - } - - - - - public void Remove(Trigger trigger) - { - if( null == trigger ) - throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException("trigger")); - - RemoveObj(trigger, new SimpleObjectKey(trigger.Name)); - } - - public void Remove(string name) - { - this.Remove(new SimpleObjectKey(name)); - } - - - - public void Add(Trigger trigger) - { - AddImpl(trigger); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - + public sealed partial class TriggerCollection : RemovableCollectionBase + { } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/UserCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/UserCollection.cs index 6738c445..41aa6a93 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/UserCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/UserCollection.cs @@ -1,249 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class UserCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal UserCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public User this[Int32 index] - { - get - { - return GetObjectByIndex(index) as User; - } - } - - - // returns wrapper class - public User this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as User; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(User[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public User ItemById(int id) - { - return (User)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(User); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new User(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(User user) - { - AddImpl(user); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class UserCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/UserDefinedAggregateCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/UserDefinedAggregateCollection.cs index 1cf872aa..8047090e 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/UserDefinedAggregateCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/UserDefinedAggregateCollection.cs @@ -1,170 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590, 1591, 1592, 1573, 1571, 1570, 1572, 1587 - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed collection of MAPPED_TYPE objects - /// Supports indexing objects by their Name and Schema properties - /// - public sealed class UserDefinedAggregateCollection : SchemaCollectionBase - { - - internal UserDefinedAggregateCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public UserDefinedAggregate this[Int32 index] - { - get - { - return GetObjectByIndex(index) as UserDefinedAggregate; - } - } - - public UserDefinedAggregate this[string name] - { - get - { - if (name == null) - { - throw new ArgumentNullException("name cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, GetDefaultSchema())) as UserDefinedAggregate; - } - } - - public UserDefinedAggregate this[string name, string schema] - { - get - { - if (name == null) - { - throw new ArgumentNullException("name cannot be null"); - } - else if (schema == null) - { - throw new ArgumentNullException("schema cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, schema)) as UserDefinedAggregate; - } - } - - public void CopyTo(UserDefinedAggregate[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public UserDefinedAggregate ItemById(int id) - { - return (UserDefinedAggregate)GetItemById(id); - } - - - protected override Type GetCollectionElementType() - { - return typeof(UserDefinedAggregate); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new UserDefinedAggregate(this, key, state); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - public void Add(UserDefinedAggregate userDefinedAggregate) - { - if( null == userDefinedAggregate ) - throw new FailedOperationException(ExceptionTemplates.AddCollection, this, new ArgumentNullException("userDefinedAggregate")); - - AddImpl(userDefinedAggregate); - } - - internal SqlSmoObject GetObjectByName(string name) - { - if (name == null) - { - throw new ArgumentNullException("schema cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, GetDefaultSchema())); - } - - } + public sealed partial class UserDefinedAggregateCollection : SchemaCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/UserDefinedAggregateParameterCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/UserDefinedAggregateParameterCollection.cs index 68257db0..cb119efd 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/UserDefinedAggregateParameterCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/UserDefinedAggregateParameterCollection.cs @@ -1,148 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590, 1591, 1592, 1573, 1571, 1570, 1572, 1587 - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class UserDefinedAggregateParameterCollection : ParameterCollectionBase - { - internal UserDefinedAggregateParameterCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - public UserDefinedAggregate Parent - { - get - { - return this.ParentInstance as UserDefinedAggregate; - } - } - - - public UserDefinedAggregateParameter this[Int32 index] - { - get - { - return GetObjectByIndex(index) as UserDefinedAggregateParameter; - } - } - - public void CopyTo(UserDefinedAggregateParameter[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - // returns wrapper class - public UserDefinedAggregateParameter this[string name] - { - get - { - return GetObjectByKey( new SimpleObjectKey(name)) as UserDefinedAggregateParameter; - } - } - - - protected override Type GetCollectionElementType() - { - return typeof(UserDefinedAggregateParameter); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new UserDefinedAggregateParameter(this, key, state); - } - - - public void Add(UserDefinedAggregateParameter userDefinedAggregateParameter) - { - AddImpl(userDefinedAggregateParameter); - } - - public void Add(UserDefinedAggregateParameter userDefinedAggregateParameter, string insertAtColumnName) - { - AddImpl(userDefinedAggregateParameter, new SimpleObjectKey(insertAtColumnName)); - } - - public void Add(UserDefinedAggregateParameter userDefinedAggregateParameter, int insertAtPosition) - { - AddImpl(userDefinedAggregateParameter, insertAtPosition); - } - - - public void Remove(UserDefinedAggregateParameter userDefinedAggregateParameter) - { - if( null == userDefinedAggregateParameter ) - throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException("userDefinedAggregateParameter")); - - RemoveObj(userDefinedAggregateParameter, userDefinedAggregateParameter.key); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - public UserDefinedAggregateParameter ItemById(int id) - { - return (UserDefinedAggregateParameter)GetItemById(id); - } - - - } + public sealed partial class UserDefinedAggregateParameterCollection : ParameterCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/UserDefinedDataTypeCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/UserDefinedDataTypeCollection.cs index 19bafd62..bd60f992 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/UserDefinedDataTypeCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/UserDefinedDataTypeCollection.cs @@ -1,170 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590, 1591, 1592, 1573, 1571, 1570, 1572, 1587 - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed collection of MAPPED_TYPE objects - /// Supports indexing objects by their Name and Schema properties - /// - public sealed class UserDefinedDataTypeCollection : SchemaCollectionBase - { - - internal UserDefinedDataTypeCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public UserDefinedDataType this[Int32 index] - { - get - { - return GetObjectByIndex(index) as UserDefinedDataType; - } - } - - public UserDefinedDataType this[string name] - { - get - { - if (name == null) - { - throw new ArgumentNullException("name cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, GetDefaultSchema())) as UserDefinedDataType; - } - } - - public UserDefinedDataType this[string name, string schema] - { - get - { - if (name == null) - { - throw new ArgumentNullException("name cannot be null"); - } - else if (schema == null) - { - throw new ArgumentNullException("schema cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, schema)) as UserDefinedDataType; - } - } - - public void CopyTo(UserDefinedDataType[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public UserDefinedDataType ItemById(int id) - { - return (UserDefinedDataType)GetItemById(id); - } - - - protected override Type GetCollectionElementType() - { - return typeof(UserDefinedDataType); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new UserDefinedDataType(this, key, state); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - public void Add(UserDefinedDataType userDefinedDataType) - { - if( null == userDefinedDataType ) - throw new FailedOperationException(ExceptionTemplates.AddCollection, this, new ArgumentNullException("userDefinedDataType")); - - AddImpl(userDefinedDataType); - } - - internal SqlSmoObject GetObjectByName(string name) - { - if (name == null) - { - throw new ArgumentNullException("schema cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, GetDefaultSchema())); - } - - } + public sealed partial class UserDefinedDataTypeCollection : SchemaCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/UserDefinedFunctionCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/UserDefinedFunctionCollection.cs index cf394fde..64cdb13a 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/UserDefinedFunctionCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/UserDefinedFunctionCollection.cs @@ -1,170 +1,10 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590, 1591, 1592, 1573, 1571, 1570, 1572, 1587 - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - /// - /// Strongly typed collection of MAPPED_TYPE objects - /// Supports indexing objects by their Name and Schema properties - /// - public sealed class UserDefinedFunctionCollection : SchemaCollectionBase - { - - internal UserDefinedFunctionCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public UserDefinedFunction this[Int32 index] - { - get - { - return GetObjectByIndex(index) as UserDefinedFunction; - } - } - - public UserDefinedFunction this[string name] - { - get - { - if (name == null) - { - throw new ArgumentNullException("name cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, GetDefaultSchema())) as UserDefinedFunction; - } - } - - public UserDefinedFunction this[string name, string schema] - { - get - { - if (name == null) - { - throw new ArgumentNullException("name cannot be null"); - } - else if (schema == null) - { - throw new ArgumentNullException("schema cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, schema)) as UserDefinedFunction; - } - } - - public void CopyTo(UserDefinedFunction[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public UserDefinedFunction ItemById(int id) - { - return (UserDefinedFunction)GetItemById(id); - } - - - protected override Type GetCollectionElementType() - { - return typeof(UserDefinedFunction); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new UserDefinedFunction(this, key, state); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - public void Add(UserDefinedFunction userDefinedFunction) - { - if( null == userDefinedFunction ) - throw new FailedOperationException(ExceptionTemplates.AddCollection, this, new ArgumentNullException("userDefinedFunction")); - - AddImpl(userDefinedFunction); - } - - internal SqlSmoObject GetObjectByName(string name) - { - if (name == null) - { - throw new ArgumentNullException("schema cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, GetDefaultSchema())); - } - - } + public sealed partial class UserDefinedFunctionCollection : SchemaCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/UserDefinedFunctionParameterCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/UserDefinedFunctionParameterCollection.cs index e8ab492b..f5b11b35 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/UserDefinedFunctionParameterCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/UserDefinedFunctionParameterCollection.cs @@ -1,148 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590, 1591, 1592, 1573, 1571, 1570, 1572, 1587 - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class UserDefinedFunctionParameterCollection : ParameterCollectionBase - { - internal UserDefinedFunctionParameterCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - public UserDefinedFunction Parent - { - get - { - return this.ParentInstance as UserDefinedFunction; - } - } - - - public UserDefinedFunctionParameter this[Int32 index] - { - get - { - return GetObjectByIndex(index) as UserDefinedFunctionParameter; - } - } - - public void CopyTo(UserDefinedFunctionParameter[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - // returns wrapper class - public UserDefinedFunctionParameter this[string name] - { - get - { - return GetObjectByKey( new SimpleObjectKey(name)) as UserDefinedFunctionParameter; - } - } - - - protected override Type GetCollectionElementType() - { - return typeof(UserDefinedFunctionParameter); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new UserDefinedFunctionParameter(this, key, state); - } - - - public void Add(UserDefinedFunctionParameter userDefinedFunctionParameter) - { - AddImpl(userDefinedFunctionParameter); - } - - public void Add(UserDefinedFunctionParameter userDefinedFunctionParameter, string insertAtColumnName) - { - AddImpl(userDefinedFunctionParameter, new SimpleObjectKey(insertAtColumnName)); - } - - public void Add(UserDefinedFunctionParameter userDefinedFunctionParameter, int insertAtPosition) - { - AddImpl(userDefinedFunctionParameter, insertAtPosition); - } - - - public void Remove(UserDefinedFunctionParameter userDefinedFunctionParameter) - { - if( null == userDefinedFunctionParameter ) - throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException("userDefinedFunctionParameter")); - - RemoveObj(userDefinedFunctionParameter, userDefinedFunctionParameter.key); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - public UserDefinedFunctionParameter ItemById(int id) - { - return (UserDefinedFunctionParameter)GetItemById(id); - } - - - } + public sealed partial class UserDefinedFunctionParameterCollection : ParameterCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/UserDefinedMessageCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/UserDefinedMessageCollection.cs index a12aa6e7..9b1678e8 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/UserDefinedMessageCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/UserDefinedMessageCollection.cs @@ -1,123 +1,22 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590, 1591, 1592, 1573, 1571, 1570, 1572, 1587 - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { + /// + /// A collection of UserDefinedMessage instances associated with a Server + /// + public sealed class UserDefinedMessageCollection : MessageCollectionBase + { - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class UserDefinedMessageCollection : MessageCollectionBase - { - - internal UserDefinedMessageCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - public Server Parent - { - get - { - return this.ParentInstance as Server; - } - } - - - public UserDefinedMessage this[Int32 index] - { - get - { - return GetObjectByIndex(index) as UserDefinedMessage; - } - } - - // returns wrapper class - public UserDefinedMessage this[Int32 id, string language] - { - get - { - return GetObjectByKey(new MessageObjectKey(id, language)) as UserDefinedMessage; - } - } - - public UserDefinedMessage ItemByIdAndLanguage(Int32 id, string language) - { - return this[id, language]; - } - - public UserDefinedMessage ItemByIdAndLanguageId(Int32 id, Int32 languageId) - { - Language lang = (ParentInstance as Server).Languages.ItemById(languageId); - if(null != lang) - { - return this[id, lang.Name]; - } - else - { - throw new FailedOperationException(ExceptionTemplates.ObjectDoesNotExist("LanguageID", languageId.ToString(SmoApplication.DefaultCulture))); - } - } - - protected override Type GetCollectionElementType() - { - return typeof(UserDefinedMessage); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new UserDefinedMessage(this, key, state); - } - - public void CopyTo(UserDefinedMessage[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - - - - - - - - - - - + internal UserDefinedMessageCollection(SqlSmoObject parentInstance) : base(parentInstance) + { + } + protected override string UrnSuffix => UserDefinedMessage.UrnSuffix; + internal override UserDefinedMessage GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) => new UserDefinedMessage(this, key, state); - } + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/UserDefinedTableTypeCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/UserDefinedTableTypeCollection.cs index 626f7708..eaed2cb7 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/UserDefinedTableTypeCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/UserDefinedTableTypeCollection.cs @@ -1,170 +1,10 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590, 1591, 1592, 1573, 1571, 1570, 1572, 1587 - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - /// - /// Strongly typed collection of MAPPED_TYPE objects - /// Supports indexing objects by their Name and Schema properties - /// - public sealed class UserDefinedTableTypeCollection : SchemaCollectionBase - { - - internal UserDefinedTableTypeCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public UserDefinedTableType this[Int32 index] - { - get - { - return GetObjectByIndex(index) as UserDefinedTableType; - } - } - - public UserDefinedTableType this[string name] - { - get - { - if (name == null) - { - throw new ArgumentNullException("name cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, GetDefaultSchema())) as UserDefinedTableType; - } - } - - public UserDefinedTableType this[string name, string schema] - { - get - { - if (name == null) - { - throw new ArgumentNullException("name cannot be null"); - } - else if (schema == null) - { - throw new ArgumentNullException("schema cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, schema)) as UserDefinedTableType; - } - } - - public void CopyTo(UserDefinedTableType[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public UserDefinedTableType ItemById(int id) - { - return (UserDefinedTableType)GetItemById(id); - } - - - protected override Type GetCollectionElementType() - { - return typeof(UserDefinedTableType); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new UserDefinedTableType(this, key, state); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - public void Add(UserDefinedTableType userDefinedTableType) - { - if( null == userDefinedTableType ) - throw new FailedOperationException(ExceptionTemplates.AddCollection, this, new ArgumentNullException("userDefinedTableType")); - - AddImpl(userDefinedTableType); - } - - internal SqlSmoObject GetObjectByName(string name) - { - if (name == null) - { - throw new ArgumentNullException("schema cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, GetDefaultSchema())); - } - - } + public sealed partial class UserDefinedTableTypeCollection : SchemaCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/UserDefinedTypeCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/UserDefinedTypeCollection.cs index 0cda5f94..e0ad5d39 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/UserDefinedTypeCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/UserDefinedTypeCollection.cs @@ -1,170 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590, 1591, 1592, 1573, 1571, 1570, 1572, 1587 - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed collection of MAPPED_TYPE objects - /// Supports indexing objects by their Name and Schema properties - /// - public sealed class UserDefinedTypeCollection : SchemaCollectionBase - { - - internal UserDefinedTypeCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public UserDefinedType this[Int32 index] - { - get - { - return GetObjectByIndex(index) as UserDefinedType; - } - } - - public UserDefinedType this[string name] - { - get - { - if (name == null) - { - throw new ArgumentNullException("name cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, GetDefaultSchema())) as UserDefinedType; - } - } - - public UserDefinedType this[string name, string schema] - { - get - { - if (name == null) - { - throw new ArgumentNullException("name cannot be null"); - } - else if (schema == null) - { - throw new ArgumentNullException("schema cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, schema)) as UserDefinedType; - } - } - - public void CopyTo(UserDefinedType[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public UserDefinedType ItemById(int id) - { - return (UserDefinedType)GetItemById(id); - } - - - protected override Type GetCollectionElementType() - { - return typeof(UserDefinedType); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new UserDefinedType(this, key, state); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - public void Add(UserDefinedType userDefinedType) - { - if( null == userDefinedType ) - throw new FailedOperationException(ExceptionTemplates.AddCollection, this, new ArgumentNullException("userDefinedType")); - - AddImpl(userDefinedType); - } - - internal SqlSmoObject GetObjectByName(string name) - { - if (name == null) - { - throw new ArgumentNullException("schema cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, GetDefaultSchema())); - } - - } + public sealed partial class UserDefinedTypeCollection : SchemaCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/ViewCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/ViewCollection.cs index fc70c121..819743c8 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/ViewCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/ViewCollection.cs @@ -1,170 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590, 1591, 1592, 1573, 1571, 1570, 1572, 1587 - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed collection of MAPPED_TYPE objects - /// Supports indexing objects by their Name and Schema properties - /// - public sealed class ViewCollection : SchemaCollectionBase - { - - internal ViewCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public View this[Int32 index] - { - get - { - return GetObjectByIndex(index) as View; - } - } - - public View this[string name] - { - get - { - if (name == null) - { - throw new ArgumentNullException("name cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, GetDefaultSchema())) as View; - } - } - - public View this[string name, string schema] - { - get - { - if (name == null) - { - throw new ArgumentNullException("name cannot be null"); - } - else if (schema == null) - { - throw new ArgumentNullException("schema cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, schema)) as View; - } - } - - public void CopyTo(View[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public View ItemById(int id) - { - return (View)GetItemById(id); - } - - - protected override Type GetCollectionElementType() - { - return typeof(View); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new View(this, key, state); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - public void Add(View view) - { - if( null == view ) - throw new FailedOperationException(ExceptionTemplates.AddCollection, this, new ArgumentNullException("view")); - - AddImpl(view); - } - - internal SqlSmoObject GetObjectByName(string name) - { - if (name == null) - { - throw new ArgumentNullException("schema cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, GetDefaultSchema())); - } - - } + public sealed partial class ViewCollection : SchemaCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/WorkloadGroupCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/WorkloadGroupCollection.cs index 24eb4961..4ccf328e 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/WorkloadGroupCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/WorkloadGroupCollection.cs @@ -1,249 +1,10 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { + public sealed partial class WorkloadGroupCollection : SimpleObjectCollectionBase + { - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class WorkloadGroupCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal WorkloadGroupCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public ResourcePool Parent - { - get - { - return this.ParentInstance as ResourcePool; - } - } - - - public WorkloadGroup this[Int32 index] - { - get - { - return GetObjectByIndex(index) as WorkloadGroup; - } - } - - - // returns wrapper class - public WorkloadGroup this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as WorkloadGroup; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(WorkloadGroup[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public WorkloadGroup ItemById(int id) - { - return (WorkloadGroup)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(WorkloadGroup); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new WorkloadGroup(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(WorkloadGroup workloadGroup) - { - AddImpl(workloadGroup); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/WorkloadManagementWorkloadClassifierCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/WorkloadManagementWorkloadClassifierCollection.cs index d9098417..96f5a20e 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/WorkloadManagementWorkloadClassifierCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/WorkloadManagementWorkloadClassifierCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class WorkloadManagementWorkloadClassifierCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal WorkloadManagementWorkloadClassifierCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public WorkloadManagementWorkloadClassifier this[Int32 index] - { - get - { - return GetObjectByIndex(index) as WorkloadManagementWorkloadClassifier; - } - } - - - // returns wrapper class - public WorkloadManagementWorkloadClassifier this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as WorkloadManagementWorkloadClassifier; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(WorkloadManagementWorkloadClassifier[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public WorkloadManagementWorkloadClassifier ItemById(int id) - { - return (WorkloadManagementWorkloadClassifier)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(WorkloadManagementWorkloadClassifier); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new WorkloadManagementWorkloadClassifier(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(WorkloadManagementWorkloadClassifier WorkloadManagementWorkloadClassifier) - { - AddImpl(WorkloadManagementWorkloadClassifier); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } + public sealed partial class WorkloadManagementWorkloadClassifierCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/WorkloadManagementWorkloadGroupCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/WorkloadManagementWorkloadGroupCollection.cs index 32ebfd79..4e548f08 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/WorkloadManagementWorkloadGroupCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/WorkloadManagementWorkloadGroupCollection.cs @@ -1,249 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 - - - -using Microsoft.SqlServer.Management.Sdk.Sfc; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of MAPPED_TYPE objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - public sealed class WorkloadManagementWorkloadGroupCollection : SimpleObjectCollectionBase - { - - - - - - - - - - - - - - - - - - - internal WorkloadManagementWorkloadGroupCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public WorkloadManagementWorkloadGroup this[Int32 index] - { - get - { - return GetObjectByIndex(index) as WorkloadManagementWorkloadGroup; - } - } - - - // returns wrapper class - public WorkloadManagementWorkloadGroup this[string name] - { - get - { - - - - - - - - return GetObjectByName(name) as WorkloadManagementWorkloadGroup; - - - - - - - - - - - - - - - - - - - - - - } - } - - - public void CopyTo(WorkloadManagementWorkloadGroup[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public WorkloadManagementWorkloadGroup ItemById(int id) - { - return (WorkloadManagementWorkloadGroup)GetItemById(id); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - protected override Type GetCollectionElementType() - { - return typeof(WorkloadManagementWorkloadGroup); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new WorkloadManagementWorkloadGroup(this, key, state); - } - - - - - - - - - - - - - - - - - - - - public void Add(WorkloadManagementWorkloadGroup WorkloadManagementWorkloadGroup) - { - AddImpl(WorkloadManagementWorkloadGroup); - } - - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - - - - if( null == name || name.Length == 0) - - throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); - return new SimpleObjectKey(name); - } - - - - - - - - - - - - - - - - - - - } -} + public sealed partial class WorkloadManagementWorkloadGroupCollection : SimpleObjectCollectionBase + { + } +} \ No newline at end of file diff --git a/src/Microsoft/SqlServer/Management/Smo/Collections/XmlSchemaCollectionCollection.cs b/src/Microsoft/SqlServer/Management/Smo/Collections/XmlSchemaCollectionCollection.cs index f239f88d..af79242e 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Collections/XmlSchemaCollectionCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/Collections/XmlSchemaCollectionCollection.cs @@ -1,170 +1,10 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. - -using System; -using System.Collections; -#pragma warning disable 1590, 1591, 1592, 1573, 1571, 1570, 1572, 1587 - - - - - - - - - - - - - - - - - - - - - - - - namespace Microsoft.SqlServer.Management.Smo { - /// - /// Strongly typed collection of MAPPED_TYPE objects - /// Supports indexing objects by their Name and Schema properties - /// - public sealed class XmlSchemaCollectionCollection : SchemaCollectionBase - { - - internal XmlSchemaCollectionCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - - public Database Parent - { - get - { - return this.ParentInstance as Database; - } - } - - - public XmlSchemaCollection this[Int32 index] - { - get - { - return GetObjectByIndex(index) as XmlSchemaCollection; - } - } - - public XmlSchemaCollection this[string name] - { - get - { - if (name == null) - { - throw new ArgumentNullException("name cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, GetDefaultSchema())) as XmlSchemaCollection; - } - } - - public XmlSchemaCollection this[string name, string schema] - { - get - { - if (name == null) - { - throw new ArgumentNullException("name cannot be null"); - } - else if (schema == null) - { - throw new ArgumentNullException("schema cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, schema)) as XmlSchemaCollection; - } - } - - public void CopyTo(XmlSchemaCollection[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public XmlSchemaCollection ItemById(int id) - { - return (XmlSchemaCollection)GetItemById(id); - } - - - protected override Type GetCollectionElementType() - { - return typeof(XmlSchemaCollection); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new XmlSchemaCollection(this, key, state); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - public void Add(XmlSchemaCollection xmlSchemaCollection) - { - if( null == xmlSchemaCollection ) - throw new FailedOperationException(ExceptionTemplates.AddCollection, this, new ArgumentNullException("xmlSchemaCollection")); - - AddImpl(xmlSchemaCollection); - } - - internal SqlSmoObject GetObjectByName(string name) - { - if (name == null) - { - throw new ArgumentNullException("schema cannot be null"); - } - - return GetObjectByKey(new SchemaObjectKey(name, GetDefaultSchema())); - } - - } + public sealed partial class XmlSchemaCollectionCollection : SchemaCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/ColumnBase.cs b/src/Microsoft/SqlServer/Management/Smo/ColumnBase.cs index f16125e7..7d4b2e87 100644 --- a/src/Microsoft/SqlServer/Management/Smo/ColumnBase.cs +++ b/src/Microsoft/SqlServer/Management/Smo/ColumnBase.cs @@ -1961,8 +1961,7 @@ public void UpdateStatistics(StatisticsScanType scanType, int sampleValue, bool /// private void ValidatePropertyChangeForText(Property prop, object value) { - SmoCollectionBase scb = this.ParentColl as SmoCollectionBase; - if (null != scb && scb.IsCollectionLocked) + if (ParentColl is ILockableCollection scb && scb.IsCollectionLocked) { Validate_set_ChildTextObjectDDLProperty(prop, value); } diff --git a/src/Microsoft/SqlServer/Management/Smo/ColumnEncryptionKeyValueCollectionBase.cs b/src/Microsoft/SqlServer/Management/Smo/ColumnEncryptionKeyValueCollectionBase.cs index 6d0d26b7..8b39b2c1 100644 --- a/src/Microsoft/SqlServer/Management/Smo/ColumnEncryptionKeyValueCollectionBase.cs +++ b/src/Microsoft/SqlServer/Management/Smo/ColumnEncryptionKeyValueCollectionBase.cs @@ -10,35 +10,29 @@ namespace Microsoft.SqlServer.Management.Smo /// /// ColumnEncryptionKeyValueCollectionBase /// - public abstract class ColumnEncryptionKeyValueCollectionBase : SortedListCollectionBase + public abstract class ColumnEncryptionKeyValueCollectionBase : SortedListCollectionBase { internal ColumnEncryptionKeyValueCollectionBase(SqlSmoObject parent) - : base(parent) + : base((ColumnEncryptionKey)parent) { } /// /// Internal Storage /// - protected override void InitInnerCollection() - { - InternalStorage = new SmoSortedList(new ColumnEncryptionKeyValueObjectComparer()); - } + protected override void InitInnerCollection() => InternalStorage = new SmoSortedList(new ColumnEncryptionKeyValueObjectComparer()); /// /// Contains Method /// /// Column Master Key Defintion ID /// Returns if there is a CEK value encrypted by the given CMK ID. - public bool Contains(int ColumnMasterKeyID) - { - return this.Contains(new ColumnEncryptionKeyValueObjectKey(ColumnMasterKeyID)); - } + public bool Contains(int ColumnMasterKeyID) => Contains(new ColumnEncryptionKeyValueObjectKey(ColumnMasterKeyID)); internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) { - int ColumnMasterKeyID = int.Parse(urn.GetAttribute("ColumnMasterKeyID"), SmoApplication.DefaultCulture); + var ColumnMasterKeyID = int.Parse(urn.GetAttribute("ColumnMasterKeyID"), SmoApplication.DefaultCulture); return new ColumnEncryptionKeyValueObjectKey(ColumnMasterKeyID); } @@ -51,10 +45,7 @@ internal ColumnEncryptionKeyValueObjectComparer() { } - public override int Compare(object obj1, object obj2) - { - return ((ColumnEncryptionKeyValueObjectKey)obj1).ColumnMasterKeyID - ((ColumnEncryptionKeyValueObjectKey)obj2).ColumnMasterKeyID; - } + public override int Compare(object obj1, object obj2) => ((ColumnEncryptionKeyValueObjectKey)obj1).ColumnMasterKeyID - ((ColumnEncryptionKeyValueObjectKey)obj2).ColumnMasterKeyID; } internal class ColumnEncryptionKeyValueObjectKey : ObjectKeyBase @@ -64,48 +55,30 @@ internal class ColumnEncryptionKeyValueObjectKey : ObjectKeyBase public ColumnEncryptionKeyValueObjectKey(int columnMasterKeyID) : base() { - this.ColumnMasterKeyID = columnMasterKeyID; + ColumnMasterKeyID = columnMasterKeyID; } static ColumnEncryptionKeyValueObjectKey() { - fields.Add("ColumnMasterKeyID"); + _ = fields.Add(nameof(ColumnMasterKeyID)); } internal static readonly StringCollection fields = new StringCollection(); - public override string ToString() - { - return string.Format(SmoApplication.DefaultCulture, "{0}", + public override string ToString() => string.Format(SmoApplication.DefaultCulture, "{0}", ColumnMasterKeyID); - } /// /// This is the one used for constructing the Urn /// - public override string UrnFilter - { - get { return string.Format(SmoApplication.DefaultCulture, "@ColumnMasterKeyID={0}", ColumnMasterKeyID); } - } + public override string UrnFilter => string.Format(SmoApplication.DefaultCulture, "@ColumnMasterKeyID={0}", ColumnMasterKeyID); - public override StringCollection GetFieldNames() - { - return fields; - } + public override StringCollection GetFieldNames() => fields; - public override ObjectKeyBase Clone() - { - return new ColumnEncryptionKeyValueObjectKey(this.ColumnMasterKeyID); - } + public override ObjectKeyBase Clone() => new ColumnEncryptionKeyValueObjectKey(ColumnMasterKeyID); - public override bool IsNull - { - get { return false; } - } + public override bool IsNull => false; - public override ObjectComparerBase GetComparer(IComparer stringComparer) - { - return new ColumnEncryptionKeyValueObjectComparer(); - } + public override ObjectComparerBase GetComparer(IComparer stringComparer) => new ColumnEncryptionKeyValueObjectComparer(); } } \ No newline at end of file diff --git a/src/Microsoft/SqlServer/Management/Smo/DatabasePrefetch.cs b/src/Microsoft/SqlServer/Management/Smo/DatabasePrefetch.cs index b9a92f81..d32ce7a7 100644 --- a/src/Microsoft/SqlServer/Management/Smo/DatabasePrefetch.cs +++ b/src/Microsoft/SqlServer/Management/Smo/DatabasePrefetch.cs @@ -738,10 +738,10 @@ private void GetIsSystemObjectForCollection(string urnSuffix) this.Database.GetServerObject().SetDefaultInitFields(typeof(T), origInitFields, this.Database.DatabaseEngineEdition); } - private void GetUserAndSystemObjects(SmoCollectionBase collection, ICollection userObjects, ICollection systemObjects) + private void GetUserAndSystemObjects(IEnumerable collection, ICollection userObjects, ICollection systemObjects) where T : SqlSmoObject { - foreach (T item in collection) + foreach (var item in collection) { if (!item.GetPropValueOptional("IsSystemObject", false)) { diff --git a/src/Microsoft/SqlServer/Management/Smo/DatabaseReplicaStateCollectionBase.cs b/src/Microsoft/SqlServer/Management/Smo/DatabaseReplicaStateCollectionBase.cs index e8554515..2c4e260a 100644 --- a/src/Microsoft/SqlServer/Management/Smo/DatabaseReplicaStateCollectionBase.cs +++ b/src/Microsoft/SqlServer/Management/Smo/DatabaseReplicaStateCollectionBase.cs @@ -10,29 +10,27 @@ namespace Microsoft.SqlServer.Management.Smo { /// - /// this is the class that contains common features of all schema collection classes + /// Collection of DatabaseReplicaState objects associated with an AvailabilityGroup /// - public class DatabaseReplicaStateCollectionBase : SortedListCollectionBase + public class DatabaseReplicaStateCollectionBase : SortedListCollectionBase { internal DatabaseReplicaStateCollectionBase(SqlSmoObject parent) - : base(parent) + : base((AvailabilityGroup)parent) { } + protected override string UrnSuffix => DatabaseReplicaState.UrnSuffix; + protected override void InitInnerCollection() { - InternalStorage = new SmoSortedList(new DatabaseReplicaStateObjectComparer(this.StringComparer)); + InternalStorage = new SmoSortedList(new DatabaseReplicaStateObjectComparer(StringComparer)); } - protected override Type GetCollectionElementType() - { - return typeof(DatabaseReplicaState); - } internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) { - string databaseName = urn.GetAttribute("AvailabilityDatabaseName"); - string replicaName = urn.GetAttribute("AvailabilityReplicaServerName"); + var databaseName = urn.GetAttribute("AvailabilityDatabaseName"); + var replicaName = urn.GetAttribute("AvailabilityReplicaServerName"); if (string.IsNullOrEmpty(databaseName)) { @@ -46,6 +44,11 @@ internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) return new DatabaseReplicaStateObjectKey(replicaName, databaseName); } + + internal override DatabaseReplicaState GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) + { + throw new NotImplementedException(); + } } internal class DatabaseReplicaStateObjectComparer : ObjectComparerBase @@ -57,16 +60,16 @@ public DatabaseReplicaStateObjectComparer(IComparer stringComparer) public override int Compare(object obj1, object obj2) { - DatabaseReplicaStateObjectKey dbr1 = obj1 as DatabaseReplicaStateObjectKey; - DatabaseReplicaStateObjectKey dbr2 = obj2 as DatabaseReplicaStateObjectKey; + var dbr1 = obj1 as DatabaseReplicaStateObjectKey; + var dbr2 = obj2 as DatabaseReplicaStateObjectKey; - Diagnostics.TraceHelper.Assert((null != dbr1 || null != dbr2), "Can't compare null objects for DatabaseReplicaState"); + Diagnostics.TraceHelper.Assert(null != dbr1 || null != dbr2, "Can't compare null objects for DatabaseReplicaState"); //We order first by Avaialbility Replica name, then by Database name - int replicaNameComparison = this.stringComparer.Compare(dbr1.ReplicaName, dbr2.ReplicaName); + var replicaNameComparison = stringComparer.Compare(dbr1.ReplicaName, dbr2.ReplicaName); if (replicaNameComparison == 0) { - return this.stringComparer.Compare(dbr1.DatabaseName, dbr2.DatabaseName); + return stringComparer.Compare(dbr1.DatabaseName, dbr2.DatabaseName); } else { @@ -81,15 +84,17 @@ internal class DatabaseReplicaStateObjectKey : ObjectKeyBase public DatabaseReplicaStateObjectKey(string replicaName, string databaseName) { - this.ReplicaName = replicaName; - this.DatabaseName = databaseName; + ReplicaName = replicaName; + DatabaseName = databaseName; } static DatabaseReplicaStateObjectKey() { - fields = new StringCollection(); - fields.Add("AvailabilityReplicaServerName"); - fields.Add("AvailabilityDatabaseName"); + fields = new StringCollection + { + "AvailabilityReplicaServerName", + "AvailabilityDatabaseName" + }; } public string ReplicaName @@ -108,7 +113,7 @@ public override string UrnFilter { get { - return string.Format(SmoApplication.DefaultCulture, "@AvailabilityReplicaServerName='{0}' and @AvailabilityDatabaseName='{1}'", SqlSmoObject.SqlString(this.ReplicaName), SqlSmoObject.SqlString(this.DatabaseName)); + return string.Format(SmoApplication.DefaultCulture, "@AvailabilityReplicaServerName='{0}' and @AvailabilityDatabaseName='{1}'", SqlSmoObject.SqlString(ReplicaName), SqlSmoObject.SqlString(DatabaseName)); } } @@ -119,7 +124,7 @@ public override StringCollection GetFieldNames() internal override void Validate(Type objectType) { - if (string.IsNullOrEmpty(this.ReplicaName) || string.IsNullOrEmpty(this.DatabaseName)) + if (string.IsNullOrEmpty(ReplicaName) || string.IsNullOrEmpty(DatabaseName)) { throw new UnsupportedObjectNameException(ExceptionTemplates.UnsupportedObjectNameExceptionText(objectType.ToString())).SetHelpContext("UnsupportedObjectNameExceptionText"); } @@ -129,18 +134,18 @@ public override bool IsNull { get { - return null == this.DatabaseName || null == this.ReplicaName; + return null == DatabaseName || null == ReplicaName; } } public override string GetExceptionName() { - return string.Format(SmoApplication.DefaultCulture, "Database {1} in Availability Replica {0}", this.ReplicaName, this.DatabaseName); + return string.Format(SmoApplication.DefaultCulture, "Database {1} in Availability Replica {0}", ReplicaName, DatabaseName); } public override ObjectKeyBase Clone() { - return new DatabaseReplicaStateObjectKey(this.ReplicaName, this.DatabaseName); + return new DatabaseReplicaStateObjectKey(ReplicaName, DatabaseName); } public override ObjectComparerBase GetComparer(IComparer stringComparer) @@ -150,7 +155,7 @@ public override ObjectComparerBase GetComparer(IComparer stringComparer) public override string ToString() { - return string.Format(SmoApplication.DefaultCulture, "{0}/{1}", this.ReplicaName, this.DatabaseName); + return string.Format(SmoApplication.DefaultCulture, "{0}/{1}", ReplicaName, DatabaseName); } } } diff --git a/src/Microsoft/SqlServer/Management/Smo/DefaultRuleBase.cs b/src/Microsoft/SqlServer/Management/Smo/DefaultRuleBase.cs index b67f9d25..5173828a 100644 --- a/src/Microsoft/SqlServer/Management/Smo/DefaultRuleBase.cs +++ b/src/Microsoft/SqlServer/Management/Smo/DefaultRuleBase.cs @@ -9,10 +9,12 @@ using Microsoft.SqlServer.Management.Sdk.Sfc.Metadata; using Cmn = Microsoft.SqlServer.Management.Common; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 namespace Microsoft.SqlServer.Management.Smo { - public class DefaultRuleBase : ScriptSchemaObjectBase, Cmn.ICreatable, Cmn.IDroppable, Cmn.IDropIfExists, Cmn.IAlterable, IExtendedProperties, IScriptable, ITextObject + /// + /// Base class for Rules + /// + public partial class DefaultRuleBase : ScriptSchemaObjectBase, Cmn.ICreatable, Cmn.IDroppable, Cmn.IDropIfExists, Cmn.IAlterable, IExtendedProperties, IScriptable, ITextObject { internal DefaultRuleBase(AbstractCollectionBase parentColl, ObjectKeyBase key, SqlSmoState state) : base(parentColl, key, state) diff --git a/src/Microsoft/SqlServer/Management/Smo/EndpointBase.cs b/src/Microsoft/SqlServer/Management/Smo/EndpointBase.cs index 60628038..385aa67f 100644 --- a/src/Microsoft/SqlServer/Management/Smo/EndpointBase.cs +++ b/src/Microsoft/SqlServer/Management/Smo/EndpointBase.cs @@ -921,7 +921,7 @@ public override void Refresh() } } - public sealed partial class EndpointCollection : SimpleObjectCollectionBase + public sealed partial class EndpointCollection { public Endpoint[] EnumEndpoints(EndpointType endpointType) { diff --git a/src/Microsoft/SqlServer/Management/Smo/ExceptionTemplatesImpl.strings b/src/Microsoft/SqlServer/Management/Smo/ExceptionTemplatesImpl.strings index b3a0d612..d8d10a98 100644 --- a/src/Microsoft/SqlServer/Management/Smo/ExceptionTemplatesImpl.strings +++ b/src/Microsoft/SqlServer/Management/Smo/ExceptionTemplatesImpl.strings @@ -437,6 +437,7 @@ NotSupportedForVersionEarlierThan140 = This method or property is not supported NotSupportedForVersionEarlierThan150 = This method or property is not supported while working against a version earlier than SQL Server 2019. PropertySupportedOnlyOn110SP1(string propertyName) = The '{0}' property is accessible only while working against SQL Server 2012 Service Pack 1 or later. PropertySupportedOnlyOn110(string propertyName) = The '{0}' property is accessible only while working against SQL Server 2012 or later. +PropertySupportedOnlyOn170(string propertyName) = The '{0}' property is accessible only while working against SQL Server 2025 or later. PropertyNotSupportedForCloudVersion(string propertyName, string version) = The '{0}' property is not supported on version '{1}' of Microsoft Azure SQL Database. PropertyNotSupportedOnStandalone(string propertyName) = The '{0}' property is not supported on Standalone SQL Server. PropertyNotSupportedOnCloud(string propertyName) = The '{0}' property is not supported on Microsoft Azure SQL Database. @@ -491,6 +492,7 @@ NoXmlIndexUnique = An XML index cannot be unique. NoXmlIndexClustered = An XML index cannot be clustered. UnsupportedNonXmlParameters=Cannot specify ParentXmlIndex or SecondaryXmlIndexType for non-XML indexes. UnsupportedNonVectorParameters=Cannot specify VectorIndexMetric or VectorIndexType for non-Vector indexes. +UnsupportedNonJsonIndexParameters=Cannot specify JsonIndexPaths or JsonIndexBuildProperties for non-JSON indexes. CantSetDefaultFalse = The IsDefault property cannot be set to false. Please select another file group and try to make it default. TimeoutMustBePositive = A positive value must be supplied for the transaction termination time. NoPropertyChangeForDotNet(string propertyName) = The {0} property cannot be changed for .NET run-time routines. @@ -1295,6 +1297,7 @@ ConflictingIndexProperties=Cannot set the property '{0}' to '{1}' because the pr SelectiveXmlIndexDoesNotSupportReorganize=Selective Xml Index cannot be modified. MoreThenOneXmlDefaultNamespace=There can not be more than one default namespace on index '{0}'. SecondarySelectiveXmlIndexModify=Secondary Selective Xml Index cannot be modified +JsonIndexAlter=Altering JSON indexes is not currently supported. UnsupportedPropertyForSXI(string propertyName)=The property '{0}' is not supported for Selective Xml Index. InvaildSXIOption=Cannot use the following options with a Selective XML index: ONLINE. UnsupportedValueForSXI(string value, string propertyName, string suggestion)=Value '{0}' is not supported for property '{1}' with respect to Selective Xml Index. '{2}' diff --git a/src/Microsoft/SqlServer/Management/Smo/FullTextCatalogBase.cs b/src/Microsoft/SqlServer/Management/Smo/FullTextCatalogBase.cs index 78f753c7..87506f72 100644 --- a/src/Microsoft/SqlServer/Management/Smo/FullTextCatalogBase.cs +++ b/src/Microsoft/SqlServer/Management/Smo/FullTextCatalogBase.cs @@ -501,10 +501,10 @@ internal void Validate_set_IsDefault(Property prop, object newValue) if ((bool)newValue) { - SmoInternalStorage cats = ((FullTextCatalogCollection)ParentColl).InternalStorage; + var cats = ((ISmoInternalCollection)ParentColl).InternalStorage; foreach (FullTextCatalog cat in cats) { - Property pDef = cat.Properties.Get("IsDefault"); + var pDef = cat.Properties.Get(nameof(FullTextCatalog.IsDefault)); if (this != cat && (bool)pDef.Value && cat.State == SqlSmoState.Creating) diff --git a/src/Microsoft/SqlServer/Management/Smo/IndexBase.cs b/src/Microsoft/SqlServer/Management/Smo/IndexBase.cs index 02b039e5..253664e3 100644 --- a/src/Microsoft/SqlServer/Management/Smo/IndexBase.cs +++ b/src/Microsoft/SqlServer/Management/Smo/IndexBase.cs @@ -23,7 +23,7 @@ namespace Microsoft.SqlServer.Management.Smo [Microsoft.SqlServer.Management.Sdk.Sfc.PhysicalFacet] public partial class Index : ScriptNameObjectBase, Cmn::ICreatable, Cmn::IDroppable, Cmn::IDropIfExists, Cmn::IMarkForDrop, Cmn::IAlterable, Cmn::IRenamable, - IExtendedProperties, IScriptable + IExtendedProperties, IScriptable, IPartitionable { bool m_bIsOnComputed; bool xmlOrSpatialIndex; @@ -40,6 +40,7 @@ internal Index(AbstractCollectionBase parentColl, ObjectKeyBase key, SqlSmoState base(parentColl, key, state) { m_IndexedColumns = null; + m_IndexedJsonPaths = null; m_IndexedXmlPaths = null; m_IndexedXmlPathNamespaces = null; m_ExtendedProperties = null; @@ -124,6 +125,31 @@ public IndexedColumnCollection IndexedColumns } } + /// + /// Collection of IndexedJsonPath objects that represent all the paths + /// that are indexed by the JSON Index. + /// + private IndexedJsonPathCollection m_IndexedJsonPaths = null; + + /// + /// Collection of IndexedJsonPath objects that represent all the paths + /// that are indexed by the JSON Index. + /// + [SfcObject(SfcContainerRelationship.ChildContainer, SfcContainerCardinality.OneToAny, typeof(IndexedJsonPath), SfcObjectFlags.Design | SfcObjectFlags.Deploy | SfcObjectFlags.NaturalOrder)] + public IndexedJsonPathCollection IndexedJsonPaths + { + get + { + CheckObjectState(); + this.ThrowIfNotSupported(typeof(IndexedJsonPath)); + if (null == m_IndexedJsonPaths) + { + m_IndexedJsonPaths = new IndexedJsonPathCollection(this); + } + return m_IndexedJsonPaths; + } + } + /// /// Collection of IndexedXMLPath objects that represent all the paths /// that are indexed by the Selective XML Index. @@ -327,6 +353,8 @@ protected override void MarkDropped() { m_PartitionSchemeParameters.MarkAllDropped(); } + + m_IndexedJsonPaths?.MarkAllDropped(); } internal bool IsDirty(string property) @@ -874,6 +902,19 @@ private void CheckUnsupportedSXI(bool checkPrimarySXI, bool checkSecondarySXI, s } } + /// + /// Raises FailedOperationException if index is a JSON Index. + /// + /// Operation which raised exception + private void CheckUnsupportedJsonIndex(string operation) + { + Nullable indexType = this.GetPropValueOptional("IndexType"); + if (indexType.HasValue && indexType.Value == IndexType.JsonIndex) + { + throw new FailedOperationException(operation, this, null, operation); + } + } + /// /// Changes the index based on supplied index properties /// @@ -881,6 +922,7 @@ public void Alter() { CheckUnsupportedSXI(false, true, ExceptionTemplates.Alter, ExceptionTemplates.SecondarySelectiveXmlIndexModify); + CheckUnsupportedJsonIndex(ExceptionTemplates.JsonIndexAlter); if (ParentColl.ParentInstance is UserDefinedTableType) { @@ -897,6 +939,7 @@ public void Alter() public void Alter(IndexOperation operation) { CheckUnsupportedSXI(false, true, ExceptionTemplates.Alter, ExceptionTemplates.SecondarySelectiveXmlIndexModify); + CheckUnsupportedJsonIndex(ExceptionTemplates.JsonIndexAlter); if (ParentColl.ParentInstance is UserDefinedTableType) { @@ -979,6 +1022,7 @@ internal override void ScriptAlter(StringCollection alterQuery, ScriptingPrefere throw new InvalidSmoOperationException(ExceptionTemplates.OperationNotSupportedWhenPartOfAUDF); } + CheckUnsupportedJsonIndex(ExceptionTemplates.JsonIndexAlter); // Alter is only supported with the HK hash index. // @@ -2483,7 +2527,8 @@ internal static string[] GetScriptFields(Type parentType, "IsOptimizedForSequentialKey", nameof(HasXmlCompressedPartitions), nameof(VectorIndexMetric), - nameof(VectorIndexType) + nameof(VectorIndexType), + nameof(OptimizeForArraySearch) }; List list = GetSupportedScriptFields(typeof(Index.PropertyMetadataProvider), fields, version, databaseEngineType, databaseEngineEdition); @@ -2679,5 +2724,19 @@ internal bool IsSqlDwIndex return isSqlDwIndex; } } + + /// + /// Returns the PartitionSchemeParameters associated with the index partition scheme + /// + IEnumerable IPartitionable.PartitionSchemeParameters => PartitionSchemeParameters; + /// + /// Returns the PartitioningScheme associated with this object type + /// + public PartitioningScheme SchemeType => PartitioningScheme.Index; + /// + /// Returns the ColumnCollection of the parent of the index + /// + ColumnCollection IColumns.Columns => ((TableViewBase)Parent).Columns; + } } \ No newline at end of file diff --git a/src/Microsoft/SqlServer/Management/Smo/IndexScripter.cs b/src/Microsoft/SqlServer/Management/Smo/IndexScripter.cs index 277dac34..55bd5abd 100644 --- a/src/Microsoft/SqlServer/Management/Smo/IndexScripter.cs +++ b/src/Microsoft/SqlServer/Management/Smo/IndexScripter.cs @@ -171,6 +171,19 @@ protected void CheckVectorProperties() } } + /// + /// Check json properties are not set for non json index + /// + protected void CheckJsonProperties() + { + // Check that JSON index specific properties are not set for non-JSON indexes + if (index.IsSupportedProperty(nameof(Index.OptimizeForArraySearch))) + { + Exception exception = new SmoException(ExceptionTemplates.UnsupportedNonJsonIndexParameters); + this.CheckProperty(nameof(Index.OptimizeForArraySearch), false, exception); + } + } + /// /// Check non clustered properties are not set for non applicable index /// @@ -438,7 +451,8 @@ protected void ScriptIndexOptionOnline(StringBuilder sb) /// protected void ScriptIndexOptionOnline(StringBuilder sb, bool forRebuild, bool forCreateIndex) { - if (!preferences.TargetEngineIsAzureStretchDb() && index.GetPropValueOptional(nameof(Index.IndexType)) != IndexType.VectorIndex) + if (!preferences.TargetEngineIsAzureStretchDb() + && index.GetPropValueOptional(nameof(Index.IndexType)) != IndexType.VectorIndex) { StringBuilder onlinePropertiesSb = new StringBuilder(GetOnOffValue(index.onlineIndexOperation)); @@ -1540,6 +1554,8 @@ public static IndexScripter GetIndexScripter(Index index, ScriptingPreferences s return new SpatialIndexScripter(index, sp); case IndexType.VectorIndex: return new VectorIndexScripter(index, sp); + case IndexType.JsonIndex: + return new JsonIndexScripter(index, sp); case IndexType.NonClusteredColumnStoreIndex: return new NonClusteredColumnStoreIndexScripter(index, sp); case IndexType.NonClusteredHashIndex: @@ -1612,6 +1628,7 @@ protected override void Validate() this.CheckNonClusteredProperties(); this.CheckXmlProperties(); this.CheckVectorProperties(); + this.CheckJsonProperties(); this.CheckSpatialProperties(); } @@ -1803,6 +1820,7 @@ protected override void Validate() this.CheckConflictingProperties(); this.CheckXmlProperties(); this.CheckVectorProperties(); + this.CheckJsonProperties(); this.CheckSpatialProperties(); } @@ -2104,6 +2122,8 @@ protected override void Validate() this.CheckClusteredProperties(); this.CheckNonClusteredProperties(); this.CheckSpatialProperties(); + this.CheckJsonProperties(); + this.CheckVectorProperties(); } protected override void ScriptIndexStorage(StringBuilder sb) @@ -2229,6 +2249,7 @@ protected override void Validate() this.CheckNonClusteredProperties(); this.CheckXmlProperties(); this.CheckVectorProperties(); + this.CheckJsonProperties(); } protected override void ScriptCreateHeaderDdl(StringBuilder sb) @@ -2444,6 +2465,9 @@ protected override void ScriptIndexStorage(StringBuilder sb) private class VectorIndexScripter : IndexScripter { + Property vectorIndexMetric; + Property vectorIndexType; + public VectorIndexScripter(Index index, ScriptingPreferences sp) : base(index, sp) { @@ -2459,6 +2483,7 @@ protected override void Validate() this.CheckNonClusteredProperties(); this.CheckXmlProperties(); this.CheckSpatialProperties(); + this.CheckJsonProperties(); } protected override void ScriptCreateHeaderDdl(StringBuilder sb) @@ -2476,19 +2501,21 @@ protected override void ScriptIndexOptions(StringBuilder sb) private void ScriptVectorIndexOptions(StringBuilder sb) { - var vectorIndexMetric = index.GetPropValueOptional(nameof(Index.VectorIndexMetric), string.Empty); - var vectorIndexType = index.GetPropValueOptional(nameof(Index.VectorIndexType), string.Empty); + vectorIndexMetric = index.Properties.Get(nameof(Index.VectorIndexMetric)); + vectorIndexType = index.Properties.Get(nameof(Index.VectorIndexType)); // Script METRIC parameter - if (!string.IsNullOrEmpty(vectorIndexMetric)) + var strMetric = vectorIndexMetric.Value as string; + var strType = vectorIndexType.Value as string; + if (!string.IsNullOrEmpty(strMetric)) { - _ = sb.AppendFormat(SmoApplication.DefaultCulture, $"METRIC = '{SqlSmoObject.SqlString(vectorIndexMetric)}'{Globals.commaspace}"); + _ = sb.AppendFormat(SmoApplication.DefaultCulture, $"METRIC = '{SqlSmoObject.SqlString(strMetric)}'{Globals.commaspace}"); } // Script TYPE parameter - if (!string.IsNullOrEmpty(vectorIndexType)) + if (!string.IsNullOrEmpty(strType)) { - _ = sb.AppendFormat(SmoApplication.DefaultCulture, $"TYPE = '{SqlSmoObject.SqlString(vectorIndexType)}'{Globals.commaspace}"); + _ = sb.AppendFormat(SmoApplication.DefaultCulture, $"TYPE = '{SqlSmoObject.SqlString(strType)}'{Globals.commaspace}"); } } @@ -2501,6 +2528,106 @@ protected override void ScriptIndexStorage(StringBuilder sb) } } + private class JsonIndexScripter : IndexScripter + { + public JsonIndexScripter(Index index, ScriptingPreferences sp) + : base(index, sp) + { + } + + protected override void Validate() + { + this.index.ThrowIfPropertyNotSupported(nameof(Index.OptimizeForArraySearch), preferences); + + this.CheckConstraintProperties(); + this.CheckRegularIndexProperties(); + this.CheckClusteredProperties(); + this.CheckNonClusteredProperties(); + this.CheckXmlProperties(); + this.CheckSpatialProperties(); + this.CheckVectorProperties(); + } + + protected override void ScriptCreateHeaderDdl(StringBuilder sb) + { + sb.AppendFormat(SmoApplication.DefaultCulture, "CREATE JSON INDEX {0} ON {1}", + index.FormatFullNameForScripting(preferences), + parent.FormatFullNameForScripting(preferences)); + } + + protected override void ScriptIndexDetails(StringBuilder sb) + { + this.ScriptJsonPaths(sb); + } + + private void ScriptJsonPaths(StringBuilder sb) + { + // Script JSON index paths from IndexedJsonPaths collection + // Syntax: FOR ("path1", "path2", ...) + if (this.index.IndexedJsonPaths?.Count > 0) + { + sb.Append(preferences.NewLine); + sb.AppendFormat(SmoApplication.DefaultCulture, "FOR"); + sb.Append(preferences.NewLine); + sb.AppendFormat(SmoApplication.DefaultCulture, Globals.LParen); + + for (int i = 0; i < this.index.IndexedJsonPaths.Count; i++) + { + IndexedJsonPath path = this.index.IndexedJsonPaths[i]; + + // Quote the path value + sb.AppendFormat(SmoApplication.DefaultCulture, $"'{SqlString(path.Path)}'"); + + if (i != this.index.IndexedJsonPaths.Count - 1) + { + sb.AppendFormat(SmoApplication.DefaultCulture, Globals.commaspace); + } + } + + sb.AppendFormat(SmoApplication.DefaultCulture, Globals.RParen); + sb.Append(preferences.NewLine); + } + } + + protected override void ScriptIndexOptions(StringBuilder sb) + { + // Only the following options are valid for json index and need to be scripted: + // OPTIMIZE_FOR_ARRAY_SEARCH + // PAD_INDEX + // FILLFACTOR + // ALLOW_PAGE_LOCKS + // ALLOW_ROW_LOCKS + // DATA_COMPRESSION + + // Script OPTIMIZE_FOR_ARRAY_SEARCH option if set + if (index.IsSupportedProperty(nameof(Index.OptimizeForArraySearch)) && + index.GetPropValueOptional(nameof(Index.OptimizeForArraySearch), false)) + { + sb.AppendFormat(SmoApplication.DefaultCulture, "OPTIMIZE_FOR_ARRAY_SEARCH = ON"); + sb.Append(Globals.commaspace); + } + + // Script PAD_INDEX option + this.ScriptIndexOption(sb, "PAD_INDEX", GetOnOffValue(index.GetPropValueOptional(nameof(PadIndex)))); + + // Script FILLFACTOR option + this.ScriptFillFactor(sb); + + // Script ALLOW_ROW_LOCKS and ALLOW_PAGE_LOCKS options + this.ScriptIndexOption(sb, "ALLOW_ROW_LOCKS", GetOnOffValue(RevertMeaning(index.GetPropValueOptional("DisallowRowLocks")))); + this.ScriptIndexOption(sb, "ALLOW_PAGE_LOCKS", GetOnOffValue(RevertMeaning(index.GetPropValueOptional("DisallowPageLocks")))); + + // Script DATA_COMPRESSION option + this.ScriptCompression(sb); + } + + protected override void ScriptIndexStorage(StringBuilder sb) + { + // Filegroup option is not supported for JSON indexes + return; + } + } + private abstract class ColumnstoreIndexScripter : IndexScripter { public ColumnstoreIndexScripter(Index index, ScriptingPreferences sp) @@ -2626,6 +2753,8 @@ protected override void Validate() this.CheckXmlProperties(); this.CheckSpatialProperties(); this.CheckInvalidOptions(); + this.CheckJsonProperties(); + this.CheckVectorProperties(); } protected override void ScriptCreateHeaderDdl(StringBuilder sb) @@ -2692,6 +2821,8 @@ protected override void Validate() this.CheckNonClusteredProperties(); this.CheckXmlProperties(); this.CheckSpatialProperties(); + this.CheckJsonProperties(); + this.CheckVectorProperties(); } } @@ -2809,6 +2940,7 @@ protected override void Validate() this.CheckNonClusteredProperties(); this.CheckXmlProperties(); this.CheckSpatialProperties(); + this.CheckJsonProperties(); } } @@ -2982,6 +3114,8 @@ protected override void Validate() this.CheckNonClusteredProperties(); this.CheckSpatialProperties(); this.CheckInvalidOptions(); + this.CheckJsonProperties(); + this.CheckVectorProperties(); //Check for more then one default namespace bool defaultNameSpaceFound = false; @@ -3281,6 +3415,8 @@ protected override void Validate() this.CheckNonClusteredProperties(); this.CheckSpatialProperties(); this.CheckInvalidOptions(); + this.CheckJsonProperties(); + this.CheckVectorProperties(); } /// diff --git a/src/Microsoft/SqlServer/Management/Smo/IndexedJsonPathBase.cs b/src/Microsoft/SqlServer/Management/Smo/IndexedJsonPathBase.cs new file mode 100644 index 00000000..3f1f032a --- /dev/null +++ b/src/Microsoft/SqlServer/Management/Smo/IndexedJsonPathBase.cs @@ -0,0 +1,59 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +using System; +using System.Collections.Generic; +using Microsoft.SqlServer.Management.Sdk.Sfc; + +using Microsoft.SqlServer.Management.Sdk.Sfc.Metadata; +using Cmn = Microsoft.SqlServer.Management.Common; + +namespace Microsoft.SqlServer.Management.Smo +{ + public partial class IndexedJsonPath : SqlSmoObject + { + internal IndexedJsonPath(AbstractCollectionBase parentColl, ObjectKeyBase key, SqlSmoState state) : + base(parentColl, key, state) + { + } + + /// + /// Constructor for creating a new IndexedJsonPath with the specified parent index and path. + /// + /// The parent Index object + /// The JSON path (e.g., "$.customer.name") + public IndexedJsonPath(Index parent, string path) + : base() + { + this.key = new IndexedJsonPathObjectKey(path); + this.SetParentImpl(parent); + this.Path = path; + } + + /// + /// Returns the value of urn expresion. + /// + public static string UrnSuffix + { + get + { + return nameof(IndexedJsonPath); + } + } + + internal static string[] GetScriptFields(Type parentType, + Microsoft.SqlServer.Management.Common.ServerVersion version, + Cmn.DatabaseEngineType databaseEngineType, + Cmn.DatabaseEngineEdition databaseEngineEdition, + bool defaultTextMode) + { + string[] fields = + { + nameof(Path), + }; + + List list = GetSupportedScriptFields(typeof(IndexedJsonPath.PropertyMetadataProvider), fields, version, databaseEngineType, databaseEngineEdition); + return list.ToArray(); + } + } +} diff --git a/src/Microsoft/SqlServer/Management/Smo/JobBase.cs b/src/Microsoft/SqlServer/Management/Smo/JobBase.cs index 2c4aab61..dbb20436 100644 --- a/src/Microsoft/SqlServer/Management/Smo/JobBase.cs +++ b/src/Microsoft/SqlServer/Management/Smo/JobBase.cs @@ -8,6 +8,7 @@ using System.Data; using System.Globalization; +using System.Linq; using System.Text; using Microsoft.SqlServer.Management.Sdk.Sfc; using Microsoft.SqlServer.Management.Sdk.Sfc.Metadata; @@ -71,9 +72,11 @@ public JobObjectKey(string name, int categoryID) static JobObjectKey() { - jobObjectKeySingleton.jobKeyFields = new StringCollection(); - jobObjectKeySingleton.jobKeyFields.Add("Name"); - jobObjectKeySingleton.jobKeyFields.Add("CategoryID"); + jobObjectKeySingleton.jobKeyFields = new StringCollection + { + nameof(Name), + nameof(CategoryID) + }; } /// @@ -82,7 +85,7 @@ static JobObjectKey() /// public override string ToString() { - return name; + return Name; } /// @@ -96,11 +99,11 @@ public override string UrnFilter if (this.categoryID == -1) { // This should never get called when all clients are fixed - return string.Format(SmoApplication.DefaultCulture, "@Name='{0}'", Urn.EscapeString(name)); + return string.Format(SmoApplication.DefaultCulture, "@Name='{0}'", Urn.EscapeString(Name)); } else { - return string.Format(SmoApplication.DefaultCulture, "@Name='{0}' and @CategoryID='{1}'", Urn.EscapeString(name), this.categoryID.ToString(SmoApplication.DefaultCulture)); + return string.Format(SmoApplication.DefaultCulture, "@Name='{0}' and @CategoryID='{1}'", Urn.EscapeString(Name), this.categoryID.ToString(SmoApplication.DefaultCulture)); } } } @@ -120,7 +123,7 @@ public override StringCollection GetFieldNames() /// public override ObjectKeyBase Clone() { - return new JobObjectKey(this.name, this.categoryID); + return new JobObjectKey(Name, categoryID); } internal override void Validate(Type objectType) @@ -147,12 +150,13 @@ public override ObjectComparerBase GetComparer(IComparer stringComparer) } } - // here we have this customized collection - - public class JobCollection : ArrayListCollectionBase + /// + /// A collection of Job objects associated with a JobServer + /// + public class JobCollection : ArrayListCollectionBase { internal JobCollection(SqlSmoObject parent) - : base(parent) + : base((JobServer)parent) { } @@ -161,7 +165,7 @@ internal JobCollection(SqlSmoObject parent) /// protected override void InitInnerCollection() { - InternalStorage = new SmoArrayList(new JobObjectComparer(this.StringComparer), this); + InternalStorage = new SmoArrayList(new JobObjectComparer(this.StringComparer), this); } public bool Contains(string name) @@ -248,13 +252,8 @@ public JobServer Parent } } - public Job this[Int32 index] - { - get - { - return GetObjectByIndex(index) as Job; - } - } + protected override string UrnSuffix => Job.UrnSuffix; + public Job this[string name] { @@ -282,14 +281,10 @@ public Job this[string name] } } - public void CopyTo(Job[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } public StringCollection Script() { - return this.Script(new ScriptingOptions()); + return Script(new ScriptingOptions()); } public StringCollection Script(ScriptingOptions scriptingOptions) @@ -310,37 +305,17 @@ public StringCollection Script(ScriptingOptions scriptingOptions) return scr.Script(scriptList); } - protected override Type GetCollectionElementType() - { - return typeof(Job); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new Job(this, key, state); - } public void Add(Job job) { AddImpl(job); } - internal SqlSmoObject GetObjectByName(string name) + internal override SqlSmoObject GetObjectByName(string name) { - IEnumerator ie = GetEnumerator(); - while (ie.MoveNext()) - { - Job mt = (Job)ie.Current; - if (this.StringComparer.Compare(mt.Name, name) == 0) - { - return mt; - } - } - - return null; + return this.FirstOrDefault(j => StringComparer.Compare(j.Name, name) == 0); } - - internal override SqlSmoObject GetObjectByKey(ObjectKeyBase key) + internal override Job GetObjectByKey(ObjectKeyBase key) { JobObjectKey jkey = (JobObjectKey)key; // Find the best match @@ -369,6 +344,7 @@ internal override SqlSmoObject GetObjectByKey(ObjectKeyBase key) } + internal override Job GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) => new Job(this, key, state); } public partial class Job : AgentObjectBase, Cmn.IAlterable, Cmn.ICreatable, Cmn.IDroppable, Cmn.IDropIfExists, Cmn.IRenamable, IScriptable @@ -949,21 +925,23 @@ public JobStepCollection JobSteps } } - private JobScheduleCollection jobSchedules; + private JobScheduleCollection jobSchedules; /// /// JobSchedules /// /// [SfcObject(SfcContainerRelationship.ChildContainer, SfcContainerCardinality.ZeroToAny, typeof(JobSchedule))] - public JobScheduleCollection JobSchedules + public JobScheduleCollection JobSchedules { get { CheckObjectState(); if (null == jobSchedules) { - jobSchedules = new JobScheduleCollection(this); - jobSchedules.AcceptDuplicateNames = true; + jobSchedules = new JobScheduleCollection(this) + { + AcceptDuplicateNames = true + }; } return jobSchedules; } diff --git a/src/Microsoft/SqlServer/Management/Smo/JobScheduleBase.cs b/src/Microsoft/SqlServer/Management/Smo/JobScheduleBase.cs index c6885cde..fa8c95cb 100644 --- a/src/Microsoft/SqlServer/Management/Smo/JobScheduleBase.cs +++ b/src/Microsoft/SqlServer/Management/Smo/JobScheduleBase.cs @@ -9,7 +9,6 @@ using Microsoft.SqlServer.Management.Sdk.Sfc.Metadata; using Cmn = Microsoft.SqlServer.Management.Common; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 namespace Microsoft.SqlServer.Management.Smo.Agent { public class ScheduleBase : AgentObjectBase @@ -22,7 +21,7 @@ internal ScheduleBase(AbstractCollectionBase parentColl, ObjectKeyBase key, SqlS internal protected ScheduleBase() : base() { } [SfcProperty(SfcPropertyFlags.Standalone)] - public Int32 ID + public int ID { get { @@ -30,8 +29,8 @@ public Int32 ID // different, then the one in the 'key' takes precedence. // The user can only change the ID through the property bag, // so inconsistency should not be a problem. - int id = ((ScheduleObjectKey)key).ID; - if( id == JobScheduleCollectionBase.GetDefaultID() ) + var id = ((ScheduleObjectKey)key).ID; + if( id == JobScheduleConstants.DefaultID) { Property propID = Properties["ID"]; if( propID.Retrieved || propID.Dirty ) @@ -50,7 +49,7 @@ protected void SetId(int id) internal override ObjectKeyBase GetEmptyKey() { - return new ScheduleObjectKey(null, JobScheduleCollectionBase.GetDefaultID()); + return new ScheduleObjectKey(null, JobScheduleConstants.DefaultID); } } @@ -63,7 +62,7 @@ public JobSchedule() : base(){ } public JobSchedule(SqlSmoObject parent, string name) : base() { ValidateName(name); - key = new ScheduleObjectKey(name, JobScheduleCollectionBase.GetDefaultID()); + key = new ScheduleObjectKey(name, JobScheduleConstants.DefaultID); Parent = parent; } @@ -72,7 +71,9 @@ internal JobSchedule(AbstractCollectionBase parentColl, ObjectKeyBase key, SqlSm { } - // returns the name of the type in the urn expression + /// + /// Returns the name of the type in the urn expression + /// public static string UrnSuffix { get @@ -380,7 +381,7 @@ public Guid[] EnumJobReferences() r.Fields = new string[]{}; r.ParentPropertiesRequests = new PropertiesRequest[1]; PropertiesRequest parentProps = new PropertiesRequest(); - parentProps.Fields = new String[]{ "JobID"}; + parentProps.Fields = new string[]{ "JobID"}; r.ParentPropertiesRequests[0] = parentProps; DataTable jobs = ExecutionManager.GetEnumeratorData( r ); diff --git a/src/Microsoft/SqlServer/Management/Smo/JobScheduleCollectionBase.cs b/src/Microsoft/SqlServer/Management/Smo/JobScheduleCollectionBase.cs index 60bfefd1..bf361e8d 100644 --- a/src/Microsoft/SqlServer/Management/Smo/JobScheduleCollectionBase.cs +++ b/src/Microsoft/SqlServer/Management/Smo/JobScheduleCollectionBase.cs @@ -7,179 +7,165 @@ using Microsoft.SqlServer.Management.Sdk.Sfc; using Microsoft.SqlServer.Management.Smo.Agent; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 namespace Microsoft.SqlServer.Management.Smo { - // this is the class that contains common features of all schema collection classes - - public class JobScheduleCollectionBase : ArrayListCollectionBase - { - internal JobScheduleCollectionBase(SqlSmoObject parent) : base(parent) - { - } - - protected override void InitInnerCollection() - { - InternalStorage = new SmoArrayList(new ScheduleObjectComparer(this.StringComparer), this); - } - - internal void RemoveObject(string name, int id) - { - InternalStorage.Remove(new ScheduleObjectKey(name, id)); - } - - public bool Contains(String name) - { - return this.Contains(new ScheduleObjectKey(name, GetDefaultID())); - } - - public bool Contains(String name, int id) - { - return this.Contains(new ScheduleObjectKey(name, id)); - } - - internal static int GetDefaultID() - { - return -1; - } - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - if (null == name || (name.Length == 0 && !CanHaveEmptyName(urn))) + /// + /// A collection of JobSchedule objects associated with an instance of TParent + /// + /// + public class JobScheduleCollectionBase : ArrayListCollectionBase + where TParent : SqlSmoObject + { + protected override string UrnSuffix => JobSchedule.UrnSuffix; + + internal JobScheduleCollectionBase(SqlSmoObject parent) : base((TParent)parent) + { + } + + protected override void InitInnerCollection() => InternalStorage = new SmoArrayList(new ScheduleObjectComparer(StringComparer), this); + + internal void RemoveObject(string name, int id) => InternalStorage.Remove(new ScheduleObjectKey(name, id)); + + public bool Contains(string name) => Contains(new ScheduleObjectKey(name, GetDefaultID())); + + public bool Contains(string name, int id) => Contains(new ScheduleObjectKey(name, id)); + + internal static int GetDefaultID() => JobScheduleConstants.DefaultID; + + internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) + { + string name = urn.GetAttribute("Name"); + if (null == name || (name.Length == 0 && !CanHaveEmptyName(urn))) { throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); } int id = GetDefaultID(); - string idstr = urn.GetAttribute("ID"); - if (null != idstr && idstr.Length > 0) + string idstr = urn.GetAttribute("ID"); + if (null != idstr && idstr.Length > 0) { - id = Int32.Parse(idstr, SmoApplication.DefaultCulture); + id = int.Parse(idstr, SmoApplication.DefaultCulture); } return new ScheduleObjectKey(name, id); - } + } - public JobSchedule this[Guid scheduleuid] - { - get - { + internal override JobSchedule GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) => new JobSchedule(this, key, state); + + public JobSchedule this[Guid scheduleuid] + { + get + { if (!initialized && ParentInstance.State == SqlSmoState.Existing) { InitializeChildCollection(); } // The collection is not sorted by ScheduleUID, so we need linear search. // It's fine here since number of JobSchedules is typically small - foreach ( JobSchedule js in this.InternalStorage ) - { - if( js.ScheduleUid == scheduleuid ) - { - return js; - } - } - // Return null when object not found. Wrong, but consistent with other indexes - return null; - } - } - } - - internal class ScheduleObjectComparer : ObjectComparerBase - { - internal ScheduleObjectComparer(IComparer stringComparer) : base(stringComparer) - { - } - - public override int Compare(object obj1, object obj2) - { - ScheduleObjectKey x = obj1 as ScheduleObjectKey; - ScheduleObjectKey y = obj2 as ScheduleObjectKey; - - //if we have ID compare with ID - if (y.ID > -1 && x.ID > -1) - { - return x.ID - y.ID; - } - - // else compare with name - return stringComparer.Compare(x.Name, y.Name); - } - } - - internal class ScheduleObjectKey : SimpleObjectKey - { - int id; - - public ScheduleObjectKey(String name, int id) : base(name) - { - this.id = id; - } - - internal static StringCollection schemaFields; - static ScheduleObjectKey() - { - schemaFields = new StringCollection(); - schemaFields.Add("Name"); - schemaFields.Add("ID"); - } - - public Int32 ID - { - get { return id; } - set { id = value; } - } - - public override string UrnFilter - { - get - { - if (id > -1) + foreach (JobSchedule js in InternalStorage) + { + if (js.ScheduleUid == scheduleuid) + { + return js; + } + } + // Return null when object not found. Wrong, but consistent with other indexes + return null; + } + } + } + + internal class ScheduleObjectComparer : ObjectComparerBase + { + internal ScheduleObjectComparer(IComparer stringComparer) : base(stringComparer) + { + } + + public override int Compare(object obj1, object obj2) + { + ScheduleObjectKey x = obj1 as ScheduleObjectKey; + ScheduleObjectKey y = obj2 as ScheduleObjectKey; + + //if we have ID compare with ID + if (y.ID > -1 && x.ID > -1) + { + return x.ID - y.ID; + } + + // else compare with name + return stringComparer.Compare(x.Name, y.Name); + } + } + + internal class ScheduleObjectKey : SimpleObjectKey + { + public ScheduleObjectKey(string name, int id) : base(name) + { + ID = id; + } + + internal static StringCollection schemaFields; + static ScheduleObjectKey() + { + schemaFields = new StringCollection + { + "Name", + "ID" + }; + } + + public int ID { get; set; } + + public override string UrnFilter + { + get + { + if (ID > -1) { return string.Format(SmoApplication.DefaultCulture, - "@Name='{0}' and @ID='{1}'", - Urn.EscapeString(name), id ); + "@Name='{0}' and @ID='{1}'", + Urn.EscapeString(Name), ID); } else { return string.Format(SmoApplication.DefaultCulture, - "@Name='{0}'", Urn.EscapeString(name)); + "@Name='{0}'", Urn.EscapeString(Name)); } } - } - - public override string ToString() - { - return name; - } - - public override StringCollection GetFieldNames() - { - return schemaFields; - } - - public override ObjectKeyBase Clone() - { - return new ScheduleObjectKey(this.Name, this.ID); - } - - internal override void Validate(Type objectType) - { - if (null == this.Name || this.Name.Length == 0) - { - throw new UnsupportedObjectNameException(ExceptionTemplates.UnsupportedObjectNameExceptionText(objectType.ToString())).SetHelpContext("UnsupportedObjectNameExceptionText"); - } - } - - public override bool IsNull - { - get { return (null == name ); } - } - - public override ObjectComparerBase GetComparer(IComparer stringComparer) - { - return new ScheduleObjectComparer(stringComparer); - } - } + } + + public override string ToString() => Name; + + public override StringCollection GetFieldNames() => schemaFields; + + public override ObjectKeyBase Clone() => new ScheduleObjectKey(Name, ID); + + internal override void Validate(Type objectType) + { + if (string.IsNullOrEmpty(Name)) + { + throw new UnsupportedObjectNameException(ExceptionTemplates.UnsupportedObjectNameExceptionText(objectType.ToString())).SetHelpContext("UnsupportedObjectNameExceptionText"); + } + } + + public override bool IsNull + { + get { return null == Name; } + } + + public override ObjectComparerBase GetComparer(IComparer stringComparer) => new ScheduleObjectComparer(stringComparer); + } + + /// + /// Defines constants associated with JobSchedule objects + /// + public static class JobScheduleConstants + { + /// + /// The ID value for a JobSchedule that hasn't been saved yet + /// + public const int DefaultID = -1; + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/JobServerBase.cs b/src/Microsoft/SqlServer/Management/Smo/JobServerBase.cs index 942d62e2..924cd032 100644 --- a/src/Microsoft/SqlServer/Management/Smo/JobServerBase.cs +++ b/src/Microsoft/SqlServer/Management/Smo/JobServerBase.cs @@ -769,9 +769,9 @@ public JobCollection Jobs } } - private JobScheduleCollection sharedSchedules; + private JobScheduleCollection sharedSchedules; [SfcObject( SfcContainerRelationship.ObjectContainer, SfcContainerCardinality.ZeroToAny, typeof(JobSchedule))] - public JobScheduleCollection SharedSchedules + public JobScheduleCollection SharedSchedules { get { @@ -779,7 +779,7 @@ public JobScheduleCollection SharedSchedules ThrowIfBelowVersion90(); if( null == sharedSchedules ) { - sharedSchedules = new JobScheduleCollection(this) + sharedSchedules = new JobScheduleCollection(this) { AcceptDuplicateNames = true }; diff --git a/src/Microsoft/SqlServer/Management/Smo/LocalizableResources.strings b/src/Microsoft/SqlServer/Management/Smo/LocalizableResources.strings index a32ee436..c67fa9bb 100644 --- a/src/Microsoft/SqlServer/Management/Smo/LocalizableResources.strings +++ b/src/Microsoft/SqlServer/Management/Smo/LocalizableResources.strings @@ -1446,8 +1446,23 @@ Index_VectorIndexMetricDesc=Gets or sets the vector index metric type for a vect Index_VectorIndexTypeName=Vector Index Type Index_VectorIndexTypeDesc=Gets or sets the vector index type for a vector index. +Index_OptimizeForArraySearchName=Optimize for Array Search +Index_OptimizeForArraySearchDesc=Gets or sets whether the JSON index is optimized for array search operations. + ######## End Index +####### Begin IndexedJsonPath +IndexedJsonPath_PathName=Path +IndexedJsonPath_PathDesc=Gets or sets the JSON path expression for the indexed path. + +IndexedJsonPath_TableIDName=Table ID +IndexedJsonPath_TableIDDesc=Gets the ID of the table that contains the index. + +IndexedJsonPath_IndexIDName=Index ID +IndexedJsonPath_IndexIDDesc=Gets the ID of the index that contains this path. + +####### End IndexedJsonPath + ####### Begin Rule Rule_Name=Rule diff --git a/src/Microsoft/SqlServer/Management/Smo/MessageCollectionBase.cs b/src/Microsoft/SqlServer/Management/Smo/MessageCollectionBase.cs index 4c519cc0..1ee8412a 100644 --- a/src/Microsoft/SqlServer/Management/Smo/MessageCollectionBase.cs +++ b/src/Microsoft/SqlServer/Management/Smo/MessageCollectionBase.cs @@ -6,63 +6,54 @@ using System.Collections.Specialized; using Microsoft.SqlServer.Management.Sdk.Sfc; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 namespace Microsoft.SqlServer.Management.Smo { - // this is the class that contains common features of all schema collection classes - - public class MessageCollectionBase: SortedListCollectionBase - { - internal MessageCollectionBase(SqlSmoObject parent) : base(parent) - { - } - - protected override void InitInnerCollection() - { - InternalStorage = new SmoSortedList(new MessageObjectComparer(this.StringComparer)); - } - - public void Remove(Int32 id) - { - this.Remove(new MessageObjectKey(id, GetDefaultLanguage())); - } - - public void Remove(Int32 id, string language) - { - this.Remove(new MessageObjectKey(id, language)); - } - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string id = urn.GetAttribute("ID"); - if( null == id || id.Length == 0) + + /// + /// A collection of MessageObjectBase instances associated with a Server + /// + /// + public abstract class MessageCollectionBase : SortedListCollectionBase + where TObject: MessageObjectBase + { + + internal MessageCollectionBase(SqlSmoObject parent) : base((Server)parent) + { + } + + protected override void InitInnerCollection() => InternalStorage = new SmoSortedList(new MessageObjectComparer(StringComparer)); + + public Server Parent => ParentInstance as Server; + + public void Remove(int id) => Remove(new MessageObjectKey(id, GetDefaultLanguage())); + + public void Remove(int id, string language) => Remove(new MessageObjectKey(id, language)); + + internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) + { + var id = urn.GetAttribute("ID"); + if( null == id || id.Length == 0) { throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("ID", urn.Type)); } - string language = urn.GetAttribute("Language"); - if( null == language || language.Length == 0) + var language = urn.GetAttribute("Language"); + if( null == language || language.Length == 0) { language = GetDefaultLanguage(); } - return new MessageObjectKey(Int32.Parse(id, SmoApplication.DefaultCulture), language); + return new MessageObjectKey(int.Parse(id, SmoApplication.DefaultCulture), language); } - internal static string GetDefaultLanguage() - { - return "us_english"; - } + internal static string GetDefaultLanguage() => "us_english"; - public bool Contains(System.Int32 id, System.String language) - { - return Contains(new MessageObjectKey(id, language)); - } + public bool Contains(int id, string language) => Contains(new MessageObjectKey(id, language)); - public bool Contains(System.Int32 id, System.Int32 languageId) - { - Language l = this.ParentInstance.GetServerObject().Languages.ItemById(languageId); - if( null != l ) + public bool Contains(int id, int languageId) + { + var l = ParentInstance.GetServerObject().Languages.ItemById(languageId); + if( null != l ) { return Contains(new MessageObjectKey(id, l.Name)); } @@ -71,20 +62,33 @@ public bool Contains(System.Int32 id, System.Int32 languageId) throw new SmoException(ExceptionTemplates.UnknownLanguageId(languageId.ToString(SmoApplication.DefaultCulture))); } } - } - - internal class MessageObjectComparer : ObjectComparerBase - { - internal MessageObjectComparer(IComparer stringComparer) : base(stringComparer) - { - } - - public override int Compare(object obj1, object obj2) - { - MessageObjectKey x = obj1 as MessageObjectKey; - MessageObjectKey y = obj2 as MessageObjectKey; - - if( x.ID != y.ID ) + + + public TObject this[int id, string language] => GetObjectByKey(new MessageObjectKey(id, language)) as TObject; + + public TObject ItemByIdAndLanguage(int id, string language) => this[id, language]; + + public TObject ItemByIdAndLanguageId(int id, int languageId) + { + var lang = (ParentInstance as Server).Languages.ItemById(languageId); + return null != lang + ? this[id, lang.Name] + : throw new FailedOperationException(ExceptionTemplates.ObjectDoesNotExist("LanguageID", languageId.ToString(SmoApplication.DefaultCulture))); + } + } + + internal class MessageObjectComparer : ObjectComparerBase + { + internal MessageObjectComparer(IComparer stringComparer) : base(stringComparer) + { + } + + public override int Compare(object obj1, object obj2) + { + var x = obj1 as MessageObjectKey; + var y = obj2 as MessageObjectKey; + + if( x.ID != y.ID ) { return x.ID - y.ID; } @@ -93,46 +97,44 @@ public override int Compare(object obj1, object obj2) return stringComparer.Compare(x.Language, y.Language); } } - } - - internal class MessageObjectKey : ObjectKeyBase - { - private Int32 messageID; - private String language; - - - public MessageObjectKey(Int32 messageID, String language) : base() - { - this.messageID = messageID; - this.language = language; - } - - static MessageObjectKey() - { - fields = new StringCollection(); - fields.Add("ID"); - fields.Add("Language"); - } - - internal static StringCollection fields; - - public Int32 ID - { - get { return messageID; } - set { messageID = value; } - } - - public string Language - { - get { return language; } - set { language = value; } - } - - public override string UrnFilter - { - get - { - if( null != language && language.Length > 0) + } + + internal class MessageObjectKey : ObjectKeyBase + { + private int messageID; + private string language; + + + public MessageObjectKey(int messageID, string language) : base() + { + this.messageID = messageID; + this.language = language; + } + + + internal static readonly StringCollection fields = new StringCollection + { + "ID", + "Language" + }; + + public int ID + { + get { return messageID; } + set { messageID = value; } + } + + public string Language + { + get { return language; } + set { language = value; } + } + + public override string UrnFilter + { + get + { + if( null != language && language.Length > 0) { return string.Format(SmoApplication.DefaultCulture, "@ID={0} and @Language='{1}'", messageID, Urn.EscapeString(language)); @@ -142,19 +144,16 @@ public override string UrnFilter return string.Format(SmoApplication.DefaultCulture, "@ID={0}", messageID); } } - } - - public override StringCollection GetFieldNames() - { - return fields; - } - - public override string ToString() - { - if( null != language ) + } + + public override StringCollection GetFieldNames() => fields; + + public override string ToString() + { + if( null != language ) { return string.Format(SmoApplication.DefaultCulture, "{0}:'{1}'", messageID, - SqlSmoObject.SqlString(language)); + SqlSmoObject.SqlString(language)); } else { @@ -162,27 +161,18 @@ public override string ToString() } } - public override ObjectKeyBase Clone() - { - return new MessageObjectKey(this.ID, this.Language); - } - - internal override void Validate(Type objectType) - { - } - - public override bool IsNull - { - get { return (0 == messageID || null == language); } - } - - public override ObjectComparerBase GetComparer(IComparer stringComparer) - { - return new MessageObjectComparer(stringComparer); - } - } - - -} + public override ObjectKeyBase Clone() => new MessageObjectKey(ID, Language); + internal override void Validate(Type objectType) + { + } + + public override bool IsNull + { + get { return 0 == messageID || null == language; } + } + public override ObjectComparerBase GetComparer(IComparer stringComparer) => new MessageObjectComparer(stringComparer); + } + +} diff --git a/src/Microsoft/SqlServer/Management/Smo/Microsoft.SqlServer.Smo.csproj b/src/Microsoft/SqlServer/Management/Smo/Microsoft.SqlServer.Smo.csproj index 8aebf015..b528a368 100644 --- a/src/Microsoft/SqlServer/Management/Smo/Microsoft.SqlServer.Smo.csproj +++ b/src/Microsoft/SqlServer/Management/Smo/Microsoft.SqlServer.Smo.csproj @@ -11,6 +11,7 @@ $(BaseIntermediateOutputPath)$(TargetFramework)\Gen .\ true + true @@ -94,6 +95,7 @@ + @@ -241,6 +243,7 @@ + @@ -349,6 +352,7 @@ + @@ -443,6 +447,7 @@ + @@ -646,6 +651,10 @@ false TargetFramework=$(CodeGenPlatform) + + false + All + diff --git a/src/Microsoft/SqlServer/Management/Smo/NumberedCollectionBase.cs b/src/Microsoft/SqlServer/Management/Smo/NumberedCollectionBase.cs index c9b80164..2c28c73d 100644 --- a/src/Microsoft/SqlServer/Management/Smo/NumberedCollectionBase.cs +++ b/src/Microsoft/SqlServer/Management/Smo/NumberedCollectionBase.cs @@ -7,29 +7,20 @@ namespace Microsoft.SqlServer.Management.Smo { - /// - /// base class for all generic collections - /// - public abstract class NumberedObjectCollectionBase : SortedListCollectionBase + public abstract class NumberedObjectCollectionBase : SortedListCollectionBase { - internal NumberedObjectCollectionBase(SqlSmoObject parent) : base(parent) + internal NumberedObjectCollectionBase(SqlSmoObject parent) : base((StoredProcedure)parent) { } - protected override void InitInnerCollection() - { - InternalStorage = new SmoSortedList(new NumberedObjectComparer()); - } - - public bool Contains(short number) - { - return this.Contains(new NumberedObjectKey(number)); - } + protected override void InitInnerCollection() => InternalStorage = new SmoSortedList(new NumberedObjectComparer()); + + public bool Contains(short number) => Contains(new NumberedObjectKey(number)); internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) { - short number = short.Parse(urn.GetAttribute("Number"), SmoApplication.DefaultCulture); + var number = short.Parse(urn.GetAttribute(nameof(NumberedStoredProcedure.Number)), SmoApplication.DefaultCulture); return new NumberedObjectKey(number); } @@ -41,10 +32,7 @@ internal NumberedObjectComparer() : base(null) { } - public override int Compare(object obj1, object obj2) - { - return ((NumberedObjectKey)obj1).Number - ((NumberedObjectKey)obj2).Number; - } + public override int Compare(object obj1, object obj2) => ((NumberedObjectKey)obj1).Number - ((NumberedObjectKey)obj2).Number; } internal class NumberedObjectKey : ObjectKeyBase @@ -59,7 +47,7 @@ public NumberedObjectKey(short number) : base() static NumberedObjectKey() { - fields.Add("Number"); + _ = fields.Add(nameof(NumberedStoredProcedure.Number)); } internal static readonly StringCollection fields = new StringCollection(); @@ -70,40 +58,25 @@ public short Number set { number = value; } } - public override string ToString() - { - return string.Format(SmoApplication.DefaultCulture, "{0}", + public override string ToString() => string.Format(SmoApplication.DefaultCulture, "{0}", number); - } - public override string UrnFilter - { - get { return string.Format(SmoApplication.DefaultCulture, "@Number={0}", number); } - } + public override string UrnFilter => string.Format(SmoApplication.DefaultCulture, "@Number={0}", number); - public override StringCollection GetFieldNames() - { - return fields; - } + public override StringCollection GetFieldNames() => fields; - public override ObjectKeyBase Clone() - { - return new NumberedObjectKey(this.Number); - } + public override ObjectKeyBase Clone() => new NumberedObjectKey(Number); - public override bool IsNull - { - get { return false;} - } + public override bool IsNull => false; - public override ObjectComparerBase GetComparer(IComparer stringComparer) - { - return new NumberedObjectComparer(); - } + public override ObjectComparerBase GetComparer(IComparer stringComparer) => new NumberedObjectComparer(); } - public abstract class PartitionNumberedObjectCollectionBase : SortedListCollectionBase + /// + /// Collection of PhysicalPartition objects associated with an index or table + /// + public abstract class PartitionNumberedObjectCollectionBase : SortedListCollectionBase { internal PartitionNumberedObjectCollectionBase(SqlSmoObject parent) @@ -111,15 +84,14 @@ internal PartitionNumberedObjectCollectionBase(SqlSmoObject parent) { } - protected override void InitInnerCollection() - { - InternalStorage = new SmoSortedList(new PartitionNumberedObjectComparer()); - } + protected override void InitInnerCollection() => InternalStorage = new SmoSortedList(new PartitionNumberedObjectComparer()); - public bool Contains(int number) - { - return this.Contains(new PartitionNumberedObjectKey(number)); - } + /// + /// Returns whether the collection contains a partition identified by the given number + /// + /// + /// + public bool Contains(int number) => Contains(new PartitionNumberedObjectKey(number)); internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) @@ -137,10 +109,7 @@ internal PartitionNumberedObjectComparer() { } - public override int Compare(object obj1, object obj2) - { - return ((PartitionNumberedObjectKey)obj1).Number - ((PartitionNumberedObjectKey)obj2).Number; - } + public override int Compare(object obj1, object obj2) => ((PartitionNumberedObjectKey)obj1).Number - ((PartitionNumberedObjectKey)obj2).Number; } internal class PartitionNumberedObjectKey : ObjectKeyBase @@ -156,11 +125,13 @@ public PartitionNumberedObjectKey(int number) static PartitionNumberedObjectKey() { - fields = new StringCollection(); - fields.Add("PartitionNumber"); + fields = new StringCollection + { + nameof(PhysicalPartition.PartitionNumber) + }; } - internal static StringCollection fields; + internal static readonly StringCollection fields; public int Number { @@ -168,38 +139,18 @@ public int Number set { number = value; } } - public override string ToString() - { - return string.Format(SmoApplication.DefaultCulture, "{0}", + public override string ToString() => string.Format(SmoApplication.DefaultCulture, "{0}", number); - } - public override string UrnFilter - { - get { return string.Format(SmoApplication.DefaultCulture, "@PartitionNumber={0}", number); } - } + public override string UrnFilter => string.Format(SmoApplication.DefaultCulture, "@PartitionNumber={0}", number); - public override StringCollection GetFieldNames() - { - return fields; - } + public override StringCollection GetFieldNames() => fields; - public override ObjectKeyBase Clone() - { - return new PartitionNumberedObjectKey(this.Number); - } + public override ObjectKeyBase Clone() => new PartitionNumberedObjectKey(Number); - public override bool IsNull - { - get { return false; } - } + public override bool IsNull => false; - public override ObjectComparerBase GetComparer(IComparer stringComparer) - { - return new PartitionNumberedObjectComparer(); - } + public override ObjectComparerBase GetComparer(IComparer stringComparer) => new PartitionNumberedObjectComparer(); } - - -} +} diff --git a/src/Microsoft/SqlServer/Management/Smo/ParamBase.cs b/src/Microsoft/SqlServer/Management/Smo/ParamBase.cs index 49c90ac1..146f0b2f 100644 --- a/src/Microsoft/SqlServer/Management/Smo/ParamBase.cs +++ b/src/Microsoft/SqlServer/Management/Smo/ParamBase.cs @@ -9,10 +9,12 @@ using Microsoft.SqlServer.Management.Sdk.Sfc; using Microsoft.SqlServer.Management.Sdk.Sfc.Metadata; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 namespace Microsoft.SqlServer.Management.Smo { - public class ParameterBase : ScriptNameObjectBase, IExtendedProperties, IMarkForDrop + /// + /// Base class for Parameters + /// + public partial class ParameterBase : ScriptNameObjectBase, IExtendedProperties, IMarkForDrop { // this is the long under score character which engine allows in a stored proc param name const char longUderscoreChar = '\xff3f'; @@ -269,7 +271,6 @@ internal override string ScriptName /// /// Check if it is for direct execution i.e. create/alter/drop or parent is CLR type /// - /// /// protected virtual bool isParentClrImplemented() { @@ -290,7 +291,7 @@ internal StoredProcedureParameter(AbstractCollectionBase parent, ObjectKeyBase k /// /// Validate property values that are coming from the users. /// - /// + /// /// internal override void ValidateProperty(Property prop, object value) { @@ -365,7 +366,7 @@ internal NumberedStoredProcedureParameter(AbstractCollectionBase parent, ObjectK /// /// Validate property values that are coming from the users. /// - /// + /// /// internal override void ValidateProperty(Property prop, object value) { @@ -403,7 +404,7 @@ internal UserDefinedFunctionParameter(AbstractCollectionBase parent, ObjectKeyBa /// /// Validate property values that are coming from the users. /// - /// + /// /// internal override void ValidateProperty(Property prop, object value) { diff --git a/src/Microsoft/SqlServer/Management/Smo/ParameterCollectionBase.cs b/src/Microsoft/SqlServer/Management/Smo/ParameterCollectionBase.cs index 348b611a..755edf45 100644 --- a/src/Microsoft/SqlServer/Management/Smo/ParameterCollectionBase.cs +++ b/src/Microsoft/SqlServer/Management/Smo/ParameterCollectionBase.cs @@ -4,37 +4,90 @@ using System; using Microsoft.SqlServer.Management.Sdk.Sfc; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 namespace Microsoft.SqlServer.Management.Smo { - // this is the class that contains common features of all collection classes - //[StrongNameIdentityPermission(SecurityAction.InheritanceDemand, PublicKey="0x03bf8c39a7191dfd")] - public abstract class ParameterCollectionBase : ArrayListCollectionBase + /// + /// Base class for collections whose enumeration order is based on ID instead of Name + /// + public abstract class ParameterCollectionBase : ArrayListCollectionBase, IOrderedCollection, IOrderedCollectionInternal + where TObject : SqlSmoObject + where TParent : SqlSmoObject { - internal ParameterCollectionBase(SqlSmoObject parent) : base(parent) + internal ParameterCollectionBase(SqlSmoObject parent) : base((TParent)parent) { } - protected override void InitInnerCollection() - { - InternalStorage = new SmoArrayList(new SimpleObjectComparer(this.StringComparer), this); - } - - public bool Contains(String name) + protected override void InitInnerCollection() => InternalStorage = new SmoArrayList(new SimpleObjectComparer(StringComparer), this); + + /// + /// Returns the object of the given name, or null if it's not in the collection + /// + /// + /// + public TObject this[string name] => GetObjectByKey(new SimpleObjectKey(name)) as TObject; + + /// + /// Returns the Parent of the collection + /// + public TParent Parent => ParentInstance as TParent; + + /// + /// Returns whether the named object exists in the collection + /// + /// + /// + public bool Contains(string name) => Contains(new SimpleObjectKey(name)); + + /// + /// Adds an object to the collection + /// + /// + public void Add(TObject obj) => AddImpl(obj); + + /// + /// Adds an object to the collection after the object with a specific name + /// + /// The column to add + /// The name of the column already in the collection after which the column will be inserted + public void Add(TObject obj, string insertAtObjectName) => AddImpl(obj, new SimpleObjectKey(insertAtObjectName)); + + /// + /// Adds an object to the collection at particular position + /// + /// + /// + public void Add(TObject obj, int insertAtPosition) => AddImpl(obj, insertAtPosition); + + /// + /// Removes an object from the collection + /// + /// + /// + public void Remove(TObject obj) { - return this.Contains(new SimpleObjectKey(name)); + if (null == obj) + { + throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException(nameof(obj))); + } + + RemoveObj(obj, obj.key); } + /// + /// Attempts to remove the object with the given name from the collection. + /// If the object is not in Creating state, a SmoException is thrown + /// + /// public void Remove(string name) { CheckCollectionLock(); - this.Remove(new SimpleObjectKey(name)); + Remove(new SimpleObjectKey(name)); } - + internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - if( null == name || name.Length == 0) + { + var name = urn.GetAttribute("Name"); + if (string.IsNullOrEmpty(name)) { throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); } @@ -53,29 +106,39 @@ protected override void ImplAddExisting(SqlSmoObject obj) // use the most generic version of the GetPropValueOptional because // ID is int in most cases, but it's byte for some objects (IndexedColumn) - int objId = Convert.ToInt32(obj.GetPropValueOptional("ID", -1), + var objId = Convert.ToInt32(obj.GetPropValueOptional("ID", -1), SmoApplication.DefaultCulture); - for (int i = 0; i < InternalStorage.Count; i++) + for (var i = 0; i < InternalStorage.Count; i++) { - SqlSmoObject currObj = InternalStorage.GetByIndex(i); + var currObj = InternalStorage.GetByIndex(i); Diagnostics.TraceHelper.Assert(currObj.Properties.Contains("ID")); - int currObjId = Convert.ToInt32(currObj.GetPropValueOptional("ID", -1), + var currObjId = Convert.ToInt32(currObj.GetPropValueOptional("ID", -1), SmoApplication.DefaultCulture); if (-1 != currObjId) { if (objId < currObjId) { - InternalStorage.InsertAt(i, obj); + InternalStorage.InsertAt(i, (TObject)obj); return; } } } // if we could not find a position then insert it at the end - InternalStorage.InsertAt(InternalStorage.Count, obj); + InternalStorage.InsertAt(InternalStorage.Count, (TObject)obj); } + + void IOrderedCollectionInternal.Append(SqlSmoObject obj) + { + InternalStorage.InsertAt(InternalStorage.Count, (TObject)obj); + } + } + + internal interface IOrderedCollectionInternal + { + void Append(SqlSmoObject obj); } } diff --git a/src/Microsoft/SqlServer/Management/Smo/PhysicalPartitionCollectionBase.cs b/src/Microsoft/SqlServer/Management/Smo/PhysicalPartitionCollectionBase.cs index 9c5c5fe4..c5e3e870 100644 --- a/src/Microsoft/SqlServer/Management/Smo/PhysicalPartitionCollectionBase.cs +++ b/src/Microsoft/SqlServer/Management/Smo/PhysicalPartitionCollectionBase.cs @@ -6,25 +6,10 @@ using System.Diagnostics; using System.Text; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 namespace Microsoft.SqlServer.Management.Smo { public partial class PhysicalPartitionCollection { - /// - /// Copy the content of given PhysicalPartition array to this collection object. - /// Staring onward partitionNumberStart. - /// - /// - /// - public void CopyTo(PhysicalPartition[] array, Int32 partitionNumberStart) - { - if ((Int32.MaxValue < partitionNumberStart) || (partitionNumberStart < 1)) - { - throw new SmoException(ExceptionTemplates.PartitionNumberStartOutOfRange(Int32.MaxValue)); - } - ((ICollection)this).CopyTo(array, partitionNumberStart - 1); - } /// /// Copy all content of the given physical partition array in current collection @@ -421,6 +406,7 @@ private void ValidatePhysicalPartitionObject(string objectName) /// True for ALTER statement, false for CREATE /// True for ALTER/CREATE TABLE statement, false for INDEX /// Needed because columnstores have different default compression than rowstores + /// internal string GetCompressionCode(bool isOnAlter, bool isOnTable, ScriptingPreferences sp) { //If you are getting this assert failure that implies you are not checking at very early stage whether @@ -591,7 +577,8 @@ internal string GetCompressionCode(bool isOnAlter, bool isOnTable, ScriptingPref /// This method generates the XML_COMPRESSION clause for objects with 1 or more partitions. /// /// True for ALTER statement, false for CREATE - /// True for ALTER/CREATE TABLE statement, false for INDEX + /// True for ALTER/CREATE TABLE statement, false for INDEX + /// internal string GetXmlCompressionCode(bool isOnAlter, bool isOnTable, ScriptingPreferences sp) { // If you are getting this assert failure that implies you are not checking at very early stage whether diff --git a/src/Microsoft/SqlServer/Management/Smo/QueryStoreOptions.cs b/src/Microsoft/SqlServer/Management/Smo/QueryStoreOptions.cs index 3cc37eb9..286cd5e5 100644 --- a/src/Microsoft/SqlServer/Management/Smo/QueryStoreOptions.cs +++ b/src/Microsoft/SqlServer/Management/Smo/QueryStoreOptions.cs @@ -16,7 +16,6 @@ namespace Microsoft.SqlServer.Management.Smo /// /// QueryStore Options Smo Object. /// - [SfcElementType("QueryStoreOptions")] public sealed partial class QueryStoreOptions : SqlSmoObject, IAlterable, IScriptable { internal QueryStoreOptions(Database parentdb, ObjectKeyBase key, SqlSmoState state) diff --git a/src/Microsoft/SqlServer/Management/Smo/SchemaCollectionBase.cs b/src/Microsoft/SqlServer/Management/Smo/SchemaCollectionBase.cs index 74f2ef19..99557cf1 100644 --- a/src/Microsoft/SqlServer/Management/Smo/SchemaCollectionBase.cs +++ b/src/Microsoft/SqlServer/Management/Smo/SchemaCollectionBase.cs @@ -6,52 +6,120 @@ using System.Collections.Specialized; using Microsoft.SqlServer.Management.Sdk.Sfc; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 namespace Microsoft.SqlServer.Management.Smo { - // this is the class that contains common features of all schema collection classes - - public class SchemaCollectionBase: SortedListCollectionBase - { - internal SchemaCollectionBase(SqlSmoObject parent) : base(parent) - { - } - - protected override void InitInnerCollection() - { - InternalStorage = new SmoSortedList(new SchemaObjectComparer(this.StringComparer)); - } - - internal void RemoveObject(string name, string schema) - { - InternalStorage.Remove(new SchemaObjectKey(name, schema)); - } - - public bool Contains(String name) - { - return this.Contains(new SchemaObjectKey(name, GetDefaultSchema())); - } - - public bool Contains(String name, String schema) - { - return this.Contains(new SchemaObjectKey(name, schema)); - } - - internal virtual String GetDefaultSchema() - { - SqlSmoObject db = null; - - if( ParentInstance is Database ) - { - //level 1 - db = ParentInstance; - } - else if (ParentInstance is Broker.ServiceBroker) - { - //Service Broker is special - it is not in the collection. - db = ((Broker.ServiceBroker)ParentInstance).Parent; - } - else if( ParentInstance.ParentColl.ParentInstance is Database ) + /// + /// Contains common features of all schema collection classes + /// + /// + /// + + public abstract class SchemaCollectionBase : SortedListCollectionBase, ISchemaObjectCollection, ISchemaObjectCollectionInternal + where TObject : ScriptNameObjectBase + where TParent : SqlSmoObject + { + + internal SchemaCollectionBase(TParent parent) : base(parent) + { + } + + /// + /// Returns the parent object + /// + public TParent Parent => ParentInstance as TParent; + + /// + /// Returns the object of the given name in the collection, using the default schema. + /// Returns null if the object is not in the collection + /// + /// + /// + /// + public TObject this[string name] + { + get + { + return name == null + ? throw new ArgumentNullException(nameof(name)) + : GetObjectByKey(new SchemaObjectKey(name, GetDefaultSchema())); + } + } + + /// + /// Returns the object in the collection having the given name and schema. + /// Returns null if the object is not in the collection + /// + /// + /// + /// + /// + public TObject this[string name, string schema] + { + get + { + if (name == null) + { + throw new ArgumentNullException(nameof(name)); + } + else if (schema == null) + { + throw new ArgumentNullException(nameof(schema)); + } + + return GetObjectByKey(new SchemaObjectKey(name, schema)); + } + } + + /// + /// Adds the given object to the collection + /// + /// + /// + public void Add(TObject obj) + { + if (null == obj) + throw new FailedOperationException(ExceptionTemplates.AddCollection, this, new ArgumentNullException(nameof(obj))); + + AddImpl(obj); + } + + protected override void InitInnerCollection() => InternalStorage = new SmoSortedList(new SchemaObjectComparer(StringComparer)); + + void ISchemaObjectCollectionInternal.RemoveObject(string name, string schema) => InternalStorage.Remove(new SchemaObjectKey(name, schema)); + + /// + /// Returns whether an object of the given name exists in the collection. Assumes the object is a member of the default schema. + /// + /// + /// + public bool Contains(string name) => Contains(new SchemaObjectKey(name, GetDefaultSchema())); + + /// + /// Returns whether an object of the given name and schema exists in the collection + /// + /// + /// + /// + public bool Contains(string name, string schema) => Contains(new SchemaObjectKey(name, schema)); + + /// + /// Returns the default schema of the database associated with this collection + /// + /// + public virtual string GetDefaultSchema() + { + SqlSmoObject db; + if (ParentInstance is Database) + { + //level 1 + db = ParentInstance; + } + else if (ParentInstance is Broker.ServiceBroker broker) + { + //Service Broker is special - it is not in the collection. + db = broker.Parent; + } + else if (ParentInstance.ParentColl.ParentInstance is Database) { db = ParentInstance.ParentColl.ParentInstance; } @@ -63,161 +131,135 @@ internal virtual String GetDefaultSchema() // if the object is just creating or pending, then we can assume that the schema is going to be // dbo, since the user is the one that creates the database. This does not work in some // edge cases, but they are not a big user problem. - if ( db.State == SqlSmoState.Creating || db.IsDesignMode) - { - return "dbo"; - } - else - { - return db.Properties["DefaultSchema"].Value as string; - } + return db.State == SqlSmoState.Creating || db.IsDesignMode ? "dbo" : db.Properties["DefaultSchema"].Value as string; } - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - string name = urn.GetAttribute("Name"); - if( null == name || (name.Length == 0 && !CanHaveEmptyName(urn))) + internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) + { + string name = urn.GetAttribute("Name"); + if (null == name || (name.Length == 0 && !CanHaveEmptyName(urn))) { throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); } - string schema = urn.GetAttribute("Schema"); - if( null == schema || schema.Length == 0 ) + var schema = urn.GetAttribute("Schema"); + if (string.IsNullOrEmpty(schema)) { schema = GetDefaultSchema(); } return new SchemaObjectKey(name, schema); - } - - } - - internal class SchemaObjectComparer : ObjectComparerBase - { - internal SchemaObjectComparer(IComparer stringComparer) : base(stringComparer) - { - } - - public override int Compare(object obj1, object obj2) - { - SchemaObjectKey x = obj1 as SchemaObjectKey; - SchemaObjectKey y = obj2 as SchemaObjectKey; - - //if search schema is null search only by name - if( y.Schema != null ) - { - if( null == x.Schema ) - { - return 1; - } - int i = stringComparer.Compare(x.Schema, y.Schema); - if( 0 != i ) - { - return i; - } - } - return stringComparer.Compare(x.Name, y.Name); - } - } - - internal class SchemaObjectKey : SimpleObjectKey - { - String schema; - - public SchemaObjectKey(String name, String schema) : base(name) - { - this.schema = schema; - } - - internal static StringCollection schemaFields; - static SchemaObjectKey() - { - schemaFields = new StringCollection(); - schemaFields.Add("Schema"); - schemaFields.Add("Name"); - } - - public string Schema - { - get { return schema; } - set { schema = value; } - } - - public override string UrnFilter - { - get - { - if( null != schema && schema.Length > 0) + } + + } + + internal class SchemaObjectComparer : ObjectComparerBase + { + internal SchemaObjectComparer(IComparer stringComparer) : base(stringComparer) + { + } + + public override int Compare(object obj1, object obj2) + { + SchemaObjectKey x = obj1 as SchemaObjectKey; + SchemaObjectKey y = obj2 as SchemaObjectKey; + + //if search schema is null search only by name + if (y.Schema != null) + { + if (null == x.Schema) { - return string.Format(SmoApplication.DefaultCulture, "@Name='{0}' and @Schema='{1}'", - Urn.EscapeString(name), Urn.EscapeString(schema)); + return 1; } - else + int i = stringComparer.Compare(x.Schema, y.Schema); + if (0 != i) { - return string.Format(SmoApplication.DefaultCulture, "@Name='{0}'", Urn.EscapeString(name)); + return i; } } - } - - public override string ToString() - { - if( null != schema ) - { - return string.Format(SmoApplication.DefaultCulture, "[{0}].[{1}]", - SqlSmoObject.SqlBraket(schema), - SqlSmoObject.SqlBraket(name)); - } - return name; - } - - public override string GetExceptionName() - { - if (null != schema) - { - return string.Format(SmoApplication.DefaultCulture, "{0}.{1}", schema, name); - } - return name; - } - - - public override StringCollection GetFieldNames() - { - return schemaFields; - } - - public override ObjectKeyBase Clone() - { - return new SchemaObjectKey(this.Name, this.Schema); - } - - internal override void Validate(Type objectType) - { - if( null == this.Name || this.Name.Length == 0 ) - { - throw new UnsupportedObjectNameException(ExceptionTemplates.UnsupportedObjectNameExceptionText(objectType.ToString())).SetHelpContext("UnsupportedObjectNameExceptionText"); - } - - if( "Microsoft.SqlServer.Management.Smo.Table" == objectType.ToString() ) - { - Table.CheckTableName(this.Name); - } - } - - public override bool IsNull - { - get { return (null == name || null == schema); } - } - - public override ObjectComparerBase GetComparer(IComparer stringComparer) - { - return new SchemaObjectComparer(stringComparer); - } - - - - - } - - + return stringComparer.Compare(x.Name, y.Name); + } + } + + internal class SchemaObjectKey : SimpleObjectKey + { + + public SchemaObjectKey(string name, string schema) : base(name) + { + Schema = schema; + } + + internal static StringCollection schemaFields; + static SchemaObjectKey() + { + schemaFields = new StringCollection + { + nameof(Schema), + nameof(Name) + }; + } + + public string Schema + { + get; + set; + } + + public override string UrnFilter => !string.IsNullOrEmpty(Schema) + ? $"@Name='{Urn.EscapeString(Name)}' and @Schema='{Urn.EscapeString(Schema)}'" + : $"@Name='{Urn.EscapeString(Name)}'"; + + public override string ToString() + { + if (null != Schema) + { + return $"[{SqlSmoObject.SqlBraket(Schema)}].[{SqlSmoObject.SqlBraket(Name)}]"; + } + return Name; + } + + public override string GetExceptionName() + { + if (null != Schema) + { + return $"{Schema}.{Name}"; + } + return Name; + } + + + public override StringCollection GetFieldNames() => schemaFields; + + public override ObjectKeyBase Clone() => new SchemaObjectKey(Name, Schema); + + internal override void Validate(Type objectType) + { + if (string.IsNullOrEmpty(Name)) + { + throw new UnsupportedObjectNameException(ExceptionTemplates.UnsupportedObjectNameExceptionText(objectType.ToString())).SetHelpContext("UnsupportedObjectNameExceptionText"); + } + + if (typeof(Table) == objectType) + { + Table.CheckTableName(Name); + } + } + + public override bool IsNull => null == Name || null == Schema; + + public override ObjectComparerBase GetComparer(IComparer stringComparer) => new SchemaObjectComparer(stringComparer); + } + + + + internal interface ISchemaObjectCollectionInternal + { + /// + /// Removes the object with the given name and schema from the collection + /// + /// + /// + void RemoveObject(string name, string schema); + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/ScriptNameObjectBase.cs b/src/Microsoft/SqlServer/Management/Smo/ScriptNameObjectBase.cs index 0d278559..770b9ecb 100644 --- a/src/Microsoft/SqlServer/Management/Smo/ScriptNameObjectBase.cs +++ b/src/Microsoft/SqlServer/Management/Smo/ScriptNameObjectBase.cs @@ -2,9 +2,12 @@ // Licensed under the MIT license. using System; +using System.Collections; +using System.Collections.Generic; using System.Collections.Specialized; using System.Globalization; using System.Text; +using System.Xml.Linq; using Microsoft.SqlServer.Management.Diagnostics; using Cmn = Microsoft.SqlServer.Management.Common; @@ -24,7 +27,7 @@ internal ScriptNameObjectBase(ObjectKeyBase key, SqlSmoState eState) : internal protected ScriptNameObjectBase() : base() { } - private string m_sScriptName = String.Empty; + private string m_sScriptName = string.Empty; internal virtual string ScriptName { @@ -67,7 +70,7 @@ protected bool GetIsSystemNamed() { try { - return (System.Boolean)this.Properties.GetValueWithNullReplacement("IsSystemNamed"); + return (bool)this.Properties.GetValueWithNullReplacement("IsSystemNamed"); } catch (Exception) //if property not yet set { @@ -106,7 +109,7 @@ internal bool ScriptConstraintWithName(ScriptingPreferences sp) if (!sp.Table.SystemNamesForConstraints) { - Object oIsSystemNamed = GetPropValueOptional("IsSystemNamed"); + object oIsSystemNamed = GetPropValueOptional("IsSystemNamed"); if (null != oIsSystemNamed) { bIsSystemNamed = (bool)oIsSystemNamed; @@ -125,7 +128,7 @@ internal virtual string GetScriptIncludeExists(ScriptingPreferences sp, string t return string.Empty; } - internal void ConstraintScriptCreate(String scriptBody, StringCollection createQuery, ScriptingPreferences sp) + internal void ConstraintScriptCreate(string scriptBody, StringCollection createQuery, ScriptingPreferences sp) { if (scriptBody.Length == 0) { @@ -153,7 +156,7 @@ internal void ConstraintScriptCreate(String scriptBody, StringCollection createQ } else { - Object pChecked = GetPropValueOptional("IsChecked"); + object pChecked = GetPropValueOptional("IsChecked"); if (null != pChecked) { bool checkFK = (bool)pChecked; @@ -171,7 +174,7 @@ internal void ConstraintScriptCreate(String scriptBody, StringCollection createQ if (ScriptConstraintWithName(sp)) { - Object pEnabled = GetPropValueOptional("IsEnabled"); + object pEnabled = GetPropValueOptional("IsEnabled"); if (null != pEnabled) { bool enableFK = (bool)pEnabled; @@ -406,7 +409,7 @@ internal bool IsOrAlterSupported(ScriptingPreferences sp) bool m_textMode = false; bool m_isTextModeInitialized = false; - protected void SetTextMode(bool textMode, SmoCollectionBase[] collList) + protected void SetTextMode(bool textMode, IEnumerable collList) { //if the the object is existing and clr we do not support text mode = true if (true == m_textMode && false == CheckTextModeSupport()) @@ -732,14 +735,14 @@ protected string GetTextHeader(ScriptHeaderType scriptHeaderType) if (ShouldScriptForNonCreate(scriptHeaderType)) { //we need to replace CREATE with ALTER/CREATE OR ALTER - return CheckAndManipulateText(null != m_textHeader ? m_textHeader : String.Empty, + return CheckAndManipulateText(m_textHeader ?? string.Empty, null, new ScriptingPreferences(), scriptHeaderType); } - return (null != m_textHeader ? m_textHeader : String.Empty); + return m_textHeader ?? string.Empty; } - protected void SetCollectionTextMode(bool newTextModeValue, SmoCollectionBase coll) + protected void SetCollectionTextMode(bool newTextModeValue, ILockableCollection coll) { if (true == newTextModeValue) { @@ -751,11 +754,11 @@ protected void SetCollectionTextMode(bool newTextModeValue, SmoCollectionBase co } } - protected void SwitchTextMode(bool newTextModeValue, SmoCollectionBase[] collList) + protected void SwitchTextMode(bool newTextModeValue, IEnumerable collList) { if (null != collList) { - foreach (SmoCollectionBase coll in collList) + foreach (var coll in collList) { SetCollectionTextMode(newTextModeValue, coll); } @@ -914,7 +917,7 @@ internal string GetTextForScript(ScriptingPreferences sp, string[] expectedObjec //build expectedObjectTypes list if (null == expectedObjectTypes) { - expectedObjectTypes = new String[] { this.GetType().Name }; + expectedObjectTypes = new string[] { this.GetType().Name }; } // CheckAndManipulateText Would check the Name so we don't want BuildText to check the name @@ -993,10 +996,10 @@ string BuildText(ScriptingPreferences sp) Diagnostics.TraceHelper.Assert(null != textBody, "null == textBody"); //text header should end in space - if (textHeader.Length > 0 && !Char.IsWhiteSpace(textHeader[textHeader.Length - 1])) + if (textHeader.Length > 0 && !char.IsWhiteSpace(textHeader[textHeader.Length - 1])) { //else check if the text body ends in space - if (textBody.Length > 0 && !Char.IsWhiteSpace(textBody[0])) + if (textBody.Length > 0 && !char.IsWhiteSpace(textBody[0])) { //else we need to add a space text.Append(sp.NewLine); @@ -1068,7 +1071,7 @@ internal void CheckNameInTextCorrectness(string expectedName, string expectedSch { // if no schema was specified in the text, check that the default schema is what we want ScriptSchemaObjectBase schemaObject = (ScriptSchemaObjectBase)this; - SchemaCollectionBase parentCollection = (SchemaCollectionBase)schemaObject.ParentColl; + var parentCollection = (ISchemaObjectCollection)schemaObject.ParentColl; if (0 != this.StringComparer.Compare(expectedSchema, MakeSqlBraket(parentCollection.GetDefaultSchema()))) { @@ -1129,7 +1132,7 @@ protected void CheckTextCorrectness(string ddlText, bool enforceCreate, bool che bool bObjectTypeFound = false; foreach (string s in expectedObjectTypes) { - if (0 == String.Compare(s, headerInfo.objectType, StringComparison.OrdinalIgnoreCase)) + if (0 == string.Compare(s, headerInfo.objectType, StringComparison.OrdinalIgnoreCase)) { bObjectTypeFound = true; break; @@ -1147,13 +1150,13 @@ protected void CheckTextCorrectness(string ddlText, bool enforceCreate, bool che { // if the object has schema, then we'll need to do some extra validation ScriptSchemaObjectBase schemaObject = this as ScriptSchemaObjectBase; - String expectedSchema = null != schemaObject ? MakeSqlBraket(schemaObject.Schema) : String.Empty; + string expectedSchema = null != schemaObject ? MakeSqlBraket(schemaObject.Schema) : string.Empty; CheckNameInTextCorrectness(GetBraketNameForText(), expectedSchema, headerInfo.name, headerInfo.schema, headerInfo.procedureNumber); // if this is a trigger, also check the table name - if (0 == String.Compare("TRIGGER", headerInfo.objectType, StringComparison.OrdinalIgnoreCase)) + if (0 == string.Compare("TRIGGER", headerInfo.objectType, StringComparison.OrdinalIgnoreCase)) { Trigger tr = this as Trigger; @@ -1223,7 +1226,7 @@ private string CheckAndManipulateText(string ddlText, string[] expectedObjectTyp // and if the object doesn't have a schema it returns false. private bool IsSchemaNameSame(string schemaName) { - if (String.IsNullOrEmpty(schemaName)) + if (string.IsNullOrEmpty(schemaName)) { return true; } @@ -1252,7 +1255,7 @@ private void CheckAndManipulateName(ref string ddlText, ScriptingPreferences sp, // if this is a trigger, also fix the table name // note: fix it before the object's name so that the text indexes are not affected - if (0 == String.Compare("TRIGGER", headerInfo.objectType, StringComparison.OrdinalIgnoreCase)) + if (0 == string.Compare("TRIGGER", headerInfo.objectType, StringComparison.OrdinalIgnoreCase)) { Diagnostics.TraceHelper.Assert(headerInfo.indexNameStartSecondary > 0 && headerInfo.indexNameEndSecondary > 0 && headerInfo.indexNameEndSecondary > headerInfo.indexNameStartSecondary); @@ -1623,10 +1626,10 @@ private string GetTextPropertyDesignMode(string requestingProperty, ScriptingPre { sb.AppendFormat(SmoApplication.DefaultCulture, this.m_textHeader); //text header should end in space - if (this.m_textHeader.Length > 0 && !Char.IsWhiteSpace(this.m_textHeader[this.m_textHeader.Length - 1])) + if (this.m_textHeader.Length > 0 && !char.IsWhiteSpace(this.m_textHeader[this.m_textHeader.Length - 1])) { //else check if the text body starts with space - if (this.m_textBody.Length > 0 && !Char.IsWhiteSpace(this.m_textBody[0])) + if (this.m_textBody.Length > 0 && !char.IsWhiteSpace(this.m_textBody[0])) { //else we need to add a new line sb.AppendFormat(SmoApplication.DefaultCulture, sp.NewLine); diff --git a/src/Microsoft/SqlServer/Management/Smo/ScriptSchemaObjectBase.cs b/src/Microsoft/SqlServer/Management/Smo/ScriptSchemaObjectBase.cs index 21bce985..7af1576c 100644 --- a/src/Microsoft/SqlServer/Management/Smo/ScriptSchemaObjectBase.cs +++ b/src/Microsoft/SqlServer/Management/Smo/ScriptSchemaObjectBase.cs @@ -60,7 +60,7 @@ internal override string FormatFullNameForScripting(ScriptingPreferences sp) internal override void ScriptChangeOwner(StringCollection queries, ScriptingPreferences sp) { - Property prop = this.GetPropertyOptional("Owner"); + Property prop = GetPropertyOptional("Owner"); if (!prop.IsNull && (prop.Dirty || !sp.ScriptForAlter)) { @@ -69,7 +69,7 @@ internal override void ScriptChangeOwner(StringCollection queries, ScriptingPref if (sp.TargetServerVersion > SqlServerVersion.Version80) { bool schemaOwned = true; - sb.AppendFormat(SmoApplication.DefaultCulture, "ALTER AUTHORIZATION ON {0}", this.PermissionPrefix); + sb.AppendFormat(SmoApplication.DefaultCulture, "ALTER AUTHORIZATION ON {0}", PermissionPrefix); sb.AppendFormat(SmoApplication.DefaultCulture, "{0}", FormatFullNameForScripting(sp)); sb.AppendFormat(SmoApplication.DefaultCulture, " TO "); @@ -77,9 +77,9 @@ internal override void ScriptChangeOwner(StringCollection queries, ScriptingPref { schemaOwned = ((string)prop.Value == string.Empty); } - else if (this.ServerVersion.Major > 8) + else if (ServerVersion.Major > 8) { - Property isSchemaOwnedProp = this.Properties.Get("IsSchemaOwned"); + Property isSchemaOwnedProp = Properties.Get("IsSchemaOwned"); if (!isSchemaOwnedProp.IsNull) { schemaOwned = (bool)isSchemaOwnedProp.Value; @@ -94,7 +94,7 @@ internal override void ScriptChangeOwner(StringCollection queries, ScriptingPref } else { - this.ScriptOwnerForShiloh(sb,sp,(string)prop.Value); + ScriptOwnerForShiloh(sb,sp,(string)prop.Value); } if (sb.Length > 0) { @@ -111,9 +111,9 @@ internal string GetSchema(ScriptingPreferences sp) return ScriptSchema; } // use owner name only if it's available - else if (null != this.Schema) + else if (null != Schema) { - return this.Schema; + return Schema; } return string.Empty; @@ -136,17 +136,17 @@ public virtual System.String Schema throw new SmoException(ExceptionTemplates.InvalidSchema); } - if (this.State == SqlSmoState.Pending) + if (State == SqlSmoState.Pending) { // if the object is in Pending state we can set the schema ((SchemaObjectKey)key).Schema = value; return; } - else if (this.State == SqlSmoState.Creating) + else if (State == SqlSmoState.Creating) { // if the object is in Existing state we can set the schema only if the object // has not been added to the collection - if (this.ObjectInSpace) + if (ObjectInSpace) { ((SchemaObjectKey)key).Schema = value; return; @@ -154,7 +154,7 @@ public virtual System.String Schema } // all other cases are not valid, we have to throw - throw new FailedOperationException(ExceptionTemplates.SetSchema, this, new InvalidSmoOperationException(ExceptionTemplates.SetSchema, this.State)); + throw new FailedOperationException(ExceptionTemplates.SetSchema, this, new InvalidSmoOperationException(ExceptionTemplates.SetSchema, State)); } } @@ -173,7 +173,7 @@ public override string Name ValidateName(value); if (ShouldNotifyPropertyChange) { - if (this.Name != value) + if (Name != value) { ((SimpleObjectKey)key).Name = value; OnPropertyChanged("Name"); @@ -213,27 +213,26 @@ internal void ChangeSchema(string newSchema, bool bCheckExisting) return; } - SchemaCollectionBase col = this.ParentColl as SchemaCollectionBase; - if (null != this.Schema && this.Schema.Length != 0 && null != col && col.Contains(Name, this.Schema)) + if (!string.IsNullOrEmpty(Schema) && ParentColl is ISchemaObjectCollection col && col.Contains(Name, Schema)) { - if (bCheckExisting && SqlSmoState.Existing != this.State) + if (bCheckExisting && SqlSmoState.Existing != State) { throw new SmoException(ExceptionTemplates.FailedToChangeSchema); } //if object is created try to change the schema - if (SqlSmoState.Existing == this.State && !this.IsDesignMode) + if (SqlSmoState.Existing == State && !IsDesignMode) { - StringCollection queries = ScriptChangeSchema(this.Schema, newSchema); - this.ExecutionManager.ExecuteNonQuery(queries); + StringCollection queries = ScriptChangeSchema(Schema, newSchema); + ExecutionManager.ExecuteNonQuery(queries); } - //execution succedded + //execution succeeded //rearange in collection: for now for backward compatibility also for existing objects - if (!this.ExecutionManager.Recording) + if (!ExecutionManager.Recording) { - col.RemoveObject(Name, this.Schema); + ((ISchemaObjectCollectionInternal)col).RemoveObject(Name, Schema); ((SchemaObjectKey)key).Schema = newSchema; - col.AddExisting(this); + ParentColl.AddExisting(this); } } else @@ -247,10 +246,10 @@ private StringCollection ScriptChangeSchema(String oldSchema, String newSchema) { StringCollection queries = new StringCollection(); // buidl the full name - string fullName = string.Format(SmoApplication.DefaultCulture, "[{0}].[{1}]", SqlBraket(oldSchema), SqlBraket(this.Name)); + string fullName = string.Format(SmoApplication.DefaultCulture, "[{0}].[{1}]", SqlBraket(oldSchema), SqlBraket(Name)); queries.Add(string.Format(SmoApplication.DefaultCulture, Scripts.USEDB, SqlBraket(GetDBName()))); - if (this.ServerVersion.Major < 9) + if (ServerVersion.Major < 9) { queries.Add(string.Format(SmoApplication.DefaultCulture, "EXEC sp_changeobjectowner @objname=N'{0}', @newowner=N'{1}'", SqlString(fullName), SqlString(newSchema))); @@ -273,7 +272,7 @@ internal override string FullQualifiedName { get { - return string.Format(SmoApplication.DefaultCulture, "[{0}].[{1}]", SqlBraket(this.Schema), SqlBraket(this.Name)); + return string.Format(SmoApplication.DefaultCulture, "[{0}].[{1}]", SqlBraket(Schema), SqlBraket(Name)); } } diff --git a/src/Microsoft/SqlServer/Management/Smo/SearchPropertyBase.cs b/src/Microsoft/SqlServer/Management/Smo/SearchPropertyBase.cs index f859e878..08247efb 100644 --- a/src/Microsoft/SqlServer/Management/Smo/SearchPropertyBase.cs +++ b/src/Microsoft/SqlServer/Management/Smo/SearchPropertyBase.cs @@ -16,11 +16,6 @@ namespace Microsoft.SqlServer.Management.Smo /// SMO class for Search Properties in a Search Property List /// /// - - - //TODO: Uncomment the below attributes when we handle Facets in full, in later Improvements (VSTS task #280171) - //[Facets.EvaluationMode(Dmf.AutomatedPolicyEvaluationMode.CheckOnSchedule)] - //[Microsoft.SqlServer.Management.Sdk.Sfc.PhysicalFacet] public partial class SearchProperty : ScriptNameObjectBase, Cmn.ICreatable, Cmn.IDroppable, IScriptable { internal SearchProperty(AbstractCollectionBase parentColl, ObjectKeyBase key, SqlSmoState state) : diff --git a/src/Microsoft/SqlServer/Management/Smo/SecurityPredicateCollectionBase.cs b/src/Microsoft/SqlServer/Management/Smo/SecurityPredicateCollectionBase.cs index 968ac7bb..ba68bb7d 100644 --- a/src/Microsoft/SqlServer/Management/Smo/SecurityPredicateCollectionBase.cs +++ b/src/Microsoft/SqlServer/Management/Smo/SecurityPredicateCollectionBase.cs @@ -8,139 +8,106 @@ namespace Microsoft.SqlServer.Management.Smo { - /// - /// SecurityPredicateCollectionBase - /// - public abstract class SecurityPredicateCollectionBase : SortedListCollectionBase - { - - internal SecurityPredicateCollectionBase(SqlSmoObject parent) - : base(parent) - { - } - - /// - /// Internal Storage - /// - protected override void InitInnerCollection() - { - InternalStorage = new SmoSortedList(new SecurityPredicateObjectComparer()); - } - - /// - /// Contains Method - /// - /// The security predicate id - /// The security predicate if it exists. - public bool Contains(int securityPredicateID) - { - return this.Contains(new SecurityPredicateObjectKey(securityPredicateID)); - } - - /// - /// Gets the filter predicate that applies to the specified object id if it exists. - /// - /// The target object id - /// The security predicate if found, null otherwise - public SecurityPredicate GetItemByTargetObjectID(int targetObjectID) - { - return GetItemByTargetObjectID(targetObjectID, SecurityPredicateType.Filter, SecurityPredicateOperation.All); - } - - /// - /// Gets the security predicate for a given target object ID, type, and operation. - /// - /// The target object id - /// The type of the security predicate - /// The operation type of the security predicate - /// The security predicate if found, null otherwise - public SecurityPredicate GetItemByTargetObjectID(int targetObjectID, SecurityPredicateType predicateType, SecurityPredicateOperation predicateOperation) - { - foreach(SecurityPredicate secpred in InternalStorage) - { - if(secpred.TargetObjectID == targetObjectID - && secpred.PredicateType == predicateType - && secpred.PredicateOperation == predicateOperation) - { - return secpred; - } - } - - return null; - } - - internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) - { - int securityPredicateID = int.Parse(urn.GetAttribute("SecurityPredicateID"), SmoApplication.DefaultCulture); - - return new SecurityPredicateObjectKey(securityPredicateID); - } - } - - internal class SecurityPredicateObjectComparer : ObjectComparerBase - { - internal SecurityPredicateObjectComparer() - : base(null) - { - } - - public override int Compare(object obj1, object obj2) - { - return ((SecurityPredicateObjectKey)obj1).SecurityPredicateID - ((SecurityPredicateObjectKey)obj2).SecurityPredicateID; - } - } - - internal class SecurityPredicateObjectKey : ObjectKeyBase - { - protected int securityPredicateID; - - public SecurityPredicateObjectKey(int securityPredicateID) - : base() - { - this.securityPredicateID = securityPredicateID; - } - - static SecurityPredicateObjectKey() - { - fields.Add("SecurityPredicateID"); - } - - internal static readonly StringCollection fields = new StringCollection(); - - public int SecurityPredicateID - { - get { return securityPredicateID; } - set { securityPredicateID = value; } - } - - public override string ToString() - { - return string.Format(SmoApplication.DefaultCulture, "{0}", SecurityPredicateID); - } - - public override string UrnFilter - { - get { return string.Format(SmoApplication.DefaultCulture, "@SecurityPredicateID={0}", securityPredicateID); } - } - - public override StringCollection GetFieldNames() - { - return fields; - } - - public override ObjectKeyBase Clone() - { - return new SecurityPredicateObjectKey(this.SecurityPredicateID); - } - - public override bool IsNull - { - get { return false; } - } - - public override ObjectComparerBase GetComparer(IComparer stringComparer) - { - return new SecurityPredicateObjectComparer(); - } - } + public abstract class SecurityPredicateCollectionBase : SortedListCollectionBase + { + + internal SecurityPredicateCollectionBase(SqlSmoObject parent) + : base((SecurityPolicy)parent) + { + } + + /// + /// Internal Storage + /// + protected override void InitInnerCollection() => InternalStorage = new SmoSortedList(new SecurityPredicateObjectComparer()); + + /// + /// Contains Method + /// + /// The security predicate id + /// The security predicate if it exists. + public bool Contains(int securityPredicateID) => Contains(new SecurityPredicateObjectKey(securityPredicateID)); + + /// + /// Gets the filter predicate that applies to the specified object id if it exists. + /// + /// The target object id + /// The security predicate if found, null otherwise + public SecurityPredicate GetItemByTargetObjectID(int targetObjectID) => GetItemByTargetObjectID(targetObjectID, SecurityPredicateType.Filter, SecurityPredicateOperation.All); + + /// + /// Gets the security predicate for a given target object ID, type, and operation. + /// + /// The target object id + /// The type of the security predicate + /// The operation type of the security predicate + /// The security predicate if found, null otherwise + public SecurityPredicate GetItemByTargetObjectID(int targetObjectID, SecurityPredicateType predicateType, SecurityPredicateOperation predicateOperation) + { + foreach (var secpred in InternalStorage) + { + if (secpred.TargetObjectID == targetObjectID + && secpred.PredicateType == predicateType + && secpred.PredicateOperation == predicateOperation) + { + return secpred; + } + } + + return null; + } + + internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) + { + var securityPredicateID = int.Parse(urn.GetAttribute("SecurityPredicateID"), SmoApplication.DefaultCulture); + + return new SecurityPredicateObjectKey(securityPredicateID); + } + } + + internal class SecurityPredicateObjectComparer : ObjectComparerBase + { + internal SecurityPredicateObjectComparer() + : base(null) + { + } + + public override int Compare(object obj1, object obj2) => ((SecurityPredicateObjectKey)obj1).SecurityPredicateID - ((SecurityPredicateObjectKey)obj2).SecurityPredicateID; + } + + internal class SecurityPredicateObjectKey : ObjectKeyBase + { + protected int securityPredicateID; + + public SecurityPredicateObjectKey(int securityPredicateID) + : base() + { + this.securityPredicateID = securityPredicateID; + } + + static SecurityPredicateObjectKey() + { + _ = fields.Add(nameof(SecurityPredicate.SecurityPredicateID)); + } + + internal static readonly StringCollection fields = new StringCollection(); + + public int SecurityPredicateID + { + get { return securityPredicateID; } + set { securityPredicateID = value; } + } + + public override string ToString() => string.Format(SmoApplication.DefaultCulture, "{0}", SecurityPredicateID); + + public override string UrnFilter => string.Format(SmoApplication.DefaultCulture, "@SecurityPredicateID={0}", securityPredicateID); + + public override StringCollection GetFieldNames() => fields; + + public override ObjectKeyBase Clone() => new SecurityPredicateObjectKey(SecurityPredicateID); + + public override bool IsNull => false; + + public override ObjectComparerBase GetComparer(IComparer stringComparer) => new SecurityPredicateObjectComparer(); + } } \ No newline at end of file diff --git a/src/Microsoft/SqlServer/Management/Smo/SmoArrayList.cs b/src/Microsoft/SqlServer/Management/Smo/SmoArrayList.cs index fde229a5..d04dfc53 100644 --- a/src/Microsoft/SqlServer/Management/Smo/SmoArrayList.cs +++ b/src/Microsoft/SqlServer/Management/Smo/SmoArrayList.cs @@ -3,51 +3,50 @@ using System; using System.Collections; +using System.Collections.Generic; + -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 namespace Microsoft.SqlServer.Management.Smo { - public abstract class ArrayListCollectionBase : SmoCollectionBase - { - internal ArrayListCollectionBase(SqlSmoObject parent) : base(parent) - { - } - - internal ArrayList InternalList - { - get { return ((SmoArrayList)InternalStorage).innerCollection;} - } - - private void FixIDs(int startIdx) - { - int realID = startIdx; - for(int i = startIdx; i < InternalList.Count; i++) - { - Property propID = ((SqlSmoObject)InternalList[i]).Properties.Get("ID"); - if( !propID.Retrieved || Convert.ToInt32(propID.Value, SmoApplication.DefaultCulture) != 0 ) - { - propID.SetRetrieved(true); - if( propID.Type.Equals( typeof(System.Int16)) ) - { - propID.SetValue((System.Int16)(++realID)); - } - else if( propID.Type.Equals(typeof(System.Byte)) ) - { - propID.SetValue((System.Byte)(++realID)); - } - else - { - propID.SetValue(++realID); - } - } - } - } - - protected void AddImpl(SqlSmoObject obj, Int32 insertAtPosition) - { - CheckCollectionLock(); - - if( null == obj ) + public abstract class ArrayListCollectionBase : SmoCollectionBase + where TObject : SqlSmoObject + where TParent : SqlSmoObject + { + internal ArrayListCollectionBase(TParent parent) : base(parent) + { + } + + + private void FixIDs(int startIdx) + { + var realID = startIdx; + for (var i = startIdx; i < Count; i++) + { + var propID = InternalStorage.GetByIndex(i).Properties.Get("ID"); + if (!propID.Retrieved || Convert.ToInt32(propID.Value, SmoApplication.DefaultCulture) != 0) + { + propID.SetRetrieved(true); + if (propID.Type.Equals(typeof(short))) + { + propID.SetValue((short)(++realID)); + } + else if (propID.Type.Equals(typeof(byte))) + { + propID.SetValue((byte)(++realID)); + } + else + { + propID.SetValue(++realID); + } + } + } + } + + protected void AddImpl(TObject obj, int insertAtPosition) + { + CheckCollectionLock(); + + if (null == obj) { throw new FailedOperationException(ExceptionTemplates.AddCollection, this, new ArgumentNullException()); } @@ -57,121 +56,110 @@ protected void AddImpl(SqlSmoObject obj, Int32 insertAtPosition) // it is in Pending state and its key has been set if (null == obj.ParentColl) { - obj.SetParentImpl(this.ParentInstance); + obj.SetParentImpl(ParentInstance); } obj.CheckPendingState(); - ValidateParentObject(obj); + ValidateParentObject(obj); - InternalList.Insert( insertAtPosition, obj); - obj.objectInSpace = false; - obj.key.Writable = true; + InternalStorage.InsertAt(insertAtPosition, obj); + obj.objectInSpace = false; + obj.key.Writable = true; - // if we can have duplicate names in the collection this means the ID's are - // coming from the server and we don't need to rearrange them - if( !this.AcceptDuplicateNames ) + // if we can have duplicate names in the collection this means the ID's are + // coming from the server and we don't need to rearrange them + if (!AcceptDuplicateNames) { FixIDs(insertAtPosition); } } - internal void AddImpl(SqlSmoObject obj, ObjectKeyBase insertAtKey) - { - CheckCollectionLock(); + internal void AddImpl(TObject obj, ObjectKeyBase insertAtKey) + { + CheckCollectionLock(); - if( null == obj ) + if (null == obj) { throw new FailedOperationException(ExceptionTemplates.AddCollection, this, new ArgumentNullException()); } - int pos = InternalStorage.LookUp(insertAtKey); + var pos = InternalStorage.LookUp(insertAtKey); if (-1 == pos) { throw new SmoException(ExceptionTemplates.ColumnBeforeNotExisting(insertAtKey.ToString())); } AddImpl(obj, pos); - } - - internal void AddImpl(SqlSmoObject obj) - { - try - { - if (null == obj) - { - throw new ArgumentNullException(); - } + } + internal void AddImpl(TObject obj) + { + if (null == obj) + { + throw new ArgumentNullException(); + } + try + { // Since we can have column objects upto 100k through sparse columns support, look up takes a huge amount of time in case of create time // Hence we removed the look up in case of columns. Then engine throws the exception in this case. if (!(obj is Column)) { - int pos = InternalStorage.LookUp(obj.key); + var pos = InternalStorage.LookUp(obj.key); if (-1 != pos) { - throw new SmoException(ExceptionTemplates.CannotAddObject(obj.GetType().Name, obj.ToString())); + throw new SmoException(ExceptionTemplates.CannotAddObject(typeof(TObject).Name, obj.ToString())); } } - AddImpl(obj, InternalStorage.Count); - } - catch (Exception e) - { - SqlSmoObject.FilterException(e); - - throw new FailedOperationException(ExceptionTemplates.AddCollection, this, e); - } - } - } - - - internal class SmoArrayList : SmoInternalStorage - { - internal ArrayList innerCollection = null; - SmoCollectionBase parent = null; - internal SmoArrayList(IComparer keyComparer, SmoCollectionBase parent) : base(keyComparer) - { - innerCollection = new ArrayList(); - this.parent = parent; - } - - internal override bool Contains(ObjectKeyBase key) - { - return LookUp(key) != -1; - } - - internal override Int32 LookUp(ObjectKeyBase key) - { - for( int idx = 0; idx < innerCollection.Count; idx++) - { - if( 0 == keyComparer.Compare(key, ((SqlSmoObject)innerCollection[idx]).key )) + AddImpl(obj, InternalStorage.Count); + } + catch (Exception e) + { + SqlSmoObject.FilterException(e); + + throw new FailedOperationException(ExceptionTemplates.AddCollection, this, e); + } + } + } + + internal class SmoArrayList : SmoInternalStorage + where TObject : SqlSmoObject + where TParent : SqlSmoObject + { + internal readonly List innerCollection = new List(); + private readonly SmoCollectionBase parent; + internal SmoArrayList(IComparer keyComparer, SmoCollectionBase parent) : base(keyComparer) + { + this.parent = parent; + } + + internal override bool Contains(ObjectKeyBase key) => LookUp(key) != -1; + + internal override int LookUp(ObjectKeyBase key) + { + for (var idx = 0; idx < innerCollection.Count; idx++) + { + if (0 == keyComparer.Compare(key, innerCollection[idx].key)) { return idx; } } - - return -1; - } - - internal override SqlSmoObject this[ObjectKeyBase key] - { - get - { - int pos = LookUp(key); - if( pos != -1 ) - { - return innerCollection[pos] as SqlSmoObject; - } - else - { - return null; - } + + return -1; + } + + internal override TObject this[ObjectKeyBase key] + { + get + { + var pos = LookUp(key); + return pos != -1 ? innerCollection[pos] : null; } - set - { - int pos = LookUp(key); - if( pos != -1 ) + set + { + var pos = LookUp(key); + if (pos != -1) { innerCollection[pos] = value; } @@ -180,75 +168,40 @@ internal override SqlSmoObject this[ObjectKeyBase key] innerCollection.Add(value); } } - } - - internal override SqlSmoObject GetByIndex(Int32 index) - { - return innerCollection[index] as SqlSmoObject; - } - - public override Int32 Count - { - get { return innerCollection.Count;} - } - - internal override void Add(ObjectKeyBase key, SqlSmoObject o) - { - innerCollection.Add(o); - o.key.Writable = false; - } - - internal override void Remove(ObjectKeyBase key) - { - int pos = LookUp(key); - if (pos != -1) - { - ((SqlSmoObject)innerCollection[pos]).key.Writable = true; - innerCollection.RemoveAt(pos); - } - else + } + + internal override TObject GetByIndex(int index) => innerCollection[index]; + + public override int Count => innerCollection.Count; + + internal override void Add(ObjectKeyBase key, TObject o) + { + innerCollection.Add(o); + o.key.Writable = false; + } + + internal override void Remove(ObjectKeyBase key) + { + var pos = LookUp(key); + if (pos != -1) + { + innerCollection[pos].key.Writable = true; + innerCollection.RemoveAt(pos); + } + else { throw new InternalSmoErrorException(ExceptionTemplates.CouldNotFindKey(key.ToString())); } } - - internal override void Clear() - { - innerCollection.Clear(); - } - - internal override void InsertAt(int position, SqlSmoObject o) - { - innerCollection.Insert(position, o); - } - - internal override void RemoveAt(int position) - { - innerCollection.RemoveAt(position); - } - - internal override bool IsSynchronized - { - get - { - return innerCollection.IsSynchronized; - } - - } - - internal override object SyncRoot - { - get - { - return innerCollection.SyncRoot; - } - } - - public override IEnumerator GetEnumerator() - { - return innerCollection.GetEnumerator(); - } - - } + + internal override void Clear() => innerCollection.Clear(); + + internal override void InsertAt(int position, TObject o) => innerCollection.Insert(position, o); + + internal override void RemoveAt(int position) => innerCollection.RemoveAt(position); + + public override IEnumerator GetEnumerator() => innerCollection.GetEnumerator(); + + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/SmoCollectionBase.cs b/src/Microsoft/SqlServer/Management/Smo/SmoCollectionBase.cs index 46d8021a..3f9ed2c6 100644 --- a/src/Microsoft/SqlServer/Management/Smo/SmoCollectionBase.cs +++ b/src/Microsoft/SqlServer/Management/Smo/SmoCollectionBase.cs @@ -5,19 +5,23 @@ using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; -using System.Diagnostics.CodeAnalysis; using Microsoft.SqlServer.Management.Sdk.Sfc; +using Microsoft.SqlServer.Management.Smo.Agent; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 namespace Microsoft.SqlServer.Management.Smo { - using Microsoft.SqlServer.Management.Smo.Agent; - - public abstract class SmoCollectionBase : AbstractCollectionBase, ICollection + /// + /// Base implementation of ICollection for SMO objects + /// + /// + /// + public abstract class SmoCollectionBase : AbstractCollectionBase, ICollection, IEnumerable, ILockableCollection, ISmoInternalCollection, ISmoCollection + where TObject : SqlSmoObject + where TParent : SqlSmoObject { - private SmoInternalStorage internalStorage = null; - internal SmoInternalStorage InternalStorage + private SmoInternalStorage internalStorage = null; + internal SmoInternalStorage InternalStorage { get { @@ -31,44 +35,35 @@ internal SmoInternalStorage InternalStorage } - internal SmoCollectionBase(SqlSmoObject parent) + internal SmoCollectionBase(TParent parent) : base(parent) { } + /// + /// Returns the object at the given index after ensuring the collection is initialized + /// + /// + /// + public TObject this[int index] => GetObjectByIndex(index); + protected abstract void InitInnerCollection(); - protected virtual Type GetCollectionElementType() - { - return null; - } string m_lockReason = null; - internal void LockCollection(string lockReason) - { - m_lockReason = lockReason; - } + internal void LockCollection(string lockReason) => m_lockReason = lockReason; - internal void UnlockCollection() - { - m_lockReason = null; - } + internal void UnlockCollection() => m_lockReason = null; /// /// return true if the collection is locked for updates ( it gets locked /// when the parent text object in in text mode ) /// - internal bool IsCollectionLocked - { - get - { - return null != m_lockReason; - } - } + internal bool IsCollectionLocked => null != m_lockReason; internal void CheckCollectionLock() { - if (ParentInstance.IsDesignMode) + if (ParentInstance.IsDesignMode) { return; } @@ -79,105 +74,79 @@ internal void CheckCollectionLock() } } - internal virtual SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return null; - } + internal abstract TObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state); - public bool IsSynchronized - { - get - { - return InternalStorage.IsSynchronized; - } + internal override void ImplRemove(ObjectKeyBase key) => InternalStorage.Remove(key); - } + internal void Remove(ObjectKeyBase key) => RemoveObj(InternalStorage[key], key); - public object SyncRoot + internal void RemoveObj(TObject obj, ObjectKeyBase key) { - get + CheckCollectionLock(); + if (null != obj) { - return InternalStorage.SyncRoot; - } - } - - internal override void ImplRemove(ObjectKeyBase key) - { - InternalStorage.Remove(key); - } - - internal void Remove(ObjectKeyBase key) - { - RemoveObj((SqlSmoObject)InternalStorage[key], key); - } + if (obj.State == SqlSmoState.Creating || + ((obj is Column) && (obj.ParentColl.ParentInstance is View)) + ) + { + InternalStorage.Remove(key); + obj.objectInSpace = true; + } + else + { + throw new InvalidSmoOperationException("Remove", obj.State); + } - internal void RemoveObj(SqlSmoObject obj, ObjectKeyBase key) - { - CheckCollectionLock(); - if( null != obj ) - { - if( obj.State == SqlSmoState.Creating || - ((obj is Column) && (obj.ParentColl.ParentInstance is View )) - ) - { - InternalStorage.Remove(key); - obj.objectInSpace = true; } else { - throw new InvalidSmoOperationException("Remove", obj.State); - } - - } - else - { - if( !key.IsNull ) + if (!key.IsNull) { - throw new MissingObjectException(ExceptionTemplates.ObjectDoesNotExist(GetCollectionElementType().Name, key.ToString())); + throw new MissingObjectException(ExceptionTemplates.ObjectDoesNotExist(typeof(TObject).Name, key.ToString())); } else { throw new FailedOperationException(ExceptionTemplates.RemoveCollection, this, new ArgumentNullException()); } } - } - - + } - internal SqlSmoObject GetNewObject(ObjectKeyBase key) + internal TObject GetNewObject(ObjectKeyBase key) { - key.Validate(GetCollectionElementType()); + key.Validate(typeof(TObject)); - bool needsValidation = (null == ParentInstance || !ParentInstance.IsObjectInSpace()); + var needsValidation = null == ParentInstance || !ParentInstance.IsObjectInSpace(); if ((true == InternalStorage.Contains(key) || (needsValidation && (null != InitializeChildObject(key)))) && - !this.AcceptDuplicateNames) + !AcceptDuplicateNames) { - throw new SmoException(ExceptionTemplates.CannotAddObject(GetCollectionElementType().ToString(), key.ToString())); + throw new SmoException(ExceptionTemplates.CannotAddObject(typeof(TObject).ToString(), key.ToString())); } // instantiate a new child object return GetCollectionElementInstance(key, SqlSmoState.Creating); } + internal virtual SqlSmoObject GetObjectByName(string name) => GetObjectByKey(new SimpleObjectKey(name)); + // returns wrapped object - protected SqlSmoObject GetObjectByIndex(Int32 index) + protected TObject GetObjectByIndex(int index) { if (!initialized && ParentInstance.State == SqlSmoState.Existing) { InitializeChildCollection(); } - return InternalStorage.GetByIndex(index) as SqlSmoObject; + return InternalStorage.GetByIndex(index) as TObject; } // returns wrapped object - internal virtual SqlSmoObject GetObjectByKey(ObjectKeyBase key) + internal virtual TObject GetObjectByKey(ObjectKeyBase key) { object instanceObject = InternalStorage[key]; - bool needsValidation = (null == ParentInstance || !ParentInstance.IsObjectInSpace()); ; + var needsValidation = null == ParentInstance || !ParentInstance.IsObjectInSpace(); ; if ((null == instanceObject) && needsValidation && @@ -187,7 +156,7 @@ internal virtual SqlSmoObject GetObjectByKey(ObjectKeyBase key) instanceObject = InitializeChildObject(key); } - return instanceObject as SqlSmoObject; + return instanceObject as TObject; } /// @@ -203,7 +172,7 @@ internal virtual SqlSmoObject GetObjectByKey(ObjectKeyBase key) /// By setting the parameter to null or empty array, only the default fields will be included in the result public void ClearAndInitialize(string filterQuery, IEnumerable extraFields) { - this.InternalStorage.Clear(); + InternalStorage.Clear(); InitializeChildCollection(false, null, filterQuery: filterQuery, extraFields: extraFields); } @@ -216,65 +185,43 @@ public void ResetCollection() UnlockCollection(); } - private void InitializeChildCollection(bool refresh, ScriptingPreferences sp) - { - InitializeChildCollection(refresh, sp, filterQuery: null, extraFields: null); - } + private void InitializeChildCollection(bool refresh, ScriptingPreferences sp) => InitializeChildCollection(refresh, sp, filterQuery: null, extraFields: null); /// /// Initialize the child collection /// - protected void InitializeChildCollection() - { - InitializeChildCollection(false); - } + protected void InitializeChildCollection() => InitializeChildCollection(false); /// /// Initializes the child collection, optionally keeping all the old objects /// /// directs if we discard the old objects - protected void InitializeChildCollection(bool refresh) - { - InitializeChildCollection(refresh, null); - } + protected void InitializeChildCollection(bool refresh) => InitializeChildCollection(refresh, null); + + protected abstract string UrnSuffix { get; } - [SuppressMessage("Microsoft.Reliability", "CA2001:AvoidCallingProblematicMethods", - MessageId = "System.Type.InvokeMember")] private void InitializeChildCollection(bool refresh, ScriptingPreferences sp, string filterQuery, IEnumerable extraFields) { - // In design mode the objects are not retrieved, but are added by the client - if (this.ParentInstance.IsDesignMode) + // In design mode the objects are not retrieved, but are added by the client + if (ParentInstance.IsDesignMode) { - this.initialized = true; + initialized = true; return; } // keep the old collection, because we'll append all the objects to the new one - SmoInternalStorage oldColl = InternalStorage; + var oldColl = InternalStorage; InitInnerCollection(); - - string urnsuffix = null; - if( this.GetCollectionElementType().GetBaseType() == typeof(Parameter) ) - { - urnsuffix = this.GetCollectionElementType().GetBaseType().GetBaseType().InvokeMember("UrnSuffix", - SqlSmoObject.UrnSuffixBindingFlags, - null, null, new object[] {}, SmoApplication.DefaultCulture ) as string; - } - else - { - urnsuffix = this.GetCollectionElementType().InvokeMember("UrnSuffix", - SqlSmoObject.UrnSuffixBindingFlags, - null, null, new object[] {}, SmoApplication.DefaultCulture ) as string; - } - - urnsuffix += (string.IsNullOrEmpty(filterQuery) ? string.Empty : filterQuery); + + var urnsuffix = UrnSuffix + (string.IsNullOrEmpty(filterQuery) ? string.Empty : filterQuery); + // init the collection with objects - this.ParentInstance.InitChildLevel(urnsuffix, sp ?? new ScriptingPreferences(), forScripting: sp != null, extraFields: extraFields); - + ParentInstance.InitChildLevel(urnsuffix, sp ?? new ScriptingPreferences(), forScripting: sp != null, extraFields: extraFields); + // now merge the old collection into the new one - foreach (SqlSmoObject oldObj in oldColl) + foreach (var oldObj in oldColl) { - ObjectKeyBase sok = oldObj.key.Clone(); - SqlSmoObject obj = InternalStorage[sok]; + var sok = oldObj.key.Clone(); + var obj = InternalStorage[sok]; if (null != obj) { InternalStorage[sok] = oldObj; @@ -296,27 +243,27 @@ private void InitializeChildCollection(bool refresh, ScriptingPreferences sp, st } // update the state flag - this.initialized = true; + initialized = true; } - + // this function tries to instantiate a missing object // and if it exists we add it to the collection internal object InitializeChildObject(ObjectKeyBase key) { - if (this.ParentInstance.IsDesignMode) + if (ParentInstance.IsDesignMode) { // Do not try to get the object while in design mode. return null; } - SqlSmoObject childobj = GetCollectionElementInstance(key, SqlSmoState.Creating); - - if( childobj.Initialize() ) + var childobj = GetCollectionElementInstance(key, SqlSmoState.Creating); + + if (childobj.Initialize()) { // update object's state and add it to the collection childobj.SetState(SqlSmoState.Existing); - this.AddExisting(childobj); + AddExisting(childobj); return childobj; } else @@ -325,22 +272,16 @@ internal object InitializeChildObject(ObjectKeyBase key) } } - - - // behaves like this[string].get - internal bool Contains(ObjectKeyBase key) - { - return null != GetObjectByKey(key); - } + internal bool Contains(ObjectKeyBase key) => null != GetObjectByKey(key); - internal bool ContainsKey(ObjectKeyBase key) - { - return null != InternalStorage[key]; - } + internal bool ContainsKey(ObjectKeyBase key) => null != InternalStorage[key]; - public Int32 Count + /// + /// Returns the number of objects in the collection after ensuring the collection is initialized + /// + public int Count { get { @@ -352,50 +293,51 @@ public Int32 Count } } - public void Refresh() - { - Refresh(false); - } + /// + /// Recreates the collection contents from the database without refreshing properties of any existing objects in the collection. + /// + public void Refresh() => Refresh(false); + /// + /// Refreshes the contents of the collection and refreshes the properties of existing objects in the collection + /// + /// public void Refresh(bool refreshChildObjects) { InitializeChildCollection(true); if (refreshChildObjects) { - IEnumerator ienum = this.GetEnumerator(); - - if (null != ienum) + foreach (var obj in this) { - while (ienum.MoveNext()) - { - ((SqlSmoObject)ienum.Current).Refresh(); - } + obj.Refresh(); } } } + /// + /// Returns the item whose numeric ID property matches id + /// + /// + /// + public virtual TObject ItemById(int id) => GetItemById(id); + internal void Clear() { MarkAllDropped(); InternalStorage.Clear(); } - protected SqlSmoObject GetItemById(int id) - { - return GetItemById(id, "ID"); - } + protected TObject GetItemById(int id) => GetItemById(id, "ID"); - protected SqlSmoObject GetItemById(int id, string idPropName) + protected TObject GetItemById(int id, string idPropName) { - IEnumerator ie = ((IEnumerable)this).GetEnumerator(); - while (ie.MoveNext()) + foreach (var c in this) { - SqlSmoObject c = (SqlSmoObject)ie.Current; - Property p = c.Properties.Get(idPropName); + var p = c.Properties.Get(idPropName); if (null == p.Value && c.State != SqlSmoState.Creating) { - c.Initialize(true); // initialize the object to get the property value + _ = c.Initialize(true); // initialize the object to get the property value } if (null != p.Value && id == Convert.ToInt32(p.Value, SmoApplication.DefaultCulture)) // found object with the right id @@ -409,10 +351,12 @@ protected SqlSmoObject GetItemById(int id, string idPropName) internal void MarkAllDropped() { - IEnumerator collenum = this.GetEnumerator(); + // GetEnumerator returns null if the parent is already marked as Dropped + // So we can't use foreach. + var collenum = GetEnumerator(); while (collenum != null && collenum.MoveNext()) - { - ((SqlSmoObject)collenum.Current).MarkDroppedInternal(); + { + collenum.Current.MarkDroppedInternal(); } } @@ -421,7 +365,7 @@ internal void MarkAllDropped() /// /// The optional scripting settings to pass along to each SqlSmoObject. /// - internal IEnumerator GetEnumerator(ScriptingPreferences sp) + internal IEnumerator GetEnumerator(ScriptingPreferences sp) { //If our parent is dropped we can't get an enumerator //since we depend on its properties (such as DB collation) @@ -438,60 +382,39 @@ internal IEnumerator GetEnumerator(ScriptingPreferences sp) return InternalStorage.GetEnumerator(); } - /// - /// Returns an enumerator after making sure the collection is initialized with the default properties - /// - /// - public virtual IEnumerator GetEnumerator() - { - return GetEnumerator(null); - } - internal override SqlSmoObject NoFaultLookup(ObjectKeyBase key) - { - return InternalStorage[key] as SqlSmoObject; - } + internal override SqlSmoObject NoFaultLookup(ObjectKeyBase key) => InternalStorage[key]; - internal override Int32 NoFaultCount { get { return InternalStorage.Count; } } + internal override int NoFaultCount => InternalStorage.Count; - protected override void ImplAddExisting(SqlSmoObject obj) - { - InternalStorage.Add(obj.key, obj); - } + protected override void ImplAddExisting(SqlSmoObject obj) => InternalStorage.Add(obj.key, (TObject)obj); // implementing ICollection - void ICollection.CopyTo(Array array, Int32 index) + public void CopyTo(TObject[] array, int index) { - int idx = index; - foreach (SqlSmoObject sp in InternalStorage) + foreach (var obj in InternalStorage) { - array.SetValue(sp, idx++); + array[index++] = obj; } } - bool acceptDuplicateNames = false; - internal bool AcceptDuplicateNames + int ICollection.Count => Count; + object ICollection.SyncRoot => null; + bool ICollection.IsSynchronized => false; + void ICollection.CopyTo(Array array, int index) { - get { return acceptDuplicateNames; } - set { acceptDuplicateNames = value; } - } - - internal bool CanHaveEmptyName(Urn urn) - { - //all agent objects can have empty names - if (urn.Value.IndexOf("/JobServer", StringComparison.Ordinal) > 0) - { - return true; - } - if ((urn.Type == "Login" && urn.Parent.Type == "LinkedServer")) + var idx = index; + foreach (var obj in InternalStorage) { - return true; + array.SetValue(obj, idx++); } - - return false; } + internal bool AcceptDuplicateNames { get; set; } = false; + bool ILockableCollection.IsCollectionLocked => IsCollectionLocked; + + internal virtual bool CanHaveEmptyName(Urn urn) => false; - protected void ValidateParentObject(SqlSmoObject obj) + protected void ValidateParentObject(TObject obj) { // check to see if the object being added belongs to a // different collection @@ -501,7 +424,35 @@ protected void ValidateParentObject(SqlSmoObject obj) } } + /// + /// Ensures the collection is initialized and returns a strongly typed IEnumerator using default scripting preferences + /// + /// + public IEnumerator GetEnumerator() => GetEnumerator(null); + + /// + /// Ensures the collection is initialized and returns an IEnumerator using default scripting preferences + /// + /// + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + + void ILockableCollection.LockCollection(string lockReason) => LockCollection(lockReason); + + void ILockableCollection.UnlockCollection() => UnlockCollection(); + + void ILockableCollection.CheckCollectionLock() => CheckCollectionLock(); + + SqlSmoObject ISmoInternalCollection.GetObjectByKey(ObjectKeyBase key) => GetObjectByKey(key); + IEnumerable ISmoInternalCollection.InternalStorage => InternalStorage; + IEnumerator ISmoInternalCollection.GetEnumerator(ScriptingPreferences sp) => GetEnumerator(sp); + } + + internal interface ISmoInternalCollection + { + SqlSmoObject GetObjectByKey(ObjectKeyBase key); + IEnumerable InternalStorage { get; } + IEnumerator GetEnumerator(ScriptingPreferences sp); } // base class for all comparers @@ -515,7 +466,7 @@ internal ObjectComparerBase(IComparer stringComparer) this.stringComparer = stringComparer; } - public virtual int Compare(object obj1, object obj2) { return 0; } + public virtual int Compare(object obj1, object obj2) => 0; } internal class ObjectKeyBase @@ -530,20 +481,11 @@ internal virtual void Validate(Type objectType) { } - public virtual string UrnFilter - { - get { return string.Empty; } - } + public virtual string UrnFilter => string.Empty; - public virtual StringCollection GetFieldNames() - { - return new StringCollection(); - } + public virtual StringCollection GetFieldNames() => new StringCollection(); - public virtual bool IsNull - { - get { return false; } - } + public virtual bool IsNull => false; bool writable = true; internal bool Writable @@ -552,15 +494,9 @@ internal bool Writable set { writable = value; } } - public virtual ObjectComparerBase GetComparer(IComparer stringComparer) - { - return new ObjectComparerBase(stringComparer); - } + public virtual ObjectComparerBase GetComparer(IComparer stringComparer) => new ObjectComparerBase(stringComparer); - public virtual ObjectKeyBase Clone() - { - return new ObjectKeyBase(); - } + public virtual ObjectKeyBase Clone() => new ObjectKeyBase(); /// /// Returns the name that we will use while displaying an exception @@ -569,12 +505,12 @@ public virtual ObjectKeyBase Clone() /// e.g. [dbo].[t1] will be shown as 'dbo.t1' /// /// - public virtual string GetExceptionName() - { + public virtual string GetExceptionName() => // the stock implementation is to return ToString() - return ToString(); - } + ToString(); + // TODO: https://github.com/microsoft/sqlmanagementobjects/issues/139 + // Replace these static factories with instance methods on the collection classes internal static StringCollection GetFieldNames(Type t) { if (t.IsSubclassOf(typeof(ScriptSchemaObjectBase))) @@ -621,6 +557,10 @@ internal static StringCollection GetFieldNames(Type t) { return ColumnEncryptionKeyValueObjectKey.fields; } + else if (t == typeof(IndexedJsonPath)) + { + return IndexedJsonPathObjectKey.fields; + } else if (t == typeof(ExternalStream)) { return ExternalStream.RequiredFields; @@ -629,15 +569,11 @@ internal static StringCollection GetFieldNames(Type t) { return ExternalStreamingJob.RequiredFields; } - else - { - return SimpleObjectKey.fields; - } + return SimpleObjectKey.fields; } internal static ObjectKeyBase CreateKeyOffset(Type t, System.Data.IDataReader reader, int columnOffset) { - // TODO: FIX_IN_KATMAI: just say no to special cases if (t.IsSubclassOf(typeof(ScriptSchemaObjectBase))) { @@ -687,7 +623,7 @@ internal static ObjectKeyBase CreateKeyOffset(Type t, System.Data.IDataReader re { return new AvailabilityGroupListenerIPAddressObjectKey(reader.GetString(columnOffset), reader.GetString(columnOffset + 1), reader.GetString(columnOffset + 2)); } - else if(t == typeof(SecurityPredicate)) + else if (t == typeof(SecurityPredicate)) { return new SecurityPredicateObjectKey(reader.GetInt32(columnOffset)); } @@ -695,52 +631,49 @@ internal static ObjectKeyBase CreateKeyOffset(Type t, System.Data.IDataReader re { return new ColumnEncryptionKeyValueObjectKey(reader.GetInt32(columnOffset)); } - else + else if (t == typeof(IndexedJsonPath)) { - return new SimpleObjectKey(reader.GetString(columnOffset)); + return new IndexedJsonPathObjectKey(reader.GetString(columnOffset)); } + return new SimpleObjectKey(reader.GetString(columnOffset)); } } - internal abstract class SmoInternalStorage : IEnumerable + internal abstract class SmoInternalStorage : IEnumerable + where T : SqlSmoObject { - protected IComparer keyComparer = null; + protected readonly IComparer keyComparer; internal SmoInternalStorage(IComparer keyComparer) { this.keyComparer = keyComparer; } internal abstract bool Contains(ObjectKeyBase key); - internal abstract Int32 LookUp(ObjectKeyBase key); + internal abstract int LookUp(ObjectKeyBase key); - internal abstract SqlSmoObject this[ObjectKeyBase key] + internal abstract T this[ObjectKeyBase key] { get; set; } - internal abstract SqlSmoObject GetByIndex(Int32 index); + internal abstract T GetByIndex(int index); - public abstract Int32 Count { get; } + public abstract int Count { get; } - internal abstract void Add(ObjectKeyBase key, SqlSmoObject o); + internal abstract void Add(ObjectKeyBase key, T o); internal abstract void Remove(ObjectKeyBase key); - internal abstract void InsertAt(int position, SqlSmoObject o); + internal abstract void InsertAt(int position, T o); internal abstract void RemoveAt(int position); - internal abstract bool IsSynchronized { get; } - - internal abstract object SyncRoot { get; } - - public abstract IEnumerator GetEnumerator(); + public abstract IEnumerator GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); internal abstract void Clear(); } - + } - - diff --git a/src/Microsoft/SqlServer/Management/Smo/SmoDependencyDiscoverer.cs b/src/Microsoft/SqlServer/Management/Smo/SmoDependencyDiscoverer.cs index 67fcec8f..f2cfc368 100644 --- a/src/Microsoft/SqlServer/Management/Smo/SmoDependencyDiscoverer.cs +++ b/src/Microsoft/SqlServer/Management/Smo/SmoDependencyDiscoverer.cs @@ -188,14 +188,13 @@ private List GetScriptableChildren(List propInf //saving the expensive initialization process of - //collection class (esp PhyisicalPartitionCollection) inside next foreach loop + //collection class (esp PhysicalPartitionCollection) inside next foreach loop if (pi.bWithScript || pi.bPropagateScriptToChildLevel) { IEnumerator enumerator; - var smoCollection = smoObjCol as SmoCollectionBase; - if (smoCollection != null) + if (smoObjCol is ISmoInternalCollection smoCollection) { - enumerator = smoCollection.GetEnumerator(this.Preferences); + enumerator = smoCollection.GetEnumerator(Preferences); } else { diff --git a/src/Microsoft/SqlServer/Management/Smo/SmoDependencyOrderer.cs b/src/Microsoft/SqlServer/Management/Smo/SmoDependencyOrderer.cs index 9c70d56f..1751f714 100644 --- a/src/Microsoft/SqlServer/Management/Smo/SmoDependencyOrderer.cs +++ b/src/Microsoft/SqlServer/Management/Smo/SmoDependencyOrderer.cs @@ -46,6 +46,7 @@ internal class SmoDependencyOrderer : ISmoDependencyOrderer private static string COLUMNSTOREINDEX = "columnstoreindex"; private static string CLUSTEREDCOLUMNSTOREINDEX = "clusteredcolumnstoreindex"; private static string VECTORINDEX = "vectorindex"; + private static string JSONINDEX = "jsonindex"; private static string DATA = "data"; private static string SERVERPERMISSION = "serverpermission"; private static string DATABASEPERMISSION = "databasepermission"; @@ -438,6 +439,7 @@ private void ResolveIndexDependenciesWithoutFactory() List columnstoreIndex = new List(); List clusteredColumnstoreIndex = new List(); List vectorIndex = new List(); + List jsonIndex = new List(); foreach (var index in indexList) { @@ -500,6 +502,9 @@ private void ResolveIndexDependenciesWithoutFactory() case IndexType.VectorIndex: vectorIndex.Add(index); break; + case IndexType.JsonIndex: + jsonIndex.Add(index); + break; default: throw new WrongPropertyValueException(index.Properties["IndexType"]); } @@ -516,6 +521,7 @@ private void ResolveIndexDependenciesWithoutFactory() this.urnTypeDictionary.Add(new UrnTypeKey(SmoDependencyOrderer.COLUMNSTOREINDEX), columnstoreIndex.ConvertAll(p => { return p.Urn; })); this.urnTypeDictionary.Add(new UrnTypeKey(SmoDependencyOrderer.CLUSTEREDCOLUMNSTOREINDEX), clusteredColumnstoreIndex.ConvertAll(p => { return p.Urn; })); this.urnTypeDictionary.Add(new UrnTypeKey(SmoDependencyOrderer.VECTORINDEX), vectorIndex.ConvertAll(p => { return p.Urn; })); + this.urnTypeDictionary.Add(new UrnTypeKey(SmoDependencyOrderer.JSONINDEX), jsonIndex.ConvertAll(p => { return p.Urn; })); } } @@ -538,6 +544,7 @@ private void ResolveIndexDependenciesWithFactory() List columnstoreIndex = new List(); List clusteredColumnstoreIndex = new List(); List vectorIndex = new List(); + List jsonIndex = new List(); foreach (var index in indexList) { @@ -586,6 +593,9 @@ private void ResolveIndexDependenciesWithFactory() case IndexType.VectorIndex: vectorIndex.Add(index); break; + case IndexType.JsonIndex: + jsonIndex.Add(index); + break; default: Diagnostics.TraceHelper.Assert(false, "Invalid IndexType"); break; @@ -604,6 +614,7 @@ private void ResolveIndexDependenciesWithFactory() this.urnTypeDictionary.Add(new UrnTypeKey(SmoDependencyOrderer.COLUMNSTOREINDEX), columnstoreIndex); this.urnTypeDictionary.Add(new UrnTypeKey(SmoDependencyOrderer.CLUSTEREDCOLUMNSTOREINDEX), clusteredColumnstoreIndex); this.urnTypeDictionary.Add(new UrnTypeKey(SmoDependencyOrderer.VECTORINDEX), vectorIndex); + this.urnTypeDictionary.Add(new UrnTypeKey(SmoDependencyOrderer.JSONINDEX), jsonIndex); } } diff --git a/src/Microsoft/SqlServer/Management/Smo/SmoSortedList.cs b/src/Microsoft/SqlServer/Management/Smo/SmoSortedList.cs index 7fc5e978..ed581bb3 100644 --- a/src/Microsoft/SqlServer/Management/Smo/SmoSortedList.cs +++ b/src/Microsoft/SqlServer/Management/Smo/SmoSortedList.cs @@ -3,16 +3,24 @@ using System; using System.Collections; +using System.Collections.Generic; namespace Microsoft.SqlServer.Management.Smo { - public abstract class SortedListCollectionBase : SmoCollectionBase + /// + /// A collection class that stores items sorted by key + /// + /// + /// + public abstract class SortedListCollectionBase : SmoCollectionBase, ISortedListCollection + where TObject : SqlSmoObject + where TParent : SqlSmoObject { - internal SortedListCollectionBase(SqlSmoObject parent) : base(parent) + internal SortedListCollectionBase(TParent parent) : base(parent) { } - protected void AddImpl(SqlSmoObject obj) + protected void AddImpl(TObject obj) { if( null == obj ) { @@ -23,18 +31,18 @@ protected void AddImpl(SqlSmoObject obj) // check if the object already exists, and throw a meaningful exception - SqlSmoObject objLookup = GetObjectByKey(obj.key); + var objLookup = GetObjectByKey(obj.key); if( null != objLookup ) { - throw new SmoException(ExceptionTemplates.CannotAddObject(obj.GetType().Name, obj.key.ToString())); + throw new SmoException(ExceptionTemplates.CannotAddObject(typeof(TObject).Name, obj.key.ToString())); } // we can add an object to a collection if it is in Creating state, or if // it is in Pending state and its key has been set if (null == obj.ParentColl) { - obj.SetParentImpl(this.ParentInstance); + obj.SetParentImpl(ParentInstance); } // if the object is in Pending state we should be throwing @@ -47,125 +55,80 @@ protected void AddImpl(SqlSmoObject obj) protected override void ImplAddExisting(SqlSmoObject obj) { - InternalStorage.Add(obj.key, obj); + InternalStorage.Add(obj.key, (TObject)obj); obj.objectInSpace = false; obj.ParentColl = this; } } - - - internal class SmoSortedList : SmoInternalStorage + internal interface ISortedListCollection { - SortedList innerCollection = null; + + } + internal class SmoSortedList : SmoInternalStorage + where T : SqlSmoObject + { + private readonly SortedList innerCollection = null; internal SmoSortedList(IComparer keyComparer) : base(keyComparer) { innerCollection = new SortedList(keyComparer); } - internal override bool Contains(ObjectKeyBase key) - { - return innerCollection.Contains(key); - } - - internal override Int32 LookUp(ObjectKeyBase key) - { - return this.Contains(key)?1:0; - } + internal override bool Contains(ObjectKeyBase key) => innerCollection.Contains(key); - internal override SqlSmoObject this[ObjectKeyBase key] - { - get { return innerCollection[key] as SqlSmoObject;} - set { innerCollection[key] = value as SqlSmoObject; } - } - - internal override SqlSmoObject GetByIndex(Int32 index) - { - return innerCollection.GetByIndex(index) as SqlSmoObject; - } + internal override int LookUp(ObjectKeyBase key) => Contains(key) ? 1 : 0; - public override Int32 Count + internal override T this[ObjectKeyBase key] { - get { return innerCollection.Count;} + get { return innerCollection[key] as T;} + set { innerCollection[key] = value as T; } } - internal override void Add(ObjectKeyBase key, SqlSmoObject o) + internal override T GetByIndex(int index) => innerCollection.GetByIndex(index) as T; + + public override int Count => innerCollection.Count; + + internal override void Add(ObjectKeyBase key, T o) { innerCollection[key] = o; o.key.Writable = false; } - - internal override void Remove(ObjectKeyBase key) - { - innerCollection.Remove(key); - } - - internal override void InsertAt(int position, SqlSmoObject o) - { + + internal override void Remove(ObjectKeyBase key) => innerCollection.Remove(key); + + internal override void InsertAt(int position, T o) => // this should never be called Diagnostics.TraceHelper.Assert(false); - } - - internal override void RemoveAt(int position) - { - innerCollection.RemoveAt(position); - } - internal override void Clear() - { - innerCollection.Clear(); - } + internal override void RemoveAt(int position) => innerCollection.RemoveAt(position); - internal override bool IsSynchronized - { - get - { - return innerCollection.IsSynchronized; - } - - } + internal override void Clear() => innerCollection.Clear(); - internal override object SyncRoot - { - get - { - return innerCollection.SyncRoot; - } - } - - public override IEnumerator GetEnumerator() - { - return new SmoSortedListEnumerator(innerCollection.GetEnumerator()); - } + public override IEnumerator GetEnumerator() => new SmoSortedListEnumerator(innerCollection.GetEnumerator()); // nested enumerator class // we need that to override the behaviour of SortedList // that exposes an IDictionaryEnumerator interface - internal sealed class SmoSortedListEnumerator : IEnumerator + // TODO: https://github.com/microsoft/sqlmanagementobjects/issues/140 + internal sealed class SmoSortedListEnumerator : IEnumerator { - private IEnumerator baseEnumerator; + private readonly IEnumerator baseEnumerator; internal SmoSortedListEnumerator(IEnumerator enumerator) { - this.baseEnumerator = enumerator; + baseEnumerator = enumerator; } - public object Current - { - get - { - return ((DictionaryEntry)baseEnumerator.Current).Value; - } - } + public T Current => ((DictionaryEntry)baseEnumerator.Current).Value as T; - public bool MoveNext() - { - return baseEnumerator.MoveNext(); - } - - public void Reset() + object IEnumerator.Current => Current; + + public bool MoveNext() => baseEnumerator.MoveNext(); + + public void Reset() => baseEnumerator.Reset(); + + void IDisposable.Dispose() { - baseEnumerator.Reset(); } } } diff --git a/src/Microsoft/SqlServer/Management/Smo/SmoUtility.cs b/src/Microsoft/SqlServer/Management/Smo/SmoUtility.cs index 3b8ab0ad..bfc58ddf 100644 --- a/src/Microsoft/SqlServer/Management/Smo/SmoUtility.cs +++ b/src/Microsoft/SqlServer/Management/Smo/SmoUtility.cs @@ -87,6 +87,12 @@ public static bool IsSupportedObject(Type type, ServerVersion serverVersion, Dat { case nameof(ExternalLanguage): return false; + case nameof(IndexedJsonPath): + if (serverVersion.Major < 17) + { + return false; + } + break; } } if (databaseEngineType == DatabaseEngineType.Standalone) @@ -112,6 +118,14 @@ public static bool IsSupportedObject(Type type, ServerVersion serverVersion, Dat } } + if (serverVersion.Major < 17) + { + switch (type.Name) + { + case nameof(IndexedJsonPath): + return false; + } + } if (serverVersion.Major < 15) { switch (type.Name) @@ -312,6 +326,7 @@ public static bool IsSupportedObject(Type type, ServerVersion serverVersion, Dat case nameof(ColumnEncryptionKey) : case nameof(ColumnEncryptionKeyValue) : case nameof(ColumnMasterKey) : + case nameof(DatabaseScopedConfiguration): case nameof(DatabaseScopedCredential) : case nameof(Default) : case nameof(ExtendedProperty): @@ -321,6 +336,7 @@ public static bool IsSupportedObject(Type type, ServerVersion serverVersion, Dat case nameof(FullTextIndexColumn) : case nameof(FullTextService) : case nameof(FullTextStopList) : + case nameof(IndexedJsonPath): case nameof(MasterKey) : case nameof(NumberedStoredProcedure) : case nameof(PartitionFunction) : @@ -336,7 +352,6 @@ public static bool IsSupportedObject(Type type, ServerVersion serverVersion, Dat case nameof(SecurityPolicy) : case nameof(SecurityPredicate) : case nameof(SensitivityClassification) : - case nameof(DatabaseScopedConfiguration): case nameof(Sequence) : case nameof(SqlAssembly) : case nameof(SymmetricKey) : @@ -344,7 +359,7 @@ public static bool IsSupportedObject(Type type, ServerVersion serverVersion, Dat case nameof(UserDefinedAggregateParameter) : case nameof(UserDefinedType) : case nameof(UserOptions) : - case nameof(XmlSchemaCollection) : + case nameof(XmlSchemaCollection): return true; case nameof(ExternalFileFormat): case nameof(WorkloadManagementWorkloadGroup): @@ -496,6 +511,11 @@ internal static void ThrowIfNotSupported(this SqlSmoObject smoObject, Type type, message = string.IsNullOrEmpty(message) ? ExceptionTemplates.NotSupportedOnSqlEdge(type.Name) : message; throw new UnsupportedVersionException(message).SetHelpContext("NotSupportedOnSqlEdge"); } + if (minSupportedVersion.Major == 17) + { + message = string.IsNullOrEmpty(message) ? ExceptionTemplates.SupportedOnlyOn170 : message; + throw new UnsupportedVersionException(message).SetHelpContext("SupportedOnlyOn170"); + } if (minSupportedVersion.Major == 15) { message = string.IsNullOrEmpty(message) ? ExceptionTemplates.SupportedOnlyOn150 : message; diff --git a/src/Microsoft/SqlServer/Management/Smo/SoapMethodCollectionBase.cs b/src/Microsoft/SqlServer/Management/Smo/SoapMethodCollectionBase.cs index 97b50359..baca6dac 100644 --- a/src/Microsoft/SqlServer/Management/Smo/SoapMethodCollectionBase.cs +++ b/src/Microsoft/SqlServer/Management/Smo/SoapMethodCollectionBase.cs @@ -8,60 +8,44 @@ namespace Microsoft.SqlServer.Management.Smo { - // this is the class that contains common features of all schema collection classes - - public class SoapMethodCollectionBase: SimpleObjectCollectionBase + public abstract class SoapMethodCollectionBase: SimpleObjectCollectionBase + where TObject : SoapMethodObject + where TParent : SqlSmoObject { - internal SoapMethodCollectionBase(SqlSmoObject parent) : base(parent) - { - } + internal SoapMethodCollectionBase(TParent parent) : base(parent) { } + protected override void InitInnerCollection() => InternalStorage = new SmoSortedList(new SoapMethodComparer(StringComparer)); - protected override void InitInnerCollection() - { - InternalStorage = new SmoSortedList(new SoapMethodComparer(this.StringComparer)); - } + internal override ObjectKeyBase KeyFromName(string name) => new SoapMethodKey(name, string.Empty); - public void Remove(string name) - { - this.Remove(new SoapMethodKey(name, GetDefaultNamespace())); - } - - public void Remove(string name, string methodNamespace) - { - this.Remove(new SoapMethodKey(name, methodNamespace)); - } + /// + /// Removes the SoapMethod with the give name and namespace from the collection + /// + /// + /// + public void Remove(string name, string methodNamespace) => Remove(new SoapMethodKey(name, methodNamespace)); internal override ObjectKeyBase CreateKeyFromUrn(Urn urn) { - string name = urn.GetAttribute("Name"); + var name = urn.GetAttribute("Name"); if( null == name || name.Length == 0) { throw new SmoException(ExceptionTemplates.PropertyMustBeSpecifiedInUrn("Name", urn.Type)); } - string methodNamespace = urn.GetAttribute("Namespace"); - if( null == methodNamespace || methodNamespace.Length == 0) + var methodNamespace = urn.GetAttribute("Namespace"); + if(string.IsNullOrEmpty(methodNamespace)) { - methodNamespace = GetDefaultNamespace(); + methodNamespace = string.Empty; } return new SoapMethodKey(name, methodNamespace); } - internal static string GetDefaultNamespace() - { - return string.Empty; - } - public bool Contains(string name, string methodNamespace) - { - return Contains(new SoapMethodKey(name, methodNamespace)); - } + public bool Contains(string name, string methodNamespace) => Contains(new SoapMethodKey(name, methodNamespace)); + + public new bool Contains(string name) => Contains(new SoapMethodKey(name, string.Empty)); - public new bool Contains(string name) - { - return Contains(new SoapMethodKey(name, GetDefaultNamespace())); - } } internal class SoapMethodComparer : ObjectComparerBase @@ -74,21 +58,21 @@ internal SoapMethodComparer(IComparer stringComparer) : base(stringComparer) //in SimpleObjectCollectionBase will be called so be prepared to handle SimpleObjectKey public override int Compare(object obj1, object obj2) { - SoapMethodKey x = (SoapMethodKey)obj1; - SoapMethodKey y = obj2 as SoapMethodKey; + var x = (SoapMethodKey)obj1; + var y = obj2 as SoapMethodKey; //if search schema is null search only by name if( null != y ) { - string xnamespace = null != x.Namespace ? x.Namespace : SoapMethodCollectionBase.GetDefaultNamespace(); - string ynamespace = null != y.Namespace ? y.Namespace : SoapMethodCollectionBase.GetDefaultNamespace(); - int i = stringComparer.Compare(xnamespace, ynamespace); + var xnamespace = x.Namespace ?? string.Empty; + var ynamespace = y.Namespace ?? string.Empty; + var i = stringComparer.Compare(xnamespace, ynamespace); if (0 != i) { return i; } } - string yname = null != y ? y.Name : ((SimpleObjectKey)obj2).Name; + var yname = y?.Name ?? ((SimpleObjectKey)obj2).Name; return stringComparer.Compare(x.Name, yname); } @@ -108,9 +92,11 @@ public SoapMethodKey(string name, string methodNamespace) : base(name) static SoapMethodKey() { - soapMethodFields = new StringCollection(); - soapMethodFields.Add("Name"); - soapMethodFields.Add("Namespace"); + soapMethodFields = new StringCollection + { + nameof(Name), + nameof(Namespace), + }; } public string Namespace @@ -126,30 +112,27 @@ public override string UrnFilter if( null != methodNamespace && methodNamespace.Length > 0 ) { return string.Format(SmoApplication.DefaultCulture, "@Name='{0}' and @Namespace='{1}'", - Urn.EscapeString(name), Urn.EscapeString(methodNamespace)); + Urn.EscapeString(Name), Urn.EscapeString(methodNamespace)); } else { - return string.Format(SmoApplication.DefaultCulture, "@Name='{0}'", Urn.EscapeString(name)); + return string.Format(SmoApplication.DefaultCulture, "@Name='{0}'", Urn.EscapeString(Name)); } } } - - public override StringCollection GetFieldNames() - { - return fields; - } - + + public override StringCollection GetFieldNames() => fields; + public override string ToString() { if( null != methodNamespace && methodNamespace.Length > 0 ) { return string.Format(SmoApplication.DefaultCulture, "{0}.{1}", - SqlSmoObject.MakeSqlBraket(name), SqlSmoObject.MakeSqlBraket(methodNamespace)); + SqlSmoObject.MakeSqlBraket(Name), SqlSmoObject.MakeSqlBraket(methodNamespace)); } else { - return SqlSmoObject.MakeSqlBraket(name); + return SqlSmoObject.MakeSqlBraket(Name); } } @@ -158,28 +141,22 @@ public override string GetExceptionName() if (null != methodNamespace && methodNamespace.Length > 0) { return string.Format(SmoApplication.DefaultCulture, "{0}.{1}", - name, methodNamespace); + Name, methodNamespace); } else { - return name; + return Name; } } - public override ObjectKeyBase Clone() - { - return new SoapMethodKey(this.Name, this.Namespace); - } - + public override ObjectKeyBase Clone() => new SoapMethodKey(this.Name, this.Namespace); + public override bool IsNull { - get { return (null == name|| null == methodNamespace); } - } - - public override ObjectComparerBase GetComparer(IComparer stringComparer) - { - return new SoapMethodComparer(stringComparer); + get { return (null == Name|| null == methodNamespace); } } + + public override ObjectComparerBase GetComparer(IComparer stringComparer) => new SoapMethodComparer(stringComparer); } diff --git a/src/Microsoft/SqlServer/Management/Smo/SoapPayloadMethodBase.cs b/src/Microsoft/SqlServer/Management/Smo/SoapPayloadMethodBase.cs index 00045aa5..a9bdd79c 100644 --- a/src/Microsoft/SqlServer/Management/Smo/SoapPayloadMethodBase.cs +++ b/src/Microsoft/SqlServer/Management/Smo/SoapPayloadMethodBase.cs @@ -19,7 +19,7 @@ public SoapPayloadMethod(SoapPayload soapPayload, string name) : base() { ValidateName(name); - this.key = new SoapMethodKey(name, SoapMethodCollectionBase.GetDefaultNamespace()); + this.key = new SoapMethodKey(name, string.Empty); this.Parent = soapPayload; } @@ -43,7 +43,7 @@ public SoapPayloadMethod(SoapPayload soapPayload, string name, string database, : base() { ValidateName(name); - this.key = new SoapMethodKey(name, SoapMethodCollectionBase.GetDefaultNamespace()); + this.key = new SoapMethodKey(name, string.Empty); this.Parent = soapPayload; this.SetSqlMethod(database, schema, sqlMethod); } diff --git a/src/Microsoft/SqlServer/Management/Smo/SqlSmoObject.cs b/src/Microsoft/SqlServer/Management/Smo/SqlSmoObject.cs index 1366b5e0..b601678a 100644 --- a/src/Microsoft/SqlServer/Management/Smo/SqlSmoObject.cs +++ b/src/Microsoft/SqlServer/Management/Smo/SqlSmoObject.cs @@ -23,8 +23,8 @@ using Microsoft.SqlServer.Management.Smo.Agent; using Microsoft.SqlServer.Management.Sdk.Sfc.Metadata; using Microsoft.SqlServer.Management.Sdk.Sfc; +using System.Diagnostics; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 namespace Microsoft.SqlServer.Management.Smo { // Given index and value, get/set the appropriate data member in XSchema @@ -823,10 +823,7 @@ protected virtual void GetUrnRecursive(StringBuilder urnbuilder) /// the definition besides the key fields. /// /// holds the Urn - /// Us ID as key instead of the regular key - /// fields. If the object does not have this property the regular key - /// fields will still be used. - [SuppressMessage("Microsoft.Reliability", "CA2001:AvoidCallingProblematicMethods", MessageId = "System.Type.InvokeMember")] + /// protected virtual void GetUrnRecursive(StringBuilder urnbuilder, UrnIdOption idOption) { // determine the suffix, which is static member of the class @@ -973,7 +970,6 @@ internal void SetObjectKey(ObjectKeyBase key) protected SqlSmoObject singletonParent = null; - [SuppressMessage("Microsoft.Reliability", "CA2001:AvoidCallingProblematicMethods", MessageId = "System.Type.InvokeMember")] internal virtual void ValidateParent(SqlSmoObject newParent) { // we are going to use the parent to get the child collection where this object is @@ -988,7 +984,7 @@ internal virtual void ValidateParent(SqlSmoObject newParent) try { - parentColl = GetChildCollection(newParent, urnsuffix, null, newParent.ServerVersion); + parentColl = GetChildCollection(newParent, urnsuffix); } catch(ArgumentException) { @@ -1042,9 +1038,9 @@ internal protected void SetParentImpl(SqlSmoObject newParent) ScriptSchemaObjectBase schemaObj = this as ScriptSchemaObjectBase; if (schemaObj != null) { - if (this.key != null && parentColl != null && (null == schemaObj.Schema || schemaObj.Schema.Length == 0)) + if (this.key != null && parentColl != null && (string.IsNullOrEmpty(schemaObj.Schema))) { - schemaObj.ChangeSchema(((SchemaCollectionBase)parentColl).GetDefaultSchema(), false); + schemaObj.ChangeSchema(((ISchemaObjectCollection)parentColl).GetDefaultSchema(), false); } } @@ -1088,6 +1084,7 @@ private ScriptingPreferences GetScriptingPreferencesForAlter() /// method get called from the create script related method (from derived classes like Table, Index etc..) /// /// + /// internal void AddDatabaseContext(StringCollection queries, ScriptingPreferences sp) { if (DatabaseEngineType.SqlAzureDatabase == sp.TargetDatabaseEngineType) @@ -1129,7 +1126,7 @@ protected void AddDatabaseContext(StringCollection queries) /// /// changes the object according to the modification of its members - /// + /// protected void AlterImplWorker() { CheckObjectState(); @@ -1207,7 +1204,7 @@ internal void AlterImplFinish(StringCollection alterQuery, ScriptingPreferences /// /// changes the object according to the modification of its members - /// + /// protected void AlterImpl() { try @@ -1522,8 +1519,6 @@ public bool Initialize() /// /// Initializes the object, by reading its properties from the enumerator /// - /// If false, only a specified subset of the properties - /// are retrieved with this call /// public bool Initialize(bool allProperties) { @@ -2057,7 +2052,7 @@ internal Property GetPropertyOptional(string propName) /// Returns the real value for the property. /// /// The property object - /// Old value. If it is null the function queries the + /// Old value. If it is null the function queries the /// database for the old value. /// protected object GetRealValue(Property prop, object oldValue) @@ -2767,7 +2762,6 @@ internal void ClearUserPemissions() /// /// /// - /// /// internal void AddScriptPermissions(StringCollection sc, PermissionWorker.PermissionEnumKind kind, @@ -2818,7 +2812,6 @@ internal void AddScriptPermissions(StringCollection sc, /// /// Returns permission script corresponding to the permission info passed as parameter. /// - /// /// /// /// @@ -3694,7 +3687,7 @@ internal virtual PropagateInfo[] GetPropagateInfoForDiscovery(PropagateAction ac /// Control loop for propagation of actions, works recursively /// /// - /// + /// /// internal void PropagateScript(StringCollection query, ScriptingPreferences sp, PropagateAction action) { @@ -3938,9 +3931,10 @@ internal virtual void PreInitChildLevel() /// Also return the list of Urns from the query, in order, so an iterator can be layered over all this. /// Code lifted from InitChildLevel. /// - /// - /// + /// + /// /// + /// /// The list of string Urn paths that matched the query. internal List InitQueryUrns(Urn levelFilter, string[] queryFields, OrderBy[] orderByFields, string[] infrastructureFields) @@ -3954,9 +3948,12 @@ internal List InitQueryUrns(Urn levelFilter, /// Code lifted from InitChildLevel. /// We pass the edition as a parameter because prefetch calls this method on a Server object and the edition is tied to the database. /// - /// - /// + /// + /// /// + /// + /// + /// /// Engine edition of the database being scripted /// The list of string Urn paths that matched the query. internal List InitQueryUrns(Urn levelFilter, @@ -4355,6 +4352,8 @@ internal static IEnumerable GetDisabledProperties(Type type, DatabaseEng { yield return nameof(Index.VectorIndexType); yield return nameof(Index.VectorIndexMetric); + yield return nameof(Index.OptimizeForArraySearch); + yield return nameof(Index.IndexedJsonPaths); } } break; @@ -4511,7 +4510,7 @@ public void InitChildCollection(Urn childType, bool forScripting) /// The function can also initialize a child collection via the regular initialization mechanism /// /// - /// + /// /// internal void InitChildLevel(Urn levelFilter, ScriptingPreferences sp, bool forScripting) { @@ -4528,7 +4527,7 @@ internal void InitChildLevel(Urn levelFilter, ScriptingPreferences sp, bool forS /// It loads the fields the default for each object and includes the fields passed as extraFields if there are not default fields /// /// - /// + /// /// /// internal void InitChildLevel(Urn levelFilter, ScriptingPreferences sp, bool forScripting, IEnumerable extraFields) @@ -4814,7 +4813,7 @@ private void MarkChildCollRetrievedRec(SqlSmoObject currentSmoObject, } AbstractCollectionBase childColl = GetChildCollection(currentSmoObject, levelFilter, - filterIdx, GetServerObject().ServerVersion); + filterIdx); if (filterIdx == levelFilter.Length - 1) { @@ -5086,7 +5085,10 @@ private void InitObjectsFromEnumResults(Urn levelFilter, System.Data.IDataReader /// the query results that we are /// transferring to the Smo objects in the tree /// column index in the result table - /// row index in the result table + /// + /// + /// + /// private void InitObjectsFromEnumResultsRec(SqlSmoObject currentSmoObject, XPathExpression levelFilter, int filterIdx, @@ -5272,7 +5274,7 @@ private void InitObjectsFromEnumResultsRec(SqlSmoObject currentSmoObject, try { childColl = GetChildCollection(currentSmoObject, levelFilter, - filterIdx, GetServerObject().ServerVersion); + filterIdx); } catch (Exception e) { @@ -5301,8 +5303,8 @@ private void InitObjectsFromEnumResultsRec(SqlSmoObject currentSmoObject, // For singletons, we know we are on the leaf level and just need to absorb properties if (isNonCollection) { - SqlSmoObject currObj = GetChildSingleton(currentSmoObject, levelFilter, - filterIdx, GetServerObject().ServerVersion); + var currObj = GetChildSingleton(currentSmoObject, levelFilter, + filterIdx); if (!AdvanceInitRec(currObj, levelFilter, filterIdx, reader, columnIdx, columnOffset, parentRow, forScripting, urnList, startLeafIdx)) @@ -5332,7 +5334,7 @@ private void InitObjectsFromEnumResultsRec(SqlSmoObject currentSmoObject, if (CompareRows(reader, parentRow, 0, columnIdx)) { - int relativeOrder = CompareObjectToRow(currObj, + int relativeOrder = SqlSmoObject.CompareObjectToRow(currObj, reader, columnIdx, isOrderedByID, @@ -5509,10 +5511,10 @@ private SqlSmoObject CreateNewObjectFromRow(AbstractCollectionBase childColl, if (skipOrderChecking) { //Since we need to skip order checking we will add objects at the end of collection - ParameterCollectionBase orderedCollection = childColl as ParameterCollectionBase; - if (orderedCollection != null) + + if (childColl is IOrderedCollectionInternal col) { - orderedCollection.InternalStorage.InsertAt(orderedCollection.InternalStorage.Count, currObj); + col.Append(currObj); return currObj; } } @@ -5536,10 +5538,10 @@ private SqlSmoObject CreateNewObjectFromRow(AbstractCollectionBase childColl, private SqlSmoObject GetExistingOrCreateNewObject(System.Data.IDataReader reader, int columnIdx, Type childType, AbstractCollectionBase childColl, bool isOrderedByID) { SqlSmoObject sqlSmoObject = null; - if (!isOrderedByID && (childColl is SortedListCollectionBase)) + if (!isOrderedByID && (childColl is ISortedListCollection)) { //Check if object is already in collection - sqlSmoObject = ((SortedListCollectionBase)childColl).NoFaultLookup(ObjectKeyBase.CreateKeyOffset(childType, reader, columnIdx)); + sqlSmoObject = childColl.NoFaultLookup(ObjectKeyBase.CreateKeyOffset(childType, reader, columnIdx)); } if (sqlSmoObject == null) @@ -5562,6 +5564,8 @@ private SqlSmoObject GetExistingOrCreateNewObject(System.Data.IDataReader reader /// /// /// + /// + /// /// true if there are still records to read private bool AdvanceInitRec(SqlSmoObject currentSmoObject, XPathExpression levelFilter, @@ -5623,141 +5627,54 @@ private bool AdvanceInitRec(SqlSmoObject currentSmoObject, // get child collection. This should not fail, since the collection // name is hardcoded in internal prefetch calls internal static AbstractCollectionBase GetChildCollection(SqlSmoObject parent, - XPathExpression levelFilter, int filterIdx, ServerVersion srvVer) + XPathExpression levelFilter, int filterIdx) { return GetChildCollection( parent, - levelFilter[filterIdx].Name, - levelFilter[filterIdx].GetAttributeFromFilter("CategoryClass"), - srvVer); + levelFilter[filterIdx].Name); } - // Given a single type name, return plural name for collection of these types - internal static string GetPluralName(string name, SqlSmoObject parent) + internal static AbstractCollectionBase GetChildCollection(SqlSmoObject parent, + string childUrnSuffix) { - switch (name) + if (childUrnSuffix == "Permission") { - case "Index": return "Indexes"; - case "Numbered": return "NumberedStoredProcedures"; - case "Method": return "SoapPayloadMethods"; - case "Param": return "Parameters"; - case "ExtendedProperty": return "ExtendedProperties"; - case "JobCategory": return "JobCategories"; - case "AlertCategory": return "AlertCategories"; - case "OperatorCategory": return "OperatorCategories"; - case "Column": - if (parent is Statistic) - { - return "StatisticColumns"; - } - else - { - return "Columns"; - } - - case "Step": return "JobSteps"; - case "Schedule": - if (parent is Job) - { - return "JobSchedules"; - } - else - { - return "SharedSchedules"; - } - - case "Login": - if (parent is LinkedServer) - { - return "LinkedServerLogins"; - } - else - { - return "Logins"; - } - - case "SqlAssembly": return "Assemblies"; - case nameof(ExternalLanguage): return "ExternalLanguages"; - case "ExternalLibrary": return "ExternalLibraries"; - case "FullTextIndexColumn": return "IndexedColumns"; - case "DdlTrigger": return "Triggers"; - case "MailProfile": return "Profiles"; - case "MailAccount": return "Accounts"; - case "ServiceQueue": return "Queues"; - case "BrokerService": return "Services"; - case "BrokerPriority": return "Priorities"; - case "ServiceRoute": return "Routes"; - case "EventClass": return "EventClasses"; - case "NotificationClass": return "NotificationClasses"; - case "SubscriptionClass": return "SubscriptionClasses"; - case "SearchProperty": return "SearchProperties"; - case "SecurityPolicy": return "SecurityPolicies"; - case "ExternalDataSource": return "ExternalDataSources"; - case "ExternalFileFormat": return "ExternalFileFormats"; - case "AvailabilityGroupListenerIPAddress": return "AvailabilityGroupListenerIPAddresses"; - case "ResumableIndex": return "ResumableIndexes"; - - default: - return name + "s"; + return parent.Permissions; } + return parent.GetCollectionInstance(childUrnSuffix); } - - [SuppressMessage("Microsoft.Reliability", "CA2001:AvoidCallingProblematicMethods", MessageId = "System.Type.InvokeMember")] - internal static AbstractCollectionBase GetChildCollection(SqlSmoObject parent, - string childUrnSuffix, string categorystr, ServerVersion srvVer) + /// + /// Returns the collection corresponding to the given urn suffix + /// + /// + /// + /// + protected virtual AbstractCollectionBase GetCollectionInstance(string urnSuffix) { - // this actually supposes that all child collection are named like this - // For some classes we have to get the gramatically correct plural - string childCollectionName = GetPluralName(childUrnSuffix, parent); - object childCollection = null; - - // Permissions is an internal property, but we do not want to open the - // door to calls to internals methods so we limit the use of - // BindingFlags.NonPublic to Permissions - if (childCollectionName != "Permissions") - { - try - { - childCollection = parent.GetType().InvokeMember(childCollectionName, - BindingFlags.Default | BindingFlags.GetProperty | - BindingFlags.Instance | BindingFlags.Public, - null, parent, new object[] { }, SmoApplication.DefaultCulture); - } - catch (MissingMethodException) - { - throw new ArgumentException(ExceptionTemplates.InvalidPathChildCollectionNotFound(childUrnSuffix, parent.GetType().Name)); - } - } - else - { - childCollection = parent.GetType().InvokeMember(childCollectionName, - BindingFlags.Default | BindingFlags.GetProperty | - BindingFlags.Instance | BindingFlags.NonPublic, - null, parent, new object[] { }, SmoApplication.DefaultCulture); - } - - // this should always be true in SMO, a collection will never return null - // but it can be empty - Diagnostics.TraceHelper.Assert(null != childCollection, "null == childCollection"); - - return (AbstractCollectionBase)childCollection; + throw new ArgumentException(ExceptionTemplates.InvalidPathChildCollectionNotFound(urnSuffix, GetType().Name)); } + /// + /// Returns the child object of the given type + /// + /// + /// + /// + protected virtual SqlSmoObject GetSingletonInstance(string childTypeName) + { + throw new ArgumentException(ExceptionTemplates.InvalidPathChildSingletonNotFound(childTypeName, GetType().Name)); + } /// /// /// /// - /// - /// - /// + /// + /// /// - SqlSmoObject GetChildSingleton(SqlSmoObject parent, - XPathExpression levelFilter, int filterIdx, ServerVersion srvVer) + private static SqlSmoObject GetChildSingleton(SqlSmoObject parent, + XPathExpression levelFilter, int filterIdx) { - string propName = null; - object childObject = null; - // Map from Urn filter name to the real System.Type name // Handle the case where we are asking about Server by itself (only one level node) int nodeCount = levelFilter.Length; @@ -5771,54 +5688,11 @@ SqlSmoObject GetChildSingleton(SqlSmoObject parent, return parent; } - // Do we already know what parent property points to the singleton instance? - if (!s_SingletonTypeToProperty.TryGetValue(childType, out propName)) - { - SfcMetadataDiscovery metadata = new SfcMetadataDiscovery(parent.GetType()); - foreach (SfcMetadataRelation relation in metadata.Relations) - { - if (relation.Relationship == SfcRelationship.ChildObject || - relation.Relationship == SfcRelationship.Object) - { - if (childType == relation.Type) - { - // Found it - propName = relation.PropertyName; - break; - } - } - } - - // Cache this result for the next time we need to lookup this type. - // Propname will be null if we know it isn't possible to use this type. - lock (((ICollection)s_SingletonTypeToProperty).SyncRoot) - { - s_SingletonTypeToProperty[childType] = propName; - } - } - - if (propName == null) - { - throw new ArgumentException(ExceptionTemplates.InvalidPathChildSingletonNotFound(childType.Name, parent.GetType().Name)); - } - - try - { - childObject = parent.GetType().InvokeMember(propName, - BindingFlags.Default | BindingFlags.GetProperty | - BindingFlags.Instance | BindingFlags.Public, - null, parent, new object[] { }, SmoApplication.DefaultCulture); - } - catch (MissingMethodException) - { - throw new ArgumentException(ExceptionTemplates.InvalidPathChildSingletonNotFound(childType.Name, parent.GetType().Name)); - } - - return (SqlSmoObject)childObject; + return parent.GetSingletonInstance(childType.Name); } // compares the object with the current row - private int CompareObjectToRow(SqlSmoObject currObj, System.Data.IDataReader currentRow, + private static int CompareObjectToRow(SqlSmoObject currObj, System.Data.IDataReader currentRow, int colIdx, bool isOrderedByID, XPathExpression xpath, int xpathIdx) { @@ -5900,15 +5774,15 @@ internal static string[] GetQueryTypeInfrastructureFields(Type t) { // server.Information.Edition should be cached already // since all Object Queries do this as a dummy step in InitQueryUrns(). - case "Information": + case nameof(Information): return new string[] { "Edition" }; - case "Database": + case nameof(Database): return new string[] { "CompatibilityLevel", "Collation" }; - case "StoredProcedure": - case "UserDefinedFunction": - case "Trigger": + case nameof(StoredProcedure): + case nameof(UserDefinedFunction): + case nameof(Trigger): case "DdlTrigger": case "DatabaseDdlTrigger": return new string[] { "ImplementationType" }; @@ -5972,6 +5846,10 @@ private static OrderBy[] GetOrderByList(Type objType) { return new OrderBy[] { new OrderBy("ColumnMasterKeyID", OrderBy.Direction.Asc) }; } + else if (objType.Equals(typeof(IndexedJsonPath))) + { + return new OrderBy[] { new OrderBy(nameof(IndexedJsonPath.Path), OrderBy.Direction.Asc) }; + } else { return new OrderBy[] { new OrderBy("Name", OrderBy.Direction.Asc) }; @@ -6265,7 +6143,7 @@ public static Type GetChildType(string objectName, string parentName) /// /// this will traverse up the tree for every hit for each instance of Smo Objects - // check if this can turn out to be a performance hit, by any chance + /// check if this can turn out to be a performance hit, by any chance /// public virtual ExecutionManager ExecutionManager { @@ -6330,6 +6208,7 @@ protected void ThrowIfBelowVersion90(string exceptionMessage = null) /// Throws an UnsupportedVersionException if either the source or destination server is below 9.0 (SQL 2005) /// /// + /// internal void ThrowIfSourceOrDestBelowVersion90(SqlServerVersion targetVersion, string exceptionMessage = null) { //Source @@ -6376,6 +6255,7 @@ protected void ThrowIfBelowVersion160(string exceptionMessage = null) /// Throws an UnsupportedVersionException if either the source or destination server is below 10.0 (SQL 2008) /// /// + /// internal void ThrowIfSourceOrDestBelowVersion100(SqlServerVersion targetVersion, string exceptionMessage = null) { //Source @@ -6412,6 +6292,7 @@ protected void ThrowIfBelowVersion110Prop(string propertyName) /// Throws an UnsupportedVersionException if either the source or destination server is below 11.0 (SQL 2012) /// /// + /// internal void ThrowIfSourceOrDestBelowVersion110(SqlServerVersion targetVersion, string exceptionMessage = null) { //Source @@ -6448,6 +6329,7 @@ protected void ThrowIfBelowVersion120Prop(string propertyName) /// Throws an UnsupportedVersionException if either the source or destination server is below 12.0 (SQL 2014) /// /// + /// internal void ThrowIfSourceOrDestBelowVersion120(SqlServerVersion targetVersion, string exceptionMessage = null) { //Source @@ -6507,6 +6389,7 @@ protected void ThrowIfBelowVersion140Prop(string propertyName) /// Throws an UnsupportedVersionException if either the source or destination server is below 13.0 (SQL 2016) /// /// + /// internal void ThrowIfSourceOrDestBelowVersion130(SqlServerVersion targetVersion, string exceptionMessage = null) { //Source @@ -6621,7 +6504,6 @@ internal bool SupportsDesignMode /// Checks if the target engine type is Cloud, and if so /// throw an exception indicating that this is not supported. /// - /// internal static void ThrowIfCloud(DatabaseEngineType targetEngineType) { ThrowIfCloud(targetEngineType, ExceptionTemplates.NotSupportedOnCloud); @@ -6632,7 +6514,7 @@ internal static void ThrowIfCloud(DatabaseEngineType targetEngineType) /// Checks if the target engine type is cloud, and if so /// throws an exception based the exceptionMessage /// - /// + /// /// internal static void ThrowIfCloud(DatabaseEngineType targetDatabaseEngineType, string exceptionMessage) { @@ -6646,7 +6528,7 @@ internal static void ThrowIfCloud(DatabaseEngineType targetDatabaseEngineType, s /// Checks if the target engine type is not cloud, and if so /// throws an exception based the exceptionMessage /// - /// The target database engine type. + /// /// Message to include in the exception. internal static void ThrowIfNotCloud(DatabaseEngineType targetDatabaseEngineType, string exceptionMessage) { @@ -6660,7 +6542,7 @@ internal static void ThrowIfNotCloud(DatabaseEngineType targetDatabaseEngineType /// Checks if the target engine edition is not SQL DW, and if so /// throws an exception based the exceptionMessage /// - /// The target database engine type. + /// /// Message to include in the exception. internal static void ThrowIfNotSqlDw(DatabaseEngineEdition targetDatabaseEngineEdition, string exceptionMessage) { @@ -6708,6 +6590,7 @@ internal static void ThrowIfNotCloudAndBelowSpecifiedVersion(DatabaseEngineType /// throw an exception indicating that this is not supported. /// /// + /// internal static void ThrowIfBelowVersion90(SqlServerVersion targetVersion, string exceptionMessage = null) { ThrowIfBelowVersionLimit(targetVersion, SqlServerVersion.Version90, string.IsNullOrEmpty(exceptionMessage) ? ExceptionTemplates.UnsupportedVersionException : exceptionMessage); @@ -6718,6 +6601,7 @@ internal static void ThrowIfBelowVersion90(SqlServerVersion targetVersion, strin /// throw an exception indicating that this is not supported. /// /// + /// internal static void ThrowIfBelowVersion100(SqlServerVersion targetVersion, string exceptionMessage = null) { ThrowIfBelowVersionLimit(targetVersion, SqlServerVersion.Version100, string.IsNullOrEmpty(exceptionMessage) ? ExceptionTemplates.UnsupportedVersionException : exceptionMessage); @@ -6728,6 +6612,7 @@ internal static void ThrowIfBelowVersion100(SqlServerVersion targetVersion, stri /// throw an exception indicating that this is not supported. /// /// + /// internal static void ThrowIfBelowVersion105(SqlServerVersion targetVersion, string exceptionMessage) { ThrowIfBelowVersionLimit(targetVersion, SqlServerVersion.Version105, string.IsNullOrEmpty(exceptionMessage) ? ExceptionTemplates.UnsupportedVersionException : exceptionMessage); @@ -6738,6 +6623,7 @@ internal static void ThrowIfBelowVersion105(SqlServerVersion targetVersion, stri /// throw an exception indicating that this is not supported. /// /// + /// internal static void ThrowIfBelowVersion170(SqlServerVersion targetVersion, string exceptionMessage = null) { ThrowIfBelowVersionLimit(targetVersion, SqlServerVersion.Version170, string.IsNullOrEmpty(exceptionMessage) ? ExceptionTemplates.UnsupportedVersionException : exceptionMessage); @@ -6748,6 +6634,7 @@ internal static void ThrowIfBelowVersion170(SqlServerVersion targetVersion, stri /// throw an exception indicating that this is not supported. /// /// + /// internal static void ThrowIfBelowVersion110(SqlServerVersion targetVersion, string exceptionMessage = null) { ThrowIfBelowVersionLimit(targetVersion, SqlServerVersion.Version110, string.IsNullOrEmpty(exceptionMessage) ? ExceptionTemplates.UnsupportedVersionException : exceptionMessage); @@ -6758,6 +6645,7 @@ internal static void ThrowIfBelowVersion110(SqlServerVersion targetVersion, stri /// throw an exception indicating that this is not supported. /// /// + /// internal static void ThrowIfBelowVersion120(SqlServerVersion targetVersion, string exceptionMessage = null) { ThrowIfBelowVersionLimit(targetVersion, SqlServerVersion.Version120, string.IsNullOrEmpty(exceptionMessage) ? ExceptionTemplates.UnsupportedVersionException : exceptionMessage); @@ -6768,6 +6656,7 @@ internal static void ThrowIfBelowVersion120(SqlServerVersion targetVersion, stri /// throw an exception indicating that this is not supported. /// /// + /// internal static void ThrowIfBelowVersion130(SqlServerVersion targetVersion, string exceptionMessage = null) { ThrowIfBelowVersionLimit(targetVersion, SqlServerVersion.Version130, string.IsNullOrEmpty(exceptionMessage) ? ExceptionTemplates.UnsupportedVersionException : exceptionMessage); @@ -6778,6 +6667,7 @@ internal static void ThrowIfBelowVersion130(SqlServerVersion targetVersion, stri /// throw an exception indicating that this is not supported. /// /// + /// internal static void ThrowIfBelowVersion80(SqlServerVersion targetVersion, string exceptionMessage = null) { ThrowIfBelowVersionLimit(targetVersion, SqlServerVersion.Version80, string.IsNullOrEmpty(exceptionMessage) ? ExceptionTemplates.UnsupportedVersionException : exceptionMessage); @@ -6802,7 +6692,6 @@ private static void ThrowIfBelowVersionLimit(SqlServerVersion targetVersion, Sql /// has a database context then we return the compatibility level /// of the database, otherwise the translated server version. /// - /// /// internal CompatibilityLevel GetCompatibilityLevel() { @@ -6856,6 +6745,7 @@ internal static CompatibilityLevel GetCompatibilityLevel(ServerVersion ver) return CompatibilityLevel.Version140; case 15: return CompatibilityLevel.Version150; + // VBUMP //Forward Compatibility: An older version SSMS/Smo connecting to a future version sql server database engine. //That is why if the ver(ServerVersion) is unknown, we need to set it according to the latest database engine available, //so that all Latest-Version-Supported-Features in the Tools work seamlessly for the unknown future version database engines too. @@ -6922,6 +6812,7 @@ private static void ThrowIfCompatibilityLevelBelowLimit(CompatibilityLevel targe /// throw an exception indicating that create or alter is not supported. /// /// + /// internal static void ThrowIfCreateOrAlterUnsupported(SqlServerVersion targetVersion, string exceptionMessage = null) { ThrowIfBelowVersionLimit(targetVersion, SqlServerVersion.Version130, string.IsNullOrEmpty(exceptionMessage) ? ExceptionTemplates.UnsupportedVersionException : exceptionMessage); @@ -7270,67 +7161,52 @@ internal void GenerateDataSpaceScript(StringBuilder parentScript, ScriptingPrefe { stmt.AppendFormat(SmoApplication.DefaultCulture, " ON [{0}]", SqlBraket(fileGroupName)); } - else if (partitionSchemeName.Length > 0) + else if (partitionSchemeName.Length > 0 && this is IPartitionable part && (sp.Storage.PartitionSchemeInternal & part.SchemeType) == part.SchemeType) { - if (((this is Table) && ((sp.Storage.PartitionSchemeInternal & PartitioningScheme.Table) == PartitioningScheme.Table)) || - ((this is Index) && ((sp.Storage.PartitionSchemeInternal & PartitioningScheme.Index) == PartitioningScheme.Index))) - { - stmt.AppendFormat(SmoApplication.DefaultCulture, " ON [{0}]", SqlBraket(partitionSchemeName)); - stmt.AppendFormat(SmoApplication.DefaultCulture, "("); - PartitionSchemeParameterCollection pspColl = null; - ColumnCollection columns = null; + stmt.AppendFormat(SmoApplication.DefaultCulture, " ON [{0}]", SqlBraket(partitionSchemeName)); + stmt.AppendFormat(SmoApplication.DefaultCulture, "("); - if (this is Table) - { - pspColl = ((Table)this).PartitionSchemeParameters; - columns = ((Table)this).Columns; - } - else if (this is Index) + var pspColl = part.PartitionSchemeParameters; + var columns = part.Columns; + + int pspCount = 0; + foreach (PartitionSchemeParameter psp in pspColl) + { + // we check to see if the specified column exists, + Column colBase = columns[psp.Name]; + if (null == colBase) { - pspColl = ((Index)this).PartitionSchemeParameters; - columns = ((TableViewBase)((Index)this).Parent).Columns; + // for views we only enforce checking if the view is not creating as it may not have the columns populated + if (!(this.ParentColl.ParentInstance.State == SqlSmoState.Creating && this.ParentColl.ParentInstance is View)) + { + // the column does not exist, so we need to abort this scripting + throw new SmoException(ExceptionTemplates.ObjectRefsNonexCol(PartitionScheme.UrnSuffix, partitionSchemeName, this.ToString() + ".[" + SqlStringBraket(psp.Name) + "]")); + } } - // make sure we have params - if (pspColl.Count == 0) + // if this column is going to be ignored for scripting skip the whole object + if (colBase.IgnoreForScripting) { - throw new FailedOperationException(ExceptionTemplates.NeedPSParams); + // flag this object to be ignored for scripting and return from the function + this.IgnoreForScripting = true; + return; } - int pspCount = 0; - foreach (PartitionSchemeParameter psp in pspColl) + if (0 < pspCount++) { - // we check to see if the specified column exists, - Column colBase = columns[psp.Name]; - if (null == colBase) - { - // for views we only enforce checking if the view is not creating as it may not have the columns populated - if (!(this.ParentColl.ParentInstance.State == SqlSmoState.Creating && this.ParentColl.ParentInstance is View)) - { - // the column does not exist, so we need to abort this scripting - throw new SmoException(ExceptionTemplates.ObjectRefsNonexCol(PartitionScheme.UrnSuffix, partitionSchemeName, this.ToString() + ".[" + SqlStringBraket(psp.Name) + "]")); - } - } - - // if this column is going to be ignored for scripting skip the whole object - if (colBase.IgnoreForScripting) - { - // flag this object to be ignored for scripting and return from the function - this.IgnoreForScripting = true; - return; - } - - if (0 < pspCount++) - { - stmt.Append(Globals.commaspace); - } - - stmt.Append(colBase.FormatFullNameForScripting(sp)); + stmt.Append(Globals.commaspace); } - // close the parameter list - stmt.AppendFormat(SmoApplication.DefaultCulture, ")"); + stmt.Append(colBase.FormatFullNameForScripting(sp)); } + + // make sure we have params + if (pspCount == 0) + { + throw new FailedOperationException(ExceptionTemplates.NeedPSParams); + } + // close the parameter list + stmt.AppendFormat(SmoApplication.DefaultCulture, ")"); } } @@ -7455,10 +7331,10 @@ protected StringCollection ScriptImpl(ScriptingOptions so) } /// - /// Returns an IEnumerable object with the script for the object. + /// Returns an IEnumerable<string> object with the script for the object. /// - /// - /// an IEnumerable object with the script for the object. + /// + /// an IEnumerable<string> object with the script for the object. internal IEnumerable EnumScriptImpl(ScriptingPreferences sp) { CheckObjectState(false); @@ -7502,9 +7378,9 @@ internal StringCollection ScriptImplWorker(ScriptingPreferences sp) /// - /// Returns an IEnumerable object with the script for the objects. + /// Returns an IEnumerable<string> object with the script for the objects. /// - /// IEnumerable object with the script for objects + /// IEnumerable<string> object with the script for objects internal IEnumerable EnumScriptImplWorker(ScriptingPreferences sp) { if (null == sp) @@ -8484,10 +8360,10 @@ public List Discover() { try { - SmoCollectionBase smoCollection = relationObject as SmoCollectionBase; - foreach (object childObject in smoCollection) + var smoCollection = (IEnumerable)relationObject ; + foreach (var childObject in smoCollection) { - if ((childObject != null) && (childObject.GetType().Name != "SystemMessage") && + if ((childObject != null) && !(childObject is SystemMessage) && !DiscoveryHelper.IsSystemObject(childObject)) { dependentObjects.Enqueue(childObject); @@ -8599,6 +8475,7 @@ List IAlienObject.Discover() /// Throws exception if the property is not found. /// /// + /// /// void IAlienObject.SetPropertyValue(string propertyName, Type propertyType, object value) { @@ -8642,6 +8519,7 @@ Urn IAlienObject.GetUrn() /// Retrieves value for a given property. Throws if property is not found. /// /// + /// /// object IAlienObject.GetPropertyValue(string propertyName, Type propertyType) { @@ -8694,7 +8572,7 @@ private object GetPropertyValueByReflection(string propertyName, Type propertyTy /// always loaded (returns null) into the Properties bag. It must be caused /// to load by using reflection. /// - /// + /// /// /// private bool IsSpeciallyLoaded(Type t, string propertyName) @@ -8897,6 +8775,9 @@ public enum UrnIdOption NoId } + /// + /// Interface implemented by objects that have extended properties + /// public interface IExtendedProperties { ExtendedPropertyCollection ExtendedProperties @@ -8975,13 +8856,30 @@ internal PropertyMissingEventArgs(string propertyName, string typeName) } } + /// + /// Implemented by SqlSmoObject types that have columns + /// + public interface IColumns + { + ColumnCollection Columns { get; } + } + + /// + /// Implemented by SqlSmoObject types that can be partitioned + /// + public interface IPartitionable : IColumns + { + IEnumerable PartitionSchemeParameters { get; } + PartitioningScheme SchemeType { get; } + } + #region Design Mode Helpers internal static class DiscoveryHelper { internal static bool IsSystemObject(object obj) { - return (obj is SqlSmoObject) && - ((SqlSmoObject)obj).IsSystemObjectInternal(); + return (obj is SqlSmoObject smo) && + smo.IsSystemObjectInternal(); } } #endregion diff --git a/src/Microsoft/SqlServer/Management/Smo/TableViewBase.cs b/src/Microsoft/SqlServer/Management/Smo/TableViewBase.cs index e19f2856..447641c2 100644 --- a/src/Microsoft/SqlServer/Management/Smo/TableViewBase.cs +++ b/src/Microsoft/SqlServer/Management/Smo/TableViewBase.cs @@ -9,10 +9,12 @@ using Microsoft.SqlServer.Management.Sdk.Sfc; using Microsoft.SqlServer.Management.Sdk.Sfc.Metadata; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 namespace Microsoft.SqlServer.Management.Smo { - public class TableViewBase : TableViewTableTypeBase, IExtendedProperties, IScriptable + /// + /// Base class for Tables and Views + /// + public partial class TableViewBase : TableViewTableTypeBase, IExtendedProperties, IScriptable { internal TableViewBase(AbstractCollectionBase parentColl, ObjectKeyBase key, SqlSmoState state) : base(parentColl, key, state) diff --git a/src/Microsoft/SqlServer/Management/Smo/TableViewTableTypeBase.cs b/src/Microsoft/SqlServer/Management/Smo/TableViewTableTypeBase.cs index adcbf5f0..a42113f1 100644 --- a/src/Microsoft/SqlServer/Management/Smo/TableViewTableTypeBase.cs +++ b/src/Microsoft/SqlServer/Management/Smo/TableViewTableTypeBase.cs @@ -5,12 +5,12 @@ using System.Collections.Specialized; using Microsoft.SqlServer.Management.Sdk.Sfc.Metadata; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 namespace Microsoft.SqlServer.Management.Smo { - // This class contains the common properties of TableViewBase and UserDefinedTableType - // TableViewBase now extends this class - public class TableViewTableTypeBase : ScriptSchemaObjectBase, IExtendedProperties, IScriptable + /// + /// This class contains the common properties of TableViewBase and UserDefinedTableType + /// + public partial class TableViewTableTypeBase : ScriptSchemaObjectBase, IExtendedProperties, IScriptable { internal TableViewTableTypeBase(AbstractCollectionBase parentColl, ObjectKeyBase key, SqlSmoState state) : @@ -104,10 +104,9 @@ public ColumnCollection Columns if (null == m_Columns) { m_Columns = new ColumnCollection(this); - View v = this as View; - if (null != v) - { - SetCollectionTextMode(v.TextMode, m_Columns); + if (this is ITextObject text) + { + SetCollectionTextMode(text.TextMode, m_Columns); } } return m_Columns; @@ -118,7 +117,7 @@ public ColumnCollection Columns /// Overrides the permission scripting - No columns added here - TableViewBase will override this method /// /// - /// + /// internal override void AddScriptPermission(StringCollection query, ScriptingPreferences sp) { // add the object-level permissions diff --git a/src/Microsoft/SqlServer/Management/Smo/UserDefinedAggregateParameterBase.cs b/src/Microsoft/SqlServer/Management/Smo/UserDefinedAggregateParameterBase.cs index fae727a9..4e278bf9 100644 --- a/src/Microsoft/SqlServer/Management/Smo/UserDefinedAggregateParameterBase.cs +++ b/src/Microsoft/SqlServer/Management/Smo/UserDefinedAggregateParameterBase.cs @@ -8,6 +8,7 @@ namespace Microsoft.SqlServer.Management.Smo { + [SfcElementType("Param")] public partial class UserDefinedAggregateParameter : ParameterBase { internal UserDefinedAggregateParameter(AbstractCollectionBase parentColl, ObjectKeyBase key, SqlSmoState state) : diff --git a/src/Microsoft/SqlServer/Management/Smo/UserDefinedFunctionBase.cs b/src/Microsoft/SqlServer/Management/Smo/UserDefinedFunctionBase.cs index f54f8277..49930f6a 100644 --- a/src/Microsoft/SqlServer/Management/Smo/UserDefinedFunctionBase.cs +++ b/src/Microsoft/SqlServer/Management/Smo/UserDefinedFunctionBase.cs @@ -9,8 +9,6 @@ using Microsoft.SqlServer.Management.Sdk.Sfc.Metadata; using Cmn = Microsoft.SqlServer.Management.Common; - -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 namespace Microsoft.SqlServer.Management.Smo { [Facets.StateChangeEvent("CREATE_FUNCTION", "FUNCTION")] @@ -22,7 +20,7 @@ namespace Microsoft.SqlServer.Management.Smo [Microsoft.SqlServer.Management.Sdk.Sfc.PhysicalFacet(PhysicalFacetOptions.ReadOnly)] public partial class UserDefinedFunction : ScriptSchemaObjectBase, Cmn.ICreatable, Cmn.IAlterable, Cmn.ICreateOrAlterable, Cmn.IRenamable, Cmn.IDroppable, Cmn.IDropIfExists, - IExtendedProperties, IScriptable, ITextObject + IExtendedProperties, IScriptable, ITextObject, IColumns { internal UserDefinedFunction(AbstractCollectionBase parentColl, ObjectKeyBase key, SqlSmoState state) : base(parentColl, key, state) @@ -70,7 +68,7 @@ public UserDefinedFunctionParameterCollection Parameters /// Overrides the permission scripting. /// /// - /// + /// internal override void AddScriptPermission(StringCollection query, ScriptingPreferences sp) { // add the object-level permissions @@ -666,7 +664,7 @@ public ColumnCollection Columns if (null == m_Columns) { m_Columns = new ColumnCollection(this); - SetCollectionTextMode(this.TextMode, m_Columns); + SetCollectionTextMode(TextMode, m_Columns); } return m_Columns; } @@ -879,13 +877,13 @@ public string TextHeader public bool TextMode { get { CheckObjectState(); return GetTextMode(); } - set { CheckObjectState(); SetTextMode(value, new SmoCollectionBase [] { Parameters, Columns, Checks }); } + set { CheckObjectState(); SetTextMode(value, new ILockableCollection [] { Parameters, Columns, Checks }); } } /// /// Validate property values that are coming from the users. /// - /// + /// /// internal override void ValidateProperty(Property prop, object value) { diff --git a/src/Microsoft/SqlServer/Management/Smo/UserDefinedMessageBase.cs b/src/Microsoft/SqlServer/Management/Smo/UserDefinedMessageBase.cs index 6f40ce30..b6ed56e7 100644 --- a/src/Microsoft/SqlServer/Management/Smo/UserDefinedMessageBase.cs +++ b/src/Microsoft/SqlServer/Management/Smo/UserDefinedMessageBase.cs @@ -34,7 +34,7 @@ public UserDefinedMessage () : public UserDefinedMessage(Server server, System.Int32 id) : base() { - this.key = new MessageObjectKey(id, MessageCollectionBase.GetDefaultLanguage()); + this.key = new MessageObjectKey(id, MessageCollectionBase.GetDefaultLanguage()); this.Parent = server; } @@ -347,12 +347,12 @@ internal override void ScriptDrop(StringCollection queries, ScriptingPreferences protected override void PostDrop() { - string language = ((MessageObjectKey)this.key).Language; + var language = ((MessageObjectKey)key).Language; // if we have just dropped the english message, make sure the other messages // are removed from the collection if( language == "us_english" ) { - ((SmoCollectionBase)this.ParentColl).Refresh(); + Parent.Refresh(); } } diff --git a/src/Microsoft/SqlServer/Management/Smo/UserPermissionCollection.cs b/src/Microsoft/SqlServer/Management/Smo/UserPermissionCollection.cs index ddbbaf32..7316db52 100644 --- a/src/Microsoft/SqlServer/Management/Smo/UserPermissionCollection.cs +++ b/src/Microsoft/SqlServer/Management/Smo/UserPermissionCollection.cs @@ -1,72 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -using System; -using System.Collections; - namespace Microsoft.SqlServer.Management.Smo { - - /// - /// Strongly typed list of UserPermission objects - /// Has strongly typed support for all of the methods of the sorted list class - /// - internal sealed class UserPermissionCollection : SimpleObjectCollectionBase - { - - internal UserPermissionCollection(SqlSmoObject parentInstance) : base(parentInstance) - { - } - - public SqlSmoObject Parent - { - get - { - return this.ParentInstance as SqlSmoObject; - } - } - - public UserPermission this[Int32 index] - { - get - { - return GetObjectByIndex(index) as UserPermission; - } - } - - // returns wrapper class - public UserPermission this[string name] - { - get - { - return GetObjectByName(name) as UserPermission; - } - } - - public void CopyTo(UserPermission[] array, int index) - { - ((ICollection)this).CopyTo(array, index); - } - - - public UserPermission ItemById(int id) - { - return (UserPermission)GetItemById(id); - } - - protected override Type GetCollectionElementType() - { - return typeof(UserPermission); - } - - internal override SqlSmoObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state) - { - return new UserPermission(this, key, state); - } - - internal SqlSmoObject GetObjectByName(string name) - { - return GetObjectByKey(new SimpleObjectKey(name)); - } - } + internal sealed partial class UserPermissionCollection : SimpleObjectCollectionBase + { + } } diff --git a/src/Microsoft/SqlServer/Management/Smo/ViewBase.cs b/src/Microsoft/SqlServer/Management/Smo/ViewBase.cs index 1d98ed87..bb34fea9 100644 --- a/src/Microsoft/SqlServer/Management/Smo/ViewBase.cs +++ b/src/Microsoft/SqlServer/Management/Smo/ViewBase.cs @@ -12,7 +12,7 @@ using Microsoft.SqlServer.Management.Sdk.Sfc.Metadata; using Cmn = Microsoft.SqlServer.Management.Common; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 + namespace Microsoft.SqlServer.Management.Smo { @@ -42,7 +42,7 @@ public override IndexCollection Indexes } private ResumableIndexCollection m_ResumableIndexes; - [SfcObject(SfcContainerRelationship.ChildContainer, SfcContainerCardinality.ZeroToAny, typeof(Index), SfcObjectFlags.Deploy)] + [SfcObject(SfcContainerRelationship.ChildContainer, SfcContainerCardinality.ZeroToAny, typeof(ResumableIndex), SfcObjectFlags.Deploy)] public ResumableIndexCollection ResumableIndexes { get @@ -506,7 +506,7 @@ internal override PropagateInfo[] GetPropagateInfoForDiscovery(PropagateAction a /// Overrides the permission scripting. /// /// - /// + /// internal override void AddScriptPermission(StringCollection query, ScriptingPreferences sp) { // on 7.0 we do not have permissions on views @@ -597,13 +597,13 @@ public string TextHeader public bool TextMode { get { CheckObjectState(); return GetTextMode(); } - set { CheckObjectState(); SetTextMode(value, new SmoCollectionBase [] { Columns }); } + set { CheckObjectState(); SetTextMode(value, new ILockableCollection [] { Columns }); } } /// /// Validate property values that are coming from the users. /// - /// + /// /// internal override void ValidateProperty(Property prop, object value) { diff --git a/src/Microsoft/SqlServer/Management/Smo/enumerations.cs b/src/Microsoft/SqlServer/Management/Smo/enumerations.cs index 24d4b8f8..3e3ba688 100644 --- a/src/Microsoft/SqlServer/Management/Smo/enumerations.cs +++ b/src/Microsoft/SqlServer/Management/Smo/enumerations.cs @@ -282,6 +282,7 @@ public enum SqlServerVersions Version130 = 128, Version140 = 256, Version150 = 512 + // VBUMP } public enum SortOrder diff --git a/src/Microsoft/SqlServer/Management/Smo/files.cs b/src/Microsoft/SqlServer/Management/Smo/files.cs index c16c1989..1d134703 100644 --- a/src/Microsoft/SqlServer/Management/Smo/files.cs +++ b/src/Microsoft/SqlServer/Management/Smo/files.cs @@ -3,7 +3,6 @@ using System; using System.Collections; -using System.Collections.Generic; using System.Collections.Specialized; using System.Data; using System.Text; @@ -11,7 +10,6 @@ using Microsoft.SqlServer.Management.Sdk.Sfc.Metadata; using Cmn = Microsoft.SqlServer.Management.Common; -#pragma warning disable 1590,1591,1592,1573,1571,1570,1572,1587 namespace Microsoft.SqlServer.Management.Smo { /// @@ -51,9 +49,9 @@ public void Create() internal override void ScriptCreate(StringCollection createQuery, ScriptingPreferences sp) { - bool bSuppressDirtyCheck = sp.SuppressDirtyCheck; + var bSuppressDirtyCheck = sp.SuppressDirtyCheck; - StringBuilder statement = new StringBuilder(); + var statement = new StringBuilder(); statement.AppendFormat(SmoApplication.DefaultCulture, "ALTER DATABASE [{0}] ADD LOG FILE ", SqlBraket(ParentColl.ParentInstance.InternalName)); @@ -109,10 +107,10 @@ public void Create() internal override void ScriptCreate(StringCollection createQuery, ScriptingPreferences sp) { - bool bSuppressDirtyCheck = sp.SuppressDirtyCheck; + var bSuppressDirtyCheck = sp.SuppressDirtyCheck; - StringBuilder statement = new StringBuilder(); - string dbName = ParentColl.ParentInstance.ParentColl.ParentInstance.InternalName; + var statement = new StringBuilder(); + var dbName = ParentColl.ParentInstance.ParentColl.ParentInstance.InternalName; statement.AppendFormat(SmoApplication.DefaultCulture, "ALTER DATABASE [{0}] ADD FILE ", SqlBraket(dbName)); @@ -133,7 +131,7 @@ internal override void ScriptCreate(StringCollection createQuery, ScriptingPrefe internal static void Validate_set_IsPrimaryFile(Property prop, object newValue) { - DataFile thisObj = (DataFile)prop.Parent.m_parent; + var thisObj = (DataFile)prop.Parent.m_parent; // throw if parent already created if (thisObj.State != SqlSmoState.Creating) { @@ -150,10 +148,10 @@ internal static void Validate_set_IsPrimaryFile(Property prop, object newValue) // check if other files are set to be primary if ((bool)newValue) { - SmoInternalStorage files = ((DataFileCollection)thisObj.ParentColl).InternalStorage; - foreach (DataFile f in files) + var files = ((DataFileCollection)thisObj.ParentColl).InternalStorage; + foreach (var f in files) { - Property pPrim = f.Properties.Get("IsPrimaryFile"); + var pPrim = f.Properties.Get(nameof(DataFile.IsPrimaryFile)); if (thisObj != f && pPrim.Value != null && (bool)pPrim.Value) { throw new SmoException(ExceptionTemplates.OnlyOnePrimaryFile); @@ -165,7 +163,7 @@ internal static void Validate_set_IsPrimaryFile(Property prop, object newValue) /// /// Validate property values that are coming from the users. /// - /// + /// /// internal override void ValidateProperty(Property prop, object value) { @@ -215,7 +213,7 @@ internal static string[] GetScriptFields(Type parentType, { "IsPrimaryFile", }; - List list = GetSupportedScriptFields(typeof(Database.PropertyMetadataProvider), fields, version, databaseEngineType, databaseEngineEdition); + var list = GetSupportedScriptFields(typeof(Database.PropertyMetadataProvider), fields, version, databaseEngineType, databaseEngineEdition); return list.ToArray(); } } @@ -264,8 +262,8 @@ internal bool ScriptDdl(ScriptingPreferences sp, StringBuilder ddl, bool bSuppre { ddl.Append(Globals.LParen); - int changeCount = 0; - bool isManagedInstance = sp.TargetDatabaseEngineEdition == Microsoft.SqlServer.Management.Common.DatabaseEngineEdition.SqlManagedInstance; + var changeCount = 0; + var isManagedInstance = sp.TargetDatabaseEngineEdition == Microsoft.SqlServer.Management.Common.DatabaseEngineEdition.SqlManagedInstance; ddl.AppendFormat(SmoApplication.DefaultCulture, " NAME = N'{0}'", SqlString(this.Name)); @@ -341,7 +339,7 @@ private string DatabaseName private void AppendSize(ScriptingPreferences sp, StringBuilder ddl, double size) { - bool isTransformed = false; + var isTransformed = false; if (size > Int32.MaxValue) { // transform KB into GB @@ -369,7 +367,7 @@ private void AppendSize(ScriptingPreferences sp, StringBuilder ddl, double size) private void ScriptSize(ScriptingPreferences sp, StringBuilder ddl, bool bSuppressDirtyCheck, ref int changeCount) { - Property pSize = Properties.Get("Size"); + var pSize = Properties.Get("Size"); //Size cannot be specified for filestream filegroups. if (this.IsFileStreamBasedFile()) @@ -393,7 +391,7 @@ private void ScriptSize(ScriptingPreferences sp, StringBuilder ddl, private void ScriptMaxSize(ScriptingPreferences sp, StringBuilder ddl, bool bSuppressDirtyCheck, ref int changeCount) { - Property pMaxSize = Properties.Get("MaxSize"); + var pMaxSize = Properties.Get("MaxSize"); if (this.IsFileStreamBasedFile() && sp.TargetServerVersion < SqlServerVersion.Version110) { @@ -426,8 +424,8 @@ private void ScriptMaxSize(ScriptingPreferences sp, StringBuilder ddl, private void ScriptGrowth(ScriptingPreferences sp, StringBuilder ddl, bool bSuppressDirtyCheck, bool scriptCreate, ref int changeCount) { - Property pGrowthType = this.Properties.Get("GrowthType"); - Property pGrowth = this.Properties.Get("Growth"); + var pGrowthType = this.Properties.Get("GrowthType"); + var pGrowth = this.Properties.Get("Growth"); if (this.IsFileStreamBasedFile()) { @@ -455,14 +453,14 @@ private void ScriptGrowth(ScriptingPreferences sp, StringBuilder ddl, bool bSupp return; } - bool isGrowthPercent = (pGrowthType.Value != null && + var isGrowthPercent = (pGrowthType.Value != null && FileGrowthType.Percent == (FileGrowthType)pGrowthType.Value); if (pGrowth.Value != null && (bSuppressDirtyCheck || pGrowth.Dirty || pGrowthType.Dirty)) { ddl.AppendFormat(SmoApplication.DefaultCulture, ", FILEGROWTH = "); - double growth = (double)pGrowth.Value; + var growth = (double)pGrowth.Value; if (isGrowthPercent) { if (1 > growth) @@ -489,10 +487,10 @@ private bool ScriptFileName(ScriptingPreferences sp,StringBuilder ddl, bool bSup bool scriptCreate, ref int changeCount) { // FileName must not be missing - Property pFileName = Properties.Get("FileName"); + var pFileName = Properties.Get("FileName"); if (pFileName.Value != null && (bSuppressDirtyCheck || pFileName.Dirty)) { - string fileName = (string)pFileName.Value; + var fileName = (string)pFileName.Value; ddl.AppendFormat(SmoApplication.DefaultCulture, ", FILENAME = N'{0}' ", SqlString(fileName)); @@ -514,13 +512,13 @@ private bool ScriptFileName(ScriptingPreferences sp,StringBuilder ddl, bool bSup // these are either file stream groups or file groups containing memory optimized data private bool IsFileStreamBasedFile() { - DataFile df = this as DataFile; + var df = this as DataFile; if (df == null) { return false; } - FileGroup parentfg = df.Parent; + var parentfg = df.Parent; switch (parentfg.FileGroupType) { @@ -545,7 +543,7 @@ public void Alter() internal override void ScriptAlter(StringCollection alterQuery, ScriptingPreferences sp) { // TODO make sure it does nothing when no property has been modified - StringBuilder statement = new StringBuilder(); + var statement = new StringBuilder(); // for 7.0 we have to generate multiple alter statements // because this is how T-SQL works @@ -625,16 +623,16 @@ public void Shrink(Int32 newSizeInMB, ShrinkMethod shrinkType) try { CheckObjectState(); - StringCollection query = new StringCollection(); + var query = new StringCollection(); - StringBuilder statement = new StringBuilder(); - Urn urn = this.Urn; + var statement = new StringBuilder(); + var urn = this.Urn; statement.AppendFormat(SmoApplication.DefaultCulture, Scripts.USEDB, SqlBraket(urn.GetNameForType("Database"))); query.Add(statement.ToString()); statement.Remove(0, statement.Length); statement.Append("DBCC"); - string filename = this.Name; + var filename = this.Name; switch (shrinkType) { case ShrinkMethod.Default: @@ -794,19 +792,19 @@ public void Alter() internal override void ScriptAlter(StringCollection alterQuery, ScriptingPreferences sp) { - StringBuilder statement = new StringBuilder(); - string dbName = ParentColl.ParentInstance.InternalName; - string filegroup = this.Name; + var statement = new StringBuilder(); + var dbName = ParentColl.ParentInstance.InternalName; + var filegroup = this.Name; // remember the number of properties modified - int propMod = 0; + var propMod = 0; - Property p = Properties.Get("ReadOnly"); + var p = Properties.Get("ReadOnly"); if (p.Dirty && p.Value != null) { - bool readOnly = (bool)p.Value; + var readOnly = (bool)p.Value; statement.Length = 0; - string statementfmt = "declare @readonly bit{5}SELECT @readonly=convert(bit, (status & 0x08)) FROM sysfilegroups WHERE groupname=N'{0}'{5}if(@readonly={1}){5} ALTER DATABASE [{2}] MODIFY FILEGROUP [{3}] {4}"; + var statementfmt = "declare @readonly bit{5}SELECT @readonly=convert(bit, (status & 0x08)) FROM sysfilegroups WHERE groupname=N'{0}'{5}if(@readonly={1}){5} ALTER DATABASE [{2}] MODIFY FILEGROUP [{3}] {4}"; statement.AppendFormat(SmoApplication.DefaultCulture, statementfmt, SqlString(filegroup), // {0} @@ -826,9 +824,9 @@ internal override void ScriptAlter(StringCollection alterQuery, ScriptingPrefere p = Properties.Get("AutogrowAllFiles"); if (p.Dirty && p.Value != null) { - bool autogrowAllFiles = (bool)p.Value; + var autogrowAllFiles = (bool)p.Value; statement.Length = 0; - string statementfmt = "declare @autogrow bit\r\nSELECT @autogrow=convert(bit, is_autogrow_all_files) FROM sys.filegroups WHERE name=N'{0}'\r\nif(@autogrow={1})\r\n ALTER DATABASE [{2}] MODIFY FILEGROUP [{3}] {4}"; + var statementfmt = "declare @autogrow bit\r\nSELECT @autogrow=convert(bit, is_autogrow_all_files) FROM sys.filegroups WHERE name=N'{0}'\r\nif(@autogrow={1})\r\n ALTER DATABASE [{2}] MODIFY FILEGROUP [{3}] {4}"; statement.AppendFormat(SmoApplication.DefaultCulture, statementfmt, SqlString(filegroup), autogrowAllFiles ? 0 : 1, SqlBraket(dbName), SqlBraket(filegroup), autogrowAllFiles ? "AUTOGROW_ALL_FILES" : "AUTOGROW_SINGLE_FILE"); @@ -844,7 +842,7 @@ internal override void ScriptAlter(StringCollection alterQuery, ScriptingPrefere { statement.Length = 0; - string statementfmt = "declare @isdefault bit{3}SELECT @isdefault=convert(bit, (status & 0x10)) FROM sysfilegroups WHERE groupname=N'{0}'{3}if(@isdefault=0){3} ALTER DATABASE [{1}] MODIFY FILEGROUP [{2}] DEFAULT"; + var statementfmt = "declare @isdefault bit{3}SELECT @isdefault=convert(bit, (status & 0x10)) FROM sysfilegroups WHERE groupname=N'{0}'{3}if(@isdefault=0){3} ALTER DATABASE [{1}] MODIFY FILEGROUP [{2}] DEFAULT"; statement.AppendFormat(SmoApplication.DefaultCulture, statementfmt, SqlString(filegroup), SqlBraket(dbName), SqlBraket(filegroup), sp.NewLine); //This property need to be set this database as current context unlike other properties need of use master alterQuery.Add(string.Format(SmoApplication.DefaultCulture, Scripts.USEDB, SqlBraket(dbName))); @@ -866,10 +864,10 @@ public void Create() internal override void ScriptCreate(StringCollection createQuery, ScriptingPreferences sp) { - bool bSuppressDirtyCheck = sp.SuppressDirtyCheck; + var bSuppressDirtyCheck = sp.SuppressDirtyCheck; - StringBuilder statement = new StringBuilder(); - Database parentdb = (Database)ParentColl.ParentInstance; + var statement = new StringBuilder(); + var parentdb = (Database)ParentColl.ParentInstance; statement.AppendFormat(SmoApplication.DefaultCulture, "ALTER DATABASE {0} ADD FILEGROUP [{1}]", parentdb.FormatFullNameForScripting(sp), SqlBraket(this.Name)); @@ -900,9 +898,9 @@ internal override void ScriptDrop(StringCollection dropQuery, ScriptingPreferenc // first drop all the contained files // we make a roundtrip to the server, but otherwise we would have failed // We don't check if there are files to save roundtrips - for (int i = 0; i < Files.Count; i++) + for (var i = 0; i < Files.Count; i++) { - DataFile f = Files[i]; + var f = Files[i]; f.ScriptDropInternal(dropQuery, sp); } @@ -922,12 +920,12 @@ internal void ScriptDdl(ScriptingPreferences sp, StringBuilder ddl) private void ScriptFileGroupFiles(ScriptingPreferences sp, StringBuilder ddl, bool databaseIsView) { - bool firstFileScripted = false; + var firstFileScripted = false; // script the primary file first - foreach (DataFile df in this.Files) + foreach (var df in this.Files) { - bool isPrimary = df.GetPropValueOptional("IsPrimaryFile", false); + var isPrimary = df.GetPropValueOptional("IsPrimaryFile", false); if (isPrimary) { ddl.Append(Globals.newline); @@ -938,9 +936,9 @@ private void ScriptFileGroupFiles(ScriptingPreferences sp, StringBuilder ddl, bo // script all others afterwards - foreach (DataFile df in this.Files) + foreach (var df in this.Files) { - bool isPrimary = df.GetPropValueOptional("IsPrimaryFile", false); + var isPrimary = df.GetPropValueOptional("IsPrimaryFile", false); if (isPrimary) { // we should have dealt with this @@ -1003,8 +1001,8 @@ private void ScriptPrimaryFileGroup(ScriptingPreferences sp, StringBuilder ddl, */ internal void ScriptDdl(ScriptingPreferences sp, StringBuilder ddl, bool databaseIsView) { - string fgName = this.Name; - Property pDefault = Properties.Get("IsDefault"); + var fgName = this.Name; + var pDefault = Properties.Get("IsDefault"); if (string.Compare(fgName, "PRIMARY", StringComparison.Ordinal) == 0) { @@ -1014,9 +1012,9 @@ internal void ScriptDdl(ScriptingPreferences sp, StringBuilder ddl, bool databas // go into File group files scripting else if (!databaseIsView) // creating a database snapshot does not include all the complicated file stream options { - string filegroupTypeScript = string.Empty; - string filegroupDefaultScript = this.IsDefault ? " DEFAULT" : string.Empty; - string filegroupNameScript = string.Format(SmoApplication.DefaultCulture, " FILEGROUP [{0}] ", + var filegroupTypeScript = string.Empty; + var filegroupDefaultScript = this.IsDefault ? " DEFAULT" : string.Empty; + var filegroupNameScript = string.Format(SmoApplication.DefaultCulture, " FILEGROUP [{0}] ", SqlBraket(fgName)); switch (this.FileGroupType) @@ -1064,7 +1062,7 @@ public StringCollection CheckFileGroup() try { CheckObjectState(); - StringCollection queries = new StringCollection(); + var queries = new StringCollection(); queries.Add(string.Format(SmoApplication.DefaultCulture, Scripts.USEDB, SqlBraket(ParentColl.ParentInstance.InternalName))); queries.Add(string.Format(SmoApplication.DefaultCulture, "DBCC CHECKFILEGROUP( N'{0}' ) WITH NO_INFOMSGS", SqlString(Name))); @@ -1083,7 +1081,7 @@ public StringCollection CheckFileGroupDataOnly() try { CheckObjectState(); - StringCollection queries = new StringCollection(); + var queries = new StringCollection(); queries.Add(string.Format(SmoApplication.DefaultCulture, Scripts.USEDB, SqlBraket(ParentColl.ParentInstance.InternalName))); queries.Add(string.Format(SmoApplication.DefaultCulture, "DBCC CHECKFILEGROUP( N'{0}', NOINDEX ) WITH NO_INFOMSGS", SqlString(Name))); @@ -1100,9 +1098,9 @@ public StringCollection CheckFileGroupDataOnly() void AddObjects(String partialUrn, ArrayList list) { String dbUrn = this.ParentColl.ParentInstance.Urn; - String term = string.Format(SmoApplication.DefaultCulture, "[@FileGroup='{0}']", Urn.EscapeString(this.Name)); + var term = string.Format(SmoApplication.DefaultCulture, "[@FileGroup='{0}']", Urn.EscapeString(this.Name)); - DataTable dt = this.ExecutionManager.GetEnumeratorData(new Request(dbUrn + partialUrn + term, new string[] { "Urn" })); + var dt = this.ExecutionManager.GetEnumeratorData(new Request(dbUrn + partialUrn + term, new string[] { "Urn" })); foreach (DataRow dr in dt.Rows) { @@ -1114,7 +1112,7 @@ public SqlSmoObject[] EnumObjects() { CheckObjectState(); - ArrayList list = new ArrayList(); + var list = new ArrayList(); // get the tables stored on the filegroup AddObjects("/Table", list); @@ -1127,10 +1125,10 @@ public SqlSmoObject[] EnumObjects() // get the statistics stored on the filegroup AddObjects("/Table/Statistic", list); - SqlSmoObject[] retval = new SqlSmoObject[list.Count]; - int idx = 0; - Server srv = GetServerObject(); - foreach (object o in list) + var retval = new SqlSmoObject[list.Count]; + var idx = 0; + var srv = GetServerObject(); + foreach (var o in list) { retval[idx++] = srv.GetSmoObject((Urn)(string)o); } diff --git a/src/Microsoft/SqlServer/Management/Smo/numberedstoredprocedurebase.cs b/src/Microsoft/SqlServer/Management/Smo/numberedstoredprocedurebase.cs index f8545c12..10a414fa 100644 --- a/src/Microsoft/SqlServer/Management/Smo/numberedstoredprocedurebase.cs +++ b/src/Microsoft/SqlServer/Management/Smo/numberedstoredprocedurebase.cs @@ -351,7 +351,7 @@ public bool TextMode set { CheckObjectState(); - SetTextMode(value, new SmoCollectionBase[] {Parameters}); + SetTextMode(value, new ILockableCollection[] {Parameters}); } } diff --git a/src/Microsoft/SqlServer/Management/Smo/permissionWorker.cs b/src/Microsoft/SqlServer/Management/Smo/permissionWorker.cs index 3f24c363..d710321a 100644 --- a/src/Microsoft/SqlServer/Management/Smo/permissionWorker.cs +++ b/src/Microsoft/SqlServer/Management/Smo/permissionWorker.cs @@ -765,23 +765,11 @@ internal static void Execute(PermissionState ps, { if (columnNames != null && columnNames.Length != 0) { - ColumnCollection columnCol = null; - switch (obj.GetType().Name) - { - case "Table": - columnCol = ((Table)obj).Columns; - break; - case "View": - columnCol = ((View)obj).Columns; - break; - case "UserDefinedFunction": - columnCol = ((UserDefinedFunction)obj).Columns; - break; - } + var columnCol = ((IColumns)obj).Columns; - foreach (string column in columnNames) + foreach (var column in columnNames) { - Column col = columnCol[column]; + var col = columnCol[column]; if (col != null) { @@ -790,7 +778,7 @@ internal static void Execute(PermissionState ps, else { //throw exception - throw new MissingObjectException(ExceptionTemplates.ObjectDoesNotExist("Column", column)); + throw new MissingObjectException(ExceptionTemplates.ObjectDoesNotExist(nameof(Column), column)); } } } diff --git a/src/Microsoft/SqlServer/Management/Smo/propertiesMetadata.cs b/src/Microsoft/SqlServer/Management/Smo/propertiesMetadata.cs index 1e9bb9ae..cc5d0cff 100644 --- a/src/Microsoft/SqlServer/Management/Smo/propertiesMetadata.cs +++ b/src/Microsoft/SqlServer/Management/Smo/propertiesMetadata.cs @@ -158,6 +158,7 @@ protected enum StandaloneVersionIndex v150 = 9, v160 = 10, v170 = 11, + // VBUMP } /// @@ -169,6 +170,7 @@ protected enum CloudVersionIndex v100 = 0, v110 = 1, v120 = 2 + // VBUMP - Note: Cloud versions have different versioning than on-prem } internal static int[] defaultSingletonArray = new int[] { 0, 0, 0, 0, 0, 0, 0 }; @@ -365,6 +367,7 @@ internal static int GetCurrentVersionIndex(ServerVersion sv, DatabaseEngineType versionIndex = (int)CloudVersionIndex.v120; break; } + // VBUMP default: { //Default to the latest known version for unknown versions since it's @@ -649,6 +652,7 @@ private SqlServerVersions GetSupportedVersions(int index) { return ssv; } + // VBUMP ssv |= SqlServerVersions.Version140; if (index >= this.VersionCount[7]) @@ -720,6 +724,7 @@ internal SqlPropertyInfo GetPropertyInfo(int index) /// private int GetCountForVersions(SqlServerVersions m_versions) { + // VBUMP if ((m_versions | SqlServerVersions.Version150) == SqlServerVersions.Version150) { return this.VersionCount[9]; diff --git a/src/Microsoft/SqlServer/Management/Smo/serverbase.cs b/src/Microsoft/SqlServer/Management/Smo/serverbase.cs index 40c9fdaf..1c5fd0f5 100644 --- a/src/Microsoft/SqlServer/Management/Smo/serverbase.cs +++ b/src/Microsoft/SqlServer/Management/Smo/serverbase.cs @@ -652,19 +652,15 @@ private SqlSmoObject GetSmoObjectRec(Urn urn) // retrieve the child collection object childCollection = SqlSmoObject.GetChildCollection(parentNode, urn.XPathExpression, - urn.XPathExpression.Length - 1, - ServerVersion); + urn.XPathExpression.Length - 1); // transform the Urn filter into a key ObjectKeyBase childKey = ((AbstractCollectionBase)childCollection).CreateKeyFromUrn(urn); // get the child object from child collection - SqlSmoObject thisNode = ((SmoCollectionBase)childCollection).GetObjectByKey(childKey) as SqlSmoObject; - if (null == thisNode) - { - throw new MissingObjectException(ExceptionTemplates.ObjectDoesNotExist(GetTypeName(nodeType), childKey.ToString())); - } - - return thisNode; + var thisNode = ((ISmoInternalCollection)childCollection).GetObjectByKey(childKey); + return null == thisNode + ? throw new MissingObjectException(ExceptionTemplates.ObjectDoesNotExist(GetTypeName(nodeType), childKey.ToString())) + : thisNode; } /// @@ -3102,6 +3098,10 @@ private IEnumerable CreateInitFieldsColl(Type typeObject) yield return nameof(DataType.XmlDocumentConstraint); yield return "DataTypeSchema"; } + if (typeObject == typeof(IndexedJsonPath)) + { + yield return nameof(IndexedJsonPath.Path); + } } private Hashtable objectMetadataHash = new Hashtable(); diff --git a/src/Microsoft/SqlServer/Management/Smo/storedprocedurebase.cs b/src/Microsoft/SqlServer/Management/Smo/storedprocedurebase.cs index ff0d6ff3..b93113d1 100644 --- a/src/Microsoft/SqlServer/Management/Smo/storedprocedurebase.cs +++ b/src/Microsoft/SqlServer/Management/Smo/storedprocedurebase.cs @@ -795,7 +795,7 @@ public bool TextMode throw new PropertyWriteException("TextMode", this.GetType().Name, this.Name, ExceptionTemplates.ReasonNotIntextMode); } - SetTextMode(value, new SmoCollectionBase[] { Parameters }); + SetTextMode(value, new ILockableCollection[] { Parameters }); } } diff --git a/src/Microsoft/SqlServer/Management/Smo/tablebase.cs b/src/Microsoft/SqlServer/Management/Smo/tablebase.cs index c9c41f8b..9e8b6d87 100644 --- a/src/Microsoft/SqlServer/Management/Smo/tablebase.cs +++ b/src/Microsoft/SqlServer/Management/Smo/tablebase.cs @@ -50,7 +50,7 @@ enum ScriptFlag [Facets.EvaluationMode(Dmf.AutomatedPolicyEvaluationMode.CheckOnSchedule)] [Microsoft.SqlServer.Management.Sdk.Sfc.PhysicalFacet] public partial class Table : TableViewBase, Cmn.ICreatable, Cmn.IAlterable, Cmn.IDroppable, - Cmn.IDropIfExists, Cmn.IRenamable, ITableOptions + Cmn.IDropIfExists, Cmn.IRenamable, ITableOptions, IPartitionable { internal Table(AbstractCollectionBase parentColl, ObjectKeyBase key, SqlSmoState state) : base(parentColl, key, state) @@ -139,12 +139,12 @@ public ResumableIndexCollection ResumableIndexes } } - private Boolean m_OnlineHeapOperation = false; + private bool m_OnlineHeapOperation = false; /// /// Online property for rebuild heap /// - public Boolean OnlineHeapOperation + public bool OnlineHeapOperation { get { @@ -244,8 +244,8 @@ public void MarkForCreate(string start, string end) public void Reset() { - this.m_StartColumnName = String.Empty; - this.m_EndColumnName = String.Empty; + this.m_StartColumnName = string.Empty; + this.m_EndColumnName = string.Empty; this.m_MarkedForCreate = false; } @@ -288,13 +288,13 @@ public AbortAfterWait LowPriorityAbortAfterWait } } - private Int32 m_MaximumDegreeOfParallelism = -1; + private int m_MaximumDegreeOfParallelism = -1; /// /// Property for setting maximum number of processors that can be used when running /// rebuild heap /// - public Int32 MaximumDegreeOfParallelism + public int MaximumDegreeOfParallelism { get { @@ -314,11 +314,11 @@ public Int32 MaximumDegreeOfParallelism /// Whether this table is a node table. /// [SfcProperty(SfcPropertyFlags.SqlAzureDatabase | SfcPropertyFlags.Standalone)] - public Boolean IsNode + public bool IsNode { get { - return (Boolean)this.Properties.GetValueWithNullReplacement("IsNode"); + return (bool)this.Properties.GetValueWithNullReplacement("IsNode"); } set { @@ -331,11 +331,11 @@ public Boolean IsNode /// Whether this Table is an edge table. /// [SfcProperty(SfcPropertyFlags.SqlAzureDatabase | SfcPropertyFlags.Standalone)] - public Boolean IsEdge + public bool IsEdge { get { - return (Boolean)this.Properties.GetValueWithNullReplacement("IsEdge"); + return (bool)this.Properties.GetValueWithNullReplacement("IsEdge"); } set { @@ -810,12 +810,12 @@ where idx.IsClustered var isSqlDw = CheckIsSqlDwTable(); // for [Memory-Optimized|External|SQL DW] tables skip the file table checks - Boolean isFileTable = false; + bool isFileTable = false; if (!isMemoryOptimized && !isExternal && !isSqlDw) { if (IsSupportedProperty("IsFileTable")) { - Boolean isFileTableProp = this.GetPropValueOptional("IsFileTable", false); + bool isFileTableProp = this.GetPropValueOptional("IsFileTable", false); if (isFileTableProp) { // IsFileTable is supported as a hard coded 0 on Azure; we can't script file table to that target @@ -1008,7 +1008,7 @@ private void GetMemoryOptimizedTableCreationScript(ScriptingPreferences sp, Stri // string systemVersioningWithClauseContent = GenerateSystemVersioningWithClauseContent(sp); - if (!String.IsNullOrEmpty(systemVersioningWithClauseContent)) + if (!string.IsNullOrEmpty(systemVersioningWithClauseContent)) { sb.AppendFormat( Scripts.WITH_MEMORY_OPTIMIZED_AND_DURABILITY_AND_TEMPORAL_SYSTEM_VERSIONING, @@ -1353,8 +1353,8 @@ private void ScriptPeriodForSystemTime(StringBuilder sb) { Diagnostics.TraceHelper.Assert(IsSupportedProperty("HasSystemTimePeriod")); - string startCol = String.Empty; - string endCol = String.Empty; + string startCol = string.Empty; + string endCol = string.Empty; bool hasPeriod = false; hasPeriod = GetPropValueOptional("HasSystemTimePeriod", false); @@ -2742,7 +2742,7 @@ internal bool IsPaddingType(Column col) return false; } - internal static void ScriptTableInternal(ScriptingPreferences sp, StringBuilder sb, ColumnCollection columns, ICollection indexes, bool isEdgeTable = false) + internal static void ScriptTableInternal(ScriptingPreferences sp, StringBuilder sb, IEnumerable columns, ICollection indexes, bool isEdgeTable = false) { Diagnostics.TraceHelper.Assert(null != sp); Diagnostics.TraceHelper.Assert(null != sb); @@ -2753,7 +2753,7 @@ internal static void ScriptTableInternal(ScriptingPreferences sp, StringBuilder GeneratePkUkInCreateTable(sb, sp, indexes, true); } - private static void ScriptColumns(ScriptingPreferences sp, StringBuilder sb, ColumnCollection columns, bool isEdgeTable = false) + private static void ScriptColumns(ScriptingPreferences sp, StringBuilder sb, IEnumerable columns, bool isEdgeTable = false) { StringCollection col_strings = new StringCollection(); @@ -2814,7 +2814,7 @@ private static void ScriptColumns(ScriptingPreferences sp, StringBuilder sb, Col /// True to indicate the table is an edge table, False otherwise. /// The list of columns. /// True if a parenthesis should be emitted. - private static bool ShouldEmitColumnListParenthesis(bool isEdgeTable, ColumnCollection columns) + private static bool ShouldEmitColumnListParenthesis(bool isEdgeTable, IEnumerable columns) { if (!isEdgeTable) { @@ -3642,7 +3642,7 @@ public DataTable EnumLastStatisticsUpdates(string statname) req.Urn.Value += string.Format(SmoApplication.DefaultCulture, "[@Name='{0}']", Urn.EscapeString(statname)); } - req.Fields = new String[] { "Name", "LastUpdated" }; + req.Fields = new string[] { "Name", "LastUpdated" }; return this.ExecutionManager.GetEnumeratorData(req); } catch (Exception e) @@ -3669,7 +3669,7 @@ public DataTable EnumForeignKeys() req.ParentPropertiesRequests = new PropertiesRequest[1]; PropertiesRequest parentProps = new PropertiesRequest(); - parentProps.Fields = new String[] { "Schema", "Name" }; + parentProps.Fields = new string[] { "Schema", "Name" }; parentProps.OrderByList = new OrderBy[] { new OrderBy("Schema", OrderBy.Direction.Asc), new OrderBy("Name", OrderBy.Direction.Asc) }; req.ParentPropertiesRequests[0] = parentProps; @@ -3913,7 +3913,7 @@ public void AddPeriodForSystemTime(string periodStartColumn, string periodEndCol if (addPeriod) { - if (String.IsNullOrEmpty(periodStartColumn) || String.IsNullOrEmpty(periodEndColumn)) + if (string.IsNullOrEmpty(periodStartColumn) || string.IsNullOrEmpty(periodEndColumn)) { throw new SmoException(ExceptionTemplates.InvalidPeriodColumnName); } @@ -4527,11 +4527,11 @@ internal static string[] GetScriptFields2(Type parentType, Cmn.ServerVersion ver /// Whether decimal data is stored in variable-length fields in the table /// [SfcProperty(SfcPropertyFlags.Expensive | SfcPropertyFlags.Deploy | SfcPropertyFlags.Standalone | SfcPropertyFlags.SqlAzureDatabase)] - public System.Boolean IsVarDecimalStorageFormatEnabled + public bool IsVarDecimalStorageFormatEnabled { get { - return (System.Boolean)this.Properties.GetValueWithNullReplacement("IsVarDecimalStorageFormatEnabled"); + return (bool)this.Properties.GetValueWithNullReplacement("IsVarDecimalStorageFormatEnabled"); } set @@ -4545,6 +4545,13 @@ public System.Boolean IsVarDecimalStorageFormatEnabled } } + /// + /// Returns the PartitioningScheme that can be used for a Table + /// + public PartitioningScheme SchemeType => PartitioningScheme.Table; + + IEnumerable IPartitionable.PartitionSchemeParameters => PartitionSchemeParameters; + /// /// Emit script to set vardecimal storage format for the table /// @@ -4586,7 +4593,7 @@ private void ScriptAlterFileTableProp(StringCollection query, ScriptingPreferenc return; } - Boolean isFileTable = this.GetPropValueOptional("IsFileTable", false); + bool isFileTable = this.GetPropValueOptional("IsFileTable", false); Property fileTableNamespaceEnabled = this.GetPropertyOptional("FileTableNamespaceEnabled"); Property fileTableDirectoryName = this.GetPropertyOptional("FileTableDirectoryName"); @@ -4709,8 +4716,8 @@ private void ScriptSystemVersioning(StringCollection query, ScriptingPreferences } bool isSystemVersioned = false; - string histTableName = String.Empty; - string histTableSchema = String.Empty; + string histTableName = string.Empty; + string histTableSchema = string.Empty; if (!systemVersioning.IsNull) { @@ -4743,7 +4750,7 @@ private void ScriptSystemVersioning(StringCollection query, ScriptingPreferences } ScriptStringBuilder systemVersioningClauseBuilder = new ScriptStringBuilder( - String.Format( + string.Format( "SYSTEM_VERSIONING = {0}", isSystemVersioned ? "ON" : "OFF")); @@ -4766,12 +4773,12 @@ private void ScriptSystemVersioning(StringCollection query, ScriptingPreferences throw new SmoException(ExceptionTemplates.BothHistoryTableNameAndSchemaMustBeProvided); } - if (!String.IsNullOrEmpty(histTableName)) + if (!string.IsNullOrEmpty(histTableName)) { string schemaPart = MakeSqlBraket(histTableSchema); string tablePart = MakeSqlBraket(histTableName); - systemVersioningClauseBuilder.SetParameter("HISTORY_TABLE", String.Format("{0}.{1}", schemaPart, tablePart), ParameterValueFormat.NotString); + systemVersioningClauseBuilder.SetParameter("HISTORY_TABLE", string.Format("{0}.{1}", schemaPart, tablePart), ParameterValueFormat.NotString); } // Script only if set to default, otherwise it defaults to TRUE if not specified @@ -4825,13 +4832,13 @@ private void ScriptSystemVersioning(StringCollection query, ScriptingPreferences systemVersioningClauseBuilder.SetParameter( "HISTORY_RETENTION_PERIOD", - String.Format(SmoApplication.DefaultCulture, "{0} {1}", historyRetentionPeriod.ToString(), unit), + string.Format(SmoApplication.DefaultCulture, "{0} {1}", historyRetentionPeriod.ToString(), unit), ParameterValueFormat.NotString); } } } - sbSystemVersioning.Append(String.Format(SmoApplication.DefaultCulture, "ALTER TABLE {0} SET ( {1} )", + sbSystemVersioning.Append(string.Format(SmoApplication.DefaultCulture, "ALTER TABLE {0} SET ( {1} )", this.FormatFullNameForScripting(sp), systemVersioningClauseBuilder.ToString(scriptSemiColon: false))); @@ -4854,7 +4861,7 @@ private void ScriptSystemTimePeriodForAlter(StringCollection query, ScriptingPre else if (this.m_systemTimePeriodInfo.m_MarkedForDrop) { // dropping PERIOD - query.Add(String.Format(SmoApplication.DefaultCulture, "ALTER TABLE {0} DROP PERIOD FOR SYSTEM_TIME", this.FormatFullNameForScripting(sp))); + query.Add(string.Format(SmoApplication.DefaultCulture, "ALTER TABLE {0} DROP PERIOD FOR SYSTEM_TIME", this.FormatFullNameForScripting(sp))); } } else @@ -4862,7 +4869,7 @@ private void ScriptSystemTimePeriodForAlter(StringCollection query, ScriptingPre if (this.m_systemTimePeriodInfo.m_MarkedForCreate) { // adding a PERIOD - query.Add(String.Format(SmoApplication.DefaultCulture, "ALTER TABLE {0} ADD PERIOD FOR SYSTEM_TIME ( [{1}], [{2}] )", + query.Add(string.Format(SmoApplication.DefaultCulture, "ALTER TABLE {0} ADD PERIOD FOR SYSTEM_TIME ( [{1}], [{2}] )", this.FormatFullNameForScripting(sp), Util.EscapeString(this.m_systemTimePeriodInfo.m_StartColumnName, ']'), Util.EscapeString(this.m_systemTimePeriodInfo.m_EndColumnName, ']'))); diff --git a/src/Microsoft/SqlServer/Management/SmoMetadataProvider/Database.cs b/src/Microsoft/SqlServer/Management/SmoMetadataProvider/Database.cs index 0713fdba..42bf56dc 100644 --- a/src/Microsoft/SqlServer/Management/SmoMetadataProvider/Database.cs +++ b/src/Microsoft/SqlServer/Management/SmoMetadataProvider/Database.cs @@ -812,7 +812,7 @@ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() /// Type of the SMO collection that contains the objects. abstract internal class MetadataList where T : Smo.ScriptSchemaObjectBase - where U : Smo.SmoCollectionBase + where U : Smo.ISmoCollection { private static readonly IMetadataList EmptyRange = new EmptyRange(); diff --git a/src/Microsoft/SqlServer/Management/SmoMetadataProvider/DatabaseObjectBase.cs b/src/Microsoft/SqlServer/Management/SmoMetadataProvider/DatabaseObjectBase.cs index 035569da..58006eff 100644 --- a/src/Microsoft/SqlServer/Management/SmoMetadataProvider/DatabaseObjectBase.cs +++ b/src/Microsoft/SqlServer/Management/SmoMetadataProvider/DatabaseObjectBase.cs @@ -35,7 +35,7 @@ public sealed class SmoCollectionMetadataList : IMetadataList // filterPredicate is the function to filter the smoCollection. // - public SmoCollectionMetadataList(Server server, Smo.SmoCollectionBase smoCollection, Func filterPredicate = null) + public SmoCollectionMetadataList(Server server, Smo.ISmoCollection smoCollection, Func filterPredicate = null) { Debug.Assert(server != null, "SmoMetadataProvider Assert", "server != null"); Debug.Assert(smoCollection != null, "SmoMetadataProvider Assert", "smoCollection != null"); @@ -49,7 +49,7 @@ public SmoCollectionMetadataList(Server server, Smo.SmoCollectionBase smoCollect this.count = GetCount(smoCollection, server.IsConnected, filterPredicate); } - private static int GetCount(Smo.SmoCollectionBase smoCollection, bool isConnected, Func filterPredicate = null) + private static int GetCount(Smo.ISmoCollection smoCollection, bool isConnected, Func filterPredicate = null) { Debug.Assert(smoCollection != null, "SmoMetadataProvider Assert", "smoCollection != null"); @@ -73,18 +73,11 @@ private static int GetCount(Smo.SmoCollectionBase smoCollection, bool isConnecte // server version is < 10 (pre Katmai) count = 0; } - catch (Exception) + catch (Exception) when (isConnected) { // // Suppress all exceptions when working with connected server. - if (isConnected) - { - count = 0; - } - else - { - throw; - } + count = 0; } return count; diff --git a/src/Microsoft/SqlServer/Management/SmoMetadataProvider/Server.cs b/src/Microsoft/SqlServer/Management/SmoMetadataProvider/Server.cs index 064dc220..ddc7b34c 100644 --- a/src/Microsoft/SqlServer/Management/SmoMetadataProvider/Server.cs +++ b/src/Microsoft/SqlServer/Management/SmoMetadataProvider/Server.cs @@ -335,7 +335,7 @@ private static void PopulateDatabasesCollection(ServerConnection serverConnectio } } - public void TryRefreshSmoCollection(Smo.SmoCollectionBase collection, Config.SmoInitFields initFields) + public void TryRefreshSmoCollection(Smo.ISmoCollection collection, Config.SmoInitFields initFields) { TraceHelper.TraceContext.Assert(collection != null, "MetadataProvider Assert", "collection != null"); using (var methodTrace = TraceHelper.TraceContext.GetMethodContext("TryRefreshSmoCollection")) diff --git a/src/Microsoft/SqlServer/Management/SmoMetadataProvider/Utils.cs b/src/Microsoft/SqlServer/Management/SmoMetadataProvider/Utils.cs index e0dff94e..9972e47b 100644 --- a/src/Microsoft/SqlServer/Management/SmoMetadataProvider/Utils.cs +++ b/src/Microsoft/SqlServer/Management/SmoMetadataProvider/Utils.cs @@ -856,7 +856,7 @@ public static class UserDefinedFunction /// given metadata parameter collection. /// public static ParameterCollection CreateParameterCollection( - Database database, Smo.ParameterCollectionBase metadataCollection, IDictionary moduleInfo) + Database database, Smo.ISmoCollection metadataCollection, IDictionary moduleInfo) { Debug.Assert(database != null, "SmoMetadataProvider Assert", "database != null"); Debug.Assert(metadataCollection != null, "SmoMetadataProvider Assert", "metadataCollection != null"); diff --git a/src/Microsoft/SqlServer/Management/SqlEnum/Microsoft.SqlServer.SqlEnum.csproj b/src/Microsoft/SqlServer/Management/SqlEnum/Microsoft.SqlServer.SqlEnum.csproj index d0199fd4..562479d7 100644 --- a/src/Microsoft/SqlServer/Management/SqlEnum/Microsoft.SqlServer.SqlEnum.csproj +++ b/src/Microsoft/SqlServer/Management/SqlEnum/Microsoft.SqlServer.SqlEnum.csproj @@ -655,6 +655,10 @@ IndexedColumn.xml xml\IndexedColumn.xml + + IndexedJsonPath.xml + xml\IndexedJsonPath.xml + IndexedXmlPath.xml xml\IndexedXmlPath.xml diff --git a/src/Microsoft/SqlServer/Management/SqlEnum/enumstructs.cs b/src/Microsoft/SqlServer/Management/SqlEnum/enumstructs.cs index d9a9fb52..6bb5ecb5 100644 --- a/src/Microsoft/SqlServer/Management/SqlEnum/enumstructs.cs +++ b/src/Microsoft/SqlServer/Management/SqlEnum/enumstructs.cs @@ -138,7 +138,7 @@ public enum IndexType /// [TsqlSyntaxString("JSON INDEX")] [LocDisplayName("Json")] - JsonIndex = 12 + JsonIndex = 12, } diff --git a/src/Microsoft/SqlServer/Management/SqlEnum/xml/IndexedJsonPath.xml b/src/Microsoft/SqlServer/Management/SqlEnum/xml/IndexedJsonPath.xml new file mode 100644 index 00000000..995c3c14 --- /dev/null +++ b/src/Microsoft/SqlServer/Management/SqlEnum/xml/IndexedJsonPath.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + create table #jsonindexpaths (object_id int, index_id int, path varchar(8000) COLLATE Latin1_General_100_BIN2_UTF8); + begin try + exec sp_executesql N' + insert into #jsonindexpaths (object_id, index_id, path) + select object_id, index_id, path + from sys.json_index_paths' + end try + begin catch + end catch + + + drop table #jsonindexpaths + + + + + + ISNULL(jip.path, '') + + \ No newline at end of file diff --git a/src/Microsoft/SqlServer/Management/SqlEnum/xml/index.xml b/src/Microsoft/SqlServer/Management/SqlEnum/xml/index.xml index 99c5224a..76a3c861 100644 --- a/src/Microsoft/SqlServer/Management/SqlEnum/xml/index.xml +++ b/src/Microsoft/SqlServer/Management/SqlEnum/xml/index.xml @@ -58,6 +58,11 @@ i.object_id = vi.object_id AND i.index_id = vi.index_id + + + i.object_id = ji.object_id AND i.index_id = ji.index_id + + xi.object_id = indexedpaths.object_id AND xi.using_xml_index_id = indexedpaths.index_id AND xi.path_id = indexedpaths.path_id @@ -80,9 +85,23 @@ begin catch end catch + + create table #jsonindexes (object_id int, index_id int, optimize_for_array_search bit); + begin try + exec sp_executesql N' + insert into #jsonindexes (object_id, index_id, optimize_for_array_search) + select object_id, index_id, optimize_for_array_search + from sys.json_indexes' + end try + begin catch + end catch + drop table #vectorindexes + + drop table #jsonindexes + @@ -422,5 +441,13 @@ ISNULL(vi.distance_metric, N'') ISNULL(vi.vector_index_type, N'') + + + + 0 + + + ISNULL(ji.optimize_for_array_search, 0) + diff --git a/src/Microsoft/SqlServer/Management/SqlScriptPublish/SqlScriptPublishModel.cs b/src/Microsoft/SqlServer/Management/SqlScriptPublish/SqlScriptPublishModel.cs index 8f12f3e6..af2070b9 100644 --- a/src/Microsoft/SqlServer/Management/SqlScriptPublish/SqlScriptPublishModel.cs +++ b/src/Microsoft/SqlServer/Management/SqlScriptPublish/SqlScriptPublishModel.cs @@ -320,7 +320,7 @@ public void RefreshDatabaseCache() try { - SmoCollectionBase smoCollection = relationObject as SmoCollectionBase; + var smoCollection = (ISmoCollection)relationObject; smoCollection.Refresh(); } catch (EnumeratorException) diff --git a/src/UnitTest/CollectionGeneratorTest/CollectionGeneratorTest.csproj b/src/UnitTest/CollectionGeneratorTest/CollectionGeneratorTest.csproj new file mode 100644 index 00000000..86ba5ce5 --- /dev/null +++ b/src/UnitTest/CollectionGeneratorTest/CollectionGeneratorTest.csproj @@ -0,0 +1,13 @@ + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + $(TargetFrameworks) + + + + + + + + + diff --git a/src/UnitTest/CollectionGeneratorTest/SimpleObjectCollectionGeneratorTests.cs b/src/UnitTest/CollectionGeneratorTest/SimpleObjectCollectionGeneratorTests.cs new file mode 100644 index 00000000..114a08bf --- /dev/null +++ b/src/UnitTest/CollectionGeneratorTest/SimpleObjectCollectionGeneratorTests.cs @@ -0,0 +1,124 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis; +using System.Reflection; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using NUnit.Framework; +using Assert = NUnit.Framework.Assert; +using CollectionGenerator; +using System.Linq; +using System.Diagnostics; + +namespace CollectionGeneratorTest +{ + [TestClass] + public class SimpleObjectCollectionGeneratorTests + { + [TestMethod] + [TestCategory("Unit")] + public void SimpleObjectCollectionGeneratorTest() + { + var compilation = CreateCompilation(@" +namespace Microsoft.SqlServer.Management.Smo { + public abstract class AbstractCollectionBase + { + } + public enum SqlSmoState + { + } + public class ObjectKeyBase + { + } + + public class SqlSmoObject + { + internal SqlSmoObject(AbstractCollectionBase parentColl, ObjectKeyBase key, SqlSmoState state) + { + } + } + + public class Child : SqlSmoObject + { + internal Child(AbstractCollectionBase parentColl, ObjectKeyBase key, SqlSmoState state) : base(parentColl, key, state) + { + } + + public static string UrnSuffix => ""Child""; + } + + // These base class definitions are gross simplifications of the real base collection classes. + + public abstract class SimpleObjectCollectionBase : AbstractCollectionBase + where TObject: SqlSmoObject + where TParent: SqlSmoObject + { + internal SimpleObjectCollectionBase(TParent parent) + { + } + + protected abstract string UrnSuffix { get; } + + internal abstract TObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state); + } + + public abstract class ParameterCollectionBase : AbstractCollectionBase + where TObject: SqlSmoObject + where TParent: SqlSmoObject + { + internal ParameterCollectionBase(TParent parent) + { + } + + protected abstract string UrnSuffix { get; } + + internal abstract TObject GetCollectionElementInstance(ObjectKeyBase key, SqlSmoState state); + } + + public sealed partial class MySmoObjectCollection : SimpleObjectCollectionBase + { + + } + + public sealed partial class MyParameterObjectCollection : ParameterCollectionBase + { + } +} +namespace OtherNamespace +{ + using Microsoft.SqlServer.Management.Smo; + public class Parent : Microsoft.SqlServer.Management.Smo.SqlSmoObject + { + internal Parent(AbstractCollectionBase parentColl, ObjectKeyBase key, SqlSmoState state) : base(parentColl, key, state) + { + } + } +} +"); + var generator = new SmoCollectionGenerator(); + GeneratorDriver driver = CSharpGeneratorDriver.Create(generator); + driver = driver.RunGeneratorsAndUpdateCompilation(compilation, out var outputCompilation, out var diagnostics); + Assert.That(diagnostics, Is.Empty, nameof(diagnostics)); + Assert.That(outputCompilation.SyntaxTrees.Count, Is.EqualTo(3), "Output compilation should have a syntax tree per supplemented class, plus the original syntax"); + Assert.That(outputCompilation.GetDiagnostics(), Is.Empty, "Output compilation should have no errors"); + Trace.TraceInformation("Checking compilation of SimpleObjectCollectionBase"); + var outputType = outputCompilation.GetTypeByMetadataName("Microsoft.SqlServer.Management.Smo.MySmoObjectCollection"); + Assert.That(outputType, Is.Not.Null, "Compilation doesn't include the MySmoObjectCollection type"); + Assert.That(outputType.IsSealed, Is.True, nameof(outputType.IsSealed)); + Assert.That(outputType.GetMembers().Select(m => m.Name), Has.Member("UrnSuffix"), "UrnSuffix property not added"); + Trace.TraceInformation("Checking compilation of ParameterCollectionBase"); + outputType = outputCompilation.GetTypeByMetadataName("Microsoft.SqlServer.Management.Smo.MyParameterObjectCollection"); + Assert.That(outputType, Is.Not.Null, "Compilation doesn't include the MyParameterObjectCollection type"); + Assert.That(outputType.IsSealed, Is.True, nameof(outputType.IsSealed)); + Assert.That(outputType.GetMembers().Select(m => m.Name), Has.Member("UrnSuffix"), "UrnSuffix property not added"); + } + + private static Compilation CreateCompilation(string source) + => CSharpCompilation.Create("compilation", + new[] { CSharpSyntaxTree.ParseText(source) }, + new[] { MetadataReference.CreateFromFile(typeof(Binder).GetTypeInfo().Assembly.Location) }, + new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); + + } +} diff --git a/src/UnitTest/ConnectionInfo/ServerInformationTests.cs b/src/UnitTest/ConnectionInfo/ServerInformationTests.cs index 19d52052..0e9c91a4 100644 --- a/src/UnitTest/ConnectionInfo/ServerInformationTests.cs +++ b/src/UnitTest/ConnectionInfo/ServerInformationTests.cs @@ -13,7 +13,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using NUnit.Framework; -using Assert=NUnit.Framework.Assert; +using Assert = NUnit.Framework.Assert; namespace Microsoft.SqlServer.ConnectionInfoUnitTests @@ -115,6 +115,44 @@ select N'Windows' as host_platform connectMock.VerifyAll(); } + [TestMethod] + [TestCategory("Unit")] + [DataTestMethod] + [DataRow(DatabaseEngineEdition.SqlDatabase, DatabaseEngineEdition.SqlDatabase)] // Server reports self as Azure SQL Database edition, should remain unchanged + [DataRow((DatabaseEngineEdition)1000, (DatabaseEngineEdition)1000)] // Server reports self as Dynamics, should remain unchanged + [DataRow((DatabaseEngineEdition)555, DatabaseEngineEdition.SqlDatabase)] // Server reports self as unknown SqlAzureDatabase edition, should be converted to SqlDatabase + public void Edition_is_handled_properly_for_Azure_servers(DatabaseEngineEdition engineEdition, DatabaseEngineEdition expectedEdition) + { + // NOTE: Dynamics CRM databases have unique restrictions (master not accessible, CREATE TABLE not permitted) that make + // neither SqlDatabase or Unknown editions usable. Because adding it as a defined DatabaseEngineEdition would result in + // cascading changes elsewhere (query construction for SMO types, designer exemptions) and the previous behavior + // (where this went unconverted) was functioning correctly for MSSQL and Azure Data Studio, we treat it as a special case. + // This test validates that special casing. + + const string versionString = "12.00.6024.0"; + + var connectMock = new Mock(); + var commandMock = new Mock(); + var dataAdapterMock = new Mock(); + + connectMock.Setup(c => c.CreateCommand()).Returns(commandMock.Object); + dataAdapterMock.SetupSet(d => d.SelectCommand = commandMock.Object); + + dataAdapterMock.Setup(d => d.Fill(It.IsAny())).Callback( + (DataSet ds) => + { + // Simulate Azure SQL Database returning various editions + FillTestDataSet(ds, versionString, DatabaseEngineType.SqlAzureDatabase, engineEdition, 0x10000FA0, HostPlatformNames.Windows, "TCP", false); + }); + + var si = ServerInformation.GetServerInformation(connectMock.Object, dataAdapterMock.Object, versionString); + + // Verify that edition is converted as expected + Assert.That(si.DatabaseEngineType, Is.EqualTo(DatabaseEngineType.SqlAzureDatabase), "Engine type should be SqlAzureDatabase"); + Assert.That(si.DatabaseEngineEdition, Is.EqualTo(expectedEdition), $"Edition {engineEdition} from Azure should convert to {engineEdition}"); + + } + private void FillTestDataSet(DataSet ds, string productVersion, DatabaseEngineType databaseEngineType, DatabaseEngineEdition databaseEngineEdition, int microsoftVersion, string hostPlatform, string protocol, bool isFabricServer) { @@ -130,7 +168,7 @@ private void FillTestDataSet(DataSet ds, string productVersion, DatabaseEngineTy ds.Tables["Table2"].Columns.Add(new DataColumn("host_platform", typeof(string))); ds.Tables["Table2"].Rows.Add(hostPlatform); ds.Tables.Add("Table3"); - ds.Tables["Table3"].Columns.Add(new DataColumn("ConnectionProtocol", typeof (string))); + ds.Tables["Table3"].Columns.Add(new DataColumn("ConnectionProtocol", typeof(string))); ds.Tables["Table3"].Rows.Add(protocol); ds.AcceptChanges(); Trace.TraceInformation("Tables: {0}", string.Join(",", ds.Tables.OfType().Select(dt => dt.TableName).ToArray())); diff --git a/src/UnitTest/ConnectionInfo/VersionTests.cs b/src/UnitTest/ConnectionInfo/VersionTests.cs new file mode 100644 index 00000000..bfd707bf --- /dev/null +++ b/src/UnitTest/ConnectionInfo/VersionTests.cs @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +using Microsoft.VisualStudio.TestTools.UnitTesting; +using NUnit.Framework; +using Assert = NUnit.Framework.Assert; +using System.Reflection; + +namespace Microsoft.SqlServer.ConnectionInfoUnitTests +{ + [TestClass] + public class VersionTests + { + [TestMethod] + public void Applocal_minor_version_is_100() + { + var version = Assembly.GetExecutingAssembly().GetName().Version; +#if MICROSOFTDATA + Assert.That(version.Minor, Is.EqualTo(100), "Applocal minor version"); +#else + Assert.That(version.Minor, Is.EqualTo(0), "GAC minor version"); +#endif + } + } +} diff --git a/src/UnitTest/Smo/DatabaseTests.cs b/src/UnitTest/Smo/DatabaseTests.cs index 1f3ede92..e89af608 100644 --- a/src/UnitTest/Smo/DatabaseTests.cs +++ b/src/UnitTest/Smo/DatabaseTests.cs @@ -90,7 +90,7 @@ public void AllDatabaseCollectionProperties_AreVerifiedAsHavingUpdateTransferCod //See if any properties that extend SmoCollectionBase aren't in our validated list, //fail the test if there are var unknownCollections = typeof(Database).GetProperties() - .Where(p => typeof(SmoCollectionBase).IsAssignableFrom(p.PropertyType)) + .Where(p => typeof(ISmoCollection).IsAssignableFrom(p.PropertyType)) .Select(pi => pi.PropertyType) .Except(validatedCollections) .OrderBy(t => t.Name); @@ -100,7 +100,7 @@ public void AllDatabaseCollectionProperties_AreVerifiedAsHavingUpdateTransferCod 1. Add the new Collection type to the validatedCollections set above 2. Follow all the instructions listed on the ""Add new property to an existing object"" section of the OneNote 3. Submit a Code Review with your changes -3. Get confirmation (preferebly have them sign off in the CR) from a SMO Comitter that your changes are correct +3. Get confirmation (preferably have them sign off in the CR) from a SMO Committer that your changes are correct Unexpected Collection Types : {0}", string.Join(System.Environment.NewLine, unknownCollections)); diff --git a/src/UnitTest/Smo/SqlSmoObjectTests.cs b/src/UnitTest/Smo/SqlSmoObjectTests.cs index 98bb18f0..e44963c8 100644 --- a/src/UnitTest/Smo/SqlSmoObjectTests.cs +++ b/src/UnitTest/Smo/SqlSmoObjectTests.cs @@ -284,6 +284,7 @@ public class SqlSmoObjectTests : UnitTestBase "IsUnique", "IsXmlIndex", "NoAutomaticRecomputation", + nameof(Microsoft.SqlServer.Management.Smo.Index.OptimizeForArraySearch), "PadIndex", } }, @@ -807,6 +808,7 @@ then add the property to the expectedBooleanPropertiesWithoutValuesForSomeVersio typeof(FullTextIndexColumn), typeof(HttpProtocol), typeof(IndexedColumn), + typeof(IndexedJsonPath), typeof(IndexedXmlPath), typeof(IndexedXmlPathNamespace), typeof(Information),