/// <summary> /// Day to Execute for example if Monday is selected and Today is Monday then this returns true /// </summary> /// <param name="folder"></param> /// <returns></returns> public bool DayToExecute(IFolderConfig folder) { DateTime today = DateTime.Now; bool blExecuteToday = false; switch (today.DayOfWeek) { case DayOfWeek.Monday: if (folder.Monday) { blExecuteToday = true; } break; case DayOfWeek.Tuesday: if (folder.Tuesday) { blExecuteToday = true; } break; case DayOfWeek.Wednesday: if (folder.Wednesday) { blExecuteToday = true; } break; case DayOfWeek.Thursday: if (folder.Thursday) { blExecuteToday = true; } break; case DayOfWeek.Friday: if (folder.Friday) { blExecuteToday = true; } break; case DayOfWeek.Saturday: if (folder.Saturday) { blExecuteToday = true; } break; case DayOfWeek.Sunday: if (folder.Sunday) { blExecuteToday = true; } break; } return(blExecuteToday); }
/// <summary> /// Day of the Month to Execute for example the 5th day of the month or the 20th of the month /// </summary> /// <param name="folder"></param> /// <returns></returns> public bool DayOfMonthToExecute(IFolderConfig folder) { DateTime today = DateTime.Now; bool blExecuteToday = false; if (today.Day == folder.Interval && folder.Interval > 0 && folder.IntervalType == IntervalTypes.Monthly) { blExecuteToday = true; } return(blExecuteToday); }
/// <summary> /// Nth Day of the Month for example the 3rd Monday of the Month /// </summary> /// <param name="folder"></param> /// <returns></returns> private bool NthDayOfMonth(IFolderConfig folder) { DateTime today = DateTime.Now; bool blExecuteToday = false; int n = 0; n = (int)Math.Abs(folder.Interval); if (DayToExecute(folder) && folder.Interval < 0 && folder.IntervalType == IntervalTypes.Monthly) { return((today.Day - 1) / 7 == (n - 1)); } return(blExecuteToday); }
public bool ValidateEndDate(IFolderConfig folder) { bool blExecute = false; DateTime today = DateTime.Now; if (folder.EndDate != null) { if (today <= folder.EndDate || folder.EndDate == DateTime.MinValue) { blExecute = true; } } else { blExecute = true; } return(blExecute); }
/// <summary> /// Checks Multiple Conditions to see if it is the correct Month, Day, and Time to execute /// Also, that Today is in between the StartDate and EndDate /// </summary> /// <param name="folder"></param> /// <returns></returns> public bool ExecuteTime(IFolderConfig folder) { bool blTime = false; if (folder.Enabled) { if (ValidateStartDate(folder) && ValidateEndDate(folder)) { if (MonthToExecute(folder)) { if (string.IsNullOrEmpty(folder.Time) || TimeToExecute(folder)) { if (DayToExecute(folder) || DayOfMonthToExecute(folder) || NthDayOfMonth(folder)) { blTime = true; } } } } } return(blTime); }
/// <summary> /// Is Today in the Month specified to execute /// </summary> /// <param name="folder"></param> /// <returns></returns> public bool MonthToExecute(IFolderConfig folder) { DateTime today = DateTime.Now; bool blExecuteThisMonth = false; switch (today.Month) { case 1: if ((folder.Months & Month.January) == Month.January) { blExecuteThisMonth = true; } break; case 2: if ((folder.Months & Month.February) == Month.February) { blExecuteThisMonth = true; } break; case 3: if ((folder.Months & Month.March) == Month.March) { blExecuteThisMonth = true; } break; case 4: if ((folder.Months & Month.April) == Month.April) { blExecuteThisMonth = true; } break; case 5: if ((folder.Months & Month.May) == Month.May) { blExecuteThisMonth = true; } break; case 6: if ((folder.Months & Month.June) == Month.June) { blExecuteThisMonth = true; } break; case 7: if ((folder.Months & Month.July) == Month.July) { blExecuteThisMonth = true; } break; case 8: if ((folder.Months & Month.August) == Month.August) { blExecuteThisMonth = true; } break; case 9: if ((folder.Months & Month.September) == Month.September) { blExecuteThisMonth = true; } break; case 10: if ((folder.Months & Month.October) == Month.October) { blExecuteThisMonth = true; } break; case 11: if ((folder.Months & Month.November) == Month.November) { blExecuteThisMonth = true; } break; case 12: if ((folder.Months & Month.December) == Month.December) { blExecuteThisMonth = true; } break; } return(blExecuteThisMonth); }
/// <summary> /// Checks to see of the current time is within the appropriate time window to execute per RetentionExecutionTime or CompressExecutionTime /// </summary> /// <param name="strExecutionTime"></param> /// <returns></returns> public bool TimeToExecute(IFolderConfig folder) { string strExecutionTime = ""; bool blTimeStart = false; bool blFinalTimeEnd = false; TimeSpan timeStart; TimeSpan timeEnd; TimeSpan FinalTimeEnd; int intIntervalSeconds; int intIntervalMinutes; int intHours = 0; int intMinutes = 0; try { strExecutionTime = folder.Time; TimeSpan currentTime = DateTime.Now.TimeOfDay; //Interval in Minutes + 1 second to make sure the time occurs within the window of the serviceinterval intIntervalSeconds = (int)((ServiceInterval) / 1000); intIntervalSeconds = intIntervalSeconds + 1; intIntervalMinutes = (int)Math.Floor(((double)intIntervalSeconds / 60)); if (intIntervalSeconds <= 60000) { intIntervalMinutes = 0; } else { intIntervalSeconds = intIntervalSeconds % 60; } blTimeStart = TimeSpan.TryParse(strExecutionTime, out timeStart); if (blTimeStart) { timeEnd = timeStart + new TimeSpan(0, intIntervalMinutes, intIntervalSeconds); } else { //No Time to Start Specified return(false); } blFinalTimeEnd = TimeSpan.TryParse(folder.EndTime, out FinalTimeEnd); if (blTimeStart && currentTime >= timeStart && (currentTime <= timeEnd || (folder.IntervalType == IntervalTypes.Hourly)) && (!blFinalTimeEnd || currentTime <= FinalTimeEnd)) { switch (folder.IntervalType) { case IntervalTypes.Hourly: //Hourly Repetitive Interval //folder.Interval is in Minutes for Hourly int intCurrentMinutes = 0; intHours = (int)(folder.Interval / (long)60); intHours = intHours % 24; intMinutes = (int)((double)folder.Interval % (double)60.0); intCurrentMinutes = (currentTime.Hours % 24) * 60; intCurrentMinutes += currentTime.Minutes % 60; //If reoccurring time remainder is 0 when comparing the current hour and minutes combined into minutes vs the Interval minutes then it is time to execute //Also need to handle the zero remainder when the time is zero hour and zero minutes and add some exceptions (divisors of 60). if (intCurrentMinutes % folder.Interval == 0 && !(currentTime.Minutes == 0 && currentTime.Hours == 0 && !(folder.Interval == 30 || folder.Interval == 20 || folder.Interval == 15 || folder.Interval == 12 || folder.Interval == 10 || folder.Interval == 6 || folder.Interval == 5 || folder.Interval == 4 || folder.Interval == 3 || folder.Interval == 2 || folder.Interval == 1))) { return(true); } else { return(false); } default: //Daily or Monthly the repetitive time doesn't matter, should only execute once return(true); } } else { return(false); } } catch (Exception ex) { string strErr = ex.Message + ": " + ex.Source + " " + ex.StackTrace; writeError(strErr, System.Diagnostics.EventLogEntryType.Error, 6000, 60); return(false); } }
public bool ValidateStartDate(IFolderConfig folder) { bool blExecute = false; DateTime today = DateTime.Now; if (folder.StartDate != null) { if (today >= folder.StartDate || folder.StartDate == DateTime.MinValue) { blExecute = true; } } else { blExecute = true; } return blExecute; }
/// <summary> /// Nth Day of the Month for example the 3rd Monday of the Month /// </summary> /// <param name="folder"></param> /// <returns></returns> private bool NthDayOfMonth(IFolderConfig folder) { DateTime today = DateTime.Now; bool blExecuteToday = false; int n = 0; n = (int)Math.Abs(folder.Interval); if (DayToExecute(folder) && folder.Interval < 0 && folder.IntervalType == IntervalTypes.Monthly) { return (today.Day - 1) / 7 == (n - 1); } return blExecuteToday; }
/// <summary> /// Checks to see of the current time is within the appropriate time window to execute per RetentionExecutionTime or CompressExecutionTime /// </summary> /// <param name="strExecutionTime"></param> /// <returns></returns> public bool TimeToExecute(IFolderConfig folder) { string strExecutionTime = ""; bool blTimeStart = false; bool blFinalTimeEnd = false; TimeSpan timeStart; TimeSpan timeEnd; TimeSpan FinalTimeEnd; int intIntervalSecondsDoubled; int intIntervalDoubled; int intHours = 0; int intMinutes = 0; try { strExecutionTime = folder.Time; TimeSpan currentTime = DateTime.Now.TimeOfDay; //Interval in Minutes Doubled and Subtracted by 1 so that the time window code will only execute once intIntervalSecondsDoubled = (int)((ServiceInterval) / 1000); intIntervalSecondsDoubled += 1; intIntervalDoubled = (int)((ServiceInterval) / 1000 / 60); if (intIntervalSecondsDoubled <= 60000) { intIntervalDoubled = 0; } else { intIntervalSecondsDoubled = 0; } blTimeStart = TimeSpan.TryParse(strExecutionTime, out timeStart); if (blTimeStart) { timeEnd = timeStart + new TimeSpan(0, intIntervalDoubled, intIntervalSecondsDoubled); } else { //No Time to Start Specified return false; } blFinalTimeEnd = TimeSpan.TryParse(folder.EndTime, out FinalTimeEnd); if (blTimeStart && currentTime >= timeStart && (currentTime <= timeEnd || (folder.IntervalType == IntervalTypes.Hourly )) && (!blFinalTimeEnd || currentTime <= FinalTimeEnd)) { switch (folder.IntervalType) { case IntervalTypes.Hourly: //Hourly Repetitive Interval //folder.Interval is in Minutes for Hourly intHours = (int)(folder.Interval / (long)60); intHours = intHours % 24; intMinutes = (int)((double)folder.Interval % (double)60.0); if ((((double)currentTime.Minutes % (double)intMinutes) == 0) && (intHours == 0 || ((double)currentTime.Hours % (double)intHours) == 0)) { return true; } else { return false; } default: //Daily or Monthly the repetitive time doesn't matter, should only execute once return true; } } else { return false; } } catch (Exception ex) { _evt.WriteEntry(ex.Message); return false; } }
/// <summary> /// Is Today in the Month specified to execute /// </summary> /// <param name="folder"></param> /// <returns></returns> public bool MonthToExecute(IFolderConfig folder) { DateTime today = DateTime.Now; bool blExecuteThisMonth = false; switch (today.Month) { case 1: if ((folder.Months & Month.January) == Month.January) { blExecuteThisMonth= true; } break; case 2: if ((folder.Months & Month.February) == Month.February) { blExecuteThisMonth = true; } break; case 3: if ((folder.Months & Month.March) == Month.March) { blExecuteThisMonth = true; } break; case 4: if ((folder.Months & Month.April) == Month.April) { blExecuteThisMonth = true; } break; case 5: if ((folder.Months & Month.May) == Month.May) { blExecuteThisMonth = true; } break; case 6: if ((folder.Months & Month.June) == Month.June) { blExecuteThisMonth = true; } break; case 7: if ((folder.Months & Month.July) == Month.July) { blExecuteThisMonth = true; } break; case 8: if ((folder.Months & Month.August) == Month.August) { blExecuteThisMonth = true; } break; case 9: if ((folder.Months & Month.September) == Month.September) { blExecuteThisMonth = true; } break; case 10: if ((folder.Months & Month.October) == Month.October) { blExecuteThisMonth = true; } break; case 11: if ((folder.Months & Month.November) == Month.November) { blExecuteThisMonth = true; } break; case 12: if ((folder.Months & Month.December) == Month.December) { blExecuteThisMonth = true; } break; } return blExecuteThisMonth; }
/// <summary> /// Checks Multiple Conditions to see if it is the correct Month, Day, and Time to execute /// Also, that Today is in between the StartDate and EndDate /// </summary> /// <param name="folder"></param> /// <returns></returns> public bool ExecuteTime(IFolderConfig folder) { bool blTime = false; if (folder.Enabled) { if (ValidateStartDate(folder) && ValidateEndDate(folder)) { if (MonthToExecute(folder)) { if (string.IsNullOrEmpty(folder.Time) || TimeToExecute(folder)) { if (DayToExecute(folder) || DayOfMonthToExecute(folder) || NthDayOfMonth(folder)) { blTime = true; } } } } } return blTime; }
/// <summary> /// Day to Execute for example if Monday is selected and Today is Monday then this returns true /// </summary> /// <param name="folder"></param> /// <returns></returns> public bool DayToExecute(IFolderConfig folder) { DateTime today =DateTime.Now; bool blExecuteToday = false; switch (today.DayOfWeek) { case DayOfWeek.Monday: if (folder.Monday) { blExecuteToday = true; } break; case DayOfWeek.Tuesday: if (folder.Tuesday) { blExecuteToday = true; } break; case DayOfWeek.Wednesday: if (folder.Wednesday) { blExecuteToday = true; } break; case DayOfWeek.Thursday: if (folder.Thursday) { blExecuteToday = true; } break; case DayOfWeek.Friday: if (folder.Friday) { blExecuteToday = true; } break; case DayOfWeek.Saturday: if (folder.Saturday) { blExecuteToday = true; } break; case DayOfWeek.Sunday: if (folder.Sunday) { blExecuteToday = true; } break; } return blExecuteToday; }
/// <summary> /// Day of the Month to Execute for example the 5th day of the month or the 20th of the month /// </summary> /// <param name="folder"></param> /// <returns></returns> public bool DayOfMonthToExecute(IFolderConfig folder) { DateTime today = DateTime.Now; bool blExecuteToday = false; if (today.Day == folder.Interval && folder.Interval > 0 && folder.IntervalType == IntervalTypes.Monthly) { blExecuteToday = true; } return blExecuteToday; }