small changes and fixes for jobrunner
This commit is contained in:
@@ -2,22 +2,28 @@
|
||||
Imports System.Text.RegularExpressions
|
||||
|
||||
Public Class JobConfigParser
|
||||
Private Shared JobOptionsRegex As New Regex("(?<enabled>True|False)\|(?<cron>[\w\d\s,\?*-/]*)(?:\|(?<args>(?:\w*::\w*,?)*))?")
|
||||
Private Shared JobArgumentsRegex As New Regex("(?:(?:\w+::\w+,?)?)+")
|
||||
Private Shared JobOptionsRegex As New Regex("(?<enabled>True|False)\|(?<cron>[\w\d\s,\?*-/]*)(?:\|(?<args>(?:\w*::[^,\n]+,?)*))?")
|
||||
Private Shared JobArgumentsRegex As New Regex("(?:(?:\w+::[^,\n]+,?)?)+")
|
||||
Private Const ARGS_ITEM_DELIMITER As String = ","
|
||||
Private Const ARGS_KEYVALUE_DELIMITER As String = "::"
|
||||
Private Const ARGS_LIST_DELIMITER As String = "|"
|
||||
|
||||
|
||||
Public Shared Function ParseConfig(ConfigString As String) As JobConfig
|
||||
If JobOptionsRegex.IsMatch(ConfigString) Then
|
||||
Dim oMatches = JobOptionsRegex.Matches(ConfigString)
|
||||
Dim oOptions As New JobConfig
|
||||
|
||||
If oMatches.Count = 1 Then
|
||||
Dim oMatch = oMatches.Item(0)
|
||||
Dim oSplitOptions As String() = ConfigString.Split(ARGS_LIST_DELIMITER)
|
||||
|
||||
oOptions.Enabled = CBool(oMatch.Groups("enabled").Value)
|
||||
oOptions.CronExpression = oMatch.Groups("cron").Value
|
||||
oOptions.Arguments = ParseOptionalArguments(oMatch.Groups("args").Value)
|
||||
If oSplitOptions.Length = 3 Then
|
||||
oOptions.Enabled = CBool(oSplitOptions(0))
|
||||
oOptions.CronExpression = oSplitOptions(1)
|
||||
oOptions.Arguments = New Dictionary(Of String, String)
|
||||
ElseIf oSplitOptions.Length = 2 Then
|
||||
oOptions.Enabled = CBool(oSplitOptions(0))
|
||||
oOptions.CronExpression = oSplitOptions(1)
|
||||
oOptions.Arguments = ParseOptionalArguments(oSplitOptions(2))
|
||||
Else
|
||||
Throw New ArgumentException("Config Malformed")
|
||||
End If
|
||||
@@ -37,6 +43,7 @@ Public Class JobConfigParser
|
||||
For Each oArg In oArgs
|
||||
Dim oDelimiter As String() = New String() {ARGS_KEYVALUE_DELIMITER}
|
||||
Dim oArgSplit = oArg.Split(oDelimiter, StringSplitOptions.RemoveEmptyEntries)
|
||||
Regex.Split(oArg, "::")
|
||||
|
||||
If oArgSplit.Length = 2 Then
|
||||
oArgsDictionary.Add(oArgSplit(0), oArgSplit(1))
|
||||
|
||||
Reference in New Issue
Block a user