Skip to content

SAIF.Framework.Windows operations and processes

This page is the operation catalog and cross-operation hub for this library. Each operation's detailed, step-by-step logic lives in its own page under operations/.

Operation catalog

Operation Intent Trigger Inputs Outputs Rules
Program runner entry point Resolve arguments, compose the Autofac container, resolve the application, run it, and translate exceptions to a process exit code. Consuming application's Main() calls Run() on a ProgramRunnerBase/SaifStandardProgramBase subclass. RawArguments (raw command-line string array). Environment.ExitCode; console/stderr output. BR-WIN-001, BR-WIN-003, BR-WIN-004, BR-WIN-005
Console application lifecycle Execute the Initialize()/Execute()/Finish() lifecycle for the resolved application instance. Called by the program runner entry point after the Autofac container resolves the application. Application instance state established at construction (Arguments, StartTime, injected IConsoleLogService). Environment.ExitCode reset to 0; console header/footer log lines. BR-WIN-006
Argument resolution Parse and validate raw command-line arguments against the argument container's configured/auto-discovered resolvers. Called by the program runner entry point (step 2 of Run()). Raw string[] args, parsed into a dictionary via the container's ICommandLineParser. A ValidationResult (IsValid, Errors). BR-WIN-002, BR-WIN-007, BR-WIN-008, BR-WIN-009, BR-WIN-010
Command-line argument parsing Split raw argument tokens into standardized key/value pairs using a configurable regex pattern. Called from the argument container's constructor via its configured CommandLineParser. Raw string[] args; the parser's configured ParsePattern regex. Dictionary<string,string> of standardized-key → value pairs. BR-WIN-011, BR-WIN-012
Dependency and unit-of-work registration Wire core framework services and Oracle/SQL Server NHibernate unit-of-work factories/instances into the consuming application's Autofac container. Called once from a consuming application's RegisterAppDependencies override (invoked from the program runner entry point). currentUserId, optional dataClassMapAssemblies, params DatabaseConfig[] configs. Autofac registrations added to the supplied ContainerBuilder. BR-WIN-013, BR-WIN-015, BR-WIN-016
Console log service discovery Discover machine-scoped numbered log-file environment variables and register a log writer per match. Autofac resolution of IConsoleLogService (registered by dependency registration). Machine-scoped environment variables (Environment.GetEnvironmentVariables(EnvironmentVariableTarget.Machine)). A populated loggers list of LogWriter instances. BR-WIN-014

Process flow diagram

The following diagram visualizes the primary operational flow from process entry to exit.

flowchart TD
    Start([Main invokes Run]) --> Resolve[Argument resolution]
    Resolve --> Valid{Arguments valid?}
    Valid -->|No| Halt([ExitCode=1, halt before app logic])
    Valid -->|Yes| Register[Dependency and unit-of-work registration]
    Register --> Build[Build Autofac container]
    Build --> Lifecycle[Console application lifecycle<br>Initialize/Execute/Finish]
    Lifecycle --> Outcome{Exception thrown?}
    Outcome -->|SaifConsoleException| ExitEx([ExitCode = ex.ExitCode])
    Outcome -->|Other exception| Exit5([ExitCode = 5])
    Outcome -->|No| Exit0([ExitCode = 0])

Failure and edge-case behavior

  • Invalid arguments halt the process before any dependency registration, container build, or application resolution occurs, and require a console keypress before exiting (BR-WIN-003).
  • A thrown SaifConsoleException maps to its own ExitCode; any other unhandled exception maps to a fixed exit code of 5 (BR-WIN-004, BR-WIN-005).
  • A missing currentUserId argument to dependency registration throws immediately, before any registrations are added to the container (BR-WIN-013).
  • Duplicate machine-scoped log-file environment variables pointing at the same file path are not deduplicated during log service discovery.

Sources

  • Console\SAIF.Console\Console\ProgramRunnerBase.cs
  • Console\SAIF.Console\Console\SaifStandardProgramBase.cs
  • Console\SAIF.Console\Console\ConsoleBase.cs
  • Console\SAIF.Console\Console\Arguments\ArgumentContainerBase.cs
  • Console\SAIF.Console\Console\PatternCommandLineParser.cs
  • Console\SAIF.Console\Console\AutofacExtensions.cs
  • Console\SAIF.Console\Console\DatabaseConfigs\DatabaseConfig.cs
  • Console\SAIF.Console\Console\ConsoleLogService.cs
  • Console\SAIF.Console\Console\LogWriter.cs