Implemented the oe filtering (#328)

* Implemented the oe filtering
This commit is contained in:
Leila Lali
2017-04-26 14:48:17 -07:00
committed by GitHub
parent 1a16101381
commit 51916c2221
17 changed files with 3108 additions and 1030 deletions

View File

@@ -29,6 +29,11 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
/// <returns></returns>
public abstract IEnumerable<TreeNode> Expand(TreeNode parent);
/// <summary>
/// The list of filters that should be applied on the smo object list
/// </summary>
public abstract IEnumerable<NodeFilter> Filters { get; }
public abstract bool CanCreateChild(TreeNode parent, object context);
public abstract TreeNode CreateChild(TreeNode parent, object context);

View File

@@ -0,0 +1,84 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System;
using System.Collections.Generic;
namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
{
/// <summary>
/// Has information for filtering a SMO object by properties
/// </summary>
public class NodeFilter
{
/// <summary>
/// Property name
/// </summary>
public string Property { get; set; }
/// <summary>
/// Filter values
/// </summary>
public List<object> Values { get; set; }
/// <summary>
/// Type of the filter values
/// </summary>
public Type Type { get; set; }
/// <summary>
/// Indicates which platforms a filter is valid for
/// </summary>
public ValidForFlag ValidFor { get; set; }
/// <summary>
/// The type of the Querier the filter can be applied to
/// </summary>
public Type TypeToReverse { get; set; }
/// <summary>
/// Returns true if the filter can be apply to the given type and Server type
/// </summary>
/// <param name="type">Type of the querier</param>
/// <param name="validForFlag">Server Type</param>
/// <returns></returns>
public bool CanApplyFilter(Type type, ValidForFlag validForFlag)
{
bool canApplyFilter = false;
canApplyFilter = TypeToReverse == null || TypeToReverse == type;
canApplyFilter = canApplyFilter && (ValidFor == 0 || ValidFor.HasFlag(validForFlag));
return canApplyFilter;
}
/// <summary>
/// Creates a string from the filter property and values to be used in the Urn to query the SQL objects
/// Example of the output:[@ IsSystemObject = 0]
/// </summary>
/// <returns></returns>
public string ToPropertyFilterString()
{
string filter = "";
List<object> values = Values;
if (values != null)
{
for (int i = 0; i < values.Count; i++)
{
var value = values[i];
object proeprtyValue = value;
if (Type == typeof(Enum))
{
proeprtyValue = (int)Convert.ChangeType(value, Type);
}
string orPrefix = i == 0 ? "" : "or";
filter = $"{filter} {orPrefix} @{Property} = {proeprtyValue}";
}
}
filter = $"[{filter}]";
return filter;
}
}
}

View File

@@ -24,6 +24,7 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
View,
Table,
HistoryTable,
Folder,
Databases,
ExternalResources,
ServerLevelSecurity,

View File

@@ -0,0 +1,91 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System;
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
{
/// <summary>
/// Server Types
/// </summary>
public enum SqlServerType
{
Unknown,
Sql2005,
Sql2008,
Sql2012,
Sql2014,
Sql2016,
Azure,
AzureV12
}
/// <summary>
/// Includes helper functions for server version and type
/// </summary>
public class ServerVersionHelper
{
/// <summary>
/// Converts a server type to ValidForFlag
/// </summary>
public static ValidForFlag GetValidForFlag(SqlServerType serverType)
{
ValidForFlag validforFlag = ValidForFlag.All;
if (Enum.TryParse<ValidForFlag>(serverType.ToString(), out validforFlag))
{
return validforFlag;
}
return ValidForFlag.All;
}
/// <summary>
/// Creates a server type from the server version
/// </summary>
public static SqlServerType CalculateServerType(ServerInfo serverInfo)
{
SqlServerType serverType = SqlServerType.Unknown;
string serverVersion = serverInfo.ServerVersion;
if (serverInfo.IsCloud)
{
if (serverVersion.StartsWith("11", StringComparison.Ordinal))
{
serverType = SqlServerType.Azure;
}
else
{
serverType = SqlServerType.AzureV12;
}
}
else if (!string.IsNullOrWhiteSpace(serverVersion))
{
if (serverVersion.StartsWith("9", StringComparison.Ordinal) ||
serverVersion.StartsWith("09", StringComparison.Ordinal))
{
serverType = SqlServerType.Sql2005;
}
else if (serverVersion.StartsWith("10", StringComparison.Ordinal))
{
serverType = SqlServerType.Sql2008; // and 2008R2
}
else if (serverVersion.StartsWith("11", StringComparison.Ordinal))
{
serverType = SqlServerType.Sql2012;
}
else if (serverVersion.StartsWith("12", StringComparison.Ordinal))
{
serverType = SqlServerType.Sql2014;
}
else if (serverVersion.StartsWith("13", StringComparison.Ordinal))
{
serverType = SqlServerType.Sql2016;
}
}
return serverType;
}
}
}