forked from ddrilling/AsbCloudServer
65 lines
2.4 KiB
C#
65 lines
2.4 KiB
C#
using DocumentFormat.OpenXml.InkML;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Hosting;
|
|
using System;
|
|
using System.Linq;
|
|
|
|
namespace AsbCloudWebApi
|
|
{
|
|
public class Program
|
|
{
|
|
// Uncomment next line to find wired exceptions by tracing.
|
|
//static TraceListenerView trace4debug = new TraceListenerView();
|
|
|
|
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";
|
|
|
|
var context = AsbCloudInfrastructure.DependencyInjection.MakeContext(configuration.GetConnectionString(connectionStringName));
|
|
context.Database.SetCommandTimeout(TimeSpan.FromSeconds(5 * 60));
|
|
context.Database.Migrate();
|
|
|
|
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("");
|
|
}
|
|
}
|
|
}
|