Beispiel #1
0
        public async Task <IActionResult> ClearSession(string id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var ID = Guid.Parse(id);

            return(Ok(new
            {
                Name = string.Empty,
                res = await session.Clear(ID)
            }));
        }
Beispiel #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <Context>(options =>
                                            options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
            services.AddMvc();

            services.AddResponseCompression(options =>
            {
                options.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(new[]
                {
                    MediaTypeNames.Application.Octet,
                    WasmMediaTypeNames.Application.Wasm,
                });
            });
            services.AddSingleton <SessionProvider>(Session);
            services.AddScheduler(scheduler =>
            {
                scheduler.Schedule(() => Session.Clear())
                .EveryFiveMinutes();
            });
            services.AddScheduler(scheduler =>
            {
                scheduler.Schedule(() =>
                {
                    var option  = new DbContextOptionsBuilder <Context>();
                    var options = option.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")).Options;
                    using (var context = new Context(options))
                    {
                        var r = context.Ads.Where(x => x.AdTime < DateTime.Now.AddDays(-7)).ToList();
                        foreach (var item in r)
                        {
                            item.Expired = true;
                            context.Entry(item).State = EntityState.Modified;
                        }
                        context.Ads.UpdateRange(r);
                        context.SaveChanges();
                    }
                })
                .Weekly();
            });
        }
Beispiel #3
0
 /// <summary>
 /// 清空Session或者删除匹配键的Session
 /// </summary>
 /// <remarks>
 ///  2013-11-23 22:04 Created By iceStone
 /// </remarks>
 /// <param name="pattern">匹配键</param>
 public static void Clear(string pattern = "")
 {
     SessionProvider.Clear(pattern);
 }