public ActionResult Twilio(int Id, string MessageSid, string SmsStatus) { if (MessageSid.HasValue()) { TwilioHelper.Init(CurrentDatabase); var message = MessageResource.Fetch(MessageSid); var smsItem = CurrentDatabase.SMSItems.FirstOrDefault(m => m.Id == Id); if (smsItem != null && message != null) { TwilioHelper.UpdateSMSItemStatus(CurrentDatabase, smsItem, new TwilioMessageResult(message)); } } // No response needed return(new HttpStatusCodeResult(HttpStatusCode.NoContent)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var connectionString = Configuration.GetSection("HangfireConnection").Value; #region Redis //var redis = StackExchange.Redis.ConnectionMultiplexer.Connect(Configuration.GetSection("Redis").Value); //services.AddDataProtection().PersistKeysToRedis(redis) // .AddKeyManagementOptions(options => options.XmlEncryptor = new NullXmlEncryptor()); #endregion #region DataBase services.AddEntityFrameworkNpgsql().AddDbContext <CoreDataContext>(options => options.UseNpgsql(connectionString)); // custom entity framework key repository services.AddSingleton <IXmlRepository, DataProtectionKeyRepository>(); // this part is needed in 2.0 // I'll update the post once/if I find a better way to get the repository instance var built = services.BuildServiceProvider(); services.AddDataProtection().AddKeyManagementOptions(options => { options.XmlRepository = built.GetService <IXmlRepository>(); options.XmlEncryptor = new NullXmlEncryptor(); }); #endregion User.UserName = Configuration.GetSection("UserName").Value; User.Password = Configuration.GetSection("Password").Value; TwilioHelper.Init(Configuration.GetSection("TwilioAccountSid").Value, Configuration.GetSection("TwilioAuthToken").Value, Configuration.GetSection("TwilioFromPhoneNumber").Value); services.Configure <CookiePolicyOptions>(options => { options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.AddMvc() .AddRazorPagesOptions(option => { option.Conventions.AuthorizeFolder("/").AllowAnonymousToPage("/Index").AllowAnonymousToPage("/Privacy").AllowAnonymousToPage("/Account/Login"); }) .SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddAuthentication(options => { options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; }) .AddCookie(); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddHttpClient(); #region 创建文件 File.WriteAllText(Path.Combine(AppContext.BaseDirectory, "recurringjob.json"), Configuration.GetSection("recurringjob").Value); #endregion services.AddHangfire(x => { x.UsePostgreSqlStorage(connectionString, new PostgreSqlStorageOptions() { TransactionSynchronisationTimeout = TimeSpan.FromSeconds(1d) }); x.UseRecurringJob("recurringjob.json"); //x.UseDefaultActivator(); }); }