Skip to content

clsConsoleBase

clsConsoleBase (MustInherit) is the abstract ancestor class for all SAIF console applications. It defines the standard Execute() template-method lifecycle, command-line argument parsing, exception-diagnostics formatting, and application state properties that concrete console applications build on by subclassing it.

Purpose

  • Provide a reusable, consistent lifecycle skeleton (Execute() → Initialize() → ValidateCommandLine() → RunAppLogic() → Uninitialize()) for command-line applications.
  • Provide command-line argument parsing and exception-diagnostics formatting shared by all console applications.

Context

  • Namespace: SAIF.Presentation.ConsoleApplication
  • Assembly/package: SAIF.Presentation.ConsoleApplication (NuGet package SAIF.BOF.Presentation.ConsoleApplication)

Public members

Member Signature Purpose
ReturnCodes Public Enum ReturnCodes (Success=0, BadParameter=1, DatabaseError=2, DataError=3, FileIOError=4, UnknownError=5, NoDataFound=6) Standard set of process exit codes for console applications.
EnvironmentService Protected EnvironmentService As WindowsEnvironmentService Concrete environment-service instance (New WindowsEnvironmentService()), not injected through an abstraction.*
ParameterCount Public ReadOnly Property ParameterCount As Integer Number of parsed command-line arguments.
ReturnCode Public Property ReturnCode As ReturnCodes Maps to Environment.ExitCode; set by the application to signal its outcome.
AppName Public Property AppName As String Application name used in diagnostics/log output.
HelpText Public Property HelpText As String Text written to console by WriteHelp().
StartTime Public ReadOnly Property StartTime As DateTime Timestamp captured in the constructor (m_StartTime = Now).
EndTime Public ReadOnly Property EndTime As DateTime Current time (DateTime.Now) at the point of access.
RunningTime Public ReadOnly Property RunningTime As TimeSpan Elapsed time between StartTime and EndTime.
New Public Sub New() Constructor; sets m_StartTime = Now.
Execute Public Sub Execute() Template-method entry point: calls Initialize(), checks the /DEBUG flag, calls ValidateCommandLine(), then RunAppLogic() if valid (otherwise prompts "Press enter to continue..."), then always calls Uninitialize(). See BR-003.
GetExceptionInfo Public Function GetExceptionInfo(ex As Exception) As String Recursively formats exception details (including inner exceptions); for a type named clsSAIFException, reflects and prints its public properties, otherwise prints Message/Source/StackTrace.
GetParamName (by index) Protected Friend Function GetParamName(Index As Integer) As String Returns the parameter name at a given positional index.
GetParamName (by name) Protected Friend Function GetParamName(Name As String) As String Returns the matching stored parameter name for a given name, matched case-insensitively.
GetParamValue (by index) Protected Friend Function GetParamValue(Index As Integer) As String Returns the parameter value at a given positional index.
GetParamValue (by name) Protected Friend Function GetParamValue(Name As String) As String Returns the value of a named command-line parameter.
ParamExists (by index) Protected Friend Function ParamExists(Index As Integer) As Boolean Returns whether a parameter exists at a given positional index.
ParamExists (by name) Protected Friend Function ParamExists(Name As String) As Boolean Returns whether a named command-line parameter was supplied.
RunAppLogic Public MustOverride Sub RunAppLogic() Abstract method; subclasses implement the application's main logic here.
ValidateCommandLine Public MustOverride Function ValidateCommandLine() As Boolean Abstract method; subclasses implement command-line validation here. See BR-002.
WriteHelp Protected Friend Sub WriteHelp() Writes HelpText to the console.
Initialize Protected Friend Overridable Sub Initialize() Overridable lifecycle hook; parses Environment.GetCommandLineArgs, strips a leading //-, and upper-cases each argument. See BR-002.
Uninitialize Protected Friend Overridable Sub Uninitialize() Overridable lifecycle hook invoked at the end of Execute().

Behavioral notes

  • All method-entry/exit tracing is delegated to SAIF.Framework.Logging.clsLogTrace.MethodMessage/MethodBegin/MethodEnd, a framework-inherited facility not implemented locally.*
  • EnvironmentService is a concrete WindowsEnvironmentService instance rather than an injected abstraction, representing a tight coupling point for downstream consumers.*
  • GetExceptionInfo detects clsSAIFException by runtime type name (not by static type reference), since that type is not imported or declared in this library.**

Constraints and usage notes

  • Concrete console applications must subclass clsConsoleBase, implement RunAppLogic() and ValidateCommandLine(), and call Execute() from their own Sub Main.
  • Consumers requiring batch-style multi-stream logging should subclass clsBatchBase instead, which extends this class.

Note: Statements marked with * are inferred from code behavior rather than explicit documentation or comments; statements marked with ** could not be confirmed and should be treated as unknown until verified.

Sources

  • Presentation\SAIF.Presentation.ConsoleApplication\clsConsoleBase.vb