forked from ddrilling/AsbCloudServer
59 lines
2.2 KiB
C#
59 lines
2.2 KiB
C#
using AsbCloudDb.Model;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using System;
|
|
using System.Linq;
|
|
|
|
namespace AsbCloudWebApi
|
|
{
|
|
public class Program
|
|
{
|
|
public static void Main(string[] args)
|
|
{
|
|
IConfigurationRoot configuration = new ConfigurationBuilder()
|
|
.SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
|
|
.AddJsonFile("appsettings.json")
|
|
.Build();
|
|
|
|
if (args?.Length > 0 )
|
|
{
|
|
if (args.Contains("db_init")) {
|
|
var connectionStringName = "DefaultConnection";
|
|
|
|
AsbCloudInfrastructure.DependencyInjection.MakeContext(configuration.GetConnectionString(connectionStringName));
|
|
Console.WriteLine("Óñïåøíî âûïîëíåíî.");
|
|
return;
|
|
}
|
|
WriteHelp();
|
|
return;
|
|
}
|
|
|
|
var host = CreateHostBuilder(args).Build();
|
|
AsbCloudInfrastructure.Startup.BeforeRunHandler(host, configuration);
|
|
host.Run();
|
|
}
|
|
|
|
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
|
Host.CreateDefaultBuilder(args)
|
|
.ConfigureWebHostDefaults(webBuilder =>
|
|
{
|
|
webBuilder.UseStartup<Startup>();
|
|
});
|
|
|
|
private static void WriteHelp()
|
|
{
|
|
Console.WriteLine("Ïðè çàïóñêå áåç êëþ÷åé ïðîãðàììà ïðîñòî ñòàðòóåò â îáû÷íîì ðåæèìå.");
|
|
Console.WriteLine("Êëþ÷è äëÿ çàïóñêà:");
|
|
Console.WriteLine("db_init - ñîçäàòü êîíòåêñò ÁÄ è âûéòè.");
|
|
Console.WriteLine("Êîíòåêñò ñîçäàñòñÿ äëÿ ñòðîêè ïîäêëþ÷åíèÿ \"DefaultConnection\"");
|
|
Console.WriteLine("Ñîçäàíèå êîíòåêñòà ïðèâåäåò ê ñîçäàíèþ ÁÄ, åñëè åé íåò");
|
|
Console.WriteLine("è ïðèìåíåíèþ âñåõ ìèãðàöèé, åñëè ÁÄ óæå åñòü.");
|
|
Console.WriteLine("Äëÿ ñîçäàíèÿ êîíòåêñòà â ÁÄ äîëæíà áûòü ñîçäàíà ñõåìà public");
|
|
Console.WriteLine("");
|
|
}
|
|
}
|
|
}
|