Application
Energy.Core.Application provides an application lifecycle container. It wires together command-line arguments, configuration, logging, localization, database connection, and syntax substitution.
It is often used with a class that implements Energy.Interface.ICommandProgram.
Properties
| Property | Description |
|---|---|
Name |
Application name. |
Assembly |
Application assembly. |
Directory |
Application directory. |
Syntax |
Energy.Core.Syntax instance for variable substitution. |
Log |
Energy.Core.Log instance. |
Configuration |
Energy.Core.Configuration instance. |
Connection |
Energy.Source.Connection instance. |
Locale |
Energy.Core.Locale instance. |
Arguments |
Command-line arguments. |
Constructors
Application app = new Application();
Application app2 = new Application(typeof(MyCommandProgram));
Application app3 = new Application("MyApp");
Application app4 = new Application(System.Reflection.Assembly.GetExecutingAssembly());
Create and Run
Application app = Application.Create();
app.Run();
When an ICommandProgram is attached, Run() calls Setup(args), Initialize(args), and Run(args) in sequence.
CommandProgram
using System;
using Energy.Core;
using Energy.Interface;
public class MyCommandProgram : ICommandProgram
{
public bool Setup(string[] args)
{
Console.WriteLine("Setup");
return true;
}
public bool Initialize(string[] args)
{
Console.WriteLine("Initialize");
return true;
}
public bool Run(string[] args)
{
Console.WriteLine("Run");
return true;
}
}
class Program
{
static void Main(string[] args)
{
Application app = new Application(typeof(MyCommandProgram));
app.Arguments = args;
app.Run();
}
}
GetCommandName
static string Energy.Core.Application.GetCommandName()
Get the current process name. Useful for command-line help output.
Obsolete helpers
The following helpers are marked obsolete and delegate to Energy.Core.Program:
SetLanguage(string)SetDefaultLanguage()GetDefaultCultureInfo()SetConsoleEncoding(...)GetExecutionPath(...)
See also
core-programinterface-contracts