clsBatchBase¶
clsBatchBase (MustInherit, Inherits clsConsoleBase) is the abstract ancestor class for batch-style console applications. It extends the clsConsoleBase lifecycle with multi-stream, environment-variable-driven file logging and batch header/footer status reporting.
Purpose¶
- Extend the
clsConsoleBaseconsole-application lifecycle with batch-oriented logging and status reporting for long-running or scheduled batch jobs.
Context¶
- Namespace:
SAIF.Presentation.ConsoleApplication - Assembly/package:
SAIF.Presentation.ConsoleApplication(NuGet packageSAIF.BOF.Presentation.ConsoleApplication)
Public members¶
| Member | Signature | Purpose |
|---|---|---|
| BatchStreams | Public Enum BatchStreams (StandardFile, File0, File1, File2, File3, File4) |
Identifies named log streams a batch application can write to. |
| WriteErrorMsg | Public Sub WriteErrorMsg(ErrorMsg As String) |
Writes a message to Console.Error. |
| WriteStatusMsg | Protected Friend Sub WriteStatusMsg(StatusMsg As String) |
Writes a message to Console.Out. |
| WriteAppLogMsg (console) | Protected Friend Sub WriteAppLogMsg(AppLogMsg As String) |
Writes a message directly to the console. |
| WriteAppLogMsg (stream) | Protected Friend Sub WriteAppLogMsg(AppLogMsg As String, LogFile As BatchStreams) |
Writes a message to a named log stream, resolving the log file path from an environment variable named after the enum value (e.g., FILE0), or a default {AppName}.log in the current directory for StandardFile. See BR-001. |
| Initialize | Protected Friend Overrides Sub Initialize() |
Overrides clsConsoleBase.Initialize(): calls MyBase.Initialize(), scans environment variables matching pattern FILE? to pre-register log streams in m_AppLogs (Hashtable), then calls WriteBatchHeader(). |
| Uninitialize | Protected Friend Overrides Sub Uninitialize() |
Overrides clsConsoleBase.Uninitialize(): calls WriteBatchFooter(), flushes/closes any open IO.StreamWriter log streams, then calls MyBase.Uninitialize(). |
| WriteBatchHeader | Protected Overridable Sub WriteBatchHeader() |
Writes a batch start status message ({AppName} began at {StartTime}) to the console. |
| WriteBatchFooter | Protected Overridable Sub WriteBatchFooter() |
Writes batch end/elapsed-time status messages ({AppName} ended at {EndTime}, {AppName} ran for {N} seconds) to the console. |
Inherited public members¶
Members in this section are inherited from clsConsoleBase in SAIF.Presentation.ConsoleApplication (this library). They are available on this type through inheritance and are not overridden by clsBatchBase except where noted above (Initialize, Uninitialize).
| Member | Signature | Purpose | Origin |
|---|---|---|---|
| ReturnCodes | Public Enum ReturnCodes |
Standard set of process exit codes for console applications. | SAIF.Presentation.ConsoleApplication — clsConsoleBase |
| EnvironmentService | Protected EnvironmentService As WindowsEnvironmentService |
Concrete environment-service instance.* | SAIF.Presentation.ConsoleApplication — clsConsoleBase |
| ParameterCount | Public ReadOnly Property ParameterCount As Integer |
Number of parsed command-line arguments. | SAIF.Presentation.ConsoleApplication — clsConsoleBase |
| ReturnCode | Public Property ReturnCode As ReturnCodes |
Maps to Environment.ExitCode. |
SAIF.Presentation.ConsoleApplication — clsConsoleBase |
| AppName | Public Property AppName As String |
Application name used in diagnostics/log output. | SAIF.Presentation.ConsoleApplication — clsConsoleBase |
| HelpText | Public Property HelpText As String |
Text written to console by WriteHelp(). |
SAIF.Presentation.ConsoleApplication — clsConsoleBase |
| StartTime | Public ReadOnly Property StartTime As DateTime |
Timestamp captured in the constructor. | SAIF.Presentation.ConsoleApplication — clsConsoleBase |
| EndTime | Public ReadOnly Property EndTime As DateTime |
Current time at the point of access. | SAIF.Presentation.ConsoleApplication — clsConsoleBase |
| RunningTime | Public ReadOnly Property RunningTime As TimeSpan |
Elapsed time between StartTime and EndTime. |
SAIF.Presentation.ConsoleApplication — clsConsoleBase |
| Execute | Public Sub Execute() |
Template-method entry point orchestrating the console/batch lifecycle. See BR-003. | SAIF.Presentation.ConsoleApplication — clsConsoleBase |
| GetExceptionInfo | Public Function GetExceptionInfo(ex As Exception) As String |
Recursively formats exception details. | SAIF.Presentation.ConsoleApplication — clsConsoleBase |
| GetParamName (by index/name) | Protected Friend Function GetParamName(...) As String (2 overloads) |
Returns a parameter name by position or name. | SAIF.Presentation.ConsoleApplication — clsConsoleBase |
| GetParamValue (by index/name) | Protected Friend Function GetParamValue(...) As String (2 overloads) |
Returns a parameter value by position or name. | SAIF.Presentation.ConsoleApplication — clsConsoleBase |
| ParamExists (by index/name) | Protected Friend Function ParamExists(...) As Boolean (2 overloads) |
Returns whether a parameter exists by position or name. | SAIF.Presentation.ConsoleApplication — clsConsoleBase |
| RunAppLogic | Public MustOverride Sub RunAppLogic() |
Abstract method subclasses implement for main application logic. | SAIF.Presentation.ConsoleApplication — clsConsoleBase |
| ValidateCommandLine | Public MustOverride Function ValidateCommandLine() As Boolean |
Abstract method subclasses implement for command-line validation. See BR-002. | SAIF.Presentation.ConsoleApplication — clsConsoleBase |
| WriteHelp | Protected Friend Sub WriteHelp() |
Writes HelpText to the console. |
SAIF.Presentation.ConsoleApplication — clsConsoleBase |
Behavioral notes¶
Initialize()andUninitialize()are overrides:clsBatchBaselayers batch-specific behavior (log-stream registration/teardown, header/footer output) around the baseclsConsoleBaseimplementation, which it still calls viaMyBase.- Log stream file paths are resolved from process environment variables (
Environment.GetEnvironmentVariable) named after theBatchStreamsenum value, not fromConfigurationManager.AppSettings. - All method-entry/exit tracing is delegated to
SAIF.Framework.Logging.clsLogTrace, a framework-inherited facility not implemented locally.*
Constraints and usage notes¶
- Concrete batch applications must subclass
clsBatchBase, implementRunAppLogic()andValidateCommandLine()(inherited abstract members), and callExecute()from their ownSub Main. - Writing to a non-
StandardFilelog stream whose backing environment variable is unset or empty throws an exception. See BR-001.
Note: Statements marked with
*are inferred from code behavior rather than explicit documentation or comments.
Sources¶
Presentation\SAIF.Presentation.ConsoleApplication\clsBatchBase.vbPresentation\SAIF.Presentation.ConsoleApplication\clsConsoleBase.vb