-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathConnectionStringExtensions.cs
More file actions
35 lines (31 loc) · 1.21 KB
/
ConnectionStringExtensions.cs
File metadata and controls
35 lines (31 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
namespace ServiceControl.Transports.ASQ
{
using System.Collections.Generic;
using System.Text.RegularExpressions;
static class ConnectionStringExtensions
{
// using DbConnectionStringBuilder would escape account key and lead to troubles
public static string RemoveCustomConnectionStringParts(this string connectionString, out string subscriptionTable)
{
subscriptionTable = null;
var parts = new List<string>();
var groups = ConnectionStringRegex.Matches(connectionString);
foreach (Match match in groups)
{
switch (match.Groups[2].Value)
{
case SubscriptionsTableName:
subscriptionTable = match.Groups[3].Value;
break;
default:
parts.Add(match.Value);
break;
}
}
return string.Join(';', parts);
}
const string SubscriptionsTableName = "Subscriptions Table";
static readonly Regex ConnectionStringRegex =
new Regex(@"(?<key>[^=;]+)=(?<val>[^;]+(,\d+)?)", RegexOptions.Compiled);
}
}