private void ProcessTask(RecurringTask task, DateTime currentTime, int comparison) { var nearestComparisonToShowArticle = GetNearestComparison(task, currentTime); if (nearestComparisonToShowArticle == 0) { var articleWithinShowRange = _recurringService.ShowArticle(task.ArticleId); if (articleWithinShowRange != null && !articleWithinShowRange.Visible) { Logger.Log.Info($"Article [{articleWithinShowRange.Id}: {articleWithinShowRange.Name}] has been shown on customer code: {_customer.CustomerName}"); } } else if (nearestComparisonToShowArticle > 0 && comparison == 0) { var articleOutOfShowRange = _recurringService.HideArticle(task.ArticleId); if (articleOutOfShowRange != null && articleOutOfShowRange.Visible) { Logger.Log.Info($"Article [{articleOutOfShowRange.Id}: {articleOutOfShowRange.Name}] has been hidden on customer code: {_customer.CustomerName}"); } } else if (nearestComparisonToShowArticle > 0 && comparison > 0) { var articleOutOfShowAndTaskRanges = _recurringService.HideAndCloseSchedule(task.Id); if (articleOutOfShowAndTaskRanges != null && articleOutOfShowAndTaskRanges.Visible) { Logger.Log.Info($"Article [{articleOutOfShowAndTaskRanges.Id}: {articleOutOfShowAndTaskRanges.Name}] has been hidden on customer code: {_customer.CustomerName}"); } } }
public void Run(ArticleScheduleTask articleTask) { var task = RecurringTask.Create(articleTask); var currentTime = _recurringService.GetCurrentDBDateTime(); var taskRange = GetTaskRange(task); var comparison = taskRange.CompareRangeTo(currentTime); if (ShouldProcessTask(task, currentTime)) { ProcessTask(task, currentTime, comparison); } }
private static int GetNearestComparison(RecurringTask task, DateTime currentTime) { var recurringCalculator = RecurringStartCalculatorFactory.Create(task); var nearestStartDate = recurringCalculator.GetNearestStartDateBeforeSpecifiedDate(currentTime); Ensure.NotNull(nearestStartDate); // ReSharper disable once PossibleInvalidOperationException var nearestEndDate = GetNearestEndDate(task, nearestStartDate.Value + task.Duration); var nearestTaskRangeToShowArticle = GetTaskRange(nearestStartDate.Value, nearestEndDate); return(nearestTaskRangeToShowArticle.CompareRangeTo(currentTime)); }
public bool ShouldProcessTask(ArticleScheduleTask task, DateTime dateTimeToCheck, bool forMonitoring = false) { return(ShouldProcessTask(RecurringTask.Create(task), dateTimeToCheck, forMonitoring)); }
private static Tuple <DateTime, DateTime> GetTaskRange(RecurringTask task) => GetTaskRange(task.StartDate, task.EndDate);
private static DateTime GetNearestEndDate(RecurringTask task, DateTime nearestEndDate) { var taskRange = GetTaskRange(task); return(taskRange.CompareRangeTo(nearestEndDate) > 0 ? taskRange.Item2 : nearestEndDate); }
public bool ShouldProcessTask(ArticleScheduleTask task, DateTime dateTimeToCheck) => ShouldProcessTask(RecurringTask.Create(task), dateTimeToCheck);