Merge branch 'master' of http://dd-vmp07-com04:3000/AppStd/Monorepo
This commit is contained in:
commit
9a638bf814
@ -2,6 +2,7 @@
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.Config
|
||||
Imports DigitalData.Modules.Logging.LogConfig
|
||||
Imports System.Text.RegularExpressions
|
||||
|
||||
Namespace My
|
||||
' Für MyApplication sind folgende Ereignisse verfügbar:
|
||||
@ -39,6 +40,13 @@ Namespace My
|
||||
|
||||
_Logger = LogConfig.GetLogger()
|
||||
_Logger.Debug("Starting Client Suite..")
|
||||
|
||||
Dim oCommandLineArgs As New ClassCommandlineArgs(LogConfig)
|
||||
Dim oArgs = Environment.GetCommandLineArgs().Skip(1).ToList()
|
||||
oCommandLineArgs.Parse(oArgs)
|
||||
|
||||
CommandLineFunction = oCommandLineArgs.FunctionName
|
||||
CommandLineArgs = oCommandLineArgs.FunctionArgs
|
||||
End Sub
|
||||
|
||||
Public Sub App_Shutdown(sender As Object, e As EventArgs) Handles Me.Shutdown
|
||||
|
||||
62
GUIs.ZooFlow/ClassCommandlineArgs.vb
Normal file
62
GUIs.ZooFlow/ClassCommandlineArgs.vb
Normal file
@ -0,0 +1,62 @@
|
||||
Imports System.Text.RegularExpressions
|
||||
Imports DigitalData.Modules.Logging
|
||||
|
||||
''' <summary>
|
||||
''' Parses Commandline Arguments. Used to jump to a specific point in the application.
|
||||
'''
|
||||
''' Example: --start-search=id#7~doctype#ARE
|
||||
''' </summary>
|
||||
Public Class ClassCommandlineArgs
|
||||
Private CommandLineArgTypes As New List(Of String) From {
|
||||
"show-profile",
|
||||
"start-search"
|
||||
}
|
||||
Private CommandLineArgTypeString As String = String.Join("|", CommandLineArgTypes)
|
||||
Private CommandLineArgRegex As String = $"(?:-{{2}}(?:({CommandLineArgTypeString})+)=([a-zA-Z0-9~#]+)\s*)+"
|
||||
Private CommandLineArgParameterRegex As String = "(?:~{0,1}([\w\d-]+#[\w\d-]+))+"
|
||||
|
||||
Public FunctionName As String
|
||||
Public FunctionArgs As New Dictionary(Of String, String)
|
||||
|
||||
Private LogConfig As LogConfig
|
||||
Private Logger As Logger
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig)
|
||||
LogConfig = pLogConfig
|
||||
Logger = pLogConfig.GetLogger()
|
||||
End Sub
|
||||
|
||||
Public Sub Parse(Args As List(Of String))
|
||||
Dim oRegex = New Regex(CommandLineArgRegex)
|
||||
Dim oArgRegex = New Regex(CommandLineArgParameterRegex)
|
||||
|
||||
Logger.Debug("Application started with {0} arguments", Args.Count)
|
||||
|
||||
For Each oArg In Args
|
||||
Dim oMatch = oRegex.Match(oArg)
|
||||
Dim oGroups = oMatch.Groups
|
||||
|
||||
If oMatch.Success = False Then
|
||||
Logger.Warn("The Argument [{0}] did not match the required format and was discarded!", oArg)
|
||||
Continue For
|
||||
End If
|
||||
|
||||
Dim oParamName As String = oGroups.Item(1).Value.Replace("--", "")
|
||||
Dim oParamValue As String = oGroups.Item(2).Value
|
||||
|
||||
If oArgRegex.IsMatch(oParamValue) Then
|
||||
FunctionName = oParamName
|
||||
|
||||
For Each oValue As String In oParamValue.Split("~"c)
|
||||
Dim oValueArray = oValue.Split("#"c).ToList
|
||||
FunctionArgs.Add(oValueArray.Item(0), oValueArray.Item(1))
|
||||
Next
|
||||
Else
|
||||
Throw New ArgumentException($"Parameters did not match the required format!", "pValue")
|
||||
End If
|
||||
|
||||
Next
|
||||
End Sub
|
||||
|
||||
|
||||
End Class
|
||||
@ -50,7 +50,8 @@ Namespace My
|
||||
|
||||
Public Property GDPictureLicense As String
|
||||
|
||||
|
||||
Public CommandLineFunction As String
|
||||
Public CommandLineArgs As New Dictionary(Of String, String)
|
||||
End Class
|
||||
End Namespace
|
||||
|
||||
|
||||
@ -106,6 +106,7 @@
|
||||
<Compile Include="ApplicationEvents.vb" />
|
||||
<Compile Include="Base\BaseClass.vb" />
|
||||
<Compile Include="ClassClipboardWatcher.vb" />
|
||||
<Compile Include="ClassCommandlineArgs.vb" />
|
||||
<Compile Include="ClassControlCreator.vb" />
|
||||
<Compile Include="ClassFileDrop.vb" />
|
||||
<Compile Include="ClassFilehandle.vb" />
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user