コード例 #1
0
ファイル: Program.cs プロジェクト: the-fool/shakespeare
        public static int Main(string[] args)
        {
            foreach (var arg in args)
            {
                Console.WriteLine(arg);
            }
            var host = CreateWebHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope()) {
                var services = scope.ServiceProvider;

                var context = services.GetRequiredService <ApiDbContext>();
                var logger  = services.GetRequiredService <ILogger <Program> >();

                try {
                    DbInitializer.Initialize(context);
                } catch (Exception ex) {
                    logger.LogError(ex, "An error occurred creating the DB.");
                }

                if (args.Length > 0)
                {
                    if (args[0] == "csv")
                    {
                        try {
                            CsvIngester.Ingest(context);
                            return(0);
                        } catch (Exception ex) {
                            logger.LogError(ex, "An error occurred ingesting CSV");
                            return(1);
                        }
                    }
                }
            }

            host.Run();
            return(1);
        }
コード例 #2
0
        static void Main(string[] args)
        {
            var host = ShakespeareAPI.Program.CreateWebHostBuilder(args);

            using (var scope = host.Services.CreateScope()) {
                var services = scope.ServiceProvider;
                var context  = services.GetRequiredService <ApiDbContext>;

                if (args.Length == 0)
                {
                    return(0);
                }

                var arg = args[0];

                switch (arg)
                {
                case "csv": {
                    CsvIngester.Ingest(context);
                    return(0);
                }
                }
            }
        }