Startup.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using System;
  2. using System.Collections.Generic;
  3. using Microsoft.AspNetCore.Builder;
  4. using Microsoft.AspNetCore.Hosting;
  5. using Microsoft.AspNetCore.Http;
  6. using Microsoft.AspNetCore.Http.Features;
  7. using Microsoft.AspNetCore.StaticFiles;
  8. using Microsoft.Extensions.Configuration;
  9. using Microsoft.Extensions.DependencyInjection;
  10. using Microsoft.Extensions.Hosting;
  11. namespace MySystem
  12. {
  13. public class Startup
  14. {
  15. public Startup(IConfiguration configuration)
  16. {
  17. Configuration = configuration;
  18. }
  19. public IConfiguration Configuration { get; }
  20. // This method gets called by the runtime. Use this method to add services to the container.
  21. public void ConfigureServices(IServiceCollection services)
  22. {
  23. services.AddControllersWithViews();
  24. services.AddRouting(options =>
  25. {
  26. options.LowercaseUrls = true;
  27. });
  28. services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
  29. services.AddCors(option => option.AddPolicy("cors", policy => policy.AllowAnyHeader().AllowAnyMethod().AllowCredentials().SetIsOriginAllowed(_ => true)));
  30. services.AddMvc(options =>
  31. {
  32. options.EnableEndpointRouting = false;
  33. options.Filters.Add(typeof(GlobalExceptions));
  34. });
  35. services.AddSession(options =>
  36. {
  37. // 设置 Session 过期时间
  38. options.IdleTimeout = TimeSpan.FromHours(1);
  39. options.Cookie.HttpOnly = true;
  40. });
  41. services.Configure<FormOptions>(x =>
  42. {
  43. x.MultipartBodyLengthLimit = 50 * 1024 * 1024;//不到300M
  44. });
  45. MySystemLib.SystemPublicFuction.appcheck = "success";
  46. string conn = Configuration["Setting:SqlConnStr"];
  47. Dictionary<string, Dictionary<string, string>> tables = new Dictionary<string, Dictionary<string, string>>();
  48. System.Data.DataTable tablecollection = Library.CustomerSqlConn.dtable("select DISTINCT TABLE_NAME from information_schema.columns where table_schema = 'QrCodePlateMainServer'", conn);
  49. foreach (System.Data.DataRow subtable in tablecollection.Rows)
  50. {
  51. Dictionary<string, string> Columns = new Dictionary<string, string>();
  52. System.Data.DataTable columncollection = Library.CustomerSqlConn.dtable("select COLUMN_NAME,DATA_TYPE from information_schema.columns where table_schema = 'QrCodePlateMainServer' and TABLE_NAME='" + subtable["TABLE_NAME"].ToString() + "'", conn);
  53. foreach (System.Data.DataRow column in columncollection.Rows)
  54. {
  55. string datatype = column["DATA_TYPE"].ToString();
  56. if (datatype == "decimal")
  57. {
  58. datatype = "numeric";
  59. }
  60. Columns.Add(column["COLUMN_NAME"].ToString(), datatype);
  61. }
  62. tables.Add(subtable["TABLE_NAME"].ToString(), Columns);
  63. }
  64. MySystemLib.SystemPublicFuction.dbtables = tables;
  65. RedisDbconn.csredis = new CSRedis.CSRedisClient(Configuration["Setting:RedisConnStr"]);
  66. }
  67. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  68. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  69. {
  70. if (env.IsDevelopment())
  71. {
  72. app.UseDeveloperExceptionPage();
  73. // app.UseExceptionHandler("/Home/Error");
  74. Library.ConfigurationManager.EnvironmentFlag = 1;
  75. }
  76. else
  77. {
  78. app.UseExceptionHandler("/Home/Error");
  79. app.UseHsts();
  80. Library.ConfigurationManager.EnvironmentFlag = 2;
  81. }
  82. Library.function.WritePage("/", "WebRootPath.txt", env.WebRootPath);
  83. app.UseStaticFiles();
  84. app.UseStaticFiles(new StaticFileOptions
  85. {
  86. ContentTypeProvider = new FileExtensionContentTypeProvider(new Dictionary<string, string>
  87. {
  88. { ".apk", "application/vnd.android.package-archive" }
  89. })
  90. });
  91. app.UseCors("cors");
  92. app.UseAuthentication();
  93. app.UseRouting();
  94. app.UseAuthorization();
  95. app.UseSession();
  96. app.UseEndpoints(endpoints =>
  97. {
  98. endpoints.MapControllerRoute(
  99. name: "default",
  100. pattern: "{controller=Home}/{action=Index}/{Id?}");
  101. });
  102. #region 必须打开的
  103. //老平台
  104. StatService.Instance.Start(); //实时统计交易额
  105. StatResetService.Instance.StartReset(); //重置交易额
  106. StatService.Instance.StartPosActNum(); //实时统计激活数
  107. StatNewService.Instance.StartMer(); //实时统计商户交易额
  108. StatNewService.Instance.CreateTable(); //生成新的分表
  109. //好哒
  110. StatService2.Instance.Start(); //实时统计交易额
  111. StatResetService2.Instance.StartReset(); //重置交易额
  112. StatService2.Instance.StartPosActNum(); //实时统计激活数
  113. StatNewService2.Instance.StartMer(); //实时统计商户交易额
  114. StatNewService2.Instance.CreateTable(); //生成新的分表
  115. #endregion
  116. }
  117. }
  118. }