diff --git a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/Nodes/ChildFactory.cs b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/Nodes/ChildFactory.cs
index 8b26cefa..bff8cd9c 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/Nodes/ChildFactory.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/Nodes/ChildFactory.cs
@@ -26,9 +26,11 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
///
/// Expands an element in the
///
- ///
+ /// Parent Node
+ /// force to refresh
+ /// name of the sql object to filter
///
- public abstract IEnumerable Expand(TreeNode parent, bool refresh);
+ public abstract IEnumerable Expand(TreeNode parent, bool refresh, string name, bool includeSystemObjects);
///
/// The list of filters that should be applied on the smo object list
diff --git a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/Nodes/NodeFilter.cs b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/Nodes/NodeFilter.cs
index cfaea0c3..255e60b2 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/Nodes/NodeFilter.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/Nodes/NodeFilter.cs
@@ -69,13 +69,18 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
for (int i = 0; i < values.Count; i++)
{
var value = values[i];
- object proeprtyValue = value;
+ object propertyValue = value;
+ if (Type == typeof(string))
+ {
+ propertyValue = $"'{propertyValue}'";
+ }
if (Type == typeof(Enum))
{
- proeprtyValue = (int)Convert.ChangeType(value, Type);
+ propertyValue = (int)Convert.ChangeType(value, Type);
+
}
string orPrefix = i == 0 ? string.Empty : "or";
- filter = $"{filter} {orPrefix} @{Property} = {proeprtyValue}";
+ filter = $"{filter} {orPrefix} @{Property} = {propertyValue}";
}
}
filter = $"({filter})";
diff --git a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/Nodes/NodeTypes.cs b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/Nodes/NodeTypes.cs
index 2f089dd7..6ce03318 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/Nodes/NodeTypes.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/Nodes/NodeTypes.cs
@@ -44,6 +44,9 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
ServerLevelServerTriggers,
ServerLevelLinkedServers,
ServerLevelEndpoints,
+ SystemScalarValuedFunctions,
+ SystemTableValuedFunctions,
+ SystemFunctions,
DacInstancesFolder,
Tables,
Views,
diff --git a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/Nodes/TreeNode.cs b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/Nodes/TreeNode.cs
index df4f172a..b00cde92 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/Nodes/TreeNode.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/Nodes/TreeNode.cs
@@ -62,6 +62,11 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
///
public string NodeType { get; set; }
+ ///
+ // True if the node includes system object
+ ///
+ public bool IsSystemObject { get; set; }
+
///
/// Enum defining the type of the node - for example Server, Database, Folder, Table
///
@@ -196,17 +201,26 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
/// Expands this node and returns its children
///
/// Children as an IList. This is the raw children collection, not a copy
- public IList Expand()
+ public IList Expand(string name= null)
{
// TODO consider why solution explorer has separate Children and Items options
if (children.IsInitialized)
{
return children;
}
- PopulateChildren(false);
+ PopulateChildren(false, name);
return children;
}
+ ///
+ /// Expands this node and returns its children
+ ///
+ /// Children as an IList. This is the raw children collection, not a copy
+ public IList Expand()
+ {
+ return Expand(null);
+ }
+
///
/// Refresh this node and returns its children
///
@@ -214,7 +228,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
public virtual IList Refresh()
{
// TODO consider why solution explorer has separate Children and Items options
- PopulateChildren(true);
+ PopulateChildren(true, null);
return children;
}
@@ -266,13 +280,16 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
return Parent as T;
}
- protected void PopulateChildren(bool refresh)
+ protected void PopulateChildren(bool refresh, string name = null)
{
+ Logger.Write(LogLevel.Verbose, string.Format(CultureInfo.InvariantCulture, "Populating oe node :{0}", this.GetNodePath()));
Debug.Assert(IsAlwaysLeaf == false);
SmoQueryContext context = this.GetContextAs();
+ bool includeSystemObjects = context != null && context.Database != null ? ObjectExplorerUtils.IsSystemDatabaseConnection(context.Database.Name) : true;
+
- if (children.IsPopulating || context == null)
+ if (children.IsPopulating || context == null)
return;
children.Clear();
@@ -285,7 +302,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
{
foreach (var factory in childFactories)
{
- IEnumerable items = factory.Expand(this, refresh);
+ IEnumerable items = factory.Expand(this, refresh, name, includeSystemObjects);
if (items != null)
{
foreach (TreeNode item in items)
@@ -300,7 +317,9 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
}
catch(Exception ex)
{
- Logger.Write(LogLevel.Error, $"Failed populating oe children. error:{ex.Message} {ex.StackTrace}");
+ string error = string.Format(CultureInfo.InvariantCulture, "Failed populating oe children. error:{0} inner:{1} stacktrace:{2}",
+ ex.Message, ex.InnerException != null ? ex.InnerException.Message : "", ex.StackTrace);
+ Logger.Write(LogLevel.Error, error);
}
finally
{
diff --git a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/ObjectExplorerService.cs b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/ObjectExplorerService.cs
index 2c3755ee..7497add6 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/ObjectExplorerService.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/ObjectExplorerService.cs
@@ -437,7 +437,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
this.serviceProvider = serviceProvider;
this.connectionService = connectionService;
}
-
+
public string Uri { get; private set; }
public TreeNode Root { get; private set; }
@@ -450,7 +450,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
// Assuming the databases are in a folder under server node
var children = rootNode.Expand();
var databasesRoot = children.FirstOrDefault(x => x.NodeTypeId == NodeTypes.Databases);
- var databasesChildren = databasesRoot.Expand();
+ var databasesChildren = databasesRoot.Expand(response.ConnectionSummary.DatabaseName);
var databases = databasesChildren.Where(x => x.NodeType == NodeTypes.Database.ToString());
var databaseNode = databases.FirstOrDefault(d => d.Label == response.ConnectionSummary.DatabaseName);
databaseNode.Label = rootNode.Label;
diff --git a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoChildFactoryBase.cs b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoChildFactoryBase.cs
index d2b460f9..d22c5720 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoChildFactoryBase.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoChildFactoryBase.cs
@@ -6,6 +6,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
+using System.Globalization;
using System.Linq;
using System.Reflection;
using Microsoft.SqlServer.Management.Smo;
@@ -21,20 +22,26 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
return null;
}
- public override IEnumerable Expand(TreeNode parent, bool refresh)
+ public override IEnumerable Expand(TreeNode parent, bool refresh, string name, bool includeSystemObjects)
{
List allChildren = new List();
try
{
OnExpandPopulateFolders(allChildren, parent);
+ if(!includeSystemObjects)
+ {
+ allChildren.RemoveAll(x => x.IsSystemObject);
+ }
RemoveFoldersFromInvalidSqlServerVersions(allChildren, parent);
- OnExpandPopulateNonFolders(allChildren, parent, refresh);
+ OnExpandPopulateNonFolders(allChildren, parent, refresh, name);
OnBeginAsyncOperations(parent);
}
catch(Exception ex)
{
- Logger.Write(LogLevel.Error, $"Failed expanding oe children. error:{ex.Message} {ex.StackTrace}");
+ string error = string.Format(CultureInfo.InvariantCulture, "Failed expanding oe children. parent:{0} error:{1} inner:{2} stacktrace:{3}",
+ parent != null ? parent.GetNodePath() : "", ex.Message, ex.InnerException != null ? ex.InnerException.Message : "", ex.StackTrace);
+ Logger.Write(LogLevel.Error, error);
}
finally
{
@@ -56,8 +63,10 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
///
/// List to which nodes should be added
/// Parent the nodes are being added to
- protected virtual void OnExpandPopulateNonFolders(IList allChildren, TreeNode parent, bool refresh)
+ protected virtual void OnExpandPopulateNonFolders(IList allChildren, TreeNode parent, bool refresh, string name)
{
+ Logger.Write(LogLevel.Verbose, string.Format(CultureInfo.InvariantCulture, "child factory parent :{0}", parent.GetNodePath()));
+
if (ChildQuerierTypes == null)
{
// This node does not support non-folder children
@@ -73,22 +82,40 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
}
IEnumerable queriers = context.ServiceProvider.GetServices(q => IsCompatibleQuerier(q));
- var filters = this.Filters;
+ var filters = this.Filters.ToList();
+ if (!string.IsNullOrEmpty(name))
+ {
+ filters.Add(new NodeFilter
+ {
+ Property = "Name",
+ Type = typeof(string),
+ Values = new List