Esempio n. 1
0
        public ActionResult _SeedIntervals(string subplatform)
        {
            Subplatform   Subplatform = SubplatformMgr.GetSubplatform(subplatform);
            SeedIntervals huidige     = new SeedIntervals
            {
                SEED_INTERVAL_HOURS = int.Parse(SubplatformMgr.GetSubplatformSetting(
                                                    Subplatform.SubplatformId,
                                                    Setting.Platform.SEED_INTERVAL_HOURS)
                                                .Value
                                                ),
                SEND_WEEKLY_REVIEWS_INTERVAL_DAYS = int.Parse(SubplatformMgr.GetSubplatformSetting(
                                                                  Subplatform.SubplatformId,
                                                                  Setting.Platform.SEND_WEEKLY_REVIEWS_INTERVAL_DAYS)
                                                              .Value
                                                              ),
                ALERT_GENERATION_INTERVAL_HOURS = int.Parse(SubplatformMgr.GetSubplatformSetting(
                                                                Subplatform.SubplatformId,
                                                                Setting.Platform.ALERT_GENERATION_INTERVAL_HOURS)
                                                            .Value
                                                            )
            };

            return(PartialView(huidige));
        }
Esempio n. 2
0
        public ActionResult SeedIntervals(string subplatform, SeedIntervals intervals)
        {
            Subplatform Subplatform = SubplatformMgr.GetSubplatform(subplatform);
            List <SubplatformSetting> subplatformSettings = new List <SubplatformSetting>
            {
                new SubplatformSetting
                {
                    SettingName = Setting.Platform.SEND_WEEKLY_REVIEWS_INTERVAL_DAYS,
                    Value       = intervals.SEND_WEEKLY_REVIEWS_INTERVAL_DAYS.ToString(),
                    IsEnabled   = true,
                    Subplatform = Subplatform
                },
                new SubplatformSetting
                {
                    SettingName = Setting.Platform.SEED_INTERVAL_HOURS,
                    Value       = intervals.SEED_INTERVAL_HOURS.ToString(),
                    IsEnabled   = true,
                    Subplatform = Subplatform
                },
                new SubplatformSetting
                {
                    SettingName = Setting.Platform.ALERT_GENERATION_INTERVAL_HOURS,
                    Value       = intervals.ALERT_GENERATION_INTERVAL_HOURS.ToString(),
                    IsEnabled   = true,
                    Subplatform = Subplatform
                }
            };

            SubplatformMgr.ChangeSubplatformSettings(Subplatform, subplatformSettings);

            #region Reset schedules
            // Cleanup & Seed
            JobManager.AllSchedules
            .Where(s => s.Name.Equals(Subplatform.URL + "-seed")).ToList()
            .ForEach(s =>
            {
                JobManager.RemoveJob(s.Name);
            });
            JobManager.AddJob(() =>
            {
                Startup.JobSemaphore.Wait();
                try { itemMgr.CleanupOldRecords(Subplatform); }
                finally
                {
                    ItemManager.IsCleaning = false;
                    Startup.JobSemaphore.Release();
                }

                Startup.JobSemaphore.Wait();
                try { itemMgr.SyncDatabase(Subplatform); }
                finally
                {
                    ItemManager.IsSyncing = false;
                    Startup.JobSemaphore.Release();
                }
            },
                              (schedule) => schedule
                              .WithName(Subplatform.URL + "-seed")
                              .ToRunOnceAt(1, 0)
                              .AndEvery(intervals.SEED_INTERVAL_HOURS).Hours());

            // Alert generation
            JobManager.AllSchedules
            .Where(s => s.Name.Equals(Subplatform.URL + "-alert")).ToList()
            .ForEach(s =>
            {
                JobManager.RemoveJob(s.Name);
            });
            JobManager.AddJob(() =>
            {
                Startup.JobSemaphore.Wait();
                try { accountMgr.GenerateAllAlerts(itemMgr.GetItems().Where(i => i.SubPlatforms.Contains(Subplatform))); }
                finally
                {
                    AccountManager.IsGeneratingAlerts = false;
                    Startup.JobSemaphore.Release();
                }
            },
                              (schedule) => schedule
                              .WithName(Subplatform.URL + "-alert")
                              .ToRunOnceAt(4, 0)
                              .AndEvery(intervals.ALERT_GENERATION_INTERVAL_HOURS).Hours());

            // Send weekly reviews
            JobManager.AllSchedules
            .Where(s => s.Name.Equals(Subplatform.URL + "-weeklyreview")).ToList()
            .ForEach(s =>
            {
                JobManager.RemoveJob(s.Name);
            });
            DateTime dateToSendWeeklyReview = DateTime.Today.AddDays(7 - (int)DateTime.Today.DayOfWeek);
            JobManager.AddJob(() =>
            {
                Startup.JobSemaphore.Wait();
                try { accountMgr.SendWeeklyReviews(Subplatform); }
                finally
                {
                    AccountManager.IsSendingWeeklyReviews = false;
                    Startup.JobSemaphore.Release();
                }
            },
                              (schedule) => schedule
                              .WithName(Subplatform.URL + "-weeklyreview")
                              .ToRunOnceAt(dateToSendWeeklyReview.AddMinutes(30).AddHours(18))
                              .AndEvery(intervals.SEND_WEEKLY_REVIEWS_INTERVAL_DAYS).Days().At(18, 30));
            #endregion

            return(RedirectToAction("PlatformSettings", "Subplatform"));
        }