Supporting SQL DW in Object explorer (#380)

* supporting sql dw in oe
This commit is contained in:
Leila Lali
2017-06-15 12:53:32 -07:00
committed by GitHub
parent d9e68831ab
commit 71b349f67b
20 changed files with 544 additions and 152 deletions

View File

@@ -299,7 +299,16 @@ WHERE do.database_id = @DbID
ResourceManager manager = new ResourceManager("Microsoft.SqlTools.ServiceLayer.Localization.SR", typeof(DatabasePrototype).GetAssembly()); ResourceManager manager = new ResourceManager("Microsoft.SqlTools.ServiceLayer.Localization.SR", typeof(DatabasePrototype).GetAssembly());
this.owner = db.Owner; try
{
this.owner = db.Owner;
}
catch (Exception)
{
// TODO: fix the exception in SMO
this.owner = string.Empty;
}
// Databases that are restored from other servers might not have valid owners. // Databases that are restored from other servers might not have valid owners.
// If the logged in user is an administrator and the owner is not valid, show // If the logged in user is an administrator and the owner is not valid, show

View File

@@ -404,7 +404,7 @@ SET NUMERIC_ROUNDABORT OFF;";
switch (e.CurrentState) switch (e.CurrentState)
{ {
case ConnectionState.Open: case ConnectionState.Open:
RetreiveSessionId(); RetrieveSessionId();
break; break;
case ConnectionState.Broken: case ConnectionState.Broken:
case ConnectionState.Closed: case ConnectionState.Closed:
@@ -418,20 +418,24 @@ SET NUMERIC_ROUNDABORT OFF;";
} }
} }
private void RetreiveSessionId() private void RetrieveSessionId()
{ {
try try
{ {
using (IDbCommand command = CreateReliableCommand()) using (IDbCommand command = CreateReliableCommand())
{ {
command.CommandText = QueryAzureSessionId; IDbConnection connection = command.Connection;
object result = command.ExecuteScalar(); if (!IsSqlDwConnection(connection))
// Only returns a session id for SQL Azure
if (DBNull.Value != result)
{ {
string sessionId = (string)command.ExecuteScalar(); command.CommandText = QueryAzureSessionId;
_azureSessionId = new Guid(sessionId); object result = command.ExecuteScalar();
// Only returns a session id for SQL Azure
if (DBNull.Value != result)
{
string sessionId = (string)command.ExecuteScalar();
_azureSessionId = new Guid(sessionId);
}
} }
} }
} }

View File

@@ -342,15 +342,18 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
/// <param name="azureSessionId"></param> /// <param name="azureSessionId"></param>
internal static void RaiseSchemaAmbientRetryMessage(RetryState retryState, int errorCode, Guid azureSessionId) internal static void RaiseSchemaAmbientRetryMessage(RetryState retryState, int errorCode, Guid azureSessionId)
{ {
Logger.Write(LogLevel.Warning, string.Format( if (azureSessionId != Guid.Empty)
"Retry occurred: session: {0}; attempt - {1}; delay - {2}; exception - \"{3}\"", {
azureSessionId, Logger.Write(LogLevel.Warning, string.Format(
retryState.RetryCount, "Retry occurred: session: {0}; attempt - {1}; delay - {2}; exception - \"{3}\"",
retryState.Delay, azureSessionId,
retryState.LastError retryState.RetryCount,
)); retryState.Delay,
retryState.LastError
));
RaiseAmbientRetryMessage(retryState, errorCode); RaiseAmbientRetryMessage(retryState, errorCode);
}
} }
#region ProcessNetLibErrorCode enumeration #region ProcessNetLibErrorCode enumeration

View File

@@ -291,30 +291,30 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery
return szRecoveryModel; return szRecoveryModel;
} }
public string GetDefaultBackupFolder() public string GetDefaultBackupFolder()
{ {
string BackupFolder = ""; string BackupFolder = "";
Enumerator en = null; Enumerator en = null;
DataSet ds = new DataSet(); DataSet ds = new DataSet();
ds.Locale = System.Globalization.CultureInfo.InvariantCulture; ds.Locale = System.Globalization.CultureInfo.InvariantCulture;
Request req = new Request(); Request req = new Request();
en = new Enumerator(); en = new Enumerator();
req.Urn = "Server/Setting"; req.Urn = "Server/Setting";
ds = en.Process(SqlConnection, req); ds = en.Process(SqlConnection, req);
int iCount = ds.Tables[0].Rows.Count; int iCount = ds.Tables[0].Rows.Count;
if(iCount > 0) if (iCount > 0)
{ {
BackupFolder = Convert.ToString(ds.Tables[0].Rows[0]["BackupDirectory"], System.Globalization.CultureInfo.InvariantCulture); BackupFolder = Convert.ToString(ds.Tables[0].Rows[0]["BackupDirectory"], System.Globalization.CultureInfo.InvariantCulture);
} }
return BackupFolder; return BackupFolder;
} }

View File

@@ -83,9 +83,12 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery
if (sqlConn != null) if (sqlConn != null)
{ {
DisasterRecoveryService.Instance.InitializeBackup(helper.DataContainer, sqlConn); DisasterRecoveryService.Instance.InitializeBackup(helper.DataContainer, sqlConn);
BackupConfigInfo backupConfigInfo = DisasterRecoveryService.Instance.GetBackupConfigInfo(sqlConn.Database); if (!connInfo.IsSqlDW)
backupConfigInfo.DatabaseInfo = AdminService.GetDatabaseInfo(connInfo); {
response.BackupConfigInfo = backupConfigInfo; BackupConfigInfo backupConfigInfo = DisasterRecoveryService.Instance.GetBackupConfigInfo(sqlConn.Database);
backupConfigInfo.DatabaseInfo = AdminService.GetDatabaseInfo(connInfo);
response.BackupConfigInfo = backupConfigInfo;
}
} }
} }

View File

@@ -15,6 +15,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
/// Property name /// Property name
/// </summary> /// </summary>
public string Name { get; set; } public string Name { get; set; }
/// <summary> /// <summary>
/// Indicates which platforms a filter is valid for /// Indicates which platforms a filter is valid for
/// </summary> /// </summary>

View File

@@ -7,6 +7,7 @@
using System; using System;
using System.Globalization; using System.Globalization;
using Microsoft.SqlServer.Management.Smo; using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes;
using Microsoft.SqlTools.Utility; using Microsoft.SqlTools.Utility;
namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
@@ -35,6 +36,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
{ {
context.Database = db; context.Database = db;
} }
context.ValidFor = ServerVersionHelper.GetValidForFlag(context.SqlServerType, db);
} }
} }

View File

@@ -28,11 +28,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
try try
{ {
OnExpandPopulateFolders(allChildren, parent); OnExpandPopulateFoldersAndFilter(allChildren, parent, includeSystemObjects);
if(!includeSystemObjects)
{
allChildren.RemoveAll(x => x.IsSystemObject);
}
RemoveFoldersFromInvalidSqlServerVersions(allChildren, parent); RemoveFoldersFromInvalidSqlServerVersions(allChildren, parent);
OnExpandPopulateNonFolders(allChildren, parent, refresh, name); OnExpandPopulateNonFolders(allChildren, parent, refresh, name);
OnBeginAsyncOperations(parent); OnBeginAsyncOperations(parent);
@@ -50,6 +46,28 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
return allChildren; return allChildren;
} }
private void OnExpandPopulateFoldersAndFilter(List<TreeNode> allChildren, TreeNode parent, bool includeSystemObjects)
{
SmoQueryContext context = parent.GetContextAs<SmoQueryContext>();
OnExpandPopulateFolders(allChildren, parent);
if (!includeSystemObjects)
{
allChildren.RemoveAll(x => x.IsSystemObject);
}
if (context != null && context.ValidFor != 0 && context.ValidFor != ValidForFlag.All)
{
allChildren.RemoveAll(x =>
{
FolderNode folderNode = x as FolderNode;
if (folderNode != null && !ServerVersionHelper.IsValidFor(context.ValidFor, folderNode.ValidFor))
{
return true;
}
return false;
});
}
}
/// <summary> /// <summary>
/// Populates any folders for a given parent node /// Populates any folders for a given parent node
/// </summary> /// </summary>
@@ -76,15 +94,15 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
SmoQueryContext context = parent.GetContextAs<SmoQueryContext>(); SmoQueryContext context = parent.GetContextAs<SmoQueryContext>();
Validate.IsNotNull(nameof(context), context); Validate.IsNotNull(nameof(context), context);
var validForFlag = ServerVersionHelper.GetValidForFlag(context.SqlServerType); var serverValidFor = context.ValidFor;
if (ShouldFilterNode(parent, validForFlag)) if (ShouldFilterNode(parent, serverValidFor))
{ {
return; return;
} }
IEnumerable<SmoQuerier> queriers = context.ServiceProvider.GetServices<SmoQuerier>(q => IsCompatibleQuerier(q)); IEnumerable<SmoQuerier> queriers = context.ServiceProvider.GetServices<SmoQuerier>(q => IsCompatibleQuerier(q));
var filters = this.Filters.ToList(); var filters = this.Filters.ToList();
var smoProperties = this.SmoProperties.Where(p => (p.ValidFor == 0 || p.ValidFor.HasFlag(validForFlag))).Select(x => x.Name); var smoProperties = this.SmoProperties.Where(p => ServerVersionHelper.IsValidFor(serverValidFor, p.ValidFor)).Select(x => x.Name);
if (!string.IsNullOrEmpty(name)) if (!string.IsNullOrEmpty(name))
{ {
filters.Add(new NodeFilter filters.Add(new NodeFilter
@@ -96,7 +114,11 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
} }
foreach (var querier in queriers) foreach (var querier in queriers)
{ {
string propertyFilter = GetProperyFilter(filters, querier.GetType(), validForFlag); if (!querier.IsValidFor(serverValidFor))
{
continue;
}
string propertyFilter = GetProperyFilter(filters, querier.GetType(), serverValidFor);
try try
{ {
var smoObjectList = querier.Query(context, propertyFilter, refresh, smoProperties).ToList(); var smoObjectList = querier.Query(context, propertyFilter, refresh, smoProperties).ToList();
@@ -107,7 +129,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
Logger.Write(LogLevel.Error, "smoObject should not be null"); Logger.Write(LogLevel.Error, "smoObject should not be null");
} }
TreeNode childNode = CreateChild(parent, smoObject); TreeNode childNode = CreateChild(parent, smoObject);
if (childNode != null && PassesFinalFilters(childNode, smoObject) && !ShouldFilterNode(childNode, validForFlag)) if (childNode != null && PassesFinalFilters(childNode, smoObject) && !ShouldFilterNode(childNode, serverValidFor))
{ {
allChildren.Add(childNode); allChildren.Add(childNode);
} }
@@ -128,9 +150,9 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
{ {
bool filterTheNode = false; bool filterTheNode = false;
SmoTreeNode smoTreeNode = childNode as SmoTreeNode; SmoTreeNode smoTreeNode = childNode as SmoTreeNode;
if (smoTreeNode != null && smoTreeNode.ValidFor != 0) if (smoTreeNode != null)
{ {
if (!(smoTreeNode.ValidFor.HasFlag(validForFlag))) if (!ServerVersionHelper.IsValidFor(validForFlag, smoTreeNode.ValidFor))
{ {
filterTheNode = true; filterTheNode = true;
} }

View File

@@ -72,9 +72,26 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
{ {
return true; return true;
} }
/// <summary>
/// Returns true if the querier is valid for the given server version
/// </summary>
/// <param name="serverValidFor"></param>
/// <returns></returns>
public bool IsValidFor(ValidForFlag serverValidFor)
{
return ServerVersionHelper.IsValidFor(serverValidFor, ValidFor);
}
/// <summary>
/// Indicates which platforms the querier is valid for
/// </summary>
public virtual ValidForFlag ValidFor
{
get
{
return ValidForFlag.All;
}
}
} }
} }

View File

@@ -24,6 +24,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
private Database database; private Database database;
private SmoObjectBase parent; private SmoObjectBase parent;
private SmoWrapper smoWrapper; private SmoWrapper smoWrapper;
private ValidForFlag validFor = 0;
/// <summary> /// <summary>
/// Creates a context object with a server to use as the basis for any queries /// Creates a context object with a server to use as the basis for any queries
@@ -137,11 +138,31 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
{ {
database = this.Database, database = this.Database,
Parent = parent, Parent = parent,
SqlServerType = this.SqlServerType SqlServerType = this.SqlServerType,
ValidFor = ValidFor
}; };
return context; return context;
} }
/// <summary>
/// Indicates which platforms the server and database is valid for
/// </summary>
public ValidForFlag ValidFor
{
get
{
if(validFor == 0)
{
validFor = ServerVersionHelper.GetValidForFlag(SqlServerType, Database);
}
return validFor;
}
set
{
validFor = value;
}
}
private T GetObjectWithOpenedConnection<T>(T smoObj) private T GetObjectWithOpenedConnection<T>(T smoObj)
where T : SmoObjectBase where T : SmoObjectBase
{ {

View File

@@ -247,6 +247,9 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
{ {
Type[] supportedTypes = new Type[] { typeof(ServerDdlTrigger) }; Type[] supportedTypes = new Type[] { typeof(ServerDdlTrigger) };
public override ValidForFlag ValidFor { get { return ValidForFlag.NotSqlDw; } }
public override Type[] SupportedObjectTypes { get { return supportedTypes; } } public override Type[] SupportedObjectTypes { get { return supportedTypes; } }
public override IEnumerable<SqlSmoObject> Query(SmoQueryContext context, string filter, bool refresh, IEnumerable<string> extraProperties) public override IEnumerable<SqlSmoObject> Query(SmoQueryContext context, string filter, bool refresh, IEnumerable<string> extraProperties)
@@ -362,6 +365,9 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
{ {
Type[] supportedTypes = new Type[] { typeof(Synonym) }; Type[] supportedTypes = new Type[] { typeof(Synonym) };
public override ValidForFlag ValidFor { get { return ValidForFlag.NotSqlDw; } }
public override Type[] SupportedObjectTypes { get { return supportedTypes; } } public override Type[] SupportedObjectTypes { get { return supportedTypes; } }
public override IEnumerable<SqlSmoObject> Query(SmoQueryContext context, string filter, bool refresh, IEnumerable<string> extraProperties) public override IEnumerable<SqlSmoObject> Query(SmoQueryContext context, string filter, bool refresh, IEnumerable<string> extraProperties)
@@ -503,6 +509,9 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
{ {
Type[] supportedTypes = new Type[] { typeof(Trigger) }; Type[] supportedTypes = new Type[] { typeof(Trigger) };
public override ValidForFlag ValidFor { get { return ValidForFlag.NotSqlDw; } }
public override Type[] SupportedObjectTypes { get { return supportedTypes; } } public override Type[] SupportedObjectTypes { get { return supportedTypes; } }
public override IEnumerable<SqlSmoObject> Query(SmoQueryContext context, string filter, bool refresh, IEnumerable<string> extraProperties) public override IEnumerable<SqlSmoObject> Query(SmoQueryContext context, string filter, bool refresh, IEnumerable<string> extraProperties)
@@ -526,6 +535,9 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
{ {
Type[] supportedTypes = new Type[] { typeof(FullTextIndex) }; Type[] supportedTypes = new Type[] { typeof(FullTextIndex) };
public override ValidForFlag ValidFor { get { return ValidForFlag.NotSqlDw; } }
public override Type[] SupportedObjectTypes { get { return supportedTypes; } } public override Type[] SupportedObjectTypes { get { return supportedTypes; } }
public override IEnumerable<SqlSmoObject> Query(SmoQueryContext context, string filter, bool refresh, IEnumerable<string> extraProperties) public override IEnumerable<SqlSmoObject> Query(SmoQueryContext context, string filter, bool refresh, IEnumerable<string> extraProperties)
@@ -575,6 +587,9 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
{ {
Type[] supportedTypes = new Type[] { typeof(DatabaseDdlTrigger) }; Type[] supportedTypes = new Type[] { typeof(DatabaseDdlTrigger) };
public override ValidForFlag ValidFor { get { return ValidForFlag.NotSqlDw; } }
public override Type[] SupportedObjectTypes { get { return supportedTypes; } } public override Type[] SupportedObjectTypes { get { return supportedTypes; } }
public override IEnumerable<SqlSmoObject> Query(SmoQueryContext context, string filter, bool refresh, IEnumerable<string> extraProperties) public override IEnumerable<SqlSmoObject> Query(SmoQueryContext context, string filter, bool refresh, IEnumerable<string> extraProperties)
@@ -644,6 +659,9 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
{ {
Type[] supportedTypes = new Type[] { typeof(UserDefinedDataType) }; Type[] supportedTypes = new Type[] { typeof(UserDefinedDataType) };
public override ValidForFlag ValidFor { get { return ValidForFlag.NotSqlDw; } }
public override Type[] SupportedObjectTypes { get { return supportedTypes; } } public override Type[] SupportedObjectTypes { get { return supportedTypes; } }
public override IEnumerable<SqlSmoObject> Query(SmoQueryContext context, string filter, bool refresh, IEnumerable<string> extraProperties) public override IEnumerable<SqlSmoObject> Query(SmoQueryContext context, string filter, bool refresh, IEnumerable<string> extraProperties)

View File

@@ -34,6 +34,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 nodeType = GetNodeType(nodeElement, nodeName); string nodeType = GetNodeType(nodeElement, nodeName);
var validFor = nodeElement.GetAttribute("ValidFor");
string queryBaseClass = "SmoQuerier"; string queryBaseClass = "SmoQuerier";
PushIndent(indent); PushIndent(indent);
@@ -45,6 +46,13 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
// Supported Types // Supported Types
WriteLine("Type[] supportedTypes = new Type[] { typeof("+ nodeType + ") };"); WriteLine("Type[] supportedTypes = new Type[] { typeof("+ nodeType + ") };");
if (!string.IsNullOrWhiteSpace(validFor))
{
WriteLine("");
WriteLine(string.Format("public override ValidForFlag ValidFor {{ get {{ return {0}; }} }}", GetValidForFlags(validFor)));
WriteLine("");
}
WriteLine(""); WriteLine("");
WriteLine("public override Type[] SupportedObjectTypes { get { return supportedTypes; } }"); WriteLine("public override Type[] SupportedObjectTypes { get { return supportedTypes; } }");
WriteLine(""); WriteLine("");
@@ -232,4 +240,57 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
return retElements; return retElements;
} }
public static string GetValidForFlags(string validForStr)
{
List<string> flags = new List<string>();
if (validForStr.Contains("Sql2005"))
{
flags.Add("ValidForFlag.Sql2005");
}
if (validForStr.Contains("Sql2008"))
{
flags.Add("ValidForFlag.Sql2008");
}
if (validForStr.Contains("Sql2012"))
{
flags.Add("ValidForFlag.Sql2012");
}
if (validForStr.Contains("Sql2014"))
{
flags.Add("ValidForFlag.Sql2014");
}
if (validForStr.Contains("Sql2016"))
{
flags.Add("ValidForFlag.Sql2016");
}
if (validForStr.Contains("AzureV12"))
{
flags.Add("ValidForFlag.AzureV12");
}
if (validForStr.Contains("AllOnPrem"))
{
flags.Add("ValidForFlag.AllOnPrem");
}
if (validForStr.Contains("AllAzure"))
{
flags.Add("ValidForFlag.AllAzure");
}
if (validForStr.Contains("NotSqlDw"))
{
flags.Add("ValidForFlag.NotSqlDw");
}
if (validForStr == "All")
{
flags.Add("ValidForFlag.All");
}
return string.Join("|", flags);
}
#> #>

View File

@@ -29,7 +29,7 @@
<Node Name="SqlEndpoint" Parent="Server"/> <Node Name="SqlEndpoint" Parent="Server"/>
<Node Name="SqlLinkedServer" Parent="Server" /> <Node Name="SqlLinkedServer" Parent="Server" />
<Node Name="SqlServerDdlTrigger" Parent="Server" > <Node Name="SqlServerDdlTrigger" Parent="Server" ValidFor="NotSqlDw" >
<NavigationPath Parent="Server" Field="Triggers" /> <NavigationPath Parent="Server" Field="Triggers" />
</Node> </Node>
@@ -42,7 +42,7 @@
<Node Name="SqlView" Parent="Database" /> <Node Name="SqlView" Parent="Database" />
<Node Name="SqlSynonym" Parent="Database" /> <Node Name="SqlSynonym" Parent="Database" ValidFor="NotSqlDw" />
<Node Name="SqlColumn" Parent="TableViewTableTypeBase"/> <Node Name="SqlColumn" Parent="TableViewTableTypeBase"/>
<Node Name="SqlIndex" Parent="TableViewTableTypeBase"> <Node Name="SqlIndex" Parent="TableViewTableTypeBase">
@@ -52,11 +52,11 @@
<Node Name="SqlCheck" Parent="Table"/> <Node Name="SqlCheck" Parent="Table"/>
<Node Name="SqlForeignKeyConstraint" Type="ForeignKey" Parent="Table" /> <Node Name="SqlForeignKeyConstraint" Type="ForeignKey" Parent="Table" />
<Node Name="SqlDefaultConstraint" Parent="Column" Collection="False" /> <Node Name="SqlDefaultConstraint" Parent="Column" Collection="False" />
<Node Name="SqlDmlTrigger" Type="Trigger" Parent="Table" /> <Node Name="SqlDmlTrigger" Type="Trigger" Parent="Table" ValidFor="NotSqlDw" />
<Node Name="SqlFullTextIndex" Parent="Table" Collection="False" /> <Node Name="SqlFullTextIndex" Parent="Table" Collection="False" ValidFor="NotSqlDw" />
<Node Name="SqlStatistic" Parent="TableViewBase"/> <Node Name="SqlStatistic" Parent="TableViewBase"/>
<Node Name="SqlDatabaseDdlTrigger" Type="DatabaseDdlTrigger" Parent="Database"> <Node Name="SqlDatabaseDdlTrigger" Type="DatabaseDdlTrigger" Parent="Database" ValidFor="NotSqlDw">
<NavigationPath Parent="Database" Field="Triggers" /> <NavigationPath Parent="Database" Field="Triggers" />
</Node> </Node>
<Node Name="SqlAssembly" Type="SqlAssembly" Parent="Database" > <Node Name="SqlAssembly" Type="SqlAssembly" Parent="Database" >
@@ -69,7 +69,7 @@
--> -->
<Node Name="SqlSequence" Parent="Database" /> <Node Name="SqlSequence" Parent="Database" />
<Node Name="SqlUserDefinedDataType" Parent="Database" /> <Node Name="SqlUserDefinedDataType" Parent="Database" ValidFor="NotSqlDw" />
<Node Name="SqlUserDefinedTableType" Parent="Database" /> <Node Name="SqlUserDefinedTableType" Parent="Database" />
<Node Name="SqlXmlSchemaCollection" /> <Node Name="SqlXmlSchemaCollection" />

View File

@@ -92,7 +92,7 @@
<Child Name="SystemViews" IsSystemObject="1"/> <Child Name="SystemViews" IsSystemObject="1"/>
</Node> </Node>
<Node Name="Synonyms" LocLabel="SR.SchemaHierarchy_Synonyms" BaseClass="ModelBased" Strategy="MultipleElementsOfType" NodeType="Synonym" ChildQuerierTypes="SqlSynonym"/> <Node Name="Synonyms" LocLabel="SR.SchemaHierarchy_Synonyms" BaseClass="ModelBased" Strategy="MultipleElementsOfType" NodeType="Synonym" ChildQuerierTypes="SqlSynonym" ValidFor="Sql2005|Sql2008|Sql2012|Sql2014|Sql2016|Sql2017|AzureV12"/>
<Node Name="Programmability" LocLabel="SR.SchemaHierarchy_Programmability" BaseClass="ModelBased"> <Node Name="Programmability" LocLabel="SR.SchemaHierarchy_Programmability" BaseClass="ModelBased">
<Child Name="StoredProcedures"/> <Child Name="StoredProcedures"/>
<Child Name="Functions"/> <Child Name="Functions"/>
@@ -203,7 +203,7 @@
</Filters> </Filters>
</Node> </Node>
<Node Name="Constraints" LocLabel="SR.SchemaHierarchy_Constraints" BaseClass="ModelBased" NodeType="Constraint" Strategy="ElementsInRelationship" ChildQuerierTypes="SqlDefaultConstraint;SqlCheck"/> <Node Name="Constraints" LocLabel="SR.SchemaHierarchy_Constraints" BaseClass="ModelBased" NodeType="Constraint" Strategy="ElementsInRelationship" ChildQuerierTypes="SqlDefaultConstraint;SqlCheck"/>
<Node Name="Triggers" LocLabel="SR.SchemaHierarchy_Triggers" BaseClass="ModelBased" Strategy="ElementsInRelationship" NodeType="Trigger" ChildQuerierTypes="SqlDmlTrigger"/> <Node Name="Triggers" LocLabel="SR.SchemaHierarchy_Triggers" BaseClass="ModelBased" Strategy="ElementsInRelationship" NodeType="Trigger" ChildQuerierTypes="SqlDmlTrigger" ValidFor="Sql2005|Sql2008|Sql2012|Sql2014|Sql2016|Sql2017|AzureV12"/>
<Node Name="Indexes" LocLabel="SR.SchemaHierarchy_Indexes" BaseClass="ModelBased" Strategy="ElementsInRelationship" NodeType="Index" ChildQuerierTypes="SqlIndex;SqlFullTextIndex"> <Node Name="Indexes" LocLabel="SR.SchemaHierarchy_Indexes" BaseClass="ModelBased" Strategy="ElementsInRelationship" NodeType="Index" ChildQuerierTypes="SqlIndex;SqlFullTextIndex">
<Filters> <Filters>
<Filter TypeToReverse="SqlIndex" Property="IndexKeyType" Type="Enum" ValidFor="Sql2016|Sql2017|AzureV12"> <Filter TypeToReverse="SqlIndex" Property="IndexKeyType" Type="Enum" ValidFor="Sql2016|Sql2017|AzureV12">
@@ -238,7 +238,7 @@
<Child Name="SystemScalarValuedFunctions" IsSystemObject="1"/> <Child Name="SystemScalarValuedFunctions" IsSystemObject="1"/>
</Node> </Node>
<Node Name="DatabaseTriggers" LocLabel="SR.SchemaHierarchy_DatabaseTriggers" BaseClass="ModelBased" NodeType="DatabaseTrigger" Strategy="MultipleElementsOfType" ChildQuerierTypes="SqlDatabaseDdlTrigger"/> <Node Name="DatabaseTriggers" LocLabel="SR.SchemaHierarchy_DatabaseTriggers" BaseClass="ModelBased" NodeType="DatabaseTrigger" Strategy="MultipleElementsOfType" ChildQuerierTypes="SqlDatabaseDdlTrigger" ValidFor="Sql2005|Sql2008|Sql2012|Sql2014|Sql2016|Sql2017|AzureV12"/>
<Node Name="Assemblies" LocLabel="SR.SchemaHierarchy_Assemblies" BaseClass="ModelBased" Strategy="MultipleElementsOfType" NodeType="Assembly" ChildQuerierTypes="SqlAssembly" ValidFor="AllOnPrem|AzureV12"/> <Node Name="Assemblies" LocLabel="SR.SchemaHierarchy_Assemblies" BaseClass="ModelBased" Strategy="MultipleElementsOfType" NodeType="Assembly" ChildQuerierTypes="SqlAssembly" ValidFor="AllOnPrem|AzureV12"/>
<Node Name="Types" LocLabel="SR.SchemaHierarchy_Types" BaseClass="ModelBased" > <Node Name="Types" LocLabel="SR.SchemaHierarchy_Types" BaseClass="ModelBased" >
<Child Name="SystemDataTypes" IsSystemObject="1"/> <Child Name="SystemDataTypes" IsSystemObject="1"/>
@@ -264,8 +264,8 @@
<Child Name="SystemClrDataTypes"/> <Child Name="SystemClrDataTypes"/>
<Child Name="SystemSpatialDataTypes"/> <Child Name="SystemSpatialDataTypes"/>
</Node> </Node>
<Node Name="UserDefinedDataTypes" LocLabel="SR.SchemaHierarchy_UserDefinedDataTypes" BaseClass="ModelBased" NodeType="UserDefinedDataType" Strategy="MultipleElementsOfType" ChildQuerierTypes="SqlUserDefinedDataType"/> <Node Name="UserDefinedDataTypes" LocLabel="SR.SchemaHierarchy_UserDefinedDataTypes" BaseClass="ModelBased" NodeType="UserDefinedDataType" Strategy="MultipleElementsOfType" ChildQuerierTypes="SqlUserDefinedDataType" ValidFor="Sql2005|Sql2008|Sql2012|Sql2014|Sql2016|Sql2017|AzureV12"/>
<Node Name="UserDefinedTableTypes" LocLabel="SR.SchemaHierarchy_UserDefinedTableTypes" BaseClass="ModelBased" Strategy="MultipleElementsOfType" ChildQuerierTypes="SqlUserDefinedTableType" TreeNode="UserDefinedTableTypeTreeNode" ValidFor="Sql2008|Sql2012|Sql2014|Sql2016|Sql2017|AzureV11|AzureV12"/> <Node Name="UserDefinedTableTypes" LocLabel="SR.SchemaHierarchy_UserDefinedTableTypes" BaseClass="ModelBased" Strategy="MultipleElementsOfType" ChildQuerierTypes="SqlUserDefinedTableType" TreeNode="UserDefinedTableTypeTreeNode" ValidFor="Sql2008|Sql2012|Sql2014|Sql2016|Sql2017|AzureV12"/>
<Node Name="UserDefinedTypes" LocLabel="SR.SchemaHierarchy_UserDefinedTypes" BaseClass="ModelBased" Strategy="MultipleElementsOfType" NodeType="UserDefinedType" ChildQuerierTypes="SqlUserDefinedType" ValidFor="AllOnPrem|AzureV12"/> <Node Name="UserDefinedTypes" LocLabel="SR.SchemaHierarchy_UserDefinedTypes" BaseClass="ModelBased" Strategy="MultipleElementsOfType" NodeType="UserDefinedType" ChildQuerierTypes="SqlUserDefinedType" ValidFor="AllOnPrem|AzureV12"/>
<Node Name="XmlSchemaCollections" LocLabel="SR.SchemaHierarchy_XMLSchemaCollections" BaseClass="ModelBased" Strategy="MultipleElementsOfType" NodeType="XmlSchemaCollection" ChildQuerierTypes="SqlXmlSchemaCollection" ValidFor="AllOnPrem|AzureV12"/> <Node Name="XmlSchemaCollections" LocLabel="SR.SchemaHierarchy_XMLSchemaCollections" BaseClass="ModelBased" Strategy="MultipleElementsOfType" NodeType="XmlSchemaCollection" ChildQuerierTypes="SqlXmlSchemaCollection" ValidFor="AllOnPrem|AzureV12"/>
@@ -293,7 +293,7 @@
<Node Name="SystemBinaryStrings" LocLabel="SR.SchemaHierarchy_SystemBinaryStrings" BaseClass="ModelBased" Strategy="MultipleElementsOfType" NodeType="SystemBinaryString" ChildQuerierTypes="SqlBuiltInType"/> <Node Name="SystemBinaryStrings" LocLabel="SR.SchemaHierarchy_SystemBinaryStrings" BaseClass="ModelBased" Strategy="MultipleElementsOfType" NodeType="SystemBinaryString" ChildQuerierTypes="SqlBuiltInType"/>
<Node Name="SystemOtherDataTypes" LocLabel="SR.SchemaHierarchy_SystemOtherDataTypes" BaseClass="ModelBased" Strategy="MultipleElementsOfType" NodeType="SystemOtherDataType" ChildQuerierTypes="SqlBuiltInType"/> <Node Name="SystemOtherDataTypes" LocLabel="SR.SchemaHierarchy_SystemOtherDataTypes" BaseClass="ModelBased" Strategy="MultipleElementsOfType" NodeType="SystemOtherDataType" ChildQuerierTypes="SqlBuiltInType"/>
<Node Name="SystemClrDataTypes" LocLabel="SR.SchemaHierarchy_SystemCLRDataTypes" BaseClass="ModelBased" Strategy="MultipleElementsOfType" NodeType="SystemClrDataType" ChildQuerierTypes="SqlBuiltInType" ValidFor="All"/> <Node Name="SystemClrDataTypes" LocLabel="SR.SchemaHierarchy_SystemCLRDataTypes" BaseClass="ModelBased" Strategy="MultipleElementsOfType" NodeType="SystemClrDataType" ChildQuerierTypes="SqlBuiltInType" ValidFor="All"/>
<Node Name="SystemSpatialDataTypes" LocLabel="SR.SchemaHierarchy_SystemSpatialDataTypes" BaseClass="ModelBased" Strategy="MultipleElementsOfType" NodeType="SystemSpatialDataType" ChildQuerierTypes="SqlBuiltInType" ValidFor="Sql2008|Sql2012|Sql2014|Sql2016|Sql2017|AzureV11|AzureV12"/> <Node Name="SystemSpatialDataTypes" LocLabel="SR.SchemaHierarchy_SystemSpatialDataTypes" BaseClass="ModelBased" Strategy="MultipleElementsOfType" NodeType="SystemSpatialDataType" ChildQuerierTypes="SqlBuiltInType" ValidFor="Sql2008|Sql2012|Sql2014|Sql2016|Sql2017|AzureV12"/>
<!-- Childs of ExternalResources --> <!-- Childs of ExternalResources -->
<Node Name="ExternalDataSources" LocLabel="SR.SchemaHierarchy_ExternalDataSources" BaseClass="ModelBased" NodeType="ExternalDataSource" Strategy="MultipleElementsOfType" ChildQuerierTypes="SqlExternalDataSource" ValidFor="Sql2016|Sql2017|AzureV12"/> <Node Name="ExternalDataSources" LocLabel="SR.SchemaHierarchy_ExternalDataSources" BaseClass="ModelBased" NodeType="ExternalDataSource" Strategy="MultipleElementsOfType" ChildQuerierTypes="SqlExternalDataSource" ValidFor="Sql2016|Sql2017|AzureV12"/>

View File

@@ -673,6 +673,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
NodeType = "Folder", NodeType = "Folder",
NodeTypeId = NodeTypes.Synonyms, NodeTypeId = NodeTypes.Synonyms,
IsSystemObject = false, IsSystemObject = false,
ValidFor = ValidForFlag.Sql2005|ValidForFlag.Sql2008|ValidForFlag.Sql2012|ValidForFlag.Sql2014|ValidForFlag.Sql2016|ValidForFlag.AzureV12,
SortPriority = SmoTreeNode.NextSortPriority, SortPriority = SmoTreeNode.NextSortPriority,
}); });
currentChildren.Add(new FolderNode { currentChildren.Add(new FolderNode {
@@ -906,6 +907,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
NodeType = "Folder", NodeType = "Folder",
NodeTypeId = NodeTypes.DatabaseTriggers, NodeTypeId = NodeTypes.DatabaseTriggers,
IsSystemObject = false, IsSystemObject = false,
ValidFor = ValidForFlag.Sql2005|ValidForFlag.Sql2008|ValidForFlag.Sql2012|ValidForFlag.Sql2014|ValidForFlag.Sql2016|ValidForFlag.AzureV12,
SortPriority = SmoTreeNode.NextSortPriority, SortPriority = SmoTreeNode.NextSortPriority,
}); });
currentChildren.Add(new FolderNode { currentChildren.Add(new FolderNode {
@@ -1312,6 +1314,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
NodeType = "Folder", NodeType = "Folder",
NodeTypeId = NodeTypes.Triggers, NodeTypeId = NodeTypes.Triggers,
IsSystemObject = false, IsSystemObject = false,
ValidFor = ValidForFlag.Sql2005|ValidForFlag.Sql2008|ValidForFlag.Sql2012|ValidForFlag.Sql2014|ValidForFlag.Sql2016|ValidForFlag.AzureV12,
SortPriority = SmoTreeNode.NextSortPriority, SortPriority = SmoTreeNode.NextSortPriority,
}); });
currentChildren.Add(new FolderNode { currentChildren.Add(new FolderNode {
@@ -1686,6 +1689,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
NodeType = "Folder", NodeType = "Folder",
NodeTypeId = NodeTypes.Triggers, NodeTypeId = NodeTypes.Triggers,
IsSystemObject = false, IsSystemObject = false,
ValidFor = ValidForFlag.Sql2005|ValidForFlag.Sql2008|ValidForFlag.Sql2012|ValidForFlag.Sql2014|ValidForFlag.Sql2016|ValidForFlag.AzureV12,
SortPriority = SmoTreeNode.NextSortPriority, SortPriority = SmoTreeNode.NextSortPriority,
}); });
currentChildren.Add(new FolderNode { currentChildren.Add(new FolderNode {
@@ -1877,6 +1881,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
NodeType = "Folder", NodeType = "Folder",
NodeTypeId = NodeTypes.UserDefinedDataTypes, NodeTypeId = NodeTypes.UserDefinedDataTypes,
IsSystemObject = false, IsSystemObject = false,
ValidFor = ValidForFlag.Sql2005|ValidForFlag.Sql2008|ValidForFlag.Sql2012|ValidForFlag.Sql2014|ValidForFlag.Sql2016|ValidForFlag.AzureV12,
SortPriority = SmoTreeNode.NextSortPriority, SortPriority = SmoTreeNode.NextSortPriority,
}); });
currentChildren.Add(new FolderNode { currentChildren.Add(new FolderNode {
@@ -1884,7 +1889,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
NodeType = "Folder", NodeType = "Folder",
NodeTypeId = NodeTypes.UserDefinedTableTypes, NodeTypeId = NodeTypes.UserDefinedTableTypes,
IsSystemObject = false, IsSystemObject = false,
ValidFor = ValidForFlag.Sql2008|ValidForFlag.Sql2012|ValidForFlag.Sql2014|ValidForFlag.Sql2016|ValidForFlag.Azure|ValidForFlag.AzureV12, ValidFor = ValidForFlag.Sql2008|ValidForFlag.Sql2012|ValidForFlag.Sql2014|ValidForFlag.Sql2016|ValidForFlag.AzureV12,
SortPriority = SmoTreeNode.NextSortPriority, SortPriority = SmoTreeNode.NextSortPriority,
}); });
currentChildren.Add(new FolderNode { currentChildren.Add(new FolderNode {
@@ -2008,7 +2013,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
NodeType = "Folder", NodeType = "Folder",
NodeTypeId = NodeTypes.SystemSpatialDataTypes, NodeTypeId = NodeTypes.SystemSpatialDataTypes,
IsSystemObject = false, IsSystemObject = false,
ValidFor = ValidForFlag.Sql2008|ValidForFlag.Sql2012|ValidForFlag.Sql2014|ValidForFlag.Sql2016|ValidForFlag.Azure|ValidForFlag.AzureV12, ValidFor = ValidForFlag.Sql2008|ValidForFlag.Sql2012|ValidForFlag.Sql2014|ValidForFlag.Sql2016|ValidForFlag.AzureV12,
SortPriority = SmoTreeNode.NextSortPriority, SortPriority = SmoTreeNode.NextSortPriority,
}); });
} }

View File

@@ -369,11 +369,6 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
flags.Add("ValidForFlag.Sql2016"); flags.Add("ValidForFlag.Sql2016");
} }
if (validForStr.Contains("AzureV11"))
{
flags.Add("ValidForFlag.Azure");
}
if (validForStr.Contains("AzureV12")) if (validForStr.Contains("AzureV12"))
{ {
flags.Add("ValidForFlag.AzureV12"); flags.Add("ValidForFlag.AzureV12");
@@ -383,11 +378,15 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
{ {
flags.Add("ValidForFlag.AllOnPrem"); flags.Add("ValidForFlag.AllOnPrem");
} }
if (validForStr.Contains("AllAzure")) if (validForStr.Contains("AllAzure"))
{ {
flags.Add("ValidForFlag.AllAzure"); flags.Add("ValidForFlag.AllAzure");
} }
if (validForStr == "All") if (validForStr.Contains("NotSqlDw"))
{
flags.Add("ValidForFlag.NotSqlDw");
}
if (validForStr == "All")
{ {
flags.Add("ValidForFlag.All"); flags.Add("ValidForFlag.All");
} }

View File

@@ -4,9 +4,10 @@
// //
using System; using System;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts; using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
{ {
/// <summary> /// <summary>
/// Server Types /// Server Types
@@ -20,7 +21,6 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
Sql2014, Sql2014,
Sql2016, Sql2016,
Sql2017, Sql2017,
Azure,
AzureV12 AzureV12
} }
@@ -32,11 +32,38 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
/// <summary> /// <summary>
/// Converts a server type to ValidForFlag /// Converts a server type to ValidForFlag
/// </summary> /// </summary>
public static ValidForFlag GetValidForFlag(SqlServerType serverType) public static ValidForFlag GetValidForFlag(SqlServerType serverType, Database database = null)
{
return GetValidForFlag(serverType, database != null && database.IsSqlDw);
}
/// <summary>
/// Returns true if the given valid for flag is not set or it includes the server version
/// </summary>
/// <param name="serverVersion">Server version</param>
/// <param name="validFor">Valid for flag</param>
/// <returns></returns>
public static bool IsValidFor(ValidForFlag serverVersion, ValidForFlag validFor)
{
return validFor == ValidForFlag.None || validFor.HasFlag(serverVersion);
}
/// <summary>
/// Converts a server type to ValidForFlag
/// </summary>
public static ValidForFlag GetValidForFlag(SqlServerType serverType, bool isSqlDw)
{ {
ValidForFlag validforFlag = ValidForFlag.All; ValidForFlag validforFlag = ValidForFlag.All;
if (Enum.TryParse<ValidForFlag>(serverType.ToString(), out validforFlag)) if (Enum.TryParse<ValidForFlag>(serverType.ToString(), out validforFlag))
{ {
if (isSqlDw && serverType == SqlServerType.AzureV12)
{
validforFlag = ValidForFlag.SqlDw;
}
else
{
//TODO: not supporting SQL DW for on prem
}
return validforFlag; return validforFlag;
} }
return ValidForFlag.All; return ValidForFlag.All;
@@ -52,14 +79,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
if (serverInfo.IsCloud) if (serverInfo.IsCloud)
{ {
if (serverVersion.StartsWith("11", StringComparison.Ordinal)) serverType = SqlServerType.AzureV12;
{
serverType = SqlServerType.Azure;
}
else
{
serverType = SqlServerType.AzureV12;
}
} }
else if (!string.IsNullOrWhiteSpace(serverVersion)) else if (!string.IsNullOrWhiteSpace(serverVersion))
{ {

View File

@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer
{ {
/// <summary> /// <summary>
/// Indicates which type of server a given node type is valid for /// Indicates which type of server a given node type is valid for
@@ -11,16 +11,18 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
[Flags] [Flags]
public enum ValidForFlag public enum ValidForFlag
{ {
None = 0x00,
Sql2005 = 0x01, Sql2005 = 0x01,
Sql2008 = 0x02, Sql2008 = 0x02,
Sql2012 = 0x04, Sql2012 = 0x04,
Sql2014 = 0x08, Sql2014 = 0x08,
Azure = 0x10, AzureV12 = 0x10,
AzureV12 = 0x20, Sql2016 = 0x20,
Sql2016 = 0x40, Sql2017 = 0x40,
Sql2017 = 0x80, SqlDw = 0x80,
AllOnPrem = Sql2005 | Sql2008 | Sql2012 | Sql2014 | Sql2016 | Sql2017, AllOnPrem = Sql2005 | Sql2008 | Sql2012 | Sql2014 | Sql2016 | Sql2017,
AllAzure = Azure | AzureV12, AllAzure = AzureV12,
All = Sql2005 | Sql2008 | Sql2012 | Sql2014 | Sql2016 | Sql2017 | Azure | AzureV12 All = Sql2005 | Sql2008 | Sql2012 | Sql2014 | Sql2016 | Sql2017 | AzureV12 | SqlDw,
NotSqlDw = Sql2005 | Sql2008 | Sql2012 | Sql2014 | Sql2016 | Sql2017 | AzureV12
} }
} }

View File

@@ -0,0 +1,162 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer;
using Xunit;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
{
public class ServerVersionHelperTests
{
[Fact]
public void GetValidForFlagShouldReturnAllGivenUnKnownVersion()
{
ValidForFlag validforFlag = ServerVersionHelper.GetValidForFlag(SqlServerType.Unknown);
ValidForFlag expected = ValidForFlag.All;
Assert.Equal(validforFlag, expected);
}
[Fact]
public void GetValidForFlagShouldReturnTheFlagCorrectlyGivenValidVersion()
{
VerifyGetValidForFlag(SqlServerType.AzureV12, ValidForFlag.AzureV12);
VerifyGetValidForFlag(SqlServerType.Sql2005, ValidForFlag.Sql2005);
VerifyGetValidForFlag(SqlServerType.Sql2008, ValidForFlag.Sql2008);
VerifyGetValidForFlag(SqlServerType.Sql2012, ValidForFlag.Sql2012);
VerifyGetValidForFlag(SqlServerType.Sql2014, ValidForFlag.Sql2014);
VerifyGetValidForFlag(SqlServerType.Sql2016, ValidForFlag.Sql2016);
VerifyGetValidForFlag(SqlServerType.Sql2017, ValidForFlag.Sql2017);
}
[Fact]
public void GetValidForFlagShouldReturnTheFlagIncludingSqlDwGivenSqlDwdatabase()
{
ValidForFlag validforFlag = ServerVersionHelper.GetValidForFlag(SqlServerType.AzureV12, true);
ValidForFlag expected = ValidForFlag.SqlDw;
Assert.Equal(validforFlag, expected);
}
[Fact]
public void CalculateServerTypeShouldReturnSql2005Given2005Version()
{
string serverVersion = "9.1.2.3";
SqlServerType expected = SqlServerType.Sql2005;
VerifyCalculateServerType(serverVersion, expected);
}
[Fact]
public void CalculateServerTypeShouldReturnSql2008Given2008Version()
{
string serverVersion = "10.1.2.3";
SqlServerType expected = SqlServerType.Sql2008;
VerifyCalculateServerType(serverVersion, expected);
}
[Fact]
public void CalculateServerTypeShouldReturnSql2012Given2012Version()
{
string serverVersion = "11.1.2.3";
SqlServerType expected = SqlServerType.Sql2012;
VerifyCalculateServerType(serverVersion, expected);
}
[Fact]
public void CalculateServerTypeShouldReturnSql2014Given2014Version()
{
string serverVersion = "12.1.2.3";
SqlServerType expected = SqlServerType.Sql2014;
VerifyCalculateServerType(serverVersion, expected);
}
[Fact]
public void CalculateServerTypeShouldReturnSql2016Given2016Version()
{
string serverVersion = "13.1.2.3";
SqlServerType expected = SqlServerType.Sql2016;
VerifyCalculateServerType(serverVersion, expected);
}
[Fact]
public void CalculateServerTypeShouldReturnSql2017Given2017Version()
{
string serverVersion = "14.1.2.3";
SqlServerType expected = SqlServerType.Sql2017;
VerifyCalculateServerType(serverVersion, expected);
}
[Fact]
public void IsValidForShouldReturnTrueGivenSqlDwAndAll()
{
ValidForFlag serverValidFor = ValidForFlag.SqlDw;
ValidForFlag validFor = ValidForFlag.All;
bool expected = true;
VerifyIsValidFor(serverValidFor, validFor, expected);
}
[Fact]
public void IsValidForShouldReturnTrueGivenSqlDwAndNone()
{
ValidForFlag serverValidFor = ValidForFlag.SqlDw;
ValidForFlag validFor = ValidForFlag.None;
bool expected = true;
VerifyIsValidFor(serverValidFor, validFor, expected);
}
[Fact]
public void IsValidForShouldReturnTrueGivenSqlDwAndSqlDw()
{
ValidForFlag serverValidFor = ValidForFlag.SqlDw;
ValidForFlag validFor = ValidForFlag.SqlDw;
bool expected = true;
VerifyIsValidFor(serverValidFor, validFor, expected);
}
[Fact]
public void IsValidForShouldReturnTrueGivenSqlDwAndNotSqlDw()
{
ValidForFlag serverValidFor = ValidForFlag.SqlDw;
ValidForFlag validFor = ValidForFlag.NotSqlDw;
bool expected = false;
VerifyIsValidFor(serverValidFor, validFor, expected);
}
[Fact]
public void IsValidForShouldReturnTrueGivenSqlDwAndAllOnPrem()
{
ValidForFlag serverValidFor = ValidForFlag.SqlDw;
ValidForFlag validFor = ValidForFlag.AllOnPrem;
bool expected = false;
VerifyIsValidFor(serverValidFor, validFor, expected);
}
private void VerifyIsValidFor(ValidForFlag serverValidFor, ValidForFlag validFor, bool expected)
{
bool actual = ServerVersionHelper.IsValidFor(serverValidFor, validFor);
Assert.Equal(expected, actual);
}
private void VerifyCalculateServerType(string serverVersion, SqlServerType expected)
{
ServerInfo serverInfo = new ServerInfo
{
ServerVersion = serverVersion
};
SqlServerType actual = ServerVersionHelper.CalculateServerType(serverInfo);
Assert.Equal(expected, actual);
}
private void VerifyGetValidForFlag(SqlServerType serverType, ValidForFlag validForFlag)
{
ValidForFlag validforFlag = ServerVersionHelper.GetValidForFlag(serverType);
ValidForFlag expected = validForFlag;
Assert.Equal(validforFlag, expected);
}
}
}

View File

@@ -1,65 +1,108 @@
// //
// Copyright (c) Microsoft. All rights reserved. // Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
// //
using System; using System;
using System.Linq; using System.Linq;
using Microsoft.SqlServer.Management.Smo; using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlTools.Extensibility; using Microsoft.SqlTools.Extensibility;
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel; using Microsoft.SqlTools.ServiceLayer.ObjectExplorer;
using Xunit; using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel;
using Xunit;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
{ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
public class SmoQueryModelTests {
{ public class SmoQueryModelTests
{
[Fact]
public void ShouldFindDatabaseQuerierFromRealPath() [Fact]
{ public void ShouldFindDatabaseQuerierFromRealPath()
// Given the extension type loader is set to find SmoCollectionQuerier objects {
IMultiServiceProvider serviceProvider = ExtensionServiceProvider.CreateDefaultServiceProvider(); // Given the extension type loader is set to find SmoCollectionQuerier objects
// When I request a database compatible querier IMultiServiceProvider serviceProvider = ExtensionServiceProvider.CreateDefaultServiceProvider();
SmoQuerier querier = serviceProvider.GetService<SmoQuerier>(q => q.SupportedObjectTypes.Contains(typeof(Database))); // When I request a database compatible querier
// Then I expect to get back the SqlDatabaseQuerier SmoQuerier querier = serviceProvider.GetService<SmoQuerier>(q => q.SupportedObjectTypes.Contains(typeof(Database)));
Assert.NotNull(querier); // Then I expect to get back the SqlDatabaseQuerier
Assert.Equal(typeof(SqlDatabaseQuerier), querier.GetType()); Assert.NotNull(querier);
Assert.Equal(typeof(SqlDatabaseQuerier), querier.GetType());
// And I expect the service provider to have been set by the extension code
Assert.NotNull(querier.ServiceProvider); // And I expect the service provider to have been set by the extension code
} Assert.NotNull(querier.ServiceProvider);
}
[Fact]
public void ShouldFindQuerierIfInExtensionList() [Fact]
{ public void ShouldFindQuerierIfInExtensionList()
VerifyQuerierLookup(typeof(Table), typeof(SqlTableQuerier), expectExists: true); {
} VerifyQuerierLookup(typeof(Table), typeof(SqlTableQuerier), expectExists: true);
}
[Fact]
public void ShouldNotFindQuerierIfNotInExtensionList() [Fact]
{ public void ShouldNotFindQuerierIfNotInExtensionList()
VerifyQuerierLookup(typeof(Database), null, expectExists: false); {
} VerifyQuerierLookup(typeof(Database), null, expectExists: false);
}
private static void VerifyQuerierLookup(Type smoType, Type querierType, bool expectExists)
{ [Fact]
ExtensionServiceProvider serviceProvider = ExtensionServiceProvider.Create(new Type[] { public void SqlServerDdlTriggerQuerierShouldNotBeAvailableForSqlDw()
typeof(SqlTableQuerier), {
typeof(SqlLinkedServerQuerier) SmoQuerier querier = GetSmoQuerier(typeof(ServerDdlTrigger));
}); Assert.False(querier.ValidFor.HasFlag(ValidForFlag.SqlDw));
SmoQuerier querier = serviceProvider.GetService<SmoQuerier>(q => q.SupportedObjectTypes.Contains(smoType)); }
if (expectExists)
{ [Fact]
Assert.NotNull(querier); public void SqlSynonymQuerierShouldNotBeAvailableForSqlDw()
Assert.Equal(querierType, querier.GetType()); {
Assert.NotNull(querier.ServiceProvider); SmoQuerier querier = GetSmoQuerier(typeof(Synonym));
} Assert.False(querier.ValidFor.HasFlag(ValidForFlag.SqlDw));
else }
{
Assert.Null(querier); [Fact]
} public void SqlTriggerQuerierShouldNotBeAvailableForSqlDw()
} {
SmoQuerier querier = GetSmoQuerier(typeof(Trigger));
} Assert.False(querier.ValidFor.HasFlag(ValidForFlag.SqlDw));
} }
[Fact]
public void SqlFullTextIndexQuerierShouldNotBeAvailableForSqlDw()
{
SmoQuerier querier = GetSmoQuerier(typeof(FullTextIndex));
Assert.False(querier.ValidFor.HasFlag(ValidForFlag.SqlDw));
}
private SmoQuerier GetSmoQuerier(Type querierType)
{
// Given the extension type loader is set to find SmoCollectionQuerier objects
IMultiServiceProvider serviceProvider = ExtensionServiceProvider.CreateDefaultServiceProvider();
// When I request a compatible querier
SmoQuerier querier = serviceProvider.GetService<SmoQuerier>(q => q.SupportedObjectTypes.Contains(querierType));
// Then I expect to get back the Querier
Assert.NotNull(querier);
// And I expect the service provider to have been set by the extension code
Assert.NotNull(querier.ServiceProvider);
return querier;
}
private static void VerifyQuerierLookup(Type smoType, Type querierType, bool expectExists)
{
ExtensionServiceProvider serviceProvider = ExtensionServiceProvider.Create(new Type[] {
typeof(SqlTableQuerier),
typeof(SqlLinkedServerQuerier)
});
SmoQuerier querier = serviceProvider.GetService<SmoQuerier>(q => q.SupportedObjectTypes.Contains(smoType));
if (expectExists)
{
Assert.NotNull(querier);
Assert.Equal(querierType, querier.GetType());
Assert.NotNull(querier.ServiceProvider);
}
else
{
Assert.Null(querier);
}
}
}
}