// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); //添加appsettings.json services.AddOptions(); //需要存储速率和ip规则 services.AddMemoryCache(); //加载appsettings.json中的配置项 ,下面三项是加载general,rules services.Configure<IpRateLimitOptions>(Configuration.GetSection("IpRateLimiting")); services.Configure<IpRateLimitPolicies>(Configuration.GetSection("IpRateLimitPolicies")); //注入计时器和规则 services.AddSingleton<IIpPolicyStore, MemoryCacheIpPolicyStore>(); services.AddSingleton<IRateLimitCounterStore, MemoryCacheRateLimitCounterStore>(); //添加框架服务 services.AddMvc(); }
在Configure中配置RateLimit的启动
1 2 3 4 5 6 7 8 9 10
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env,ILoggerFactory loggerFactory) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); app.UseIpRateLimiting(); if (env.IsDevelopment()) app.UseDeveloperExceptionPage(); app.UseMvc(); }
X-Rate-Limit-Limit: the rate limit period (eg. 1m, 12h, 1d) X-Rate-Limit-Remaining: number of request remaining X-Rate-Limit-Reset: UTC date time (ISO 8601) when the limits resets
public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNext()){ int N=sc.nextInt(); int[] data=new int[N]; for (int i = 0; i < N; i++) { int n=sc.nextInt(); int max=sc.nextInt(); int sum=max; n--; while(n-->0) { int num=sc.nextInt(); if(sum>0) sum += num; else sum = num; if(sum>max) max = sum; } data[i]=max; } for (int i = 0; i < N; i++) { System.out.println(data[i]); } } sc.close(); } }
public class Blog { public int Id { get; set; } public string Name { get; set; } public string Url { get; set; } public bool IsDeleted { get; set; } public DateTime CreatedTime { get; set; } public DateTime ModifiedTime { get; set; } public ICollection<Post> Posts { get; set; } }
public abstract class Payment { public int PaymentId { get; set; } public decimal Amount { get; set; } public string Name { get; set; } public bool IsDeleted { get; set; } }
public class CashPayment : Payment { }
public class CreditcardPayment : Payment { public string CreditcardNumber { get; set; } }
public class Blog : ISoftDleteBaseEntity { public int Id { get; set; } public string Name { get; set; } public string Url { get; set; } public bool IsDeleted { get; set; } ...... }