public void ProcessRequest(HttpContext context) { var tenant = context.Session["TenantID"]; int tenantId = tenant as int? ?? -1; if (tenantId == -1) { tenantId = Core.Utilities.Tenant.GetMasterID(); } var sessionTool = new SessionTools(context.Session); var cachedStatus = sessionTool.GetCache(context.Cache, CacheKey.Status, tenantId) as JsonStatus; try { if (cachedStatus != null) { context.Response.ContentType = "application/json"; context.Response.Write(JsonConvert.SerializeObject(cachedStatus)); return; } } catch (Exception ex) { this.Log().Error("Error looking up status data in cache: {0}", ex.Message); } var jsonResponse = new JsonStatus(); try { var result = new TenantStatus(tenantId).CurrentStatus(); jsonResponse.RegisteredPatrons = result.RegisteredPatrons; jsonResponse.PointsEarned = result.PointsEarned; jsonResponse.PointsEarnedReading = result.PointsEarnedReading; jsonResponse.ChallengesCompleted = result.ChallengesCompleted; jsonResponse.SecretCodesRedeemed = result.SecretCodesRedeemed; jsonResponse.AdventuresCompleted = result.AdventuresCompleted; jsonResponse.BadgesAwarded = result.BadgesAwarded; jsonResponse.RedeemedProgramCodes = result.RedeemedProgramCodes; jsonResponse.Since = "All Participants"; jsonResponse.Success = true; } catch (Exception ex) { this.Log().Error("Status update error: {0}", ex.Message); jsonResponse.Success = false; } if (jsonResponse.Success) { try { DateTime cacheUntil = DateTime.UtcNow.AddSeconds(30); if (sessionTool.GetCache(context.Cache, CacheKey.Status, tenantId) == null) { //this.Log().Debug("Caching status data until {0}", // cacheUntil.ToLocalTime().ToLongTimeString()); string tenantCacheKey = sessionTool.GetTenantCacheKey(CacheKey.Status, tenantId); context.Cache.Insert(tenantCacheKey, jsonResponse, null, cacheUntil, System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Default, null); } } catch (Exception ex) { this.Log().Error("Error caching status response: {0}", ex.Message); } } context.Response.ContentType = "application/json"; context.Response.Write(JsonConvert.SerializeObject(jsonResponse)); }
public void ProcessRequest(HttpContext context) { var tenant = context.Session["TenantID"]; int tenantId = tenant as int? ?? -1; if (tenantId == -1) { tenantId = Core.Utilities.Tenant.GetMasterID(); } string cacheKey = string.Format("{0}.{1}", CacheKey.Status, tenantId); try { if (context.Cache[cacheKey] != null) { var cachedJsonResponse = context.Cache[cacheKey] as JsonStatus; if (cachedJsonResponse != null) { context.Response.ContentType = "application/json"; context.Response.Write(JsonConvert.SerializeObject(cachedJsonResponse)); return; } } } catch (Exception ex) { this.Log().Error("Error looking up status data in cache: {0}", ex.Message); } var jsonResponse = new JsonStatus(); try { DateTime startingOn = DateTime.MinValue; if (!string.IsNullOrEmpty(context.Request.QueryString["StartingOn"])) { DateTime.TryParse(context.Request.QueryString["StartingOn"], out startingOn); } ProgramStatusReport result = null; if (startingOn == DateTime.MinValue) { result = new ProgramStatus(tenantId).CurrentStatus(); } else { result = new ProgramStatus(startingOn, tenantId).CurrentStatus(); } jsonResponse.PointsEarned = result.PointsEarned; jsonResponse.BadgesAwarded = result.BadgesAwarded; jsonResponse.ChallengesCompleted = result.ChallengesCompleted; if (!string.IsNullOrEmpty(result.Since)) { jsonResponse.Since = result.Since; } else { jsonResponse.Since = "All Participants"; } jsonResponse.Success = true; } catch (Exception ex) { this.Log().Error("Status update error: {0}", ex.Message); jsonResponse.Success = false; } if (jsonResponse.Success) { try { DateTime cacheUntil = DateTime.UtcNow.AddSeconds(30); if (context.Cache[cacheKey] == null) { //this.Log().Debug("Caching status data until {0}", // cacheUntil.ToLocalTime().ToLongTimeString()); context.Cache.Insert(cacheKey, jsonResponse, null, cacheUntil, System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Default, null); } } catch (Exception ex) { this.Log().Error("Error caching status response: {0}", ex.Message); } } context.Response.ContentType = "application/json"; context.Response.Write(JsonConvert.SerializeObject(jsonResponse)); }
public void ProcessRequest(HttpContext context) { var tenant = context.Session["TenantID"]; int tenantId = tenant as int? ?? -1; if (tenantId == -1) { tenantId = Core.Utilities.Tenant.GetMasterID(); } var sessionTool = new SessionTools(context.Session); var cachedStatus = sessionTool.GetCache(context.Cache, CacheKey.Feed, tenantId) as JsonStatus; try { if (cachedStatus != null) { context.Response.ContentType = "application/json"; context.Response.Write(JsonConvert.SerializeObject(cachedStatus)); return; } } catch (Exception ex) { this.Log().Error("Error looking up status data in cache: {0}", ex.Message); } var jsonResponse = new JsonStatus(); try { TenantStatusReport result = null; result = new TenantStatus(tenantId).CurrentStatus(); jsonResponse.PointsEarned = result.PointsEarned; jsonResponse.BadgesAwarded = result.BadgesAwarded; jsonResponse.ChallengesCompleted = result.ChallengesCompleted; jsonResponse.Since = "All Participants"; jsonResponse.Success = true; } catch (Exception ex) { this.Log().Error("Status update error: {0}", ex.Message); jsonResponse.Success = false; } if (jsonResponse.Success) { try { DateTime cacheUntil = DateTime.UtcNow.AddSeconds(30); if (sessionTool.GetCache(context.Cache, CacheKey.Feed, tenantId) == null) { //this.Log().Debug("Caching status data until {0}", // cacheUntil.ToLocalTime().ToLongTimeString()); string tenantCacheKey = sessionTool.GetTenantCacheKey(CacheKey.Status, tenantId); context.Cache.Insert(tenantCacheKey, jsonResponse, null, cacheUntil, System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Default, null); } } catch (Exception ex) { this.Log().Error("Error caching status response: {0}", ex.Message); } } context.Response.ContentType = "application/json"; context.Response.Write(JsonConvert.SerializeObject(jsonResponse)); }
public void ProcessRequest(HttpContext context) { var tenant = context.Session["TenantID"]; int tenantId = tenant as int? ?? -1; if(tenantId == -1) { tenantId = Core.Utilities.Tenant.GetMasterID(); } string cacheKey = string.Format("{0}.{1}", CacheKey.Status, tenantId); try { if(context.Cache[cacheKey] != null) { var cachedJsonResponse = context.Cache[cacheKey] as JsonStatus; if(cachedJsonResponse != null) { context.Response.ContentType = "application/json"; context.Response.Write(JsonConvert.SerializeObject(cachedJsonResponse)); return; } } } catch(Exception ex) { this.Log().Error("Error looking up status data in cache: {0}", ex.Message); } var jsonResponse = new JsonStatus(); try { DateTime startingOn = DateTime.MinValue; if(!string.IsNullOrEmpty(context.Request.QueryString["StartingOn"])) { DateTime.TryParse(context.Request.QueryString["StartingOn"], out startingOn); } ProgramStatusReport result = null; if(startingOn == DateTime.MinValue) { result = new ProgramStatus(tenantId).CurrentStatus(); } else { result = new ProgramStatus(startingOn, tenantId).CurrentStatus(); } jsonResponse.PointsEarned = result.PointsEarned; jsonResponse.BadgesAwarded = result.BadgesAwarded; jsonResponse.ChallengesCompleted = result.ChallengesCompleted; if(!string.IsNullOrEmpty(result.Since)) { jsonResponse.Since = result.Since; } else { jsonResponse.Since = "All Participants"; } jsonResponse.Success = true; } catch(Exception ex) { this.Log().Error("Status update error: {0}", ex.Message); jsonResponse.Success = false; } if(jsonResponse.Success) { try { DateTime cacheUntil = DateTime.UtcNow.AddSeconds(30); if(context.Cache[cacheKey] == null) { //this.Log().Debug("Caching status data until {0}", // cacheUntil.ToLocalTime().ToLongTimeString()); context.Cache.Insert(cacheKey, jsonResponse, null, cacheUntil, System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Default, null); } } catch(Exception ex) { this.Log().Error("Error caching status response: {0}", ex.Message); } } context.Response.ContentType = "application/json"; context.Response.Write(JsonConvert.SerializeObject(jsonResponse)); }