Skip to content

Commit

Permalink
Fix | SqlDSEnumerator net core (#3)
Browse files Browse the repository at this point in the history
SqlDataSourceEnumerator test update and different file for unix, windows
  • Loading branch information
DavoudEshtehari committed Mar 8, 2022
1 parent 81e26f6 commit 7ff8220
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,5 @@ internal enum SniSpecialErrors : uint
// max error code value
MaxErrorValue = SNICommon.MaxErrorValue
}

[DllImport(SNI, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SNIServerEnumOpenWrapper")]
internal static extern IntPtr SNIServerEnumOpen();

[DllImport(SNI, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SNIServerEnumCloseWrapper")]
internal static extern void SNIServerEnumClose([In] IntPtr packet);

[DllImport(SNI, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SNIServerEnumReadWrapper", CharSet = CharSet.Unicode)]
internal static extern int SNIServerEnumRead([In] IntPtr packet,
[In][MarshalAs(UnmanagedType.LPArray)] char[] readBuffer,
[In] int bufferLength,
[MarshalAs(UnmanagedType.Bool)] out bool more);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,19 @@ internal struct SNI_Error

[DllImport(SNI, CallingConvention = CallingConvention.Cdecl)]
private static extern uint SNIWriteSyncOverAsync(SNIHandle pConn, [In] SNIPacket pPacket);
#endregion

[DllImport(SNI, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SNIServerEnumOpenWrapper")]
internal static extern IntPtr SNIServerEnumOpen();

[DllImport(SNI, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SNIServerEnumCloseWrapper")]
internal static extern void SNIServerEnumClose([In] IntPtr packet);

[DllImport(SNI, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SNIServerEnumReadWrapper", CharSet = CharSet.Unicode)]
internal static extern int SNIServerEnumRead([In] IntPtr packet,
[In][MarshalAs(UnmanagedType.LPArray)] char[] readBuffer,
[In] int bufferLength,
[MarshalAs(UnmanagedType.Bool)] out bool more);
#endregion

internal static uint SniGetConnectionId(SNIHandle pConn, ref Guid connId)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@
</Compile>
<Compile Include="..\..\src\Microsoft\Data\Sql\SqlDataSourceEnumeratorManagedHelper.cs">
<Link>Microsoft\Data\Sql\SqlDataSourceEnumeratorManagedHelper.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\Sql\SqlDataSourceEnumeratorNativeHelper.cs">
<Link>Microsoft\Data\Sql\SqlDataSourceEnumeratorNativeHelper.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\Sql\SqlDataSourceEnumeratorUtil.cs">
<Link>Microsoft\Data\Sql\SqlDataSourceEnumeratorUtil.cs</Link>
Expand Down Expand Up @@ -645,6 +642,12 @@
</ItemGroup>
<!-- Windows only -->
<ItemGroup Condition="'$(TargetsWindows)' == 'true'">
<Compile Include="..\..\src\Microsoft\Data\Sql\SqlDataSourceEnumeratorNativeHelper.cs">
<Link>Microsoft\Data\Sql\SqlDataSourceEnumeratorNativeHelper.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\Sql\SqlDataSourceEnumerator.Windows.cs">
<Link>Microsoft\Data\Sql\SqlDataSourceEnumerator.Windows.cs</Link>
</Compile>
<Compile Include="Microsoft\Data\SqlClient\SqlColumnEncryptionCertificateStoreProvider.Windows.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlColumnEncryptionCngProvider.Windows.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlColumnEncryptionCspProvider.Windows.cs" />
Expand Down Expand Up @@ -873,6 +876,7 @@
</Compile>
</ItemGroup>
<ItemGroup Condition="'$(TargetsWindows)' != 'true' AND '$(OSGroup)' != 'AnyOS'">
<Compile Include="Microsoft\Data\Sql\SqlDataSourceEnumerator.Unix.cs" />
<Compile Include="Microsoft\Data\ProviderBase\DbConnectionPoolIdentity.Unix.cs" />
<Compile Include="Interop\SNINativeMethodWrapper.Unix.cs" />
<Compile Include="$(CommonPath)\System\Net\Security\NegotiateStreamPal.Unix.cs">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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.Data;
using System.Data.Common;
using Microsoft.Data.SqlClient.Server;

namespace Microsoft.Data.Sql
{
/// <include file='../../../../doc/snippets/Microsoft.Data.Sql/SqlDataSourceEnumerator.xml' path='docs/members[@name="SqlDataSourceEnumerator"]/SqlDataSourceEnumerator/*' />
public sealed partial class SqlDataSourceEnumerator : DbDataSourceEnumerator
{
private partial DataTable GetDataSourcesInternal() => SqlDataSourceEnumeratorManagedHelper.GetDataSources();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@
<Compile Include="..\..\src\Microsoft\Data\Sql\SqlDataSourceEnumerator.cs">
<Link>Microsoft\Data\Sql\SqlDataSourceEnumerator.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\Sql\SqlDataSourceEnumerator.Windows.cs">
<Link>Microsoft\Data\Sql\SqlDataSourceEnumerator.Windows.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\Sql\SqlDataSourceEnumeratorNativeHelper.cs">
<Link>Microsoft\Data\Sql\SqlDataSourceEnumeratorNativeHelper.cs</Link>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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.Data;
using System.Data.Common;
using Microsoft.Data.SqlClient.Server;

namespace Microsoft.Data.Sql
{
/// <include file='../../../../doc/snippets/Microsoft.Data.Sql/SqlDataSourceEnumerator.xml' path='docs/members[@name="SqlDataSourceEnumerator"]/SqlDataSourceEnumerator/*' />
public sealed partial class SqlDataSourceEnumerator : DbDataSourceEnumerator
{
private partial DataTable GetDataSourcesInternal()
{
#if NETFRAMEWORK
return SqlDataSourceEnumeratorNativeHelper.GetDataSources();
#else
return SqlClient.TdsParserStateObjectFactory.UseManagedSNI ? SqlDataSourceEnumeratorManagedHelper.GetDataSources() : SqlDataSourceEnumeratorNativeHelper.GetDataSources();
#endif
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,22 @@
using System;
using System.Data;
using System.Data.Common;
using Microsoft.Data.SqlClient.Server;

namespace Microsoft.Data.Sql
{
/// <include file='../../../../doc/snippets/Microsoft.Data.Sql/SqlDataSourceEnumerator.xml' path='docs/members[@name="SqlDataSourceEnumerator"]/SqlDataSourceEnumerator/*' />
public sealed class SqlDataSourceEnumerator : DbDataSourceEnumerator
public sealed partial class SqlDataSourceEnumerator : DbDataSourceEnumerator
{
private static readonly SqlDataSourceEnumerator s_singletonInstance = new();
private static readonly Lazy<SqlDataSourceEnumerator> s_singletonInstance = new(() => new SqlDataSourceEnumerator());

private SqlDataSourceEnumerator() : base()
{
}
private SqlDataSourceEnumerator() : base(){}

/// <include file='../../../../doc/snippets/Microsoft.Data.Sql/SqlDataSourceEnumerator.xml' path='docs/members[@name="SqlDataSourceEnumerator"]/Instance/*' />
public static SqlDataSourceEnumerator Instance => SqlDataSourceEnumerator.s_singletonInstance;
public static SqlDataSourceEnumerator Instance => s_singletonInstance.Value;

/// <include file='../../../../doc/snippets/Microsoft.Data.Sql/SqlDataSourceEnumerator.xml' path='docs/members[@name="SqlDataSourceEnumerator"]/GetDataSources/*' />
override public DataTable GetDataSources()
{
#if NETFRAMEWORK
return SqlDataSourceEnumeratorNativeHelper.GetDataSources();
#else
return SqlClient.TdsParserStateObjectFactory.UseManagedSNI ? throw new NotImplementedException() : SqlDataSourceEnumeratorNativeHelper.GetDataSources();
#endif
}
override public DataTable GetDataSources() => GetDataSourcesInternal();

private partial DataTable GetDataSourcesInternal();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Collections.Generic;
using System.Data;
using Microsoft.Data.Sql;
using Microsoft.Data.SqlClient.SNI;

namespace Microsoft.Data.SqlClient.Server
{
Expand All @@ -19,7 +18,8 @@ internal static class SqlDataSourceEnumeratorManagedHelper
/// <returns>DataTable with ServerName,InstanceName,IsClustered and Version</returns>
internal static DataTable GetDataSources()
{
return ParseServerEnumString(SSRP.SendBroadcastUDPRequest());
// TODO: Implement multicast request besides the implemented broadcast request.
throw new System.NotImplementedException(StringsHelper.net_MethodNotImplementedException);
}

private static DataTable ParseServerEnumString(string serverInstances)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
<Compile Include="SqlCredentialTest.cs" />
<Compile Include="SqlDataRecordTest.cs" />
<Compile Include="SqlErrorTest.cs" />
<Compile Include="SqlDataSourceEnumeratorTest.cs" />
<Compile Include="SqlExceptionTest.cs" />
<Compile Include="SqlFacetAttributeTest.cs" />
<Compile Include="SqlNotificationRequestTest.cs" />
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<Link>TCECryptoNativeBaselineRsa.txt</Link>
</Content>
</ItemGroup>
<ItemGroup Condition="'$(TargetsWindows)' == 'true' AND !$(ReferenceType.Contains('NetStandard')) AND ('$(TestSet)' == '' OR '$(TestSet)' == 'AE')" >
<ItemGroup Condition="'$(TargetsWindows)' == 'true' AND !$(ReferenceType.Contains('NetStandard')) AND ('$(TestSet)' == '' OR '$(TestSet)' == 'AE')">
<Compile Include="AlwaysEncrypted\CspProviderExt.cs" />
<Compile Include="AlwaysEncrypted\TestFixtures\Setup\CertificateUtilityWin.cs" />
<Compile Include="AlwaysEncrypted\TestFixtures\Setup\CspProviderColumnMasterKey.cs" />
Expand Down Expand Up @@ -158,6 +158,7 @@
<Compile Include="SQL\SqlBulkCopyTest\TableLock.cs" />
<Compile Include="SQL\SqlBulkCopyTest\DataConversionErrorMessageTest.cs" />
<Compile Include="SQL\SqlBulkCopyTest\CopyWidenNullInexactNumerics.cs" />
<Compile Include="SQL\SqlDSEnumeratorTest\SqlDataSourceEnumeratorTest.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TestSet)' == '' OR '$(TestSet)' == '3'">
<Compile Include="DDBasics\DDAsyncTest\DDAsyncTest.cs" />
Expand Down Expand Up @@ -239,7 +240,7 @@
<None Include="SQL\ParameterTest\SqlParameterTest_ReleaseMode.bsl" />
<None Include="SQL\ParameterTest\SqlParameterTest_ReleaseMode_Azure.bsl" />
</ItemGroup>
<ItemGroup Condition="'$(TargetGroup)'=='netcoreapp' AND ('$(TestSet)' == '' OR '$(TestSet)' == '3')" >
<ItemGroup Condition="'$(TargetGroup)'=='netcoreapp' AND ('$(TestSet)' == '' OR '$(TestSet)' == '3')">
<Compile Include="TracingTests\EventCounterTest.cs" />
<Compile Include="TracingTests\DiagnosticTest.cs" />
<Compile Include="TracingTests\FakeDiagnosticListenerObserver.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// 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;
using System.ServiceProcess;
using Microsoft.Data.Sql;
using Xunit;

namespace Microsoft.Data.SqlClient.ManualTesting.Tests
{
public class SqlDataSourceEnumeratorTest
{
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsNotUsingManagedSNIOnWindows))]
[PlatformSpecific(TestPlatforms.Windows)]
public void SqlDataSourceEnumerator_NativeSNI()
{
// The returned rows depends on the running services which could be zero or more.
int count = GetDSEnumerator().GetDataSources().Rows.Count;
Assert.InRange(count, 0, 65536);
}

[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsUsingManagedSNI))]
[PlatformSpecific(TestPlatforms.Windows)]
public void SqlDataSourceEnumerator_ManagedSNI()
{
// after adding the managed SNI support, this test should have the same result as SqlDataSourceEnumerator_NativeSNI
Assert.Throws<NotImplementedException>(() => GetDSEnumerator().GetDataSources());
}

private SqlDataSourceEnumerator GetDSEnumerator()
{
ServiceController sc = new("SQLBrowser");
Assert.Equal(ServiceControllerStatus.Running, sc.Status);

return SqlDataSourceEnumerator.Instance;
}
}
}

0 comments on commit 7ff8220

Please sign in to comment.