public static async Task <int> Main(string[] args) { //options parsing first if (CommandLineParser.TryParse(args, out OptionsBase programArgs)) { if (programArgs.ApiCommand == null) //interactive mode { Bootstrap boot = new Bootstrap(); boot.SetCmdOptions(programArgs); return(await boot.Run().ConfigureAwait(false)); } if (programArgs.ApiCommand.InstantiatedCommand is CommandBase <NeuraliumApi <IApiMethods>, IApiMethods> command) { var configuration = Bootstrap.BuildConfiguration(programArgs); AppSettings appSettings = configuration.GetSection("AppSettings").Get <AppSettings>() ?? new AppSettings(); Log.Logger = new LoggerConfiguration().ReadFrom.Configuration(configuration).CreateLogger(); NeuraliumApi <IApiMethods> api = new NeuraliumApi <IApiMethods>(); api.Init(appSettings, programArgs, NeuraliumApi.UseModes.SendReceive); await api.Connect().ConfigureAwait(false); command.Api = api; command.Arguments = programArgs; CommandResult result = command.ExecuteAsync(CancellationToken.None).Result; await api.Disconnect().ConfigureAwait(false); Log.CloseAndFlush(); return(result == CommandResult.Success ? 0 : 1); } NLog.Default.Error($"Unexpected command type: {programArgs.ApiCommand.InstantiatedCommand.GetType()}"); } return(-1); }