public async Task <JsonResult> PollForTasks(string key) { int notificationsSent = 0; MirrorStatus mirrorStatus = null; //poll for periodic tasks (subscription notifications etc) if (key == System.Configuration.ConfigurationManager.AppSettings["AdminPollingAPIKey"]) { //send all pending subscription notifications try { notificationsSent = new UserSubscriptionManager().SendAllPendingSubscriptionNotifications(); } catch (Exception) { ;; //failed to send notifications } //update cache mirror try { HttpContext.Application["_MirrorRefreshInProgress"] = true; mirrorStatus = await new CacheProviderMongoDB().PopulatePOIMirror(CacheProviderMongoDB.CacheUpdateStrategy.Modified); } catch (Exception) { ;; //failed to update cache } finally { HttpContext.Application["_MirrorRefreshInProgress"] = false; } } return(Json(new { NotificationsSent = notificationsSent, MirrorStatus = mirrorStatus }, JsonRequestBehavior.AllowGet)); }
public async Task <JsonResult> PollForTasks(string key) { int notificationsSent = 0; MirrorStatus mirrorStatus = null; //poll for periodic tasks (subscription notifications etc) if (key == System.Configuration.ConfigurationManager.AppSettings["AdminPollingAPIKey"]) { //send all pending subscription notifications if (bool.Parse(ConfigurationManager.AppSettings["EnableSubscriptionChecks"]) == true) { try { //TODO: can't run in seperate async thread becuase HttpContext is not available string templateFolderPath = Server.MapPath("~/templates/notifications"); await Task.Run(() => { notificationsSent = new UserSubscriptionManager().SendAllPendingSubscriptionNotifications(templateFolderPath); }); } catch (Exception) { ;; //failed to send notifications } } //update cache mirror try { HttpContext.Application["_MirrorRefreshInProgress"] = true; mirrorStatus = await CacheManager.RefreshCachedData(CacheUpdateStrategy.Modified); } catch (Exception) { ;; //failed to update cache } finally { HttpContext.Application["_MirrorRefreshInProgress"] = false; } //update stats if (this.HttpContext.Cache["_StatsRefreshed"] == null) { var dataSummaryManager = new API.Common.DataSummary.DataSummaryManager(); dataSummaryManager.RefreshStats(); this.HttpContext.Cache.Insert("_StatsRefreshed", true, null, DateTime.Now.AddHours(6), System.Web.Caching.Cache.NoSlidingExpiration); } } return(Json(new { NotificationsSent = notificationsSent, MirrorStatus = mirrorStatus }, JsonRequestBehavior.AllowGet)); }
public async Task <JsonResult> PollForTasks(string key) { int notificationsSent = 0; MirrorStatus mirrorStatus = null; //poll for periodic tasks (subscription notifications etc) if (key == System.Configuration.ConfigurationManager.AppSettings["AdminPollingAPIKey"]) { //send all pending subscription notifications if (bool.Parse(ConfigurationManager.AppSettings["EnableSubscriptionChecks"]) == true) { try { //TODO: can't run in seperate async thread becuase HttpContext is not available string templateFolderPath = _host.ContentRootPath + "/templates/Notifications"; notificationsSent = await new UserSubscriptionManager().SendAllPendingSubscriptionNotifications(templateFolderPath); } catch (Exception) { ;; //failed to send notifications } } //update cache mirror try { _cache.Set("_MirrorRefreshInProgress", true); mirrorStatus = await CacheManager.RefreshCachedData(CacheUpdateStrategy.Modified); } catch (Exception) { ;; //failed to update cache } finally { _cache.Set("_MirrorRefreshInProgress", false); } //update stats if (_cache.Get("_StatsRefreshed") == null) { using (var dataSummaryManager = new API.Common.DataSummary.DataSummaryManager()) { await dataSummaryManager.RefreshStats(); _cache.Set("_StatsRefreshed", true); } } } return(Json(new { NotificationsSent = notificationsSent, MirrorStatus = mirrorStatus })); }
public async Task <JsonResult> RefreshPOIMirror(string mode) { MirrorStatus status = new MirrorStatus(); if (_cache.TryGetValue <bool>("_MirrorRefreshInProgress", out var inProgress) && inProgress == true) { status.StatusCode = System.Net.HttpStatusCode.PartialContent; status.Description = "Update currently in progress"; } else { _cache.Set("_MirrorRefreshInProgress", true); try { if (mode == "repeat") { status = await CacheManager.RefreshCachedData(CacheUpdateStrategy.Incremental); while (status.NumPOILastUpdated > 0) { System.Diagnostics.Debug.WriteLine("Mirror Update:" + status.LastUpdated + " updated, " + status.TotalPOIInCache + " total"); status = await CacheManager.RefreshCachedData(CacheUpdateStrategy.Incremental); } } else if (mode == "all") { status = await CacheManager.RefreshCachedData(CacheUpdateStrategy.All); } else { status = await CacheManager.RefreshCachedData(CacheUpdateStrategy.Modified); } } catch (Exception exp) { status.TotalPOIInCache = 0; status.Description = "Cache update error:" + exp.ToString(); status.StatusCode = System.Net.HttpStatusCode.InternalServerError; } _cache.Set("_MirrorRefreshInProgress", false); } return(Json(status)); }
public async Task <JsonResult> RefreshPOIMirror(string mode) { MirrorStatus status = new MirrorStatus(); if (HttpContext.Application["_MirrorRefreshInProgress"] == null || (bool)HttpContext.Application["_MirrorRefreshInProgress"] == false) { HttpContext.Application["_MirrorRefreshInProgress"] = true; var mirrorManager = new CacheProviderMongoDB(); try { if (mode == "repeat") { status = await mirrorManager.PopulatePOIMirror(CacheProviderMongoDB.CacheUpdateStrategy.Incremental); while (status.NumPOILastUpdated > 0) { System.Diagnostics.Debug.WriteLine("Mirror Update:" + status.LastUpdated + " updated, " + status.TotalPOI + " total"); status = await mirrorManager.PopulatePOIMirror(CacheProviderMongoDB.CacheUpdateStrategy.Incremental); } } else if (mode == "all") { status = await mirrorManager.PopulatePOIMirror(CacheProviderMongoDB.CacheUpdateStrategy.All); } else { status = await mirrorManager.PopulatePOIMirror(CacheProviderMongoDB.CacheUpdateStrategy.Modified); } } catch (Exception exp) { status.TotalPOI = 0; status.Description = "Cache update error:" + exp.ToString(); status.StatusCode = System.Net.HttpStatusCode.InternalServerError; } HttpContext.Application["_MirrorRefreshInProgress"] = false; } else { status.StatusCode = System.Net.HttpStatusCode.PartialContent; status.Description = "Update currently in progress"; } return(Json(status, JsonRequestBehavior.AllowGet)); }
public async Task <ActionResult> CheckPOIMirrorStatus(bool includeDupeCheck = false) { var status = await CacheManager.GetCacheStatus(includeDupeCheck); if (status == null) { status = new MirrorStatus(); status.StatusCode = System.Net.HttpStatusCode.NotFound; status.Description = "Cache is offline"; } else { if (_cache.TryGetValue <bool>("_MirrorRefreshInProgress", out var inProgress) && inProgress == true) { status.Description += " (Update in progress)"; } } return(View(status)); }
public async Task <ActionResult> CheckPOIMirrorStatus(bool includeDupeCheck = false) { var status = await CacheManager.GetCacheStatus(includeDupeCheck); if (status == null) { status = new MirrorStatus(); status.StatusCode = System.Net.HttpStatusCode.NotFound; status.Description = "Cache is offline"; } else { if (HttpContext.Application["_MirrorRefreshInProgress"] != null && (bool)HttpContext.Application["_MirrorRefreshInProgress"] == true) { status.Description += " (Update in progress)"; } } return(View(status)); }
public ActionResult CheckPOIMirrorStatus() { var mirrorManager = new CacheProviderMongoDB(); var status = mirrorManager.GetMirrorStatus(); if (status == null) { status = new MirrorStatus(); status.StatusCode = System.Net.HttpStatusCode.NotFound; status.Description = "Cache is offline"; } else { if (HttpContext.Application["_MirrorRefreshInProgress"] != null && (bool)HttpContext.Application["_MirrorRefreshInProgress"] == true) { status.Description += " (Update in progress)"; } } return(View(status)); }
public async Task<JsonResult> RefreshPOIMirror(string mode) { MirrorStatus status = new MirrorStatus(); if (HttpContext.Application["_MirrorRefreshInProgress"] == null || (bool)HttpContext.Application["_MirrorRefreshInProgress"] == false) { HttpContext.Application["_MirrorRefreshInProgress"] = true; try { if (mode == "repeat") { status = await CacheManager.RefreshCachedData(CacheUpdateStrategy.Incremental); while (status.NumPOILastUpdated > 0) { System.Diagnostics.Debug.WriteLine("Mirror Update:" + status.LastUpdated + " updated, " + status.TotalPOIInCache + " total"); status = await CacheManager.RefreshCachedData(CacheUpdateStrategy.Incremental); } } else if (mode == "all") { status = await CacheManager.RefreshCachedData(CacheUpdateStrategy.All); } else { status = await CacheManager.RefreshCachedData(CacheUpdateStrategy.Modified); } } catch (Exception exp) { status.TotalPOIInCache = 0; status.Description = "Cache update error:" + exp.ToString(); status.StatusCode = System.Net.HttpStatusCode.InternalServerError; } HttpContext.Application["_MirrorRefreshInProgress"] = false; } else { status.StatusCode = System.Net.HttpStatusCode.PartialContent; status.Description = "Update currently in progress"; } return Json(status, JsonRequestBehavior.AllowGet); }
public async Task<ActionResult> CheckPOIMirrorStatus(bool includeDupeCheck = false) { var status = await CacheManager.GetCacheStatus(includeDupeCheck); if (status == null) { status = new MirrorStatus(); status.StatusCode = System.Net.HttpStatusCode.NotFound; status.Description = "Cache is offline"; } else { if (HttpContext.Application["_MirrorRefreshInProgress"] != null && (bool)HttpContext.Application["_MirrorRefreshInProgress"] == true) { status.Description += " (Update in progress)"; } } return View(status); }
public async Task <JsonResult> PollForTasks(string key) { int notificationsSent = 0; MirrorStatus mirrorStatus = null; //poll for periodic tasks (subscription notifications etc) if (key == System.Configuration.ConfigurationManager.AppSettings["AdminPollingAPIKey"]) { //send all pending subscription notifications if (bool.Parse(ConfigurationManager.AppSettings["EnableSubscriptionChecks"]) == true) { try { //TODO: can't run in seperate async thread becuase HttpContext is not available string templateFolderPath = _host.ContentRootPath + "/templates/Notifications"; notificationsSent = await new UserSubscriptionManager().SendAllPendingSubscriptionNotifications(templateFolderPath); } catch (Exception) { ;; //failed to send notifications } } var autoApproveDays = 3; var poiManager = new POIManager(); var newPois = await poiManager.GetPOIListAsync(new APIRequestParams { SubmissionStatusTypeID = 1 }); var user = new UserManager().GetUser((int)StandardUsers.System); foreach (var poi in newPois) { if (poi.SubmissionStatusTypeID == (int)StandardSubmissionStatusTypes.Submitted_UnderReview || poi.SubmissionStatusTypeID == (int)StandardSubmissionStatusTypes.Imported_UnderReview) { if (poi.DateCreated < DateTime.UtcNow.AddDays(-autoApproveDays)) { poi.SubmissionStatusTypeID = (int)StandardSubmissionStatusTypes.Submitted_Published; new SubmissionManager().PerformPOISubmission(poi, user); } } } // check for edit queue items to auto approve using (var editQueueManager = new EditQueueManager()) { var queueItems = editQueueManager.GetEditQueueItems(new EditQueueFilter { ShowProcessed = false }) .Where(q => q.DateProcessed == null).ToList() .OrderBy(q => q.DateSubmitted); foreach (var i in queueItems) { if (i.DateSubmitted < DateTime.UtcNow.AddDays(-autoApproveDays)) { editQueueManager.ProcessEditQueueItem(i.ID, true, (int)StandardUsers.System, true, "Auto Approved"); } } } //update cache mirror try { _cache.Set("_MirrorRefreshInProgress", true); mirrorStatus = await CacheManager.RefreshCachedData(CacheUpdateStrategy.Modified); } catch (Exception) { ;; //failed to update cache } finally { _cache.Set("_MirrorRefreshInProgress", false); } //update stats if (_cache.Get("_StatsRefreshed") == null) { using (var dataSummaryManager = new API.Common.DataSummary.DataSummaryManager()) { await dataSummaryManager.RefreshStats(); _cache.Set("_StatsRefreshed", true); } } } return(Json(new { NotificationsSent = notificationsSent, MirrorStatus = mirrorStatus })); }
private Status(MirrorStatus status) { MirrorStatus = status; }