Editing ProcessShellRequest
Jump to:
navigation
,
search
When doing a [[Batch Mode and Command-Line Arguments]] setup, here is code for processing the request. Each case selector calls the routine that actually does the work. I typically build the work-code from an interactive GUI form with buttons, then strip the work-code from the button handler, place into a sub, call the sub from the button handler '''and''' from the ProcessShellRequest below. That way, I can run the code in a batch file, but also still run it from the GUI if I need to do some "manual processing." Private Function ProcessShellRequest(ByVal TheArgs() As String, ByVal TheSource As String) As ShellResult Dim ArgArray As List(Of String) = New List(Of String) ArgArray.Clear() Dim StartArg As Integer If Not RunningBatchFile Then ''UserInteractive AndAlso StartArg = 1 ' If interactive, ignore first item (exe file) Else StartArg = 0 ' otherwise, batch mode starts with command End If 'StartArg = 1 'HACK: try this to see if it works better... LogFile.LogEntry("Command line arg count passed to ProcessShellRequest= " & My.Application.CommandLineArgs.Count) For ArgCount = StartArg To TheArgs.Length - 1 Dim Arg As String = TheArgs(ArgCount) LogFile.LogEntry("Command line arg " & ArgCount & " = " & Arg) ArgArray.Add(Arg) Next If ArgArray.Count = 0 Then System.Environment.ExitCode = QuietMode_ExitCode.No_Arg0_Present ' Indicate shell started with no Args LogFile.LogEntry("Exiting due to no Arg present, ExitCode = " & QuietMode_ExitCode.No_Arg0_Present) Exit Function End If Dim ShellRequest As String = LCase(ArgArray(0)) ' Note: ALL "case" selections below MUST be LOWERCASE! LogFile.LogEntry("Shell request = " & ShellRequest) Console.WriteLine("Shell request = " & ShellRequest) Select Case ShellRequest ' Some items removed from examples... Case "db", "database" LogDBinfo() Case "test", "testdb" ' Defaults to Live DB... this sets to Test My.Settings.ITSec_ConnString_RunTime = My.Settings.ITSec_Test_ConnString LogDBinfo() Case "send_email_notices" Dim SEN As New EmailNotices SEN.Send_Email_Notices(LogFile) Case "get_active_imports", "run_active_imports" Process_Run_Active_Imports(ArgArray) Case "get_ad_account_info" Process_Get_AD_Account_Info(ArgArray) Case "do_special_processing_org" DoSpecialProcessing.Process_Special_Organization_Data(LogFile) Case "ignore" ' yep, do nothing here... LogFile.LogEntry("""Ignore"" - no additional action taken") Case "runbatch" LogFile.LogEntry("""RunBatch"" - setting up batch file...") ProcessBatch(ArgArray(1)) Case "stop" LogFile.LogEntry("""Stop"" - stopping any batch file in progress...") ' This is here primarily for early-exit of batch files Return ShellResult.Shell_Stop Exit Function Case Else LogFile.LogEntry("Exiting due to unrecognized Arg0, ExitCode = " & QuietMode_ExitCode.Unknown_Arg0) System.Environment.ExitCode = QuietMode_ExitCode.Unknown_Arg0 ' Indicate shell started with Bad Arg(0) Return ShellResult.Shell_Error Exit Function End Select Return ShellResult.Shell_OK 'Rely on calling routine to exit form and shut down... End Function
|
Editing help
Personal tools
Create account
Log in
Namespaces
Page
Discussion
Variants
Views
Read
Edit
View history
Actions
Search
Navigation
Main page
Community portal
Current events
Recent changes
Random page
Help
Toolbox
What links here
Related changes
Special pages