diff --git a/AsbCloudInfrastructure/Helper.cs b/AsbCloudInfrastructure/Helper.cs deleted file mode 100644 index 01fc97b5..00000000 --- a/AsbCloudInfrastructure/Helper.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System; - -namespace AsbCloudInfrastructure -{ - public static class Helper - { - public static T Max(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(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(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); - } - } -} diff --git a/AsbCloudInfrastructure/MapsterExtension.cs b/AsbCloudInfrastructure/MapsterExtension.cs deleted file mode 100644 index 94ed630c..00000000 --- a/AsbCloudInfrastructure/MapsterExtension.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace Mapster -{ - public static class MapsterExtension - { - //public static IEnumerable Adapt(this IEnumerable sourceList) - //{ - // return sourceList.Select(item => item.Adapt()); - //} - - - } -} diff --git a/AsbCloudInfrastructure/CacheExtentions.cs b/AsbCloudInfrastructure/MemoryCacheExtentions.cs similarity index 100% rename from AsbCloudInfrastructure/CacheExtentions.cs rename to AsbCloudInfrastructure/MemoryCacheExtentions.cs diff --git a/AsbCloudInfrastructure/Startup.cs b/AsbCloudInfrastructure/Startup.cs index 5ccb0df7..c8dc24a9 100644 --- a/AsbCloudInfrastructure/Startup.cs +++ b/AsbCloudInfrastructure/Startup.cs @@ -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(); diff --git a/AsbCloudWebApi/Middlewares/RequerstTrackerMiddleware.cs b/AsbCloudWebApi/Middlewares/RequerstTrackerMiddleware.cs index b35b40e5..551b4d03 100644 --- a/AsbCloudWebApi/Middlewares/RequerstTrackerMiddleware.cs +++ b/AsbCloudWebApi/Middlewares/RequerstTrackerMiddleware.cs @@ -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; } diff --git a/AsbCloudWebApi/Middlewares/SimplifyExceptionsMiddleware.cs b/AsbCloudWebApi/Middlewares/SimplifyExceptionsMiddleware.cs index c09f9749..dd9fff9f 100644 --- a/AsbCloudWebApi/Middlewares/SimplifyExceptionsMiddleware.cs +++ b/AsbCloudWebApi/Middlewares/SimplifyExceptionsMiddleware.cs @@ -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."); diff --git a/AsbCloudWebApi/Program.cs b/AsbCloudWebApi/Program.cs index b21fa05f..18825902 100644 --- a/AsbCloudWebApi/Program.cs +++ b/AsbCloudWebApi/Program.cs @@ -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(); }); - - private static void WriteHelp() - { - Console.WriteLine("Ïðè çàïóñêå áåç êëþ÷åé ïðîãðàììà ïðîñòî ñòàðòóåò â îáû÷íîì ðåæèìå."); - Console.WriteLine("Êëþ÷è äëÿ çàïóñêà:"); - Console.WriteLine("db_init - ñîçäàòü êîíòåêñò ÁÄ è âûéòè."); - Console.WriteLine("Êîíòåêñò ñîçäàñòñÿ äëÿ ñòðîêè ïîäêëþ÷åíèÿ \"DefaultConnection\""); - Console.WriteLine("Ñîçäàíèå êîíòåêñòà ïðèâåäåò ê ñîçäàíèþ ÁÄ, åñëè åé íåò"); - Console.WriteLine("è ïðèìåíåíèþ âñåõ ìèãðàöèé, åñëè ÁÄ óæå åñòü."); - Console.WriteLine("Äëÿ ñîçäàíèÿ êîíòåêñòà â ÁÄ äîëæíà áûòü ñîçäàíà ñõåìà public"); - Console.WriteLine(""); - } } }