Пример #1
0
        public static List <SchedulerSettings> GetActiveSchedulerSettings()
        {
            SchedulerSettings        schedulerSettings;
            List <SchedulerSettings> schedulerSettingsList = null;
            DataSet dsSchedulerSettings = SchedulerDao.GetActiveSchedulerSettings();

            if (dsSchedulerSettings != null)
            {
                if (dsSchedulerSettings.Tables[0].Rows.Count > 0)
                {
                    schedulerSettingsList = new List <SchedulerSettings>();
                    foreach (DataRow dr in dsSchedulerSettings.Tables[0].Rows)
                    {
                        schedulerSettings = new SchedulerSettings();

                        int.TryParse(dr["SchedulerSettingsId"].ToString(), out int iSchedulerSettingsId);
                        schedulerSettings.SchedulerSettingsId = iSchedulerSettingsId;
                        int.TryParse(dr["SchedulerId"].ToString(), out int iSchedulerId);
                        schedulerSettings.SchedulerId = iSchedulerId;
                        DateTime.TryParse(dr["ExecutionTimeStamp"].ToString(), out DateTime dExecutionTime);
                        schedulerSettings.ExecutionTime = dExecutionTime;
                        int.TryParse(dr["HourlyRecurrence"].ToString(), out int iHourlyRecurrence);
                        schedulerSettings.HourlyRecurrence = iHourlyRecurrence;
                        int.TryParse(dr["DailyRecurrence"].ToString(), out int iDailyRecurrence);
                        schedulerSettings.DailyRecurrence = iDailyRecurrence;
                        int.TryParse(dr["WeeklyRecurrence"].ToString(), out int iWeeklyRecurrence);
                        schedulerSettings.WeeklyRecurrence = iWeeklyRecurrence;
                        int.TryParse(dr["SelectedDayOfWeek"].ToString(), out int iSelectedDayOfWeek);
                        schedulerSettings.SelectedDayOfWeek = iSelectedDayOfWeek;
                        int.TryParse(dr["SelectedMonth"].ToString(), out int iSelectedMonth);
                        schedulerSettings.SelectedMonth = iSelectedMonth;
                        int.TryParse(dr["SelectedDayOfMonth"].ToString(), out int iSelectedDayOfMonth);
                        schedulerSettings.SelectedDayOfMonth = iSelectedDayOfMonth;
                        bool.TryParse(dr["Enabled"].ToString(), out bool bEnabled);
                        schedulerSettings.Enabled = bEnabled;

                        // Add scheduler settings to the list
                        schedulerSettingsList.Add(schedulerSettings);
                    }
                }
            }
            return(schedulerSettingsList);
        }
Пример #2
0
        /// <summary>
        /// Get upcoming scheduler execution
        /// </summary>
        /// <param name="iRecurrenceFrequency"></param>
        /// <param name="dLastExecution"></param>
        /// <param name="dLastLoggedExecution"></param>
        /// <param name="oSchedulerSettings"></param>
        /// <param name="iRecordActionStatus"></param>
        /// <returns></returns>
        public static DateTime?GetUpcomingSchedulerExecution(int iRecurrenceFrequency, ref SchedulerExecution oExecution, DateTime?dLastLoggedExecution,
                                                             ref SchedulerSettings oSchedulerSettings, ref int iRecordActionStatus)
        {
            DateTime?dtReturnValue        = null;
            TimeSpan settingExecutionTime = oSchedulerSettings.ExecutionTime.TimeOfDay;

            switch (iRecurrenceFrequency)
            {
            case (int)Enumerations.RecurrenceFrequency.OneTime:
                #region commented

                /*if (DateTime.Now < oSchedulerSettings.ExecutionTime)
                 *  dtReturnValue = oSchedulerSettings.ExecutionTime;
                 * else
                 * {
                 *  oSchedulerSettings.Enabled = false;
                 *  return null;
                 * }*/
                #endregion
                break;

            case (int)Enumerations.RecurrenceFrequency.Daily:

                int dailyRecurrence = oSchedulerSettings.DailyRecurrence;
                if (oExecution.ExecutionTimeStamp != null)
                {
                    // If last execution > now then it is pending
                    if (oExecution.ExecutionTimeStamp > DateTime.Now)
                    {
                        // Flag that indicates that no new execution should be inserted in TPioSchedulerExecution
                        iRecordActionStatus = (int)Enumerations.RecordActionStatus.Keep;

                        dtReturnValue = oExecution.ExecutionTimeStamp;
                    }
                    else
                    {
                        // If the execution is completed update the execution time, else keep
                        if (oExecution.Status == (int)Enumerations.ExecutionStatus.Completed)
                        {
                            // Flag that indicates that a new execution should replace the old one in TPioSchedulerExecution
                            iRecordActionStatus = (int)Enumerations.RecordActionStatus.Update;

                            // Add daily recurrence to the last execution
                            dtReturnValue = oExecution.ExecutionTimeStamp.Value.AddDays(dailyRecurrence);
                            // If dtReturnValue > now return it, else calculate the nearest timestamp
                            if (dtReturnValue < DateTime.Now)
                            {
                                if (DateTime.Now.TimeOfDay < settingExecutionTime)
                                {
                                    dtReturnValue = DateTime.Today.Add(settingExecutionTime);
                                }
                                else
                                {
                                    dtReturnValue = DateTime.Today.AddDays(1).Add(settingExecutionTime);
                                }
                            }
                        }
                        else
                        {
                            iRecordActionStatus = (int)Enumerations.RecordActionStatus.Keep;
                        }
                    }
                }
                else
                {
                    // Flag that indicates that a new execution should be inserted in TPioSchedulerExecution
                    iRecordActionStatus = (int)Enumerations.RecordActionStatus.Insert;

                    // If no execution found, refer to the log
                    if (dLastLoggedExecution != null)
                    {
                        dtReturnValue = dLastLoggedExecution.Value.AddDays(dailyRecurrence);
                        // If dtReturnValue > now return it, else calculate the nearest timestamp
                        if (dtReturnValue < DateTime.Now)
                        {
                            if (DateTime.Now.TimeOfDay < settingExecutionTime)
                            {
                                dtReturnValue = DateTime.Today.Add(settingExecutionTime);
                            }
                            else
                            {
                                dtReturnValue = DateTime.Today.AddDays(1).Add(settingExecutionTime);
                            }
                        }
                    }
                    else
                    {
                        // No past execution found, calculate the nearest timestamp
                        if (DateTime.Now.TimeOfDay < settingExecutionTime)
                        {
                            dtReturnValue = DateTime.Today.Add(settingExecutionTime);
                        }
                        else
                        {
                            dtReturnValue = DateTime.Today.AddDays(1).Add(settingExecutionTime);
                        }
                    }
                }
                break;

            case (int)Enumerations.RecurrenceFrequency.Weekly:
                break;

            case (int)Enumerations.RecurrenceFrequency.Monthly:
                break;

            default:
                break;
            }


            return(dtReturnValue);
        }
Пример #3
0
 public static bool SetSchedulerSettingState(SchedulerSettings settings)
 {
     return(SchedulerDao.SetSchedulerSettingState(settings.SchedulerSettingsId, settings.Enabled));
 }