mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-28 17:24:27 -05:00
Address remaining comments for Object Management Database Handler (#2081)
This commit is contained in:
@@ -19,7 +19,7 @@ using System.Security;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Utility
|
||||
{
|
||||
public class DatabaseUtils
|
||||
public static class DatabaseUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// Check if the database is a system database
|
||||
@@ -328,5 +328,22 @@ namespace Microsoft.SqlTools.ServiceLayer.Utility
|
||||
return new string[0];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes invalid characters from a filename string, replacing each invalid character with an underscore.
|
||||
/// </summary>
|
||||
public static string SanitizeDatabaseFileName(string fileName)
|
||||
{
|
||||
char[] nameChars = fileName.ToCharArray();
|
||||
for (int i = 0; i < nameChars.Length; i++)
|
||||
{
|
||||
if (illegalFilenameCharacters.Contains(nameChars[i]))
|
||||
{
|
||||
nameChars[i] = '_';
|
||||
}
|
||||
}
|
||||
return new string(nameChars);
|
||||
}
|
||||
private static readonly HashSet<char> illegalFilenameCharacters = new HashSet<char>(new char[] { '\\', '/', ':', '*', '?', '"', '<', '>', '|' });
|
||||
}
|
||||
}
|
||||
|
||||
28
src/Microsoft.SqlTools.ServiceLayer/Utility/ServerUtils.cs
Normal file
28
src/Microsoft.SqlTools.ServiceLayer/Utility/ServerUtils.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// 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;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Utility
|
||||
{
|
||||
public static class ServerUtils
|
||||
{
|
||||
public static bool IsManagedInstance(this Server server)
|
||||
{
|
||||
return server.Information?.DatabaseEngineEdition == DatabaseEngineEdition.SqlManagedInstance;
|
||||
}
|
||||
|
||||
public static bool IsArcEnabledManagedInstance(this Server server)
|
||||
{
|
||||
return server.Information?.DatabaseEngineEdition == DatabaseEngineEdition.SqlAzureArcManagedInstance;
|
||||
}
|
||||
|
||||
public static bool IsAnyManagedInstance(this Server server)
|
||||
{
|
||||
return (IsManagedInstance(server) || IsArcEnabledManagedInstance(server));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user