You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

102 lines
4.0 KiB

using System;
using System.IO.Compression;
using System.Linq;
using System.Text.RegularExpressions;
using Coravel;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.ApplicationModels;
using Microsoft.AspNetCore.ResponseCompression;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.AspNetCore.StaticFiles;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using SettleAccount.Job.SignalR;
//using ShardingCore;
using Win.Sfs.SettleAccount.Entities.BQ;
using Win.Sfs.SettleAccount.Entities.BQ.Syncs;
using Win.Sfs.SettleAccount.EntityFrameworkCore;
namespace Win.Sfs.SettleAccount;
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.Configure<GzipCompressionProviderOptions>(options => options.Level = CompressionLevel.Fastest);
services.AddResponseCompression(options =>
{
options.EnableForHttps = true;
options.Providers.Add<GzipCompressionProvider>();
options.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(new[] { "image/svg+xml" });
});
services.AddScheduler();
services.AddCors(options =>
{
options.AddPolicy("Default", builder =>
{
builder.SetIsOriginAllowed(isOriginAllowed => true)
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials();
});
});
services.AddSingleton<JisBBACSeEdiCompareAppService>();
services.AddSingleton<JisHBPOSeEdiCompareAppService>();
services.AddSignalR(o => o.EnableDetailedErrors = true);
JobHostdService.AddService(services);
services.AddSingleton<JobHostdService>();
services.AddHostedService(o => o.GetRequiredService<JobHostdService>());
services.AddRouting(options => options.ConstraintMap["slugify"] = typeof(SlugifyParameterTransformer));
services.AddMvc(options => options.Conventions.Add(new RouteTokenTransformerConvention(new SlugifyParameterTransformer())));
services.AddApplication<SettleAccountHttpApiHostModule>();
services.Configure<KestrelServerOptions>(options =>
{
// Set the limit to 256 MB
options.Limits.MaxRequestBodySize = 268435456;
});
//上传文件大小限制IIS设置
services.Configure<IISServerOptions>(options =>
{
options.MaxRequestBodySize = 268435456;
options.AllowSynchronousIO = true;
});
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
{
app.UseCors("Default");
app.UseResponseCompression();
app.UseRouting();
app.UseEndpoints(endpoints => endpoints.MapHub<PageHub>("/api/hub"));
app.ApplicationServices.UseScheduler(scheduler =>
{
//scheduler.Schedule<JisBBACSeEdiCompareAppService>().EverySeconds(10);
//scheduler.Schedule<JisHBPOSeEdiCompareAppService>().EverySeconds(10);
});
var contentTypeProvider = new FileExtensionContentTypeProvider();
contentTypeProvider.Mappings.Add(".mjs", "text/javascript");
app.UseStaticFiles(new StaticFileOptions { ContentTypeProvider = contentTypeProvider });
app.InitializeApplication();
}
public class SlugifyParameterTransformer : IOutboundParameterTransformer
{
public string TransformOutbound(object value)
{
if (value == null) { return null; }
var str = value.ToString();
if (string.IsNullOrEmpty(str)) { return null; }
return Regex.Replace(str?.ToString(), "([a-z])([A-Z])", "$1-$2").ToLowerInvariant();
}
}
}