mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
Don't query for unsupported properties (#1471)
* Don't query for unsupported properties * add using
This commit is contained in:
@@ -14,6 +14,7 @@ using System.Security;
|
|||||||
using Microsoft.SqlTools.Utility;
|
using Microsoft.SqlTools.Utility;
|
||||||
using Microsoft.SqlServer.Management.Common;
|
using Microsoft.SqlServer.Management.Common;
|
||||||
using Microsoft.SqlServer.Management.Smo;
|
using Microsoft.SqlServer.Management.Smo;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
|
namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
|
||||||
{
|
{
|
||||||
@@ -795,9 +796,24 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection
|
|||||||
{
|
{
|
||||||
SqlConnection sqlConnection = GetAsSqlConnection(connection);
|
SqlConnection sqlConnection = GetAsSqlConnection(connection);
|
||||||
var server = new Server(new ServerConnection(sqlConnection));
|
var server = new Server(new ServerConnection(sqlConnection));
|
||||||
server.SetDefaultInitFields(server.GetType(), new String[] { nameof(server.Processors), nameof(server.PhysicalMemory) });
|
var defaultFields = new List<string>();
|
||||||
sysInfo.CpuCount = server.Processors;
|
var isProcessorsSupported = server.IsSupportedProperty(nameof(server.Processors));
|
||||||
sysInfo.PhysicalMemoryInMB = server.PhysicalMemory;
|
if (isProcessorsSupported)
|
||||||
|
{
|
||||||
|
defaultFields.Add(nameof(server.Processors));
|
||||||
|
}
|
||||||
|
var isPhysicalMemorySupported = server.IsSupportedProperty(nameof(server.PhysicalMemory));
|
||||||
|
if (isPhysicalMemorySupported)
|
||||||
|
{
|
||||||
|
defaultFields.Add(nameof(server.PhysicalMemory));
|
||||||
|
}
|
||||||
|
if (defaultFields.Any())
|
||||||
|
{
|
||||||
|
server.SetDefaultInitFields(server.GetType(), defaultFields.ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
sysInfo.CpuCount = isProcessorsSupported ? server.Processors as int? : null;
|
||||||
|
sysInfo.PhysicalMemoryInMB = isPhysicalMemorySupported ? server.PhysicalMemory as int? : null;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user