forked from ddrilling/AsbCloudServer
nit. comments and cleanup
This commit is contained in:
parent
89e0495d09
commit
71aff8d1ec
@ -1,55 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace AsbCloudInfrastructure
|
||||
{
|
||||
public static class Helper
|
||||
{
|
||||
public static T Max<T>(params T[] items)
|
||||
where T : IComparable
|
||||
{
|
||||
var count = items.Length;
|
||||
if (count < 1)
|
||||
throw new ArgumentException("Count of params must be greater than 1");
|
||||
|
||||
var max = items[0];
|
||||
for (var i = 1; i < count; i++)
|
||||
if (max.CompareTo(items[i]) < 0)
|
||||
max = items[i];
|
||||
|
||||
return max;
|
||||
}
|
||||
|
||||
public static T Min<T>(params T[] items)
|
||||
where T : IComparable
|
||||
{
|
||||
var count = items.Length;
|
||||
if (count < 1)
|
||||
throw new ArgumentException("Count of params must be greater than 1");
|
||||
|
||||
var min = items[0];
|
||||
for (var i = 1; i < count; i++)
|
||||
if (min.CompareTo(items[i]) > 0)
|
||||
min = items[i];
|
||||
|
||||
return min;
|
||||
}
|
||||
|
||||
public static (T min, T max) MinMax<T>(params T[] items)
|
||||
where T : IComparable
|
||||
{
|
||||
var count = items.Length;
|
||||
if (count < 1)
|
||||
throw new ArgumentException("Count of params must be greater than 1");
|
||||
|
||||
var min = items[0];
|
||||
var max = items[0];
|
||||
for (var i = 1; i < count; i++)
|
||||
if (max.CompareTo(items[i]) < 0)
|
||||
max = items[i];
|
||||
else if (min.CompareTo(items[i]) > 0)
|
||||
min = items[i];
|
||||
|
||||
return (min, max);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
namespace Mapster
|
||||
{
|
||||
public static class MapsterExtension
|
||||
{
|
||||
//public static IEnumerable<TDestination> Adapt<TDestination>(this IEnumerable<object> sourceList)
|
||||
//{
|
||||
// return sourceList.Select(item => item.Adapt<TDestination>());
|
||||
//}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -1,17 +1,15 @@
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace AsbCloudInfrastructure
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
public static void BeforeRunHandler(IHost host, IConfigurationRoot configuration)
|
||||
public static void BeforeRunHandler(IHost host)
|
||||
{
|
||||
using var scope = host.Services.CreateScope();
|
||||
var context = scope.ServiceProvider.GetService<IAsbCloudDbContext>();
|
||||
|
@ -43,6 +43,7 @@ namespace AsbCloudWebApi.Middlewares
|
||||
sw.Stop();
|
||||
requestLog.ElapsedMilliseconds = sw.ElapsedMilliseconds;
|
||||
requestLog.Status = context.Response.StatusCode;
|
||||
// TODO: Add request params and body size.
|
||||
service.RegisterRequestError(requestLog, ex);
|
||||
throw;
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ namespace AsbCloudWebApi.Middlewares
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (Exception ex) // TODO: find explicit exception. Use Trace. Add body size to message.
|
||||
{
|
||||
if (ex.Message.Contains("Reading the request body timed out due to data arriving too slowly. See MinRequestBodyDataRate."))
|
||||
Console.WriteLine("Reading the request body timed out due to data arriving too slowly.");
|
||||
|
@ -1,10 +1,5 @@
|
||||
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
|
||||
{
|
||||
@ -15,30 +10,8 @@ namespace AsbCloudWebApi
|
||||
|
||||
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);
|
||||
AsbCloudInfrastructure.Startup.BeforeRunHandler(host);
|
||||
host.Run();
|
||||
}
|
||||
|
||||
@ -48,17 +21,5 @@ namespace AsbCloudWebApi
|
||||
{
|
||||
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("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user