Skip to content

Commit 2013a71

Browse files
authored
Merge | LocalDbConfig (#3171)
* Move the localdb config classes into common project * Split the LocalDbConfig file into a separate files in the right namespaces (and cleaning them up)
1 parent dcf6ac4 commit 2013a71

File tree

7 files changed

+105
-89
lines changed

7 files changed

+105
-89
lines changed

src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,15 @@
397397
<Compile Include="$(CommonSourceROot)Microsoft\Data\SqlClient\LocalDBAPI.Windows.cs">
398398
<Link>Microsoft\Data\SqlClient\LocalDBAPI.Windows.cs</Link>
399399
</Compile>
400+
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\LocalDb\LocalDbConfigurationSection.netfx.cs">
401+
<Link>Microsoft\Data\SqlClient\LocalDb\LocalDbConfigurationSection.netfx.cs</Link>
402+
</Compile>
403+
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\LocalDb\LocalDbInstanceElement.netfx.cs">
404+
<Link>Microsoft\Data\SqlClient\LocalDb\LocalDbInstanceElement.netfx.cs</Link>
405+
</Compile>
406+
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\LocalDb\LocalDbInstancesCollection.netfx.cs">
407+
<Link>Microsoft\Data\SqlClient\LocalDb\LocalDbInstancesCollection.netfx.cs</Link>
408+
</Compile>
400409
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\LocalAppContextSwitches.cs">
401410
<Link>Microsoft\Data\SqlClient\LocalAppContextSwitches.cs</Link>
402411
</Compile>
@@ -845,7 +854,6 @@
845854
<Compile Include="Microsoft\Data\Common\DbConnectionString.cs" />
846855
<Compile Include="Microsoft\Data\Common\GreenMethods.cs" />
847856
<Compile Include="Microsoft\Data\SqlClient\assemblycache.cs" />
848-
<Compile Include="Microsoft\Data\SqlClient\LocalDBConfig.cs" />
849857
<Compile Include="Microsoft\Data\SqlClient\Reliability\SqlConfigurableRetryLogicManager.LoadType.cs" />
850858
<Compile Include="Microsoft\Data\SqlClient\Server\SmiConnection.cs" />
851859
<Compile Include="Microsoft\Data\SqlClient\Server\SmiContext.cs" />

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/LocalDBConfig.cs

Lines changed: 0 additions & 81 deletions
This file was deleted.

src/Microsoft.Data.SqlClient/src/Microsoft.Data.SqlClient.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<Reference Include="System.Configuration" Condition="'$(TargetFramework)' == 'net462'" />
9+
<Reference Include="System.Configuration" Condition="'$(TargetFramework)' == 'net462'"/>
1010
<Reference Include="System.Transactions" Condition="'$(TargetFramework)' == 'net462'" />
1111
</ItemGroup>
1212
<ItemGroup>

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalDBAPI.Windows.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@
88
using System.Runtime.InteropServices;
99
using System.Security;
1010
using System.Text;
11+
using Interop.Windows.Kernel32;
1112
using Interop.Windows.Sni;
1213
using Microsoft.Data.SqlClient;
13-
using Interop.Windows.Kernel32;
1414

1515
#if NETFRAMEWORK
1616
using System.Collections.Generic;
1717
using System.Configuration;
1818
using System.Runtime.CompilerServices;
1919
using System.Threading;
20+
using Microsoft.Data.SqlClient.LocalDb;
2021
#endif
2122

2223
namespace Microsoft.Data
@@ -182,13 +183,13 @@ internal static void CreateLocalDBInstance(string instance)
182183
if (section != null) // if no section just skip creation
183184
{
184185
// validate section type
185-
LocalDBConfigurationSection configSection = section as LocalDBConfigurationSection;
186+
LocalDbConfigurationSection configSection = section as LocalDbConfigurationSection;
186187
if (configSection == null)
187188
{
188189
throw CreateLocalDBException(errorMessage: StringsHelper.GetString("LocalDB_BadConfigSectionType"));
189190
}
190-
191-
foreach (LocalDBInstanceElement confElement in configSection.LocalDbInstances)
191+
192+
foreach (LocalDbInstanceElement confElement in configSection.LocalDbInstances)
192193
{
193194
Debug.Assert(confElement.Name != null && confElement.Version != null, "Both name and version should not be null");
194195
tempConfigurableInstances.Add(confElement.Name.Trim(), new InstanceInfo(confElement.Version.Trim()));
@@ -215,7 +216,7 @@ internal static void CreateLocalDBInstance(string instance)
215216
if (!s_configurableInstances.TryGetValue(instance, out instanceInfo))
216217
{
217218
// instance name was not in the config
218-
return;
219+
return;
219220
}
220221

221222
if (instanceInfo.created)
@@ -364,7 +365,7 @@ private static SqlException CreateLocalDBException(string errorMessage, string i
364365

365366
if (localDbError != 0)
366367
{
367-
collection.Add(new SqlError(errorCode, 0, TdsEnums.FATAL_ERROR_CLASS, instance, GetLocalDBMessage(localDbError), null, 0));
368+
collection.Add(new SqlError(errorCode, 0, TdsEnums.FATAL_ERROR_CLASS, instance, GetLocalDBMessage(localDbError), null, 0));
368369
}
369370

370371
SqlException exc = SqlException.CreateException(collection, null);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
#if NETFRAMEWORK
6+
7+
using System.Configuration;
8+
9+
namespace Microsoft.Data.SqlClient.LocalDb
10+
{
11+
internal sealed class LocalDbConfigurationSection : ConfigurationSection
12+
{
13+
[ConfigurationProperty("localdbinstances", IsRequired = true)]
14+
public LocalDbInstancesCollection LocalDbInstances =>
15+
(LocalDbInstancesCollection)this["localdbinstances"] ?? new LocalDbInstancesCollection();
16+
}
17+
}
18+
19+
#endif
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
#if NETFRAMEWORK
6+
7+
using System.Configuration;
8+
9+
namespace Microsoft.Data.SqlClient.LocalDb
10+
{
11+
internal sealed class LocalDbInstanceElement : ConfigurationElement
12+
{
13+
[ConfigurationProperty("name", IsRequired = true)]
14+
public string Name => this["name"] as string;
15+
16+
[ConfigurationProperty("version", IsRequired = true)]
17+
public string Version => this["version"] as string;
18+
}
19+
}
20+
21+
#endif
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
#if NETFRAMEWORK
6+
7+
using System;
8+
using System.Collections;
9+
using System.Configuration;
10+
11+
namespace Microsoft.Data.SqlClient.LocalDb
12+
{
13+
internal sealed class LocalDbInstancesCollection : ConfigurationElementCollection
14+
{
15+
private static readonly TrimOrdinalIgnoreCaseStringComparer s_comparer = new TrimOrdinalIgnoreCaseStringComparer();
16+
17+
internal LocalDbInstancesCollection()
18+
: base(s_comparer)
19+
{
20+
}
21+
22+
protected override ConfigurationElement CreateNewElement() =>
23+
new LocalDbInstanceElement();
24+
25+
protected override object GetElementKey(ConfigurationElement element) =>
26+
((LocalDbInstanceElement)element).Name;
27+
28+
private class TrimOrdinalIgnoreCaseStringComparer : IComparer
29+
{
30+
public int Compare(object x, object y)
31+
{
32+
if (x is string xStr)
33+
{
34+
x = xStr.Trim();
35+
}
36+
37+
if (y is string yStr)
38+
{
39+
y = yStr.Trim();
40+
}
41+
42+
return StringComparer.OrdinalIgnoreCase.Compare(x, y);
43+
}
44+
}
45+
}
46+
}
47+
48+
#endif

0 commit comments

Comments
 (0)