diff --git a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/Nodes/ChildFactory.cs b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/Nodes/ChildFactory.cs
index cb412d79..95b3c4da 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/Nodes/ChildFactory.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/Nodes/ChildFactory.cs
@@ -29,6 +29,11 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
///
public abstract IEnumerable Expand(TreeNode parent);
+ ///
+ /// The list of filters that should be applied on the smo object list
+ ///
+ public abstract IEnumerable Filters { get; }
+
public abstract bool CanCreateChild(TreeNode parent, object context);
public abstract TreeNode CreateChild(TreeNode parent, object context);
diff --git a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/Nodes/NodeFilter.cs b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/Nodes/NodeFilter.cs
new file mode 100644
index 00000000..0c101c04
--- /dev/null
+++ b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/Nodes/NodeFilter.cs
@@ -0,0 +1,84 @@
+//
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+//
+
+using System;
+using System.Collections.Generic;
+
+namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
+{
+ ///
+ /// Has information for filtering a SMO object by properties
+ ///
+ public class NodeFilter
+ {
+ ///
+ /// Property name
+ ///
+ public string Property { get; set; }
+
+ ///
+ /// Filter values
+ ///
+ public List Values { get; set; }
+
+ ///
+ /// Type of the filter values
+ ///
+ public Type Type { get; set; }
+
+ ///
+ /// Indicates which platforms a filter is valid for
+ ///
+ public ValidForFlag ValidFor { get; set; }
+
+ ///
+ /// The type of the Querier the filter can be applied to
+ ///
+ public Type TypeToReverse { get; set; }
+
+ ///
+ /// Returns true if the filter can be apply to the given type and Server type
+ ///
+ /// Type of the querier
+ /// Server Type
+ ///
+ public bool CanApplyFilter(Type type, ValidForFlag validForFlag)
+ {
+ bool canApplyFilter = false;
+ canApplyFilter = TypeToReverse == null || TypeToReverse == type;
+ canApplyFilter = canApplyFilter && (ValidFor == 0 || ValidFor.HasFlag(validForFlag));
+
+ return canApplyFilter;
+ }
+
+ ///
+ /// Creates a string from the filter property and values to be used in the Urn to query the SQL objects
+ /// Example of the output:[@ IsSystemObject = 0]
+ ///
+ ///
+ public string ToPropertyFilterString()
+ {
+ string filter = "";
+ List values = Values;
+ if (values != null)
+ {
+ for (int i = 0; i < values.Count; i++)
+ {
+ var value = values[i];
+ object proeprtyValue = value;
+ if (Type == typeof(Enum))
+ {
+ proeprtyValue = (int)Convert.ChangeType(value, Type);
+ }
+ string orPrefix = i == 0 ? "" : "or";
+ filter = $"{filter} {orPrefix} @{Property} = {proeprtyValue}";
+ }
+ }
+ filter = $"[{filter}]";
+
+ return filter;
+ }
+ }
+}
diff --git a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/Nodes/NodeTypes.cs b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/Nodes/NodeTypes.cs
index 10812a95..2f089dd7 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/Nodes/NodeTypes.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/Nodes/NodeTypes.cs
@@ -24,6 +24,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
View,
Table,
HistoryTable,
+ Folder,
Databases,
ExternalResources,
ServerLevelSecurity,
diff --git a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/Nodes/SqlServerType.cs b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/Nodes/SqlServerType.cs
new file mode 100644
index 00000000..7b7f7eaf
--- /dev/null
+++ b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/Nodes/SqlServerType.cs
@@ -0,0 +1,91 @@
+//
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+//
+
+using System;
+using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
+
+namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
+{
+ ///
+ /// Server Types
+ ///
+ public enum SqlServerType
+ {
+ Unknown,
+ Sql2005,
+ Sql2008,
+ Sql2012,
+ Sql2014,
+ Sql2016,
+ Azure,
+ AzureV12
+ }
+
+ ///
+ /// Includes helper functions for server version and type
+ ///
+ public class ServerVersionHelper
+ {
+ ///
+ /// Converts a server type to ValidForFlag
+ ///
+ public static ValidForFlag GetValidForFlag(SqlServerType serverType)
+ {
+ ValidForFlag validforFlag = ValidForFlag.All;
+ if (Enum.TryParse(serverType.ToString(), out validforFlag))
+ {
+ return validforFlag;
+ }
+ return ValidForFlag.All;
+ }
+
+ ///
+ /// Creates a server type from the server version
+ ///
+ public static SqlServerType CalculateServerType(ServerInfo serverInfo)
+ {
+ SqlServerType serverType = SqlServerType.Unknown;
+ string serverVersion = serverInfo.ServerVersion;
+
+ if (serverInfo.IsCloud)
+ {
+ if (serverVersion.StartsWith("11", StringComparison.Ordinal))
+ {
+ serverType = SqlServerType.Azure;
+ }
+ else
+ {
+ serverType = SqlServerType.AzureV12;
+ }
+ }
+ else if (!string.IsNullOrWhiteSpace(serverVersion))
+ {
+ if (serverVersion.StartsWith("9", StringComparison.Ordinal) ||
+ serverVersion.StartsWith("09", StringComparison.Ordinal))
+ {
+ serverType = SqlServerType.Sql2005;
+ }
+ else if (serverVersion.StartsWith("10", StringComparison.Ordinal))
+ {
+ serverType = SqlServerType.Sql2008; // and 2008R2
+ }
+ else if (serverVersion.StartsWith("11", StringComparison.Ordinal))
+ {
+ serverType = SqlServerType.Sql2012;
+ }
+ else if (serverVersion.StartsWith("12", StringComparison.Ordinal))
+ {
+ serverType = SqlServerType.Sql2014;
+ }
+ else if (serverVersion.StartsWith("13", StringComparison.Ordinal))
+ {
+ serverType = SqlServerType.Sql2016;
+ }
+ }
+
+ return serverType;
+ }
+ }
+}
diff --git a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/ServerNode.cs b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/ServerNode.cs
index 0cf839ad..208930ea 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/ServerNode.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/ServerNode.cs
@@ -31,6 +31,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
private Lazy context;
private ConnectionService connectionService;
private SmoServerCreator serverCreator;
+ private SqlServerType sqlServerType;
public ServerNode(ConnectionCompleteParams connInfo, IMultiServiceProvider serviceProvider)
: base()
@@ -42,6 +43,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
this.connectionSummary = connInfo.ConnectionSummary;
this.serverInfo = connInfo.ServerInfo;
this.connectionUri = connInfo.OwnerUri;
+ this.sqlServerType = ServerVersionHelper.CalculateServerType(this.serverInfo);
this.connectionService = serviceProvider.GetService();
@@ -123,6 +125,8 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
return label;
}
+
+
private SmoQueryContext CreateContext(IMultiServiceProvider serviceProvider)
{
string exceptionMessage;
@@ -160,7 +164,8 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
Server server = ServerCreator.Create(connection);
return new SmoQueryContext(server, serviceProvider)
{
- Parent = server
+ Parent = server,
+ SqlServerType = this.sqlServerType
};
}
catch (ConnectionFailureException cfe)
diff --git a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoChildFactoryBase.cs b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoChildFactoryBase.cs
index 6aa7a072..89b9641d 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoChildFactoryBase.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoChildFactoryBase.cs
@@ -1,133 +1,169 @@
-//
-// Copyright (c) Microsoft. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-//
-
-using System;
-using System.Collections.Generic;
+//
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+//
+
+using System;
+using System.Collections.Generic;
using System.Diagnostics;
-using System.Linq;
-using System.Reflection;
-using Microsoft.SqlServer.Management.Smo;
-using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes;
-using Microsoft.SqlTools.ServiceLayer.Utility;
+using System.Linq;
+using System.Reflection;
+using Microsoft.SqlServer.Management.Smo;
+using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes;
using Microsoft.SqlTools.Utility;
-namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
-{
- public class SmoChildFactoryBase : ChildFactory
- {
- public override IEnumerable ApplicableParents()
- {
- return null;
- }
-
- public override IEnumerable Expand(TreeNode parent)
- {
- //parent.BeginChildrenInit();
- try
- {
- List allChildren = new List();
- OnExpandPopulateFolders(allChildren, parent);
- RemoveFoldersFromInvalidSqlServerVersions(allChildren, parent);
- OnExpandPopulateNonFolders(allChildren, parent);
- OnBeginAsyncOperations(parent);
- return allChildren;
- }
- finally
- {
- //parent.EndChildrenInit();
- }
- }
-
- ///
- /// Populates any folders for a given parent node
- ///
- /// List to which nodes should be added
- /// Parent the nodes are being added to
- protected virtual void OnExpandPopulateFolders(IList allChildren, TreeNode parent)
- {
- }
-
- ///
- /// Populates any non-folder nodes such as specific items in the tree.
- ///
- /// List to which nodes should be added
- /// Parent the nodes are being added to
- protected virtual void OnExpandPopulateNonFolders(IList allChildren, TreeNode parent)
- {
- if (ChildQuerierTypes == null)
- {
- // This node does not support non-folder children
- return;
- }
- SmoQueryContext context = parent.GetContextAs();
- Validate.IsNotNull(nameof(context), context);
- IEnumerable queriers = context.ServiceProvider.GetServices(q => IsCompatibleQuerier(q));
- foreach (var querier in queriers)
- {
- foreach(var smoObject in querier.Query(context))
- {
+namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
+{
+ public class SmoChildFactoryBase : ChildFactory
+ {
+ public override IEnumerable ApplicableParents()
+ {
+ return null;
+ }
+
+ public override IEnumerable Expand(TreeNode parent)
+ {
+ //parent.BeginChildrenInit();
+ try
+ {
+ List allChildren = new List();
+ OnExpandPopulateFolders(allChildren, parent);
+ RemoveFoldersFromInvalidSqlServerVersions(allChildren, parent);
+ OnExpandPopulateNonFolders(allChildren, parent);
+ OnBeginAsyncOperations(parent);
+ return allChildren;
+ }
+ finally
+ {
+ //parent.EndChildrenInit();
+ }
+ }
+
+ ///
+ /// Populates any folders for a given parent node
+ ///
+ /// List to which nodes should be added
+ /// Parent the nodes are being added to
+ protected virtual void OnExpandPopulateFolders(IList allChildren, TreeNode parent)
+ {
+ }
+
+ ///
+ /// Populates any non-folder nodes such as specific items in the tree.
+ ///
+ /// List to which nodes should be added
+ /// Parent the nodes are being added to
+ protected virtual void OnExpandPopulateNonFolders(IList allChildren, TreeNode parent)
+ {
+ if (ChildQuerierTypes == null)
+ {
+ // This node does not support non-folder children
+ return;
+ }
+ SmoQueryContext context = parent.GetContextAs();
+ Validate.IsNotNull(nameof(context), context);
+ IEnumerable queriers = context.ServiceProvider.GetServices(q => IsCompatibleQuerier(q));
+ var filters = this.Filters;
+ var validForFlag = ServerVersionHelper.GetValidForFlag(context.SqlServerType);
+
+ foreach (var querier in queriers)
+ {
+ string propertyFilter = GetProperyFilter(filters, querier.GetType(), validForFlag);
+
+ foreach (var smoObject in querier.Query(context, propertyFilter))
+ {
if (smoObject == null)
{
Console.WriteLine("smoObject should not be null");
- }
- TreeNode childNode = CreateChild(parent, smoObject);
- if (childNode != null)
- {
- allChildren.Add(childNode);
- }
- }
- }
- }
-
- private bool IsCompatibleQuerier(SmoQuerier querier)
- {
- if (ChildQuerierTypes == null)
- {
- return false;
- }
-
- Type actualType = querier.GetType();
- foreach (Type childType in ChildQuerierTypes)
- {
- // We will accept any querier that is compatible with the listed querier type
- if (childType.IsAssignableFrom(actualType))
- {
- return true;
- }
- }
- return false;
-
- }
-
- ///
- /// Filters out invalid folders if they cannot be displayed for the current server version
- ///
- /// List to which nodes should be added
- /// Parent the nodes are being added to
- protected virtual void RemoveFoldersFromInvalidSqlServerVersions(IList allChildren, TreeNode parent)
- {
- }
-
- // TODO Assess whether async operations node is required
- protected virtual void OnBeginAsyncOperations(TreeNode parent)
- {
- }
-
- public override bool CanCreateChild(TreeNode parent, object context)
- {
- return false;
- }
-
- public override TreeNode CreateChild(TreeNode parent, object context)
- {
- throw new NotImplementedException();
- }
-
- protected virtual void InitializeChild(TreeNode child, object context)
- {
- NamedSmoObject smoObj = context as NamedSmoObject;
+ }
+ TreeNode childNode = CreateChild(parent, smoObject);
+ if (childNode != null && !ShouldFilterNode(childNode, validForFlag))
+ {
+ allChildren.Add(childNode);
+ }
+ }
+ }
+ }
+
+ private bool ShouldFilterNode(TreeNode childNode, ValidForFlag validForFlag)
+ {
+ bool filterTheNode = false;
+ SmoTreeNode smoTreeNode = childNode as SmoTreeNode;
+ if (smoTreeNode != null && smoTreeNode.ValidFor != 0)
+ {
+ if (!(smoTreeNode.ValidFor.HasFlag(validForFlag)))
+ {
+ filterTheNode = true;
+ }
+ }
+
+ return filterTheNode;
+ }
+
+ private string GetProperyFilter(IEnumerable filters, Type querierType, ValidForFlag validForFlag)
+ {
+ string filter = "";
+ if (filters != null)
+ {
+ var filterToApply = filters.FirstOrDefault(f => f.CanApplyFilter(querierType, validForFlag));
+ filter = "";
+
+ if (filterToApply != null)
+ {
+ filter = filterToApply.ToPropertyFilterString();
+ }
+ }
+
+ return filter;
+ }
+
+ private bool IsCompatibleQuerier(SmoQuerier querier)
+ {
+ if (ChildQuerierTypes == null)
+ {
+ return false;
+ }
+
+ Type actualType = querier.GetType();
+ foreach (Type childType in ChildQuerierTypes)
+ {
+ // We will accept any querier that is compatible with the listed querier type
+ if (childType.IsAssignableFrom(actualType))
+ {
+ return true;
+ }
+ }
+ return false;
+
+ }
+
+ ///
+ /// Filters out invalid folders if they cannot be displayed for the current server version
+ ///
+ /// List to which nodes should be added
+ /// Parent the nodes are being added to
+ protected virtual void RemoveFoldersFromInvalidSqlServerVersions(IList allChildren, TreeNode parent)
+ {
+ }
+
+ // TODO Assess whether async operations node is required
+ protected virtual void OnBeginAsyncOperations(TreeNode parent)
+ {
+ }
+
+ public override bool CanCreateChild(TreeNode parent, object context)
+ {
+ return false;
+ }
+
+ public override TreeNode CreateChild(TreeNode parent, object context)
+ {
+ throw new NotImplementedException();
+ }
+
+ protected virtual void InitializeChild(TreeNode child, object context)
+ {
+ NamedSmoObject smoObj = context as NamedSmoObject;
if (smoObj == null)
{
Debug.WriteLine("context is not a NamedSmoObject. type: " + context.GetType());
@@ -136,26 +172,34 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
{
SmoTreeNode childAsMeItem = (SmoTreeNode)child;
childAsMeItem.CacheInfoFromModel(smoObj);
- }
- }
-
- internal virtual Type[] ChildQuerierTypes {
- get
- {
- return null;
- }
- }
-
- ///
- /// Returns true if any final validation of the object to be added passes, and false
- /// if validation fails. This provides a chance to filter specific items out of a list
- ///
- ///
- ///
- /// boolean
- public virtual bool PassesFinalFilters(TreeNode parent, object context)
- {
- return true;
- }
- }
-}
+ }
+ }
+
+ internal virtual Type[] ChildQuerierTypes {
+ get
+ {
+ return null;
+ }
+ }
+
+ public override IEnumerable Filters
+ {
+ get
+ {
+ return Enumerable.Empty();
+ }
+ }
+
+ ///
+ /// Returns true if any final validation of the object to be added passes, and false
+ /// if validation fails. This provides a chance to filter specific items out of a list
+ ///
+ ///
+ ///
+ /// boolean
+ public virtual bool PassesFinalFilters(TreeNode parent, object context)
+ {
+ return true;
+ }
+ }
+}
diff --git a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoQuerier.cs b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoQuerier.cs
index 87373258..aececc7a 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoQuerier.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoQuerier.cs
@@ -1,42 +1,91 @@
-//
-// Copyright (c) Microsoft. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-//
-
-using System;
-using System.Collections.Generic;
-using Microsoft.SqlServer.Management.Smo;
+//
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+//
+
+using System;
+using System.Collections.Generic;
+using System.Data;
+using Microsoft.Data.Tools.DataSets;
+using Microsoft.SqlServer.Management.Sdk.Sfc;
+using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlTools.Extensibility;
-namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
-{
- ///
- /// A handles SMO queries for one or more SMO object types.
- /// The property defines which types can be queried.
- ///
- /// To query multiple
- ///
- public abstract class SmoQuerier : IComposableService
- {
- public abstract Type[] SupportedObjectTypes { get; }
-
- ///
- /// Queries SMO for a collection of objects using the
- ///
- ///
- ///
- public abstract IEnumerable Query(SmoQueryContext context);
-
- internal IMultiServiceProvider ServiceProvider
- {
- get;
- private set;
- }
-
- public void SetServiceProvider(IMultiServiceProvider provider)
- {
- ServiceProvider = provider;
- }
- }
-
-}
+namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
+{
+ ///
+ /// A handles SMO queries for one or more SMO object types.
+ /// The property defines which types can be queried.
+ ///
+ /// To query multiple
+ ///
+ public abstract class SmoQuerier : IComposableService
+ {
+ public abstract Type[] SupportedObjectTypes { get; }
+
+ ///
+ /// Queries SMO for a collection of objects using the
+ ///
+ ///
+ ///
+ public abstract IEnumerable Query(SmoQueryContext context, string filter);
+
+ internal IMultiServiceProvider ServiceProvider
+ {
+ get;
+ private set;
+ }
+
+ public void SetServiceProvider(IMultiServiceProvider provider)
+ {
+ ServiceProvider = provider;
+ }
+
+ ///
+ /// Convert the data to data reader is possible
+ ///
+ protected IDataReader GetDataReader(object data)
+ {
+ IDataReader reader = null;
+ if (data is IDataReader)
+ {
+
+ reader = data as IDataReader;
+ }
+ else if(data is Data.Tools.DataSets.DataTable)
+ {
+ reader = ((Data.Tools.DataSets.DataTable)data).CreateDataReader();
+ }
+
+ else if (data is DataSet)
+ {
+ reader = ((DataSet)data).Tables[0].CreateDataReader();
+ }
+
+ return reader;
+ }
+
+ ///
+ /// Gets the urn from the enumResult
+ ///
+ protected HashSet GetUrns(EnumResult enumResult)
+ {
+ HashSet urns = null;
+ if (enumResult != null && enumResult.Data != null)
+ {
+ urns = new HashSet();
+ IDataReader reader = GetDataReader(enumResult.Data);
+ if (reader != null)
+ {
+ while (reader.Read())
+ {
+ urns.Add(reader.GetString(0));
+ }
+ }
+ }
+
+ return urns;
+ }
+ }
+
+}
diff --git a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoQueryContext.cs b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoQueryContext.cs
index 73758a3c..d6ebdfec 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoQueryContext.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoQueryContext.cs
@@ -28,6 +28,11 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
ServiceProvider = serviceProvider;
}
+ ///
+ /// The server type
+ ///
+ public SqlServerType SqlServerType { get; set; }
+
///
/// The server SMO will query against
///
@@ -94,7 +99,8 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
SmoQueryContext context = new SmoQueryContext(this.Server, this.ServiceProvider)
{
Database = this.Database,
- Parent = parent
+ Parent = parent,
+ SqlServerType = this.SqlServerType
};
return context;
}
diff --git a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoQueryModel.cs b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoQueryModel.cs
index f2407b6b..f8a05fc3 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoQueryModel.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoQueryModel.cs
@@ -6,6 +6,8 @@ using System;
using System.Collections.Generic;
using System.Composition;
using System.Linq;
+using Microsoft.SqlServer.Management.Common;
+using Microsoft.SqlServer.Management.Sdk.Sfc;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Smo.Broker;
@@ -19,15 +21,33 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
public override Type[] SupportedObjectTypes { get { return supportedTypes; } }
- public override IEnumerable Query(SmoQueryContext context)
+ public override IEnumerable Query(SmoQueryContext context, string filter)
{
Server parentServer = context.Parent as Server;
if (parentServer != null)
{
var retValue = parentServer.Databases;
- if(retValue != null)
+ bool hasFilter = !string.IsNullOrEmpty(filter);
+ HashSet urns = null;
+ if (hasFilter)
{
- return new SmoCollectionWrapper(retValue);
+ string urn = $"{parentServer.Urn.ToString()}/Database" + filter;
+ Enumerator en = new Enumerator();
+ Request request = new Request(new Urn(urn));
+ ServerConnection serverConnection = new ServerConnection(context.Server.ConnectionContext.SqlConnectionObject);
+ EnumResult result = en.Process(serverConnection, request);
+ urns = GetUrns(result);
+ }
+ if (retValue != null)
+ {
+ if (hasFilter && urns != null)
+ {
+ return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn));
+ }
+ else
+ {
+ return new SmoCollectionWrapper(retValue);
+ }
}
}
return Enumerable.Empty();
@@ -41,15 +61,33 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
public override Type[] SupportedObjectTypes { get { return supportedTypes; } }
- public override IEnumerable Query(SmoQueryContext context)
+ public override IEnumerable Query(SmoQueryContext context, string filter)
{
Server parentServer = context.Parent as Server;
if (parentServer != null)
{
var retValue = parentServer.LinkedServers;
- if(retValue != null)
+ bool hasFilter = !string.IsNullOrEmpty(filter);
+ HashSet urns = null;
+ if (hasFilter)
{
- return new SmoCollectionWrapper(retValue);
+ string urn = $"{parentServer.Urn.ToString()}/LinkedServer" + filter;
+ Enumerator en = new Enumerator();
+ Request request = new Request(new Urn(urn));
+ ServerConnection serverConnection = new ServerConnection(context.Server.ConnectionContext.SqlConnectionObject);
+ EnumResult result = en.Process(serverConnection, request);
+ urns = GetUrns(result);
+ }
+ if (retValue != null)
+ {
+ if (hasFilter && urns != null)
+ {
+ return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn));
+ }
+ else
+ {
+ return new SmoCollectionWrapper(retValue);
+ }
}
}
return Enumerable.Empty();
@@ -63,15 +101,33 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
public override Type[] SupportedObjectTypes { get { return supportedTypes; } }
- public override IEnumerable Query(SmoQueryContext context)
+ public override IEnumerable Query(SmoQueryContext context, string filter)
{
Server parentServer = context.Parent as Server;
if (parentServer != null)
{
var retValue = parentServer.Logins;
- if(retValue != null)
+ bool hasFilter = !string.IsNullOrEmpty(filter);
+ HashSet urns = null;
+ if (hasFilter)
{
- return new SmoCollectionWrapper(retValue);
+ string urn = $"{parentServer.Urn.ToString()}/Login" + filter;
+ Enumerator en = new Enumerator();
+ Request request = new Request(new Urn(urn));
+ ServerConnection serverConnection = new ServerConnection(context.Server.ConnectionContext.SqlConnectionObject);
+ EnumResult result = en.Process(serverConnection, request);
+ urns = GetUrns(result);
+ }
+ if (retValue != null)
+ {
+ if (hasFilter && urns != null)
+ {
+ return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn));
+ }
+ else
+ {
+ return new SmoCollectionWrapper(retValue);
+ }
}
}
return Enumerable.Empty();
@@ -85,15 +141,33 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
public override Type[] SupportedObjectTypes { get { return supportedTypes; } }
- public override IEnumerable Query(SmoQueryContext context)
+ public override IEnumerable Query(SmoQueryContext context, string filter)
{
Server parentServer = context.Parent as Server;
if (parentServer != null)
{
var retValue = parentServer.Roles;
- if(retValue != null)
+ bool hasFilter = !string.IsNullOrEmpty(filter);
+ HashSet urns = null;
+ if (hasFilter)
{
- return new SmoCollectionWrapper(retValue);
+ string urn = $"{parentServer.Urn.ToString()}/ServerRole" + filter;
+ Enumerator en = new Enumerator();
+ Request request = new Request(new Urn(urn));
+ ServerConnection serverConnection = new ServerConnection(context.Server.ConnectionContext.SqlConnectionObject);
+ EnumResult result = en.Process(serverConnection, request);
+ urns = GetUrns(result);
+ }
+ if (retValue != null)
+ {
+ if (hasFilter && urns != null)
+ {
+ return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn));
+ }
+ else
+ {
+ return new SmoCollectionWrapper(retValue);
+ }
}
}
return Enumerable.Empty();
@@ -107,15 +181,33 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
public override Type[] SupportedObjectTypes { get { return supportedTypes; } }
- public override IEnumerable Query(SmoQueryContext context)
+ public override IEnumerable Query(SmoQueryContext context, string filter)
{
Server parentServer = context.Parent as Server;
if (parentServer != null)
{
var retValue = parentServer.Credentials;
- if(retValue != null)
+ bool hasFilter = !string.IsNullOrEmpty(filter);
+ HashSet urns = null;
+ if (hasFilter)
{
- return new SmoCollectionWrapper(retValue);
+ string urn = $"{parentServer.Urn.ToString()}/Credential" + filter;
+ Enumerator en = new Enumerator();
+ Request request = new Request(new Urn(urn));
+ ServerConnection serverConnection = new ServerConnection(context.Server.ConnectionContext.SqlConnectionObject);
+ EnumResult result = en.Process(serverConnection, request);
+ urns = GetUrns(result);
+ }
+ if (retValue != null)
+ {
+ if (hasFilter && urns != null)
+ {
+ return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn));
+ }
+ else
+ {
+ return new SmoCollectionWrapper(retValue);
+ }
}
}
return Enumerable.Empty();
@@ -129,15 +221,33 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
public override Type[] SupportedObjectTypes { get { return supportedTypes; } }
- public override IEnumerable Query(SmoQueryContext context)
+ public override IEnumerable Query(SmoQueryContext context, string filter)
{
Server parentServer = context.Parent as Server;
if (parentServer != null)
{
var retValue = parentServer.CryptographicProviders;
- if(retValue != null)
+ bool hasFilter = !string.IsNullOrEmpty(filter);
+ HashSet urns = null;
+ if (hasFilter)
{
- return new SmoCollectionWrapper(retValue);
+ string urn = $"{parentServer.Urn.ToString()}/CryptographicProvider" + filter;
+ Enumerator en = new Enumerator();
+ Request request = new Request(new Urn(urn));
+ ServerConnection serverConnection = new ServerConnection(context.Server.ConnectionContext.SqlConnectionObject);
+ EnumResult result = en.Process(serverConnection, request);
+ urns = GetUrns(result);
+ }
+ if (retValue != null)
+ {
+ if (hasFilter && urns != null)
+ {
+ return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn));
+ }
+ else
+ {
+ return new SmoCollectionWrapper(retValue);
+ }
}
}
return Enumerable.Empty();
@@ -151,15 +261,33 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
public override Type[] SupportedObjectTypes { get { return supportedTypes; } }
- public override IEnumerable Query(SmoQueryContext context)
+ public override IEnumerable Query(SmoQueryContext context, string filter)
{
Server parentServer = context.Parent as Server;
if (parentServer != null)
{
var retValue = parentServer.Audits;
- if(retValue != null)
+ bool hasFilter = !string.IsNullOrEmpty(filter);
+ HashSet urns = null;
+ if (hasFilter)
{
- return new SmoCollectionWrapper(retValue);
+ string urn = $"{parentServer.Urn.ToString()}/Audit" + filter;
+ Enumerator en = new Enumerator();
+ Request request = new Request(new Urn(urn));
+ ServerConnection serverConnection = new ServerConnection(context.Server.ConnectionContext.SqlConnectionObject);
+ EnumResult result = en.Process(serverConnection, request);
+ urns = GetUrns(result);
+ }
+ if (retValue != null)
+ {
+ if (hasFilter && urns != null)
+ {
+ return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn));
+ }
+ else
+ {
+ return new SmoCollectionWrapper(retValue);
+ }
}
}
return Enumerable.Empty();
@@ -173,15 +301,33 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
public override Type[] SupportedObjectTypes { get { return supportedTypes; } }
- public override IEnumerable Query(SmoQueryContext context)
+ public override IEnumerable Query(SmoQueryContext context, string filter)
{
Server parentServer = context.Parent as Server;
if (parentServer != null)
{
var retValue = parentServer.ServerAuditSpecifications;
- if(retValue != null)
+ bool hasFilter = !string.IsNullOrEmpty(filter);
+ HashSet urns = null;
+ if (hasFilter)
{
- return new SmoCollectionWrapper(retValue);
+ string urn = $"{parentServer.Urn.ToString()}/ServerAuditSpecification" + filter;
+ Enumerator en = new Enumerator();
+ Request request = new Request(new Urn(urn));
+ ServerConnection serverConnection = new ServerConnection(context.Server.ConnectionContext.SqlConnectionObject);
+ EnumResult result = en.Process(serverConnection, request);
+ urns = GetUrns(result);
+ }
+ if (retValue != null)
+ {
+ if (hasFilter && urns != null)
+ {
+ return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn));
+ }
+ else
+ {
+ return new SmoCollectionWrapper(retValue);
+ }
}
}
return Enumerable.Empty();
@@ -195,15 +341,33 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
public override Type[] SupportedObjectTypes { get { return supportedTypes; } }
- public override IEnumerable Query(SmoQueryContext context)
+ public override IEnumerable Query(SmoQueryContext context, string filter)
{
Server parentServer = context.Parent as Server;
if (parentServer != null)
{
var retValue = parentServer.Endpoints;
- if(retValue != null)
+ bool hasFilter = !string.IsNullOrEmpty(filter);
+ HashSet urns = null;
+ if (hasFilter)
{
- return new SmoCollectionWrapper(retValue);
+ string urn = $"{parentServer.Urn.ToString()}/Endpoint" + filter;
+ Enumerator en = new Enumerator();
+ Request request = new Request(new Urn(urn));
+ ServerConnection serverConnection = new ServerConnection(context.Server.ConnectionContext.SqlConnectionObject);
+ EnumResult result = en.Process(serverConnection, request);
+ urns = GetUrns(result);
+ }
+ if (retValue != null)
+ {
+ if (hasFilter && urns != null)
+ {
+ return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn));
+ }
+ else
+ {
+ return new SmoCollectionWrapper(retValue);
+ }
}
}
return Enumerable.Empty();
@@ -217,15 +381,33 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
public override Type[] SupportedObjectTypes { get { return supportedTypes; } }
- public override IEnumerable Query(SmoQueryContext context)
+ public override IEnumerable Query(SmoQueryContext context, string filter)
{
Server parentServer = context.Parent as Server;
if (parentServer != null)
{
var retValue = parentServer.LinkedServers;
- if(retValue != null)
+ bool hasFilter = !string.IsNullOrEmpty(filter);
+ HashSet urns = null;
+ if (hasFilter)
{
- return new SmoCollectionWrapper(retValue);
+ string urn = $"{parentServer.Urn.ToString()}/LinkedServer" + filter;
+ Enumerator en = new Enumerator();
+ Request request = new Request(new Urn(urn));
+ ServerConnection serverConnection = new ServerConnection(context.Server.ConnectionContext.SqlConnectionObject);
+ EnumResult result = en.Process(serverConnection, request);
+ urns = GetUrns(result);
+ }
+ if (retValue != null)
+ {
+ if (hasFilter && urns != null)
+ {
+ return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn));
+ }
+ else
+ {
+ return new SmoCollectionWrapper(retValue);
+ }
}
}
return Enumerable.Empty();
@@ -239,15 +421,33 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
public override Type[] SupportedObjectTypes { get { return supportedTypes; } }
- public override IEnumerable Query(SmoQueryContext context)
+ public override IEnumerable Query(SmoQueryContext context, string filter)
{
Server parentServer = context.Parent as Server;
if (parentServer != null)
{
var retValue = parentServer.Triggers;
- if(retValue != null)
+ bool hasFilter = !string.IsNullOrEmpty(filter);
+ HashSet urns = null;
+ if (hasFilter)
{
- return new SmoCollectionWrapper(retValue);
+ string urn = $"{parentServer.Urn.ToString()}/ServerDdlTrigger" + filter;
+ Enumerator en = new Enumerator();
+ Request request = new Request(new Urn(urn));
+ ServerConnection serverConnection = new ServerConnection(context.Server.ConnectionContext.SqlConnectionObject);
+ EnumResult result = en.Process(serverConnection, request);
+ urns = GetUrns(result);
+ }
+ if (retValue != null)
+ {
+ if (hasFilter && urns != null)
+ {
+ return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn));
+ }
+ else
+ {
+ return new SmoCollectionWrapper(retValue);
+ }
}
}
return Enumerable.Empty();
@@ -261,15 +461,33 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
public override Type[] SupportedObjectTypes { get { return supportedTypes; } }
- public override IEnumerable Query(SmoQueryContext context)
+ public override IEnumerable Query(SmoQueryContext context, string filter)
{
Server parentServer = context.Parent as Server;
if (parentServer != null)
{
var retValue = parentServer.UserDefinedMessages;
- if(retValue != null)
+ bool hasFilter = !string.IsNullOrEmpty(filter);
+ HashSet urns = null;
+ if (hasFilter)
{
- return new SmoCollectionWrapper(retValue);
+ string urn = $"{parentServer.Urn.ToString()}/UserDefinedMessage" + filter;
+ Enumerator en = new Enumerator();
+ Request request = new Request(new Urn(urn));
+ ServerConnection serverConnection = new ServerConnection(context.Server.ConnectionContext.SqlConnectionObject);
+ EnumResult result = en.Process(serverConnection, request);
+ urns = GetUrns(result);
+ }
+ if (retValue != null)
+ {
+ if (hasFilter && urns != null)
+ {
+ return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn));
+ }
+ else
+ {
+ return new SmoCollectionWrapper(retValue);
+ }
}
}
return Enumerable.Empty();
@@ -283,15 +501,33 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
public override Type[] SupportedObjectTypes { get { return supportedTypes; } }
- public override IEnumerable Query(SmoQueryContext context)
+ public override IEnumerable Query(SmoQueryContext context, string filter)
{
Database parentDatabase = context.Parent as Database;
if (parentDatabase != null)
{
var retValue = parentDatabase.Tables;
- if(retValue != null)
+ bool hasFilter = !string.IsNullOrEmpty(filter);
+ HashSet urns = null;
+ if (hasFilter)
{
- return new SmoCollectionWrapper(retValue);
+ string urn = $"{parentDatabase.Urn.ToString()}/Table" + filter;
+ Enumerator en = new Enumerator();
+ Request request = new Request(new Urn(urn));
+ ServerConnection serverConnection = new ServerConnection(context.Server.ConnectionContext.SqlConnectionObject);
+ EnumResult result = en.Process(serverConnection, request);
+ urns = GetUrns(result);
+ }
+ if (retValue != null)
+ {
+ if (hasFilter && urns != null)
+ {
+ return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn));
+ }
+ else
+ {
+ return new SmoCollectionWrapper(retValue);
+ }
}
}
return Enumerable.Empty();
@@ -305,15 +541,33 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
public override Type[] SupportedObjectTypes { get { return supportedTypes; } }
- public override IEnumerable Query(SmoQueryContext context)
+ public override IEnumerable Query(SmoQueryContext context, string filter)
{
Database parentDatabase = context.Parent as Database;
if (parentDatabase != null)
{
var retValue = parentDatabase.Views;
- if(retValue != null)
+ bool hasFilter = !string.IsNullOrEmpty(filter);
+ HashSet urns = null;
+ if (hasFilter)
{
- return new SmoCollectionWrapper(retValue);
+ string urn = $"{parentDatabase.Urn.ToString()}/View" + filter;
+ Enumerator en = new Enumerator();
+ Request request = new Request(new Urn(urn));
+ ServerConnection serverConnection = new ServerConnection(context.Server.ConnectionContext.SqlConnectionObject);
+ EnumResult result = en.Process(serverConnection, request);
+ urns = GetUrns(result);
+ }
+ if (retValue != null)
+ {
+ if (hasFilter && urns != null)
+ {
+ return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn));
+ }
+ else
+ {
+ return new SmoCollectionWrapper(retValue);
+ }
}
}
return Enumerable.Empty();
@@ -327,15 +581,33 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
public override Type[] SupportedObjectTypes { get { return supportedTypes; } }
- public override IEnumerable Query(SmoQueryContext context)
+ public override IEnumerable Query(SmoQueryContext context, string filter)
{
Database parentDatabase = context.Parent as Database;
if (parentDatabase != null)
{
var retValue = parentDatabase.Synonyms;
- if(retValue != null)
+ bool hasFilter = !string.IsNullOrEmpty(filter);
+ HashSet urns = null;
+ if (hasFilter)
{
- return new SmoCollectionWrapper(retValue);
+ string urn = $"{parentDatabase.Urn.ToString()}/Synonym" + filter;
+ Enumerator en = new Enumerator();
+ Request request = new Request(new Urn(urn));
+ ServerConnection serverConnection = new ServerConnection(context.Server.ConnectionContext.SqlConnectionObject);
+ EnumResult result = en.Process(serverConnection, request);
+ urns = GetUrns(result);
+ }
+ if (retValue != null)
+ {
+ if (hasFilter && urns != null)
+ {
+ return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn));
+ }
+ else
+ {
+ return new SmoCollectionWrapper(retValue);
+ }
}
}
return Enumerable.Empty();
@@ -349,15 +621,33 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
public override Type[] SupportedObjectTypes { get { return supportedTypes; } }
- public override IEnumerable Query(SmoQueryContext context)
+ public override IEnumerable Query(SmoQueryContext context, string filter)
{
TableViewTableTypeBase parentTableViewTableTypeBase = context.Parent as TableViewTableTypeBase;
if (parentTableViewTableTypeBase != null)
{
var retValue = parentTableViewTableTypeBase.Columns;
- if(retValue != null)
+ bool hasFilter = !string.IsNullOrEmpty(filter);
+ HashSet urns = null;
+ if (hasFilter)
{
- return new SmoCollectionWrapper(retValue);
+ string urn = $"{parentTableViewTableTypeBase.Urn.ToString()}/Column" + filter;
+ Enumerator en = new Enumerator();
+ Request request = new Request(new Urn(urn));
+ ServerConnection serverConnection = new ServerConnection(context.Server.ConnectionContext.SqlConnectionObject);
+ EnumResult result = en.Process(serverConnection, request);
+ urns = GetUrns(result);
+ }
+ if (retValue != null)
+ {
+ if (hasFilter && urns != null)
+ {
+ return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn));
+ }
+ else
+ {
+ return new SmoCollectionWrapper(retValue);
+ }
}
}
return Enumerable.Empty();
@@ -371,15 +661,33 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
public override Type[] SupportedObjectTypes { get { return supportedTypes; } }
- public override IEnumerable Query(SmoQueryContext context)
+ public override IEnumerable Query(SmoQueryContext context, string filter)
{
TableViewTableTypeBase parentTableViewTableTypeBase = context.Parent as TableViewTableTypeBase;
if (parentTableViewTableTypeBase != null)
{
var retValue = parentTableViewTableTypeBase.Indexes;
- if(retValue != null)
+ bool hasFilter = !string.IsNullOrEmpty(filter);
+ HashSet urns = null;
+ if (hasFilter)
{
- return new SmoCollectionWrapper(retValue);
+ string urn = $"{parentTableViewTableTypeBase.Urn.ToString()}/Index" + filter;
+ Enumerator en = new Enumerator();
+ Request request = new Request(new Urn(urn));
+ ServerConnection serverConnection = new ServerConnection(context.Server.ConnectionContext.SqlConnectionObject);
+ EnumResult result = en.Process(serverConnection, request);
+ urns = GetUrns(result);
+ }
+ if (retValue != null)
+ {
+ if (hasFilter && urns != null)
+ {
+ return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn));
+ }
+ else
+ {
+ return new SmoCollectionWrapper(retValue);
+ }
}
}
return Enumerable.Empty();
@@ -393,15 +701,33 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
public override Type[] SupportedObjectTypes { get { return supportedTypes; } }
- public override IEnumerable Query(SmoQueryContext context)
+ public override IEnumerable Query(SmoQueryContext context, string filter)
{
Table parentTable = context.Parent as Table;
if (parentTable != null)
{
var retValue = parentTable.Checks;
- if(retValue != null)
+ bool hasFilter = !string.IsNullOrEmpty(filter);
+ HashSet urns = null;
+ if (hasFilter)
{
- return new SmoCollectionWrapper(retValue);
+ string urn = $"{parentTable.Urn.ToString()}/Check" + filter;
+ Enumerator en = new Enumerator();
+ Request request = new Request(new Urn(urn));
+ ServerConnection serverConnection = new ServerConnection(context.Server.ConnectionContext.SqlConnectionObject);
+ EnumResult result = en.Process(serverConnection, request);
+ urns = GetUrns(result);
+ }
+ if (retValue != null)
+ {
+ if (hasFilter && urns != null)
+ {
+ return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn));
+ }
+ else
+ {
+ return new SmoCollectionWrapper(retValue);
+ }
}
}
return Enumerable.Empty();
@@ -415,15 +741,33 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
public override Type[] SupportedObjectTypes { get { return supportedTypes; } }
- public override IEnumerable Query(SmoQueryContext context)
+ public override IEnumerable Query(SmoQueryContext context, string filter)
{
Table parentTable = context.Parent as Table;
if (parentTable != null)
{
var retValue = parentTable.ForeignKeys;
- if(retValue != null)
+ bool hasFilter = !string.IsNullOrEmpty(filter);
+ HashSet urns = null;
+ if (hasFilter)
{
- return new SmoCollectionWrapper(retValue);
+ string urn = $"{parentTable.Urn.ToString()}/ForeignKey" + filter;
+ Enumerator en = new Enumerator();
+ Request request = new Request(new Urn(urn));
+ ServerConnection serverConnection = new ServerConnection(context.Server.ConnectionContext.SqlConnectionObject);
+ EnumResult result = en.Process(serverConnection, request);
+ urns = GetUrns(result);
+ }
+ if (retValue != null)
+ {
+ if (hasFilter && urns != null)
+ {
+ return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn));
+ }
+ else
+ {
+ return new SmoCollectionWrapper(retValue);
+ }
}
}
return Enumerable.Empty();
@@ -437,13 +781,24 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
public override Type[] SupportedObjectTypes { get { return supportedTypes; } }
- public override IEnumerable Query(SmoQueryContext context)
+ public override IEnumerable Query(SmoQueryContext context, string filter)
{
Column parentColumn = context.Parent as Column;
if (parentColumn != null)
{
var retValue = parentColumn.DefaultConstraint;
- if(retValue != null)
+ bool hasFilter = !string.IsNullOrEmpty(filter);
+ HashSet urns = null;
+ if (hasFilter)
+ {
+ string urn = $"{parentColumn.Urn.ToString()}/DefaultConstraint" + filter;
+ Enumerator en = new Enumerator();
+ Request request = new Request(new Urn(urn));
+ ServerConnection serverConnection = new ServerConnection(context.Server.ConnectionContext.SqlConnectionObject);
+ EnumResult result = en.Process(serverConnection, request);
+ urns = GetUrns(result);
+ }
+ if (retValue != null)
{
return new SqlSmoObject[] { retValue };
}
@@ -459,15 +814,33 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
public override Type[] SupportedObjectTypes { get { return supportedTypes; } }
- public override IEnumerable Query(SmoQueryContext context)
+ public override IEnumerable Query(SmoQueryContext context, string filter)
{
Table parentTable = context.Parent as Table;
if (parentTable != null)
{
var retValue = parentTable.Triggers;
- if(retValue != null)
+ bool hasFilter = !string.IsNullOrEmpty(filter);
+ HashSet urns = null;
+ if (hasFilter)
{
- return new SmoCollectionWrapper(retValue);
+ string urn = $"{parentTable.Urn.ToString()}/Trigger" + filter;
+ Enumerator en = new Enumerator();
+ Request request = new Request(new Urn(urn));
+ ServerConnection serverConnection = new ServerConnection(context.Server.ConnectionContext.SqlConnectionObject);
+ EnumResult result = en.Process(serverConnection, request);
+ urns = GetUrns(result);
+ }
+ if (retValue != null)
+ {
+ if (hasFilter && urns != null)
+ {
+ return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn));
+ }
+ else
+ {
+ return new SmoCollectionWrapper(retValue);
+ }
}
}
return Enumerable.Empty();
@@ -481,13 +854,24 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
public override Type[] SupportedObjectTypes { get { return supportedTypes; } }
- public override IEnumerable Query(SmoQueryContext context)
+ public override IEnumerable Query(SmoQueryContext context, string filter)
{
Table parentTable = context.Parent as Table;
if (parentTable != null)
{
var retValue = parentTable.FullTextIndex;
- if(retValue != null)
+ bool hasFilter = !string.IsNullOrEmpty(filter);
+ HashSet urns = null;
+ if (hasFilter)
+ {
+ string urn = $"{parentTable.Urn.ToString()}/FullTextIndex" + filter;
+ Enumerator en = new Enumerator();
+ Request request = new Request(new Urn(urn));
+ ServerConnection serverConnection = new ServerConnection(context.Server.ConnectionContext.SqlConnectionObject);
+ EnumResult result = en.Process(serverConnection, request);
+ urns = GetUrns(result);
+ }
+ if (retValue != null)
{
return new SqlSmoObject[] { retValue };
}
@@ -503,15 +887,33 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
public override Type[] SupportedObjectTypes { get { return supportedTypes; } }
- public override IEnumerable Query(SmoQueryContext context)
+ public override IEnumerable Query(SmoQueryContext context, string filter)
{
TableViewBase parentTableViewBase = context.Parent as TableViewBase;
if (parentTableViewBase != null)
{
var retValue = parentTableViewBase.Statistics;
- if(retValue != null)
+ bool hasFilter = !string.IsNullOrEmpty(filter);
+ HashSet urns = null;
+ if (hasFilter)
{
- return new SmoCollectionWrapper(retValue);
+ string urn = $"{parentTableViewBase.Urn.ToString()}/Statistic" + filter;
+ Enumerator en = new Enumerator();
+ Request request = new Request(new Urn(urn));
+ ServerConnection serverConnection = new ServerConnection(context.Server.ConnectionContext.SqlConnectionObject);
+ EnumResult result = en.Process(serverConnection, request);
+ urns = GetUrns(result);
+ }
+ if (retValue != null)
+ {
+ if (hasFilter && urns != null)
+ {
+ return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn));
+ }
+ else
+ {
+ return new SmoCollectionWrapper(retValue);
+ }
}
}
return Enumerable.Empty();
@@ -525,15 +927,33 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
public override Type[] SupportedObjectTypes { get { return supportedTypes; } }
- public override IEnumerable Query(SmoQueryContext context)
+ public override IEnumerable Query(SmoQueryContext context, string filter)
{
Database parentDatabase = context.Parent as Database;
if (parentDatabase != null)
{
var retValue = parentDatabase.Triggers;
- if(retValue != null)
+ bool hasFilter = !string.IsNullOrEmpty(filter);
+ HashSet urns = null;
+ if (hasFilter)
{
- return new SmoCollectionWrapper(retValue);
+ string urn = $"{parentDatabase.Urn.ToString()}/Trigger" + filter;
+ Enumerator en = new Enumerator();
+ Request request = new Request(new Urn(urn));
+ ServerConnection serverConnection = new ServerConnection(context.Server.ConnectionContext.SqlConnectionObject);
+ EnumResult result = en.Process(serverConnection, request);
+ urns = GetUrns(result);
+ }
+ if (retValue != null)
+ {
+ if (hasFilter && urns != null)
+ {
+ return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn));
+ }
+ else
+ {
+ return new SmoCollectionWrapper(retValue);
+ }
}
}
return Enumerable.Empty();
@@ -547,15 +967,33 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
public override Type[] SupportedObjectTypes { get { return supportedTypes; } }
- public override IEnumerable Query(SmoQueryContext context)
+ public override IEnumerable Query(SmoQueryContext context, string filter)
{
Database parentDatabase = context.Parent as Database;
if (parentDatabase != null)
{
var retValue = parentDatabase.Assemblies;
- if(retValue != null)
+ bool hasFilter = !string.IsNullOrEmpty(filter);
+ HashSet urns = null;
+ if (hasFilter)
{
- return new SmoCollectionWrapper(retValue);
+ string urn = $"{parentDatabase.Urn.ToString()}/SqlAssembly" + filter;
+ Enumerator en = new Enumerator();
+ Request request = new Request(new Urn(urn));
+ ServerConnection serverConnection = new ServerConnection(context.Server.ConnectionContext.SqlConnectionObject);
+ EnumResult result = en.Process(serverConnection, request);
+ urns = GetUrns(result);
+ }
+ if (retValue != null)
+ {
+ if (hasFilter && urns != null)
+ {
+ return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn));
+ }
+ else
+ {
+ return new SmoCollectionWrapper(retValue);
+ }
}
}
return Enumerable.Empty();
@@ -569,15 +1007,33 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
public override Type[] SupportedObjectTypes { get { return supportedTypes; } }
- public override IEnumerable Query(SmoQueryContext context)
+ public override IEnumerable Query(SmoQueryContext context, string filter)
{
Database parentDatabase = context.Parent as Database;
if (parentDatabase != null)
{
var retValue = parentDatabase.Rules;
- if(retValue != null)
+ bool hasFilter = !string.IsNullOrEmpty(filter);
+ HashSet urns = null;
+ if (hasFilter)
{
- return new SmoCollectionWrapper(retValue);
+ string urn = $"{parentDatabase.Urn.ToString()}/Rule" + filter;
+ Enumerator en = new Enumerator();
+ Request request = new Request(new Urn(urn));
+ ServerConnection serverConnection = new ServerConnection(context.Server.ConnectionContext.SqlConnectionObject);
+ EnumResult result = en.Process(serverConnection, request);
+ urns = GetUrns(result);
+ }
+ if (retValue != null)
+ {
+ if (hasFilter && urns != null)
+ {
+ return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn));
+ }
+ else
+ {
+ return new SmoCollectionWrapper(retValue);
+ }
}
}
return Enumerable.Empty();
@@ -591,15 +1047,33 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
public override Type[] SupportedObjectTypes { get { return supportedTypes; } }
- public override IEnumerable Query(SmoQueryContext context)
+ public override IEnumerable Query(SmoQueryContext context, string filter)
{
Database parentDatabase = context.Parent as Database;
if (parentDatabase != null)
{
var retValue = parentDatabase.Defaults;
- if(retValue != null)
+ bool hasFilter = !string.IsNullOrEmpty(filter);
+ HashSet urns = null;
+ if (hasFilter)
{
- return new SmoCollectionWrapper(retValue);
+ string urn = $"{parentDatabase.Urn.ToString()}/Default" + filter;
+ Enumerator en = new Enumerator();
+ Request request = new Request(new Urn(urn));
+ ServerConnection serverConnection = new ServerConnection(context.Server.ConnectionContext.SqlConnectionObject);
+ EnumResult result = en.Process(serverConnection, request);
+ urns = GetUrns(result);
+ }
+ if (retValue != null)
+ {
+ if (hasFilter && urns != null)
+ {
+ return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn));
+ }
+ else
+ {
+ return new SmoCollectionWrapper(retValue);
+ }
}
}
return Enumerable.Empty();
@@ -613,15 +1087,33 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
public override Type[] SupportedObjectTypes { get { return supportedTypes; } }
- public override IEnumerable Query(SmoQueryContext context)
+ public override IEnumerable Query(SmoQueryContext context, string filter)
{
Database parentDatabase = context.Parent as Database;
if (parentDatabase != null)
{
var retValue = parentDatabase.Sequences;
- if(retValue != null)
+ bool hasFilter = !string.IsNullOrEmpty(filter);
+ HashSet urns = null;
+ if (hasFilter)
{
- return new SmoCollectionWrapper(retValue);
+ string urn = $"{parentDatabase.Urn.ToString()}/Sequence" + filter;
+ Enumerator en = new Enumerator();
+ Request request = new Request(new Urn(urn));
+ ServerConnection serverConnection = new ServerConnection(context.Server.ConnectionContext.SqlConnectionObject);
+ EnumResult result = en.Process(serverConnection, request);
+ urns = GetUrns(result);
+ }
+ if (retValue != null)
+ {
+ if (hasFilter && urns != null)
+ {
+ return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn));
+ }
+ else
+ {
+ return new SmoCollectionWrapper(retValue);
+ }
}
}
return Enumerable.Empty();
@@ -635,15 +1127,33 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
public override Type[] SupportedObjectTypes { get { return supportedTypes; } }
- public override IEnumerable Query(SmoQueryContext context)
+ public override IEnumerable Query(SmoQueryContext context, string filter)
{
Server parentServer = context.Parent as Server;
if (parentServer != null)
{
var retValue = parentServer.SystemDataTypes;
- if(retValue != null)
+ bool hasFilter = !string.IsNullOrEmpty(filter);
+ HashSet urns = null;
+ if (hasFilter)
{
- return new SmoCollectionWrapper(retValue);
+ string urn = $"{parentServer.Urn.ToString()}/SystemDataType" + filter;
+ Enumerator en = new Enumerator();
+ Request request = new Request(new Urn(urn));
+ ServerConnection serverConnection = new ServerConnection(context.Server.ConnectionContext.SqlConnectionObject);
+ EnumResult result = en.Process(serverConnection, request);
+ urns = GetUrns(result);
+ }
+ if (retValue != null)
+ {
+ if (hasFilter && urns != null)
+ {
+ return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn));
+ }
+ else
+ {
+ return new SmoCollectionWrapper(retValue);
+ }
}
}
return Enumerable.Empty();
@@ -657,15 +1167,33 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
public override Type[] SupportedObjectTypes { get { return supportedTypes; } }
- public override IEnumerable Query(SmoQueryContext context)
+ public override IEnumerable Query(SmoQueryContext context, string filter)
{
Database parentDatabase = context.Parent as Database;
if (parentDatabase != null)
{
var retValue = parentDatabase.UserDefinedDataTypes;
- if(retValue != null)
+ bool hasFilter = !string.IsNullOrEmpty(filter);
+ HashSet urns = null;
+ if (hasFilter)
{
- return new SmoCollectionWrapper(retValue);
+ string urn = $"{parentDatabase.Urn.ToString()}/UserDefinedDataType" + filter;
+ Enumerator en = new Enumerator();
+ Request request = new Request(new Urn(urn));
+ ServerConnection serverConnection = new ServerConnection(context.Server.ConnectionContext.SqlConnectionObject);
+ EnumResult result = en.Process(serverConnection, request);
+ urns = GetUrns(result);
+ }
+ if (retValue != null)
+ {
+ if (hasFilter && urns != null)
+ {
+ return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn));
+ }
+ else
+ {
+ return new SmoCollectionWrapper(retValue);
+ }
}
}
return Enumerable.Empty();
@@ -679,15 +1207,33 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
public override Type[] SupportedObjectTypes { get { return supportedTypes; } }
- public override IEnumerable Query(SmoQueryContext context)
+ public override IEnumerable Query(SmoQueryContext context, string filter)
{
Database parentDatabase = context.Parent as Database;
if (parentDatabase != null)
{
var retValue = parentDatabase.UserDefinedTableTypes;
- if(retValue != null)
+ bool hasFilter = !string.IsNullOrEmpty(filter);
+ HashSet urns = null;
+ if (hasFilter)
{
- return new SmoCollectionWrapper(retValue);
+ string urn = $"{parentDatabase.Urn.ToString()}/UserDefinedTableType" + filter;
+ Enumerator en = new Enumerator();
+ Request request = new Request(new Urn(urn));
+ ServerConnection serverConnection = new ServerConnection(context.Server.ConnectionContext.SqlConnectionObject);
+ EnumResult result = en.Process(serverConnection, request);
+ urns = GetUrns(result);
+ }
+ if (retValue != null)
+ {
+ if (hasFilter && urns != null)
+ {
+ return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn));
+ }
+ else
+ {
+ return new SmoCollectionWrapper(retValue);
+ }
}
}
return Enumerable.Empty();
@@ -701,15 +1247,33 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
public override Type[] SupportedObjectTypes { get { return supportedTypes; } }
- public override IEnumerable Query(SmoQueryContext context)
+ public override IEnumerable Query(SmoQueryContext context, string filter)
{
Database parentDatabase = context.Parent as Database;
if (parentDatabase != null)
{
var retValue = parentDatabase.XmlSchemaCollections;
- if(retValue != null)
+ bool hasFilter = !string.IsNullOrEmpty(filter);
+ HashSet urns = null;
+ if (hasFilter)
{
- return new SmoCollectionWrapper(retValue);
+ string urn = $"{parentDatabase.Urn.ToString()}/XmlSchemaCollection" + filter;
+ Enumerator en = new Enumerator();
+ Request request = new Request(new Urn(urn));
+ ServerConnection serverConnection = new ServerConnection(context.Server.ConnectionContext.SqlConnectionObject);
+ EnumResult result = en.Process(serverConnection, request);
+ urns = GetUrns(result);
+ }
+ if (retValue != null)
+ {
+ if (hasFilter && urns != null)
+ {
+ return new SmoCollectionWrapper(retValue).Where(c => urns.Contains(c.Urn));
+ }
+ else
+ {
+ return new SmoCollectionWrapper(retValue);
+ }
}
}
return Enumerable.Empty();
@@ -723,15 +1287,33 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
public override Type[] SupportedObjectTypes { get { return supportedTypes; } }
- public override IEnumerable Query(SmoQueryContext context)
+ public override IEnumerable Query(SmoQueryContext context, string filter)
{
Database parentDatabase = context.Parent as Database;
if (parentDatabase != null)
{
var retValue = parentDatabase.UserDefinedTypes;
- if(retValue != null)
+ bool hasFilter = !string.IsNullOrEmpty(filter);
+ HashSet urns = null;
+ if (hasFilter)
{
- return new SmoCollectionWrapper