mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-16 01:25:41 -05:00
Adding schema based object folders in OE (#1849)
* Making node types automated * Adding schema based OE * added folder types in NodeTypes * Fixing stuff * Moving schema to parent and cleaning up some code * Replacing strings with nameof * Sorting nodetypes generated by tt * Adding option to put folders after nodes * Fixing folder and children order * Fixing tests * Formatting file * Formatting tt files * Fixing tt * fixing types * Update src/Microsoft.SqlTools.ServiceLayer/SqlContext/ObjectExplorerSettings.cs Co-authored-by: Charles Gagnon <chgagnon@microsoft.com> * Fixing stuff * Updating schema definitions and adding more logs * Fixing copyright * Adding Integration and Unit Tests * Fixing test --------- Co-authored-by: Charles Gagnon <chgagnon@microsoft.com>
This commit is contained in:
@@ -71,5 +71,11 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
|
||||
// TODO Consider whether Remove operations need to be supported
|
||||
//public abstract bool CanRemoveChild(TreeNode parent, object context);
|
||||
//public abstract int GetChildIndexToRemove(TreeNode parent, object context);
|
||||
|
||||
/// <summary>
|
||||
/// A flag that puts child folders after nodes when the node is expanded.
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public virtual bool PutFoldersAfterNodes => false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,9 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
//using System.Linq;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
|
||||
@@ -44,7 +42,8 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
|
||||
{
|
||||
string andPrefix = filter.Length == 0 ? string.Empty : " and ";
|
||||
var filterString = value.ToPropertyFilterString(type, validForFlag);
|
||||
if (filterString != string.Empty) {
|
||||
if (filterString != string.Empty)
|
||||
{
|
||||
filter.Append($"{andPrefix}{filterString}");
|
||||
}
|
||||
}
|
||||
@@ -55,5 +54,25 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Appends a list of property filters to an URN query string
|
||||
/// </summary>
|
||||
public static string AddPropertyFilterToFilterString(string filterString, IEnumerable<INodeFilter> filters, Type type, ValidForFlag validForFlag)
|
||||
{
|
||||
if (string.IsNullOrEmpty(filterString))
|
||||
{
|
||||
return GetPropertyFilter(filters, type, validForFlag);
|
||||
}
|
||||
foreach (var value in filters ?? Enumerable.Empty<INodeFilter>())
|
||||
{
|
||||
var filter = value.ToPropertyFilterString(type, validForFlag);
|
||||
if (filter != string.Empty)
|
||||
{
|
||||
filterString = filterString.Remove(filterString.Length - 1, 1) + $" and {filter}" + "]";
|
||||
}
|
||||
}
|
||||
return filterString;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,147 +1,142 @@
|
||||
//
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
// This file was generated by a T4 Template. Do not modify directly, instead update the SmoTreeNodesDefinition.xml file
|
||||
// and re-run the T4 template. This can be done in Visual Studio by right-click in and choosing "Run Custom Tool",
|
||||
// or from the command-line on any platform by running "build.cmd -Target=CodeGen" or "build.sh -Target=CodeGen"
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
|
||||
{
|
||||
/// <summary>
|
||||
/// Enum listing possible node types in the object explorer tree
|
||||
/// </summary>
|
||||
// TODO Consider replacing this with an auto-gen'd version
|
||||
public enum NodeTypes
|
||||
{
|
||||
None,
|
||||
SqlServersRoot,
|
||||
Database,
|
||||
Server,
|
||||
ScalarValuedFunction,
|
||||
TableValuedFunction,
|
||||
AggregateFunction,
|
||||
FileGroup,
|
||||
StoredProcedure,
|
||||
UserDefinedTableType,
|
||||
View,
|
||||
Table,
|
||||
HistoryTable,
|
||||
Folder,
|
||||
Databases,
|
||||
ExternalResources,
|
||||
ServerLevelSecurity,
|
||||
ServerLevelServerObjects,
|
||||
ServerLevelManagement,
|
||||
SystemDatabases,
|
||||
ServerLevelLinkedServerLogins,
|
||||
ServerLevelServerAudits,
|
||||
ServerLevelCryptographicProviders,
|
||||
ServerLevelCredentials,
|
||||
ServerLevelServerRoles,
|
||||
ServerLevelLogins,
|
||||
ServerLevelEventSessions,
|
||||
ServerLevelServerAuditSpecifications,
|
||||
ServerLevelEventNotifications,
|
||||
ServerLevelErrorMessages,
|
||||
ServerLevelServerTriggers,
|
||||
ServerLevelLinkedServers,
|
||||
ServerLevelEndpoints,
|
||||
SystemScalarValuedFunctions,
|
||||
SystemTableValuedFunctions,
|
||||
SystemFunctions,
|
||||
DacInstancesFolder,
|
||||
Tables,
|
||||
Views,
|
||||
Synonyms,
|
||||
Programmability,
|
||||
ServiceBroker,
|
||||
Storage,
|
||||
Security,
|
||||
SystemTables,
|
||||
FileTables,
|
||||
SystemViews,
|
||||
StoredProcedures,
|
||||
Functions,
|
||||
ExtendedStoredProcedures,
|
||||
DatabaseTriggers,
|
||||
Defaults,
|
||||
Rules,
|
||||
Types,
|
||||
Assemblies,
|
||||
MessageTypes,
|
||||
Contracts,
|
||||
Queues,
|
||||
Services,
|
||||
Routes,
|
||||
DatabaseAndQueueEventNotifications,
|
||||
RemoteServiceBindings,
|
||||
BrokerPriorities,
|
||||
FileGroups,
|
||||
FullTextCatalogs,
|
||||
FullTextStopLists,
|
||||
SqlLogFiles,
|
||||
PartitionFunctions,
|
||||
PartitionSchemes,
|
||||
SearchPropertyLists,
|
||||
Users,
|
||||
Roles,
|
||||
Schemas,
|
||||
AsymmetricKeys,
|
||||
Certificates,
|
||||
SymmetricKeys,
|
||||
DatabaseEncryptionKeys,
|
||||
MasterKeys,
|
||||
Signatures,
|
||||
DatabaseAuditSpecifications,
|
||||
Columns,
|
||||
Keys,
|
||||
Constraints,
|
||||
Triggers,
|
||||
Indexes,
|
||||
Statistics,
|
||||
TableValuedFunctions,
|
||||
ScalarValuedFunctions,
|
||||
AggregateFunctions,
|
||||
SystemDataTypes,
|
||||
UserDefinedDataTypes,
|
||||
UserDefinedTableTypes,
|
||||
UserDefinedTypes,
|
||||
XmlSchemaCollections,
|
||||
SystemExactNumerics,
|
||||
SystemApproximateNumerics,
|
||||
SystemDateAndTimes,
|
||||
SystemCharacterStrings,
|
||||
SystemUnicodeCharacterStrings,
|
||||
SystemBinaryStrings,
|
||||
SystemOtherDataTypes,
|
||||
SystemClrDataTypes,
|
||||
SystemSpatialDataTypes,
|
||||
UserDefinedTableTypeColumns,
|
||||
UserDefinedTableTypeKeys,
|
||||
UserDefinedTableTypeConstraints,
|
||||
SystemStoredProcedures,
|
||||
StoredProcedureParameters,
|
||||
TableValuedFunctionParameters,
|
||||
ScalarValuedFunctionParameters,
|
||||
AggregateFunctionParameters,
|
||||
DatabaseRoles,
|
||||
ApplicationRoles,
|
||||
FileGroupFiles,
|
||||
SystemMessageTypes,
|
||||
SystemContracts,
|
||||
SystemServices,
|
||||
SystemQueues,
|
||||
Sequences,
|
||||
SecurityPolicies,
|
||||
DatabaseScopedCredentials,
|
||||
ExternalTables,
|
||||
ExternalResource,
|
||||
ExternalDataSources,
|
||||
ExternalFileFormats,
|
||||
ExternalTable,
|
||||
AggregateFunctions,
|
||||
AlwaysEncryptedKeys,
|
||||
ColumnMasterKeys,
|
||||
ApplicationRoles,
|
||||
Assemblies,
|
||||
AsymmetricKeys,
|
||||
BrokerPriorities,
|
||||
Certificates,
|
||||
ColumnEncryptionKeys,
|
||||
ColumnMasterKeys,
|
||||
Columns,
|
||||
Constraints,
|
||||
Contracts,
|
||||
Database,
|
||||
DatabaseAndQueueEventNotifications,
|
||||
DatabaseAuditSpecifications,
|
||||
DatabaseEncryptionKeys,
|
||||
DatabaseRoles,
|
||||
Databases,
|
||||
DatabaseScopedCredentials,
|
||||
DatabaseTriggers,
|
||||
DroppedLedgerColumns,
|
||||
DroppedLedgerTables,
|
||||
DroppedLedgerViews,
|
||||
DroppedLedgerColumns,
|
||||
ExpandableSchema,
|
||||
ExpandableSchemaProgrammability,
|
||||
ExternalDataSources,
|
||||
ExternalFileFormats,
|
||||
ExternalResource,
|
||||
ExternalResources,
|
||||
ExternalTable,
|
||||
ExternalTables,
|
||||
FileGroup,
|
||||
FileGroupFiles,
|
||||
FileGroups,
|
||||
Folder,
|
||||
FullTextCatalogs,
|
||||
FullTextStopLists,
|
||||
Functions,
|
||||
HistoryTable,
|
||||
Indexes,
|
||||
Keys,
|
||||
MasterKeys,
|
||||
MessageTypes,
|
||||
PartitionFunctions,
|
||||
PartitionSchemes,
|
||||
Programmability,
|
||||
Queues,
|
||||
RemoteServiceBindings,
|
||||
Roles,
|
||||
ScalarValuedFunction,
|
||||
ScalarValuedFunctionParameters,
|
||||
ScalarValuedFunctions,
|
||||
Schemas,
|
||||
SearchPropertyLists,
|
||||
Security,
|
||||
SecurityPolicies,
|
||||
Sequences,
|
||||
Server,
|
||||
ServerLevelCredentials,
|
||||
ServerLevelCryptographicProviders,
|
||||
ServerLevelEndpoints,
|
||||
ServerLevelErrorMessages,
|
||||
ServerLevelLinkedServerLogins,
|
||||
ServerLevelLinkedServers,
|
||||
ServerLevelLogins,
|
||||
ServerLevelSecurity,
|
||||
ServerLevelServerAudits,
|
||||
ServerLevelServerAuditSpecifications,
|
||||
ServerLevelServerObjects,
|
||||
ServerLevelServerRoles,
|
||||
ServerLevelServerTriggers,
|
||||
ServiceBroker,
|
||||
Services,
|
||||
Signatures,
|
||||
SqlLogFiles,
|
||||
Statistics,
|
||||
Storage,
|
||||
StoredProcedure,
|
||||
StoredProcedureParameters,
|
||||
StoredProcedures,
|
||||
SymmetricKeys,
|
||||
Synonyms,
|
||||
SystemApproximateNumerics,
|
||||
SystemBinaryStrings,
|
||||
SystemCharacterStrings,
|
||||
SystemClrDataTypes,
|
||||
SystemContracts,
|
||||
SystemDatabases,
|
||||
SystemDataTypes,
|
||||
SystemDateAndTimes,
|
||||
SystemExactNumerics,
|
||||
SystemFunctions,
|
||||
SystemMessageTypes,
|
||||
SystemOtherDataTypes,
|
||||
SystemQueues,
|
||||
SystemScalarValuedFunctions,
|
||||
SystemServices,
|
||||
SystemSpatialDataTypes,
|
||||
SystemStoredProcedures,
|
||||
SystemTables,
|
||||
SystemTableValuedFunctions,
|
||||
SystemUnicodeCharacterStrings,
|
||||
SystemViews,
|
||||
Table,
|
||||
Tables,
|
||||
TableValuedFunction,
|
||||
TableValuedFunctionParameters,
|
||||
TableValuedFunctions,
|
||||
Triggers,
|
||||
Types,
|
||||
UserDefinedDataTypes,
|
||||
UserDefinedTableType,
|
||||
UserDefinedTableTypeColumns,
|
||||
UserDefinedTableTypeConstraints,
|
||||
UserDefinedTableTypeKeys,
|
||||
UserDefinedTableTypes,
|
||||
UserDefinedTypes,
|
||||
Users,
|
||||
View,
|
||||
Views,
|
||||
XmlSchemaCollections,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
<#@ template debug="false" hostspecific="true" language="C#" #>
|
||||
<#@ output extension=".cs" #>
|
||||
<#@ assembly name="System.Xml.dll" #>
|
||||
<#@ assembly name="System.Core.dll" #>
|
||||
<#@ import namespace="System" #>
|
||||
<#@ import namespace="System.Globalization" #>
|
||||
<#@ import namespace="System.Text" #>
|
||||
<#@ import namespace="System.Xml" #>
|
||||
<#@ import namespace="System.Collections.Generic" #>
|
||||
<#@ import namespace="System.IO" #>
|
||||
<#@ import namespace="System.Linq"#>
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
// This file was generated by a T4 Template. Do not modify directly, instead update the SmoTreeNodesDefinition.xml file
|
||||
// and re-run the T4 template. This can be done in Visual Studio by right-click in and choosing "Run Custom Tool",
|
||||
// or from the command-line on any platform by running "build.cmd -Target=CodeGen" or "build.sh -Target=CodeGen"
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
|
||||
{
|
||||
/// <summary>
|
||||
/// Enum listing possible node types in the object explorer tree
|
||||
/// </summary>
|
||||
public enum NodeTypes
|
||||
{
|
||||
<#
|
||||
var directory = Path.GetDirectoryName(Host.TemplateFile);
|
||||
|
||||
string xmlFile = Path.Combine(directory, "..\\SmoModel\\SmoTreeNodesDefinition.xml");
|
||||
|
||||
var allTreeNodes = GetUniqueNodeTypes(xmlFile);
|
||||
|
||||
foreach (var name in allTreeNodes)
|
||||
{
|
||||
WriteLine(" {0},", name);
|
||||
}
|
||||
|
||||
#>
|
||||
}
|
||||
}
|
||||
|
||||
<#+
|
||||
public static List<string> GetUniqueNodeTypes(string xmlFile)
|
||||
{
|
||||
XmlDocument doc = new XmlDocument();
|
||||
doc.Load(xmlFile);
|
||||
|
||||
|
||||
// Adding all node types
|
||||
HashSet<string> retElements = new HashSet<string>();
|
||||
XmlNodeList nodeList = doc.SelectNodes("/ServerExplorerTree/Node");
|
||||
foreach (XmlElement item in nodeList)
|
||||
{
|
||||
retElements.Add(item.GetAttribute("Name"));
|
||||
foreach (XmlElement child in GetChildren(xmlFile, item.GetAttribute("Name")))
|
||||
{
|
||||
retElements.Add(child.GetAttribute("Name"));
|
||||
}
|
||||
}
|
||||
|
||||
// Adding UniqueTreeNodes
|
||||
foreach(var name in GetUniqueTreeNodes(xmlFile))
|
||||
{
|
||||
retElements.Add(name);
|
||||
}
|
||||
|
||||
// Adding types that are not present anywhere. These types are referred in tests.
|
||||
retElements.Add("Folder");
|
||||
|
||||
var retList = retElements.ToList();
|
||||
retList.Sort();
|
||||
return retList;
|
||||
}
|
||||
|
||||
public static List<XmlElement> GetChildren(string xmlFile, string parentName)
|
||||
{
|
||||
XmlElement nodeElement = GetNodeElement(xmlFile, parentName);
|
||||
XmlDocument doc = new XmlDocument();
|
||||
doc.Load(xmlFile);
|
||||
|
||||
List<XmlElement> retElements = new List<XmlElement>();
|
||||
XmlNodeList nodeList = doc.SelectNodes(string.Format("/ServerExplorerTree/Node[@Name='{0}']/Child", parentName));
|
||||
foreach (var item in nodeList)
|
||||
{
|
||||
XmlElement itemAsElement = item as XmlElement;
|
||||
if (itemAsElement != null)
|
||||
{
|
||||
retElements.Add(itemAsElement);
|
||||
}
|
||||
}
|
||||
return retElements;
|
||||
}
|
||||
|
||||
public static XmlElement GetNodeElement(string xmlFile, string nodeName)
|
||||
{
|
||||
XmlDocument doc = new XmlDocument();
|
||||
doc.Load(xmlFile);
|
||||
return (XmlElement)doc.SelectSingleNode(string.Format("/ServerExplorerTree/Node[@Name='{0}']", nodeName));
|
||||
}
|
||||
|
||||
public static List<string> GetUniqueTreeNodes(string xmlFile)
|
||||
{
|
||||
XmlDocument doc = new XmlDocument();
|
||||
doc.Load(xmlFile);
|
||||
|
||||
List<string> retElements = new List<string>();
|
||||
XmlNodeList nodeList = doc.SelectNodes("/ServerExplorerTree/CodeGenOptions/UniqueTreeNode");
|
||||
foreach (XmlElement item in nodeList)
|
||||
{
|
||||
retElements.Add(item.GetAttribute("Name").Replace("TreeNode", string.Empty));
|
||||
|
||||
}
|
||||
return retElements;
|
||||
}
|
||||
#>
|
||||
Reference in New Issue
Block a user