Skip to content

Commit

Permalink
Deduplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
David-Engel committed May 19, 2022
1 parent d732366 commit 55aff92
Showing 1 changed file with 1 addition and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static void ConnectManagedWithInstanceNameTest(bool useMultiSubnetFailove
builder.IPAddressPreference = ipPreference;


Assert.True(ParseDataSource(builder.DataSource, out string hostname, out _, out string instanceName));
Assert.True(DataTestUtility.ParseDataSource(builder.DataSource, out string hostname, out _, out string instanceName));

if (IsBrowserAlive(hostname) && IsValidInstance(hostname, instanceName))
{
Expand Down Expand Up @@ -82,40 +82,6 @@ public static void ConnectManagedWithInstanceNameTest(bool useMultiSubnetFailove
}
}

private static bool ParseDataSource(string dataSource, out string hostname, out int port, out string instanceName)
{
hostname = string.Empty;
port = -1;
instanceName = string.Empty;

if (dataSource.Contains(",") && dataSource.Contains("\\"))
return false;

if (dataSource.Contains(":"))
{
dataSource = dataSource.Substring(dataSource.IndexOf(":") + 1);
}

if (dataSource.Contains(","))
{
if (!int.TryParse(dataSource.Substring(dataSource.LastIndexOf(",") + 1), out port))
{
return false;
}
dataSource = dataSource.Substring(0, dataSource.IndexOf(",") - 1);
}

if (dataSource.Contains("\\"))
{
instanceName = dataSource.Substring(dataSource.LastIndexOf("\\") + 1);
dataSource = dataSource.Substring(0, dataSource.LastIndexOf("\\"));
}

hostname = dataSource;

return hostname.Length > 0 && hostname.IndexOfAny(new char[] { '\\', ':', ',' }) == -1;
}

private static bool IsBrowserAlive(string browserHostname)
{
const byte ClntUcastEx = 0x03;
Expand Down

0 comments on commit 55aff92

Please sign in to comment.