Ejemplo n.º 1
0
        /// <summary>
        /// The main setup and execution logic for the SynchroFeed.Console program.
        /// </summary>
        /// <param name="commandLineApp">The command line application containing the parsed command line parameters.</param>
        /// <returns>System.Int32.</returns>
        private static async Task <int> ExecuteAsync(ConsoleCommandLine commandLineApp)
        {
            try
            {
                var host = CreateHostBuilder(commandLineApp)
                           .Build();

                host.Services
                .GetService <ILoggerFactory>();

                NLog.LogManager.LoadConfiguration("nlog.config");

                try
                {
                    var actionProcessor = host.Services.GetRequiredService <IActionProcessor>();
                    await actionProcessor.ExecuteAsync(commandLineApp.Actions);
                }
                finally
                {
                    NLog.LogManager.Shutdown();
                }
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message);
                return(1);
            }

            return(0);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The entry point of the SynchroFeed.Console application.
        /// </summary>
        /// <param name="args">The arguments.</param>
        public static void Main(string[] args)
        {
            var commandLineApp = new ConsoleCommandLine();

            commandLineApp.OnExecute(() => ExecuteAsync(commandLineApp));
            commandLineApp.Execute(args);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates the host builder and initializes the application.
        /// </summary>
        /// <param name="commandLineApp">The parsed command line arguments.</param>
        /// <returns>Returns an instance of IHostBuilder.</returns>
        private static IHostBuilder CreateHostBuilder(ConsoleCommandLine commandLineApp)
        {
            var builder = new HostBuilder()
                          .ConfigureAppConfiguration((hostingContext, config) =>
            {
                config.SetBasePath(Directory.GetCurrentDirectory());
                config.AddJsonFile(Path.GetFullPath(commandLineApp.ConfigFile));
            })
                          .ConfigureServices((hostContext, services) =>
            {
                services.AddOptions();
                services.AddLogging();
                services.Configure <ApplicationSettings>(hostContext.Configuration.GetSection("FeedSettings"));
                services.AddSingleton(commandLineApp);
                services.AddSynchroFeed();
            })
                          .ConfigureLogging((hostingContext, logging) =>
            {
                logging.SetMinimumLevel(LogLevel.Trace);
                logging.AddNLog();
            });

            return(builder);
        }