mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-13 17:23:02 -05:00
TreeNodeGenerator -> SmoTreeNodes (#1579)
* TreeNodeGenerator -> SmoTreeNodes * space
This commit is contained in:
@@ -1,29 +1,35 @@
|
||||
# Object Explorer Service
|
||||
|
||||
> Object Explorer service provides functionality to retrieve the hierarchical objects in each instance of SQL Server. It handles requests to expand or refresh a node in the hierarchy.
|
||||
Object Explorer service provides functionality to retrieve the hierarchical objects in each instance of SQL Server. It handles requests to expand or refresh a node in the hierarchy.
|
||||
|
||||
> The service uses generated classes to create the objects hierarchy and there are two xml files used as sources to generated the classes.
|
||||
The service uses generated classes to create the objects hierarchy and there are two xml files used as sources to generated the classes.
|
||||
|
||||
## TreeNodeDefinition.xml
|
||||
> TreeNodeDefinition.xml defines all the hierarchies and all the supported objects types. It includes:
|
||||
## Key Files
|
||||
|
||||
### SmoTreeNodesDefinition.xml
|
||||
|
||||
SmoTreeNodesDefinition.xml defines all the hierarchies and all the supported objects types. It includes:
|
||||
|
||||
* The hierarchy of the SQL objects
|
||||
* The supported objects for each version of SQL Server.
|
||||
* How to filter objects based on the properties in each node
|
||||
* How to query each object (Reference to another generated code to query each object type)
|
||||
|
||||
## SmoQueryModelDefinition.xml
|
||||
> SmoQueryModelDefinition.xml defines the supported object types and how to query each type using SMO library. ChildQuerierTypes attribute in TreeNodeDefinition.xml nodes has reference to the types in this xml file. It includes:
|
||||
### SmoQueryModelDefinition.xml
|
||||
|
||||
SmoQueryModelDefinition.xml defines the supported object types and how to query each type using SMO library. ChildQuerierTypes attribute in SmoTreeNodesDefinition.xml nodes has reference to the types in this xml file. It includes:
|
||||
|
||||
* List of types that are defined in SMO library
|
||||
* Name of the parent and the field to query each type
|
||||
|
||||
## Query optimization
|
||||
To get each object type, SMO by default only gets the name and schema and not all it's properties.
|
||||
To optimize the query to get the properties needed to create each node, add the properties to the node element in TreeNodeDefinition.xml.
|
||||
For example, to get the table node, we also need to get two properties IsSystemVersioned and TemporalType which are included as properties in the table node:
|
||||
To get each object type, SMO by default only gets the name and schema and not all its properties.
|
||||
|
||||
## Sample
|
||||
To optimize the query to get the properties needed to create each node, add the properties to the node element in SmoTreeNodesDefinition.xml.
|
||||
|
||||
For example, to get the table node, we also need to get two properties IsSystemVersioned and TemporalType which are included as properties in the table node:
|
||||
|
||||
### Sample
|
||||
|
||||
```xml
|
||||
<Node Name="Tables" LocLabel="SR.SchemaHierarchy_Tables" BaseClass="ModelBased" Strategy="MultipleElementsOfType" ChildQuerierTypes="SqlTable" TreeNode="TableTreeNode">
|
||||
@@ -45,7 +51,7 @@
|
||||
## Guides
|
||||
### Add a new SQL object type
|
||||
|
||||
1. Add the type to TreeNodeDefinition.xml and SmoQueryModelDefinition.xml.
|
||||
1. Add the type to SmoTreeNodesDefinition.xml and SmoQueryModelDefinition.xml.
|
||||
2. Regenerate the classes by running `build.[cmd|sh] -target=CodeGen`
|
||||
|
||||
### Add new SQL Server Type/Version
|
||||
@@ -53,8 +59,8 @@
|
||||
1. Add friendly names for the type to the [SqlServerType enum](https://github.com/Microsoft/sqltoolsservice/blob/main/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SqlServerType.cs)
|
||||
2. Update [CalculateServerType](https://github.com/Microsoft/sqltoolsservice/blob/main/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SqlServerType.cs) method to support calculating the new server type
|
||||
3. Update [ValidForFlag](https://github.com/Microsoft/sqltoolsservice/blob/main/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/ValidForFlag.cs) with the new type, adding it to the flag unions as necessary.
|
||||
4. Update [TreeNodeDefinition.xml](https://github.com/Microsoft/sqltoolsservice/blob/main/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/TreeNodeDefinition.xml) - adding the new type to any ValidFor fields that are supported on the new type.
|
||||
5. Run `build.[cmd|sh] -target=CodeGen` to regenerate the class definition file (note that you may not see any changes, this is expected unless folder nodes are being updated)
|
||||
4. Update [SmoTreeNodesDefinition.xml](https://github.com/Microsoft/sqltoolsservice/blob/main/src/Microsoft.SqlTools.ServiceLayer/ObjectExplorer/SmoModel/SmoTreeNodesDefinition.xml) - adding the new type to any ValidFor fields that are supported on the new type.
|
||||
5. Run `build.[cmd|sh] -target=CodeGen` to regenerate the class definition file (note that you may not see any changes, this is expected unless folder nodes or property fields are being updated)
|
||||
6. Build and verify that your changes result in the expected nodes being shown when connected to a server of the new type
|
||||
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@
|
||||
<Content Include="..\..\Notice.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<EmbeddedResource Include="ObjectExplorer\SmoModel\TreeNodeDefinition.xml" />
|
||||
<EmbeddedResource Include="ObjectExplorer\SmoModel\SmoTreeNodesDefinition.xml" />
|
||||
<EmbeddedResource Include="Localization\*.resx" />
|
||||
<None Include="Localization\sr.strings" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
|
||||
}
|
||||
|
||||
var assembly = typeof(ObjectExplorerService).Assembly;
|
||||
var resource = assembly.GetManifestResourceStream("Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel.TreeNodeDefinition.xml");
|
||||
var resource = assembly.GetManifestResourceStream("Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel.SmoTreeNodesDefinition.xml");
|
||||
var serializer = new XmlSerializer(typeof(ServerExplorerTree));
|
||||
NodeTypeDictionary = new Dictionary<string, HashSet<Node>>();
|
||||
using (var reader = new StreamReader(resource))
|
||||
@@ -149,7 +149,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
|
||||
returnSet.Add(newPath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return returnSet;
|
||||
}
|
||||
}
|
||||
@@ -225,7 +225,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
var containedNode = TreeRoot.GetNode(containedType);
|
||||
if (containedNode == this)
|
||||
{
|
||||
@@ -241,7 +241,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
|
||||
{
|
||||
return SR.Keys.GetString(this.LocLabel.Remove(0, 3));
|
||||
}
|
||||
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
// 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".
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Composition;
|
||||
@@ -14,6 +14,10 @@
|
||||
// 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".
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Composition;
|
||||
@@ -25,7 +29,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
|
||||
|
||||
<#
|
||||
var directory = Path.GetDirectoryName(Host.TemplateFile);
|
||||
string xmlFile = Path.Combine(directory, "TreeNodeDefinition.xml");
|
||||
string xmlFile = Path.Combine(directory, "SmoTreeNodesDefinition.xml");
|
||||
|
||||
/////////
|
||||
// TODO - is Generate all the ReverseDependencies needed?
|
||||
@@ -353,6 +357,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
|
||||
|
||||
return string.Join("|", flags);
|
||||
}
|
||||
|
||||
public static string[] GetNodes(string xmlFile)
|
||||
{
|
||||
List<string> typesList = new List<string>();
|
||||
Reference in New Issue
Block a user