示例#1
0
        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}");
                }
            }
        }
示例#2
0
        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);
            }
        }
示例#3
0
        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));
        }
示例#4
0
 public bool ShouldProcessTask(ArticleScheduleTask task, DateTime dateTimeToCheck, bool forMonitoring = false)
 {
     return(ShouldProcessTask(RecurringTask.Create(task), dateTimeToCheck, forMonitoring));
 }
示例#5
0
 private static Tuple <DateTime, DateTime> GetTaskRange(RecurringTask task) => GetTaskRange(task.StartDate, task.EndDate);
示例#6
0
        private static DateTime GetNearestEndDate(RecurringTask task, DateTime nearestEndDate)
        {
            var taskRange = GetTaskRange(task);

            return(taskRange.CompareRangeTo(nearestEndDate) > 0 ? taskRange.Item2 : nearestEndDate);
        }
示例#7
0
 public bool ShouldProcessTask(ArticleScheduleTask task, DateTime dateTimeToCheck) => ShouldProcessTask(RecurringTask.Create(task), dateTimeToCheck);