| | |
| | | using Microsoft.Extensions.DependencyInjection; |
| | | using Microsoft.Extensions.Hosting; |
| | | using Microsoft.OpenApi.Models; |
| | | using NLog; |
| | | using Rhea.Common; |
| | | using Sundial; |
| | | using System; |
| | | using System.IO; |
| | | using System.Linq; |
| | | using System.Reflection; |
| | | using Tiger.Api.Controllers; |
| | | using Tiger.Api.DbCache; |
| | | using Tiger.IBusiness; |
| | | using Tiger.IBusiness.Utility; |
| | | |
| | | namespace Tiger.Api |
| | | { |
| | |
| | | public Startup(IConfiguration configuration) |
| | | { |
| | | Configuration = configuration; |
| | | //初始化 ApiConfig |
| | | ApiConfig.InitConfig(configuration); |
| | | |
| | | //测试代码 |
| | |
| | | { |
| | | //services.RegisterAssembly("Tiger.Service"); |
| | | //services.AddTransient(typeof(IBaseService<>), typeof(BaseService<>)); |
| | | services.AddControllers().AddNewtonsoftJson(opt => |
| | | services.AddControllersWithViews().AddExtraControllers().AddNewtonsoftJson(opt => |
| | | { |
| | | opt.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver(); |
| | | opt.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss"; |
| | | }); |
| | | //services.AddControllers().AddApplicationPart(typeof(_WMSTestController).Assembly); |
| | | //services.AddControllers(); |
| | | |
| | | //配置跨域处理cors |
| | | services.AddCors(options => |
| | |
| | | BizConfig.InitConfig(bizConfig, DI.Resolve<ILanguage>().GetDictionary()); |
| | | |
| | | //加载配置文件 |
| | | NLog.LogManager.LoadConfiguration("nlog.config").GetCurrentClassLogger(); |
| | | NLog.LogManager.Setup().LoadConfigurationFromFile("nlog.config").GetCurrentClassLogger(); |
| | | app.UseMiddleware<LogMiddleware>(); |
| | | |
| | | app.UseSwagger(); |
| | |
| | | app.UseCors(anyAllowSpecificOrigins);//支持跨域:允许特定来源的主机访问 |
| | | |
| | | //app.UseHttpsRedirection(); |
| | | app.UseStaticFiles(); |
| | | |
| | | //app.UseAuthorization(); |
| | | app.UseEndpoints(endpoints => |
| | | { |
| | | endpoints.MapControllerRoute(name: "default", pattern: "{controller=Home}/{action=Index}/{id?}").RequireCors(anyAllowSpecificOrigins); |
| | | endpoints.MapControllers().RequireCors(anyAllowSpecificOrigins); |
| | | //endpoints.MapControllers(); |
| | | }); |
| | | |
| | | ConsoleExt.Write($"Api Run as{((ApiConfig.IsDevVersion || ApiConfig.IsTestVersion) ? ((ApiConfig.IsDevVersion ? " Dev" : "") + (ApiConfig.IsTestVersion ? " Test" : "")) : " Release")} Edition", ConsoleColor.Cyan); |
| | |
| | | (BizConfig.Configuration[$"Databases:Main:ConnectionString"].Split(';').Any(q => q.Contains("port")) ? "," : "") + |
| | | BizConfig.Configuration[$"Databases:Main:ConnectionString"].Split(';').Where(q => q.Contains("Data Source") || q.Contains("DataSource") || q.Contains("database")).FirstOrDefault(), ConsoleColor.Cyan); |
| | | } |
| | | |
| | | //初始化Business的AutoFacContainer |
| | | DI.Resolve<IBiz>().SetContainer(AutoFacContainer.Instance); |
| | | //开启Api监控总线 |
| | |
| | | //开启服务总线 |
| | | DI.Resolve<IServicesBus>().StartServices(app.ApplicationServices.GetService<ISchedulerFactory>()); |
| | | //开启DB缓存自动更新 |
| | | DI.Resolve<IDbCacheBus>().StartAutoUpdate(); |
| | | //DI.Resolve<IDbCacheBus>().StartAutoUpdate(); |
| | | DbCacheBus.StartAutoUpdate(); |
| | | //开启MQTT服务 |
| | | MQTTHelper.Start(); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// </summary> |
| | | public void DeleteLogs() |
| | | { |
| | | DirectoryInfo di = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory + "\\Logs"); |
| | | var logFiles = di.GetFiles("*.log", SearchOption.AllDirectories); |
| | | foreach (var file in logFiles) |
| | | DirectoryInfo di = new (AppDomain.CurrentDomain.BaseDirectory + "\\Logs"); |
| | | if(di.Exists) |
| | | { |
| | | if ((DateTime.Now - file.LastWriteTime).TotalDays > 30) |
| | | var logFiles = di.GetFiles("*.log", SearchOption.AllDirectories); |
| | | foreach (var file in logFiles) |
| | | { |
| | | file.Delete(); |
| | | if ((DateTime.Now - file.LastWriteTime).TotalDays > 30) |
| | | { |
| | | file.Delete(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | }//endClass |
| | | } |