-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathTaskParameterWrapper.cs
More file actions
38 lines (33 loc) · 1.26 KB
/
TaskParameterWrapper.cs
File metadata and controls
38 lines (33 loc) · 1.26 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
36
37
38
using System.Text.RegularExpressions;
using HackSystem.WebAPI.TaskServer.Application.ParameterWrappers;
namespace HackSystem.WebAPI.TaskServer.Infrastructure.ParameterWrappers;
public class TaskParameterWrapper : ITaskParameterWrapper
{
protected Regex ParameterRegex { get; init; } = new Regex(
"\\|?(?<Name>[^=\\|]+)=(?<Value>[^\\|]+)",
RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.Compiled);
/// <remarks>
/// Shouldn't have '=' or '|' in parameter name.
/// Shouldn't have '|' in value, to support BASE64 value.
/// </remarks>
public Dictionary<string, string>? WrapTaskParameters(string taskParameters)
{
if (string.IsNullOrWhiteSpace(taskParameters))
{
return default;
}
var matches = this.ParameterRegex.Matches(taskParameters);
if (matches.Count == 0)
{
return default;
}
var parameterDictionary = new Dictionary<string, string>();
foreach (var match in matches.Cast<Match>().Where(m => m.Success))
{
var name = match.Groups["Name"].Value;
var value = match.Groups["Value"].Value;
parameterDictionary[name] = value;
}
return parameterDictionary;
}
}