static void Main(string[] args) { ConsoleUtil.ApplyCustomFont(); ConsoleUtil.AllocConsole(); ConsoleUtil.InstallCustomFontAndApply(); Assembly a = Assembly.GetExecutingAssembly(); Icon icon = new Icon(a.GetManifestResourceStream("WCell.Terminal.Resources.WCell.Terminal.ico")); ConsoleUtil.SetConsoleIcon(icon); AppUtil.AddApplicationExitHandler(ConsoleEventHandler); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("({0}) <Terminal> Initializing...", DateTime.Now.ToString("hh:mm")); Version vrs = new Version(Application.ProductVersion); try { String ExePath = Directory.GetCurrentDirectory(); String SourcePath = Directory.GetParent(Directory.GetParent(ExePath).FullName).FullName; int Revision = WCell.Util.SvnUtil.GetVersionNumber(SourcePath); Console.Title = String.Format("WCell.Terminal v{0}.{1} rev {2}", vrs.Major, vrs.Minor, Revision); } catch (DirectoryNotFoundException) { Console.Title = String.Format("WCell.Terminal v{0}.{1}", vrs.Major, vrs.Minor); } catch (NullReferenceException) { Console.Title = String.Format("WCell.Terminal v{0}.{1}", vrs.Major, vrs.Minor); } Application.Run(new TerminalMain()); }
public int Run(string[] args) { // create a console window for this application (or assign it to the existing console window) if (!ConsoleUtil.AttachConsole(-1)) { ConsoleUtil.AllocConsole(); } // set up special console logging for headless mode using (var log = new LoggerConfiguration() .MinimumLevel.ControlledBy(LoggingUtil.LoggingLevelSwitch) .WriteTo.Logger(Log.Logger) .WriteTo.Console(outputTemplate: HEADLESS_LOG_FORMAT) .CreateLogger()) { Log.Logger = log; // parse the arguments, and log any errors int exitCode = 0; try { var commandTypes = Commands.Select(c => c.OptionsType).ToArray(); var parseResult = Parser.Default.ParseArguments(args, commandTypes); foreach (var command in Commands) { command.Register(ref parseResult); } } catch (HeadlessException e) { Log.Fatal(e.Message); exitCode = 1; } catch (Exception e) { var errString = $"{e.Message}\n{e.StackTrace}"; Log.Fatal(errString); exitCode = 1; } finally { ConsoleUtil.FreeConsole(); } return(exitCode); } }