mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-29 17:24:34 -05:00
Added service class for machine learning services operations (#906)
* Added service class for server configurations and language extension
This commit is contained in:
@@ -18,6 +18,8 @@ using Microsoft.SqlTools.ServiceLayer.EditData;
|
||||
using Microsoft.SqlTools.ServiceLayer.FileBrowser;
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting;
|
||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices;
|
||||
using Microsoft.SqlTools.ServiceLayer.ServerConfigurations;
|
||||
using Microsoft.SqlTools.ServiceLayer.LanguageExtensions;
|
||||
using Microsoft.SqlTools.ServiceLayer.Metadata;
|
||||
using Microsoft.SqlTools.ServiceLayer.Profiler;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||
@@ -122,6 +124,12 @@ namespace Microsoft.SqlTools.ServiceLayer
|
||||
SchemaCompare.SchemaCompareService.Instance.InitializeService(serviceHost);
|
||||
serviceProvider.RegisterSingleService(SchemaCompareService.Instance);
|
||||
|
||||
ServerConfigService.Instance.InitializeService(serviceHost);
|
||||
serviceProvider.RegisterSingleService(ServerConfigService.Instance);
|
||||
|
||||
LanguageExtensionsService.Instance.InitializeService(serviceHost);
|
||||
serviceProvider.RegisterSingleService(LanguageExtensionsService.Instance);
|
||||
|
||||
InitializeHostedServices(serviceProvider, serviceHost);
|
||||
serviceHost.ServiceProvider = serviceProvider;
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
//
|
||||
// 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.Hosting.Protocol.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.LanguageExtensions.Contracts
|
||||
{
|
||||
public class ExternalLanguageStatusRequestParams
|
||||
{
|
||||
/// <summary>
|
||||
/// Connection uri
|
||||
/// </summary>
|
||||
public string OwnerUri { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Language name
|
||||
/// </summary>
|
||||
public string LanguageName { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Response class for external language status
|
||||
/// </summary>
|
||||
public class ExternalLanguageStatusResponseParams
|
||||
{
|
||||
/// <summary>
|
||||
/// Language status
|
||||
/// </summary>
|
||||
public bool Status { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request class for external language status
|
||||
/// </summary>
|
||||
public class ExternalLanguageStatusRequest
|
||||
{
|
||||
public static readonly
|
||||
RequestType<ExternalLanguageStatusRequestParams, ExternalLanguageStatusResponseParams> Type =
|
||||
RequestType<ExternalLanguageStatusRequestParams, ExternalLanguageStatusResponseParams>.Create("languageextension/status");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System.Data;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.LanguageExtensions
|
||||
{
|
||||
public class LanguageExtensionOperations
|
||||
{
|
||||
private const string LanguageStatusScript = @"SELECT is_installed
|
||||
FROM sys.dm_db_external_language_stats s, sys.external_languages l
|
||||
WHERE s.external_language_id = l.external_language_id AND language = @LanguageName";
|
||||
|
||||
/// <summary>
|
||||
/// Returns the status of external languages in a connection
|
||||
/// </summary>
|
||||
/// <param name="connection"></param>
|
||||
/// <param name="languageName"></param>
|
||||
/// <returns></returns>
|
||||
public bool GetLanguageStatus(IDbConnection connection, string languageName)
|
||||
{
|
||||
bool status = false;
|
||||
try
|
||||
{
|
||||
using (IDbCommand command = connection.CreateCommand())
|
||||
{
|
||||
command.CommandText = LanguageStatusScript;
|
||||
var parameter = command.CreateParameter();
|
||||
parameter.ParameterName = "@LanguageName";
|
||||
parameter.Value = languageName;
|
||||
command.Parameters.Add(parameter);
|
||||
using (IDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
status = (reader[0].ToString() == "True");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
status = false;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
//
|
||||
// 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.Hosting.Protocol;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting;
|
||||
using Microsoft.SqlTools.ServiceLayer.LanguageExtensions.Contracts;
|
||||
using Microsoft.SqlTools.Utility;
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.LanguageExtensions
|
||||
{
|
||||
public class LanguageExtensionsService
|
||||
{
|
||||
private LanguageExtensionOperations serviceOperations = new LanguageExtensionOperations();
|
||||
private ConnectionService connectionService = null;
|
||||
private static readonly Lazy<LanguageExtensionsService> instance = new Lazy<LanguageExtensionsService>(() => new LanguageExtensionsService());
|
||||
|
||||
/// <summary>
|
||||
/// Gets the singleton instance object
|
||||
/// </summary>
|
||||
public static LanguageExtensionsService Instance
|
||||
{
|
||||
get { return instance.Value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Internal for testing purposes only
|
||||
/// </summary>
|
||||
internal ConnectionService ConnectionServiceInstance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (connectionService == null)
|
||||
{
|
||||
connectionService = ConnectionService.Instance;
|
||||
}
|
||||
return connectionService;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
connectionService = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void InitializeService(ServiceHost serviceHost)
|
||||
{
|
||||
serviceHost.SetRequestHandler(ExternalLanguageStatusRequest.Type, this.HandleExternalLanguageStatusRequest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles external language status request
|
||||
/// </summary>
|
||||
/// <param name="parameters">Request parameters</param>
|
||||
/// <param name="requestContext">Request Context</param>
|
||||
/// <returns></returns>
|
||||
public async Task HandleExternalLanguageStatusRequest(ExternalLanguageStatusRequestParams parameters, RequestContext<ExternalLanguageStatusResponseParams> requestContext)
|
||||
{
|
||||
Logger.Write(TraceEventType.Verbose, "HandleExternalLanguageStatusRequest");
|
||||
try
|
||||
{
|
||||
ConnectionInfo connInfo;
|
||||
ConnectionServiceInstance.TryFindConnection(
|
||||
parameters.OwnerUri,
|
||||
out connInfo);
|
||||
ExternalLanguageStatusResponseParams response = new ExternalLanguageStatusResponseParams
|
||||
{
|
||||
Status = false,
|
||||
};
|
||||
|
||||
if (connInfo == null)
|
||||
{
|
||||
await requestContext.SendError(new Exception(SR.ProfilerConnectionNotFound));
|
||||
}
|
||||
else
|
||||
{
|
||||
using (IDbConnection dbConnection = ConnectionService.OpenSqlConnection(connInfo))
|
||||
{
|
||||
response.Status = serviceOperations.GetLanguageStatus(dbConnection, parameters.LanguageName);
|
||||
}
|
||||
|
||||
await requestContext.SendResult(response);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Exception related to run task will be captured here
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
//
|
||||
// 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.Hosting.Protocol.Contracts;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.ServerConfigurations.Contracts
|
||||
{
|
||||
public class ServerConfigListRequestParams
|
||||
{
|
||||
/// <summary>
|
||||
/// Connection uri
|
||||
/// </summary>
|
||||
public string OwnerUri { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Config Number
|
||||
/// </summary>
|
||||
public int ConfigNumber { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Response class for config list
|
||||
/// </summary>
|
||||
public class ServerConfigListResponseParams
|
||||
{
|
||||
/// <summary>
|
||||
/// Config Property
|
||||
/// </summary>
|
||||
public List<ServerConfigProperty> ConfigProperties { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request class for config list
|
||||
/// </summary>
|
||||
public class ServerConfigListRequest
|
||||
{
|
||||
public static readonly
|
||||
RequestType<ServerConfigListRequestParams, ServerConfigListResponseParams> Type =
|
||||
RequestType<ServerConfigListRequestParams, ServerConfigListResponseParams>.Create("config/List");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlServer.Management.Smo;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.ServerConfigurations.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// A wrapper for SMO config property
|
||||
/// </summary>
|
||||
public class ServerConfigProperty
|
||||
{
|
||||
public int Number { get; set; }
|
||||
|
||||
public string DisplayName { get; set; }
|
||||
|
||||
public string Description { get; set; }
|
||||
|
||||
public int ConfigValue { get; set; }
|
||||
|
||||
public int Maximum { get; set; }
|
||||
|
||||
public int Minimum { get; set; }
|
||||
|
||||
public static ServerConfigProperty ToServerConfigProperty(ConfigProperty configProperty)
|
||||
{
|
||||
if (configProperty != null)
|
||||
{
|
||||
return new ServerConfigProperty
|
||||
{
|
||||
Number = configProperty.Number,
|
||||
DisplayName = configProperty.DisplayName,
|
||||
ConfigValue = configProperty.ConfigValue,
|
||||
Maximum = configProperty.Maximum,
|
||||
Minimum = configProperty.Minimum
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
//
|
||||
// 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.Hosting.Protocol.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.ServerConfigurations.Contracts
|
||||
{
|
||||
public class ServerConfigUpdateRequestParams
|
||||
{
|
||||
/// <summary>
|
||||
/// Connection uri
|
||||
/// </summary>
|
||||
public string OwnerUri { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Config number
|
||||
/// </summary>
|
||||
public int ConfigNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Config value
|
||||
/// </summary>
|
||||
public int ConfigValue { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Response class for config update
|
||||
/// </summary>
|
||||
public class ServerConfigUpdateResponseParams
|
||||
{
|
||||
/// <summary>
|
||||
/// Config Property
|
||||
/// </summary>
|
||||
public ServerConfigProperty ConfigProperty { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request class for config update
|
||||
/// </summary>
|
||||
public class ServerConfigUpdateRequest
|
||||
{
|
||||
public static readonly
|
||||
RequestType<ServerConfigUpdateRequestParams, ServerConfigUpdateResponseParams> Type =
|
||||
RequestType<ServerConfigUpdateRequestParams, ServerConfigUpdateResponseParams>.Create("config/update");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
//
|
||||
// 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.Hosting.Protocol.Contracts;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.ServerConfigurations.Contracts
|
||||
{
|
||||
public class ServerConfigViewRequestParams
|
||||
{
|
||||
/// <summary>
|
||||
/// Connection uri
|
||||
/// </summary>
|
||||
public string OwnerUri { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Config Number
|
||||
/// </summary>
|
||||
public int ConfigNumber { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Response class for config view
|
||||
/// </summary>
|
||||
public class ServerConfigViewResponseParams
|
||||
{
|
||||
/// <summary>
|
||||
/// Config Property
|
||||
/// </summary>
|
||||
public ServerConfigProperty ConfigProperty { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request class for config view
|
||||
/// </summary>
|
||||
public class ServerConfigViewRequest
|
||||
{
|
||||
public static readonly
|
||||
RequestType<ServerConfigViewRequestParams, ServerConfigViewResponseParams> Type =
|
||||
RequestType<ServerConfigViewRequestParams, ServerConfigViewResponseParams>.Create("config/view");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.ServerConfigurations
|
||||
{
|
||||
/// <summary>
|
||||
/// Exception raised from machine learning services operations
|
||||
/// </summary>
|
||||
public class ServerConfigException : Exception
|
||||
{
|
||||
internal ServerConfigException() : base()
|
||||
{
|
||||
}
|
||||
|
||||
internal ServerConfigException(string m) : base(m)
|
||||
{
|
||||
}
|
||||
|
||||
internal ServerConfigException(string m, Exception innerException) : base(m, innerException)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,244 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlServer.Management.Common;
|
||||
using Microsoft.SqlServer.Management.Smo;
|
||||
using Microsoft.SqlTools.Hosting.Protocol;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting;
|
||||
using Microsoft.SqlTools.ServiceLayer.ServerConfigurations.Contracts;
|
||||
using Microsoft.SqlTools.Utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.ServerConfigurations
|
||||
{
|
||||
public class ServerConfigService
|
||||
{
|
||||
private ConnectionService connectionService = null;
|
||||
private static readonly Lazy<ServerConfigService> instance = new Lazy<ServerConfigService>(() => new ServerConfigService());
|
||||
|
||||
/// <summary>
|
||||
/// Gets the singleton instance object
|
||||
/// </summary>
|
||||
public static ServerConfigService Instance
|
||||
{
|
||||
get { return instance.Value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Internal for testing purposes only
|
||||
/// </summary>
|
||||
internal ConnectionService ConnectionServiceInstance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (connectionService == null)
|
||||
{
|
||||
connectionService = ConnectionService.Instance;
|
||||
}
|
||||
return connectionService;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
connectionService = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void InitializeService(ServiceHost serviceHost)
|
||||
{
|
||||
serviceHost.SetRequestHandler(ServerConfigViewRequest.Type, this.HandleServerConfigViewRequest);
|
||||
serviceHost.SetRequestHandler(ServerConfigUpdateRequest.Type, this.HandleServerConfigUpdateRequest);
|
||||
serviceHost.SetRequestHandler(ServerConfigListRequest.Type, this.HandleServerConfigListRequest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles config view request
|
||||
/// </summary>
|
||||
/// <param name="parameters">Request parameters</param>
|
||||
/// <param name="requestContext">Request Context</param>
|
||||
/// <returns></returns>
|
||||
public async Task HandleServerConfigViewRequest(ServerConfigViewRequestParams parameters, RequestContext<ServerConfigViewResponseParams> requestContext)
|
||||
{
|
||||
Logger.Write(TraceEventType.Verbose, "HandleServerConfigViewRequest");
|
||||
try
|
||||
{
|
||||
ConnectionInfo connInfo;
|
||||
ConnectionServiceInstance.TryFindConnection(
|
||||
parameters.OwnerUri,
|
||||
out connInfo);
|
||||
if (connInfo == null)
|
||||
{
|
||||
await requestContext.SendError(new Exception(SR.ProfilerConnectionNotFound));
|
||||
}
|
||||
else
|
||||
{
|
||||
var serverConnection = ConnectionService.OpenServerConnection(connInfo);
|
||||
ServerConfigProperty serverConfig = GetConfig(serverConnection, parameters.ConfigNumber);
|
||||
await requestContext.SendResult(new ServerConfigViewResponseParams
|
||||
{
|
||||
ConfigProperty = serverConfig
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Exception related to run task will be captured here
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles config update request
|
||||
/// </summary>
|
||||
/// <param name="parameters">Request parameters</param>
|
||||
/// <param name="requestContext">Request Context</param>
|
||||
/// <returns></returns>
|
||||
public async Task HandleServerConfigUpdateRequest(ServerConfigUpdateRequestParams parameters, RequestContext<ServerConfigUpdateResponseParams> requestContext)
|
||||
{
|
||||
Logger.Write(TraceEventType.Verbose, "HandleServerConfigUpdateRequest");
|
||||
try
|
||||
{
|
||||
ConnectionInfo connInfo;
|
||||
ConnectionServiceInstance.TryFindConnection(
|
||||
parameters.OwnerUri,
|
||||
out connInfo);
|
||||
ServerConfigUpdateResponseParams response = new ServerConfigUpdateResponseParams
|
||||
{
|
||||
};
|
||||
|
||||
if (connInfo == null)
|
||||
{
|
||||
await requestContext.SendError(new Exception(SR.ProfilerConnectionNotFound));
|
||||
}
|
||||
else
|
||||
{
|
||||
var serverConnection = ConnectionService.OpenServerConnection(connInfo);
|
||||
UpdateConfig(serverConnection, parameters.ConfigNumber, parameters.ConfigValue);
|
||||
response.ConfigProperty = GetConfig(serverConnection, parameters.ConfigNumber);
|
||||
await requestContext.SendResult(response);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Exception related to run task will be captured here
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles config list request
|
||||
/// </summary>
|
||||
/// <param name="parameters">Request parameters</param>
|
||||
/// <param name="requestContext">Request Context</param>
|
||||
public async Task HandleServerConfigListRequest(ServerConfigListRequestParams parameters, RequestContext<ServerConfigListResponseParams> requestContext)
|
||||
{
|
||||
Logger.Write(TraceEventType.Verbose, "HandleServerConfigListRequest");
|
||||
try
|
||||
{
|
||||
ConnectionInfo connInfo;
|
||||
ConnectionServiceInstance.TryFindConnection(
|
||||
parameters.OwnerUri,
|
||||
out connInfo);
|
||||
ServerConfigListResponseParams response = new ServerConfigListResponseParams
|
||||
{
|
||||
};
|
||||
|
||||
if (connInfo == null)
|
||||
{
|
||||
await requestContext.SendError(new Exception(SR.ProfilerConnectionNotFound));
|
||||
}
|
||||
else
|
||||
{
|
||||
var serverConnection = ConnectionService.OpenServerConnection(connInfo);
|
||||
response.ConfigProperties = GetConfigs(serverConnection);
|
||||
await requestContext.SendResult(response);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Exception related to run task will be captured here
|
||||
await requestContext.SendError(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Updates external script in a given server. Throws exception if server doesn't support external script
|
||||
/// </summary>
|
||||
/// <param name="serverConnection"></param>
|
||||
/// <param name="configValue"></param>
|
||||
public void UpdateConfig(ServerConnection serverConnection, int configNumber, int configValue)
|
||||
{
|
||||
Server server = new Server(serverConnection);
|
||||
ConfigProperty serverConfig = GetSmoConfig(server, configNumber);
|
||||
|
||||
if (serverConfig != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
serverConfig.ConfigValue = configValue;
|
||||
server.Configuration.Alter(true);
|
||||
}
|
||||
catch (FailedOperationException ex)
|
||||
{
|
||||
throw new ServerConfigException($"Failed to update config. config number: ${configNumber}", ex);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ServerConfigException($"Server doesn't have config. config number: ${configNumber}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns current value of external script config
|
||||
/// </summary>
|
||||
/// <param name="serverConnection"></param>
|
||||
/// <returns></returns>
|
||||
private ServerConfigProperty GetConfig(ServerConnection serverConnection, int configNumber)
|
||||
{
|
||||
Server server = new Server(serverConnection);
|
||||
ConfigProperty serverConfig = GetSmoConfig(server, configNumber);
|
||||
return serverConfig != null ? ServerConfigProperty.ToServerConfigProperty(serverConfig) : null;
|
||||
}
|
||||
|
||||
private List<ServerConfigProperty> GetConfigs(ServerConnection serverConnection)
|
||||
{
|
||||
Server server = new Server(serverConnection);
|
||||
List<ServerConfigProperty> list = new List<ServerConfigProperty>();
|
||||
foreach (ConfigProperty serverConfig in server.Configuration.Properties)
|
||||
{
|
||||
list.Add(serverConfig != null ? ServerConfigProperty.ToServerConfigProperty(serverConfig) : null);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private ConfigProperty GetSmoConfig(Server server, int configNumber)
|
||||
{
|
||||
try
|
||||
{
|
||||
ConfigProperty serverConfig = null;
|
||||
foreach (ConfigProperty configProperty in server.Configuration.Properties)
|
||||
{
|
||||
if (configProperty.Number == configNumber)
|
||||
{
|
||||
serverConfig = configProperty;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return serverConfig;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new ServerConfigException($"Failed to get config. config number: ${configNumber}", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user