Beispiel #1
0
        public static void AddActionsToScheduler(
            ReportJobConfiguration config,
            CoreBusinessLayerService service)
        {
            if (!config.get_Enabled())
            {
                return;
            }
            ReportingActionContext reportingActionContext = new ReportingActionContext();

            reportingActionContext.set_AccountID(config.get_AccountID());
            reportingActionContext.set_UrlsGroupedByLeftPart(ReportJobInitializer.GroupUrls(config));
            reportingActionContext.set_WebsiteID(config.get_WebsiteID());
            ReportingActionContext reportingContext  = reportingActionContext;
            MacroContext           macroContext      = ((ActionContextBase)reportingContext).get_MacroContext();
            ReportingContext       reportingContext1 = new ReportingContext();

            reportingContext1.set_AccountID(config.get_AccountID());
            reportingContext1.set_ScheduleName(config.get_Name());
            reportingContext1.set_ScheduleDescription(config.get_Description());
            reportingContext1.set_LastRun(config.get_LastRun());
            reportingContext1.set_WebsiteID(config.get_WebsiteID());
            macroContext.Add((ContextBase)reportingContext1);
            ((ActionContextBase)reportingContext).get_MacroContext().Add((ContextBase) new GenericContext());
            int num = 0;

            if (config.get_Schedules() == null)
            {
                return;
            }
            using (List <ReportSchedule> .Enumerator enumerator1 = config.get_Schedules().GetEnumerator())
            {
                while (enumerator1.MoveNext())
                {
                    ReportSchedule current  = enumerator1.Current;
                    DateTime       dateTime = !current.get_EndTime().HasValue ? DateTime.MaxValue : current.get_EndTime().Value;
                    Scheduler.get_Instance().Add(new ScheduledTask(string.Format("ReportJob-{0}_{1}", (object)config.get_ReportJobID(), (object)num), (TimerCallback)(o =>
                    {
                        ReportJobInitializer.log.Info((object)"Starting action execution");
                        using (List <ActionDefinition> .Enumerator enumerator = config.get_Actions().GetEnumerator())
                        {
                            while (enumerator.MoveNext())
                            {
                                service.ExecuteAction(enumerator.Current, (ActionContextBase)reportingContext);
                            }
                        }
                        config.set_LastRun(new DateTime?(DateTime.Now.ToUniversalTime()));
                        ReportJobDAL.UpdateLastRun(config.get_ReportJobID(), config.get_LastRun());
                    }), (object)null, current.get_CronExpression(), current.get_StartTime(), dateTime, config.get_LastRun(), current.get_CronExpressionTimeZoneInfo()), true);
                    ++num;
                }
            }
        }