-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for aliases on netcore+Windows (#1588)
* Add support for aliases on netcore+Windows * Add test * Revert spacing * Better partition Windows/Unix code * Add missing files * Fix attempt * Re-work new test * Applying review suggestions * Deduplicate code Co-authored-by: DavoudEshtehari <61173489+DavoudEshtehari@users.noreply.github.com>
- Loading branch information
1 parent
c45c507
commit 3082ae5
Showing
11 changed files
with
330 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/Microsoft.Data.SqlClient/src/Microsoft/Data/Common/AdapterUtil.Unix.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
namespace Microsoft.Data.Common | ||
{ | ||
/// <summary> | ||
/// The class ADP defines the exceptions that are specific to the Adapters. | ||
/// The class contains functions that take the proper informational variables and then construct | ||
/// the appropriate exception with an error string obtained from the resource framework. | ||
/// The exception is then returned to the caller, so that the caller may then throw from its | ||
/// location so that the catcher of the exception will have the appropriate call stack. | ||
/// This class is used so that there will be compile time checking of error messages. | ||
/// The resource Framework.txt will ensure proper string text based on the appropriate locale. | ||
/// </summary> | ||
internal static partial class ADP | ||
{ | ||
internal static object LocalMachineRegistryValue(string subkey, string queryvalue) | ||
{ | ||
// No registry in non-Windows environments | ||
return null; | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/Microsoft.Data.SqlClient/src/Microsoft/Data/Common/AdapterUtil.Windows.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Runtime.InteropServices; | ||
using System.Runtime.Versioning; | ||
using System.Security; | ||
using System.Security.Permissions; | ||
using Microsoft.Win32; | ||
|
||
namespace Microsoft.Data.Common | ||
{ | ||
/// <summary> | ||
/// The class ADP defines the exceptions that are specific to the Adapters. | ||
/// The class contains functions that take the proper informational variables and then construct | ||
/// the appropriate exception with an error string obtained from the resource framework. | ||
/// The exception is then returned to the caller, so that the caller may then throw from its | ||
/// location so that the catcher of the exception will have the appropriate call stack. | ||
/// This class is used so that there will be compile time checking of error messages. | ||
/// The resource Framework.txt will ensure proper string text based on the appropriate locale. | ||
/// </summary> | ||
internal static partial class ADP | ||
{ | ||
[ResourceExposure(ResourceScope.Machine)] | ||
[ResourceConsumption(ResourceScope.Machine)] | ||
internal static object LocalMachineRegistryValue(string subkey, string queryvalue) | ||
{ // MDAC 77697 | ||
(new RegistryPermission(RegistryPermissionAccess.Read, "HKEY_LOCAL_MACHINE\\" + subkey)).Assert(); // MDAC 62028 | ||
try | ||
{ | ||
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(subkey, false)) | ||
{ | ||
return key?.GetValue(queryvalue); | ||
} | ||
} | ||
catch (SecurityException e) | ||
{ | ||
// Even though we assert permission - it's possible there are | ||
// ACL's on registry that cause SecurityException to be thrown. | ||
ADP.TraceExceptionWithoutRethrow(e); | ||
return null; | ||
} | ||
finally | ||
{ | ||
RegistryPermission.RevertAssert(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.