mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
using the new smo method to initialize the smo collections (#367)
* using the new smo method to initialize the smo collections
This commit is contained in:
BIN
bin/nuget/Microsoft.SqlServer.Smo.140.17054.0.nupkg
Normal file
BIN
bin/nuget/Microsoft.SqlServer.Smo.140.17054.0.nupkg
Normal file
Binary file not shown.
@@ -77,90 +77,9 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
|
|||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected HashSet<string> GetUrns(SmoQueryContext context, SqlSmoObject smoObject, string filter, string objectName)
|
|
||||||
{
|
|
||||||
HashSet<string> urns = null;
|
|
||||||
string urn = string.Empty;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
string parentUrn = smoObject.Urn != null ? smoObject.Urn.Value : string.Empty;
|
|
||||||
urn = parentUrn != null ? $"{parentUrn.ToString()}/{objectName}" + filter : string.Empty;
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(urn))
|
|
||||||
{
|
|
||||||
Enumerator en = new Enumerator();
|
|
||||||
Request request = new Request(new Urn(urn));
|
|
||||||
ServerConnection serverConnection = new ServerConnection(context.Server.ConnectionContext.SqlConnectionObject);
|
|
||||||
if (!serverConnection.IsOpen)
|
|
||||||
{
|
|
||||||
serverConnection.Connect();
|
|
||||||
}
|
|
||||||
EnumResult result = en.Process(serverConnection, request);
|
|
||||||
|
|
||||||
urns = GetUrns(result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
string error = string.Format(CultureInfo.InvariantCulture, "Failed getting urns. error:{0} inner:{1} stacktrace:{2}",
|
|
||||||
ex.Message, ex.InnerException != null ? ex.InnerException.Message : "", ex.StackTrace);
|
|
||||||
Logger.Write(LogLevel.Error, error);
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
|
|
||||||
return urns;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the urn from the enumResult
|
|
||||||
/// </summary>
|
|
||||||
protected HashSet<string> GetUrns(EnumResult enumResult)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
HashSet<string> urns = null;
|
|
||||||
if (enumResult != null && enumResult.Data != null)
|
|
||||||
{
|
|
||||||
urns = new HashSet<string>();
|
|
||||||
using (IDataReader reader = GetDataReader(enumResult.Data))
|
|
||||||
{
|
|
||||||
if (reader != null)
|
|
||||||
{
|
|
||||||
while (reader.Read())
|
|
||||||
{
|
|
||||||
urns.Add(reader.GetString(0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return urns;
|
|
||||||
}
|
|
||||||
catch(Exception ex)
|
|
||||||
{
|
|
||||||
string error = string.Format(CultureInfo.InvariantCulture, "Failed getting urns. error:{0} inner:{1} stacktrace:{2}",
|
|
||||||
ex.Message, ex.InnerException != null ? ex.InnerException.Message : "", ex.StackTrace);
|
|
||||||
Logger.Write(LogLevel.Error, error);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected IEnumerable<T> GetSmoCollectionResult<T>(HashSet<string> urns, SmoCollectionBase retValue, SqlSmoObject parent) where T : SqlSmoObject
|
|
||||||
{
|
|
||||||
// the below code is filtering out tables on helsinki system
|
|
||||||
return new SmoCollectionWrapper<T>(retValue);
|
|
||||||
|
|
||||||
// if (urns != null)
|
|
||||||
// {
|
|
||||||
// return new SmoCollectionWrapper<T>(retValue).Where(c => PassesFinalFilters(parent, c) && urns.Contains(c.Urn));
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// return new SmoCollectionWrapper<T>(retValue).Where(c => PassesFinalFilters(parent, c));
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -33,6 +33,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
|
|||||||
{
|
{
|
||||||
XmlElement nodeElement = GetNodeElement(xmlFile, nodeName);
|
XmlElement nodeElement = GetNodeElement(xmlFile, nodeName);
|
||||||
IList<string> parents = GetParents(nodeElement, xmlFile, nodeName);
|
IList<string> parents = GetParents(nodeElement, xmlFile, nodeName);
|
||||||
|
string properties = GetProperties(nodeElement, xmlFile, nodeName);
|
||||||
string nodeType = GetNodeType(nodeElement, nodeName);
|
string nodeType = GetNodeType(nodeElement, nodeName);
|
||||||
|
|
||||||
string queryBaseClass = "SmoQuerier";
|
string queryBaseClass = "SmoQuerier";
|
||||||
@@ -62,15 +63,9 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
|
|||||||
WriteLine(string.Format("if ({0} != null)", parentVar));
|
WriteLine(string.Format("if ({0} != null)", parentVar));
|
||||||
WriteLine("{");
|
WriteLine("{");
|
||||||
PushIndent(indent);
|
PushIndent(indent);
|
||||||
WriteLine("bool hasFilter = !string.IsNullOrEmpty(filter);");
|
|
||||||
|
|
||||||
string navigationPath = GetNavigationPath(nodeElement, xmlFile, nodeName, parentType);
|
string navigationPath = GetNavigationPath(nodeElement, xmlFile, nodeName, parentType);
|
||||||
WriteLine("if (refresh)");
|
|
||||||
WriteLine("{");
|
|
||||||
PushIndent(indent);
|
|
||||||
WriteLine(string.Format("{0}.{1}.Refresh({2});", parentVar, navigationPath, IsCollection(nodeElement) ? "true" : ""));
|
|
||||||
PopIndent();
|
|
||||||
WriteLine("}");
|
|
||||||
|
|
||||||
WriteLine(string.Format("var retValue = {0}.{1};", parentVar, navigationPath));
|
WriteLine(string.Format("var retValue = {0}.{1};", parentVar, navigationPath));
|
||||||
WriteLine("if (retValue != null)");
|
WriteLine("if (retValue != null)");
|
||||||
@@ -80,27 +75,17 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
|
|||||||
|
|
||||||
if (IsCollection(nodeElement))
|
if (IsCollection(nodeElement))
|
||||||
{
|
{
|
||||||
string fieldForUrn = GetNavPathFieldForUrn(xmlFile, nodeName, parentType);
|
WriteLine(string.Format("retValue.InitializeCollection(filter, new string[] {{ {0} }});", properties));
|
||||||
if (!string.IsNullOrEmpty(fieldForUrn))
|
WriteLine(string.Format("return new SmoCollectionWrapper<{0}>(retValue).Where(c => PassesFinalFilters({1}, c));", nodeType, parentVar));
|
||||||
{
|
|
||||||
fieldForUrn = string.Format("{0}.{1}", parentVar, fieldForUrn);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fieldForUrn = parentVar;
|
|
||||||
}
|
|
||||||
WriteLine("HashSet<string> urns = null;");
|
|
||||||
|
|
||||||
WriteLine("if (hasFilter)");
|
|
||||||
WriteLine("{");
|
|
||||||
PushIndent(indent);
|
|
||||||
WriteLine(string.Format("urns = GetUrns(context, {0}, filter, \"{1}\");", fieldForUrn, nodeType));
|
|
||||||
PopIndent();
|
|
||||||
WriteLine("}");
|
|
||||||
WriteLine(string.Format("return GetSmoCollectionResult<{0}>(urns, retValue, {1});", nodeType, parentVar));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
WriteLine("if (refresh)");
|
||||||
|
WriteLine("{");
|
||||||
|
PushIndent(indent);
|
||||||
|
WriteLine(string.Format("{0}.{1}.Refresh();", parentVar, navigationPath));
|
||||||
|
PopIndent();
|
||||||
|
WriteLine("}");
|
||||||
WriteLine("return new SqlSmoObject[] { retValue };");
|
WriteLine("return new SqlSmoObject[] { retValue };");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,6 +213,22 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
|
|||||||
// default to assuming a type is under Database
|
// default to assuming a type is under Database
|
||||||
return new string[] { "Database" };
|
return new string[] { "Database" };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string GetProperties(XmlElement nodeElement, string xmlFile, string parentName)
|
||||||
|
{
|
||||||
|
var propertiesAttr = nodeElement.GetAttribute("Properties");
|
||||||
|
string result = string.Empty;
|
||||||
|
if (!string.IsNullOrEmpty(propertiesAttr))
|
||||||
|
{
|
||||||
|
var properties = propertiesAttr.Split(';');
|
||||||
|
foreach (var item in properties)
|
||||||
|
{
|
||||||
|
result = result + (string.IsNullOrEmpty(result) ? "" : ",") + "\"" + item + "\"";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public static List<XmlElement> GetChildren(string xmlFile, string parentName, string childNode)
|
public static List<XmlElement> GetChildren(string xmlFile, string parentName, string childNode)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
|
|
||||||
<Node Name="SqlErrorMessage" Type="UserDefinedMessage" Parent="Server" />
|
<Node Name="SqlErrorMessage" Type="UserDefinedMessage" Parent="Server" />
|
||||||
|
|
||||||
<Node Name="SqlTable" Parent="Database" />
|
<Node Name="SqlTable" Parent="Database" Properties="IsSystemVersioned" />
|
||||||
<Node Name="SqlHistoryTable" Type="Table" Parent="Table" >
|
<Node Name="SqlHistoryTable" Type="Table" Parent="Table" >
|
||||||
<NavigationPath Parent="Table" Type="Table" Field="Parent.Tables" FieldForUrn="Parent" />
|
<NavigationPath Parent="Table" Type="Table" Field="Parent.Tables" FieldForUrn="Parent" />
|
||||||
</Node>
|
</Node>
|
||||||
|
|||||||
@@ -14,13 +14,11 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
|
|||||||
{
|
{
|
||||||
public override string GetNodeCustomName(object smoObject, SmoQueryContext smoContext)
|
public override string GetNodeCustomName(object smoObject, SmoQueryContext smoContext)
|
||||||
{
|
{
|
||||||
// TODO: this code makes expanding the tables slow because of loading the IsSystemVersioned property for each table.
|
Table table = smoObject as Table;
|
||||||
// Have to uncomment this after optimizing the way properties are loaded for SMO objects
|
if (table != null && table.IsSystemVersioned)
|
||||||
//Table table = smoObject as Table;
|
{
|
||||||
//if (table != null && table.IsSystemVersioned)
|
return $"{table.Schema}.{table.Name} ({SR.SystemVersioned_LabelPart})";
|
||||||
//{
|
}
|
||||||
// return $"{table.Schema}.{table.Name} ({SR.SystemVersioned_LabelPart})";
|
|
||||||
//}
|
|
||||||
|
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
"Newtonsoft.Json": "9.0.1",
|
"Newtonsoft.Json": "9.0.1",
|
||||||
"System.Data.Common": "4.1.0",
|
"System.Data.Common": "4.1.0",
|
||||||
"System.Data.SqlClient": "4.4.0-sqltools-24613-04",
|
"System.Data.SqlClient": "4.4.0-sqltools-24613-04",
|
||||||
"Microsoft.SqlServer.Smo": "140.17053.0",
|
"Microsoft.SqlServer.Smo": "140.17054.0",
|
||||||
"Microsoft.SqlServer.Management.SqlScriptPublishModel": "140.17049.0",
|
"Microsoft.SqlServer.Management.SqlScriptPublishModel": "140.17049.0",
|
||||||
"System.Security.SecureString": "4.0.0",
|
"System.Security.SecureString": "4.0.0",
|
||||||
"System.Collections.Specialized": "4.0.1",
|
"System.Collections.Specialized": "4.0.1",
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
"System.Runtime.Serialization.Primitives": "4.1.1",
|
"System.Runtime.Serialization.Primitives": "4.1.1",
|
||||||
"System.Data.Common": "4.1.0",
|
"System.Data.Common": "4.1.0",
|
||||||
"System.Data.SqlClient": "4.4.0-sqltools-24613-04",
|
"System.Data.SqlClient": "4.4.0-sqltools-24613-04",
|
||||||
"Microsoft.SqlServer.Smo": "140.17053.0",
|
"Microsoft.SqlServer.Smo": "140.17054.0",
|
||||||
"System.Security.SecureString": "4.0.0",
|
"System.Security.SecureString": "4.0.0",
|
||||||
"System.Collections.Specialized": "4.0.1",
|
"System.Collections.Specialized": "4.0.1",
|
||||||
"System.ComponentModel.TypeConverter": "4.1.0",
|
"System.ComponentModel.TypeConverter": "4.1.0",
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ NodeType: Constraint Label: CK_Employee_VacationHours SubType: Status:
|
|||||||
NodeType: Index Label: NonClusteredIndex-Login (Non-Unique, Non-Clustered) SubType: Status:
|
NodeType: Index Label: NonClusteredIndex-Login (Non-Unique, Non-Clustered) SubType: Status:
|
||||||
NodeType: Statistic Label: NonClusteredIndex-Login SubType: Status:
|
NodeType: Statistic Label: NonClusteredIndex-Login SubType: Status:
|
||||||
NodeType: Statistic Label: PK_Employee_BusinessEntityID SubType: Status:
|
NodeType: Statistic Label: PK_Employee_BusinessEntityID SubType: Status:
|
||||||
NodeType: Table Label: HumanResources.Employee_Temporal SubType: Status:
|
NodeType: Table Label: HumanResources.Employee_Temporal (System-Versioned) SubType: Status:
|
||||||
NodeType: Column Label: BusinessEntityID (PK, int, not null) SubType: Status:
|
NodeType: Column Label: BusinessEntityID (PK, int, not null) SubType: Status:
|
||||||
NodeType: Column Label: NationalIDNumber (nvarchar(15), not null) SubType: Status:
|
NodeType: Column Label: NationalIDNumber (nvarchar(15), not null) SubType: Status:
|
||||||
NodeType: Column Label: LoginID (nvarchar(256), not null) SubType: Status:
|
NodeType: Column Label: LoginID (nvarchar(256), not null) SubType: Status:
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
"System.Runtime.Serialization.Primitives": "4.1.1",
|
"System.Runtime.Serialization.Primitives": "4.1.1",
|
||||||
"System.Data.Common": "4.1.0",
|
"System.Data.Common": "4.1.0",
|
||||||
"System.Data.SqlClient": "4.4.0-sqltools-24613-04",
|
"System.Data.SqlClient": "4.4.0-sqltools-24613-04",
|
||||||
"Microsoft.SqlServer.Smo": "140.17053.0",
|
"Microsoft.SqlServer.Smo": "140.17054.0",
|
||||||
"System.Security.SecureString": "4.0.0",
|
"System.Security.SecureString": "4.0.0",
|
||||||
"System.Collections.Specialized": "4.0.1",
|
"System.Collections.Specialized": "4.0.1",
|
||||||
"System.ComponentModel.TypeConverter": "4.1.0",
|
"System.ComponentModel.TypeConverter": "4.1.0",
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
"System.Runtime.Serialization.Primitives": "4.1.1",
|
"System.Runtime.Serialization.Primitives": "4.1.1",
|
||||||
"System.Data.Common": "4.1.0",
|
"System.Data.Common": "4.1.0",
|
||||||
"System.Data.SqlClient": "4.4.0-sqltools-24613-04",
|
"System.Data.SqlClient": "4.4.0-sqltools-24613-04",
|
||||||
"Microsoft.SqlServer.Smo": "140.17053.0",
|
"Microsoft.SqlServer.Smo": "140.17054.0",
|
||||||
"System.Security.SecureString": "4.0.0",
|
"System.Security.SecureString": "4.0.0",
|
||||||
"System.Collections.Specialized": "4.0.1",
|
"System.Collections.Specialized": "4.0.1",
|
||||||
"System.ComponentModel.TypeConverter": "4.1.0",
|
"System.ComponentModel.TypeConverter": "4.1.0",
|
||||||
|
|||||||
Reference in New Issue
Block a user