Exemple #1
0
        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> 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 }));
        }