Example #1
0
        public static List <SchedulerExecution> GetCurrentExecutions()
        {
            SchedulerExecution        schedulerExecution;
            List <SchedulerExecution> schedulerExecutionList = null;
            DataSet dsSchedulerExecutions = SchedulerDao.GetCurrentExecutions();

            if (dsSchedulerExecutions != null)
            {
                if (dsSchedulerExecutions.Tables[0].Rows.Count > 0)
                {
                    schedulerExecutionList = new List <SchedulerExecution>();
                    foreach (DataRow dr in dsSchedulerExecutions.Tables[0].Rows)
                    {
                        schedulerExecution = new SchedulerExecution();

                        int.TryParse(dr["SchedulerExecutionId"].ToString(), out int iSchedulerExecutionId);
                        schedulerExecution.SchedulerExecutionId = iSchedulerExecutionId;
                        int.TryParse(dr["SchedulerSettingsId"].ToString(), out int iSchedulerSettingsId);
                        schedulerExecution.SchedulerSettingsId = iSchedulerSettingsId;

                        DateTime.TryParse(dr["ExecutionTimeStamp"].ToString(), out DateTime dExecutionTimeStamp);
                        schedulerExecution.ExecutionTimeStamp = dExecutionTimeStamp;
                        int.TryParse(dr["Status"].ToString(), out int iStatus);
                        schedulerExecution.Status = iStatus;

                        // Add scheduler settings to the list
                        schedulerExecutionList.Add(schedulerExecution);
                    }
                }
            }
            return(schedulerExecutionList);
        }
Example #2
0
        public static bool CreateExecution(ref SchedulerExecution execution)
        {
            int iSchedulerExecutionId = SchedulerDao.AddExecution(execution);

            if (iSchedulerExecutionId != 0)
            {
                execution.SchedulerExecutionId = iSchedulerExecutionId;
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #3
0
 public static bool UpdateExecution(SchedulerExecution execution)
 {
     return(SchedulerDao.UpdateExecution(execution.SchedulerExecutionId, execution.ExecutionTimeStamp, execution.Status));
 }
Example #4
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);
        }