Exemplo n.º 1
0
        public async Task <IEnumerable <int> > GetMissingDates(IEnumerable <IPost> posts, Schedule schedule)
        {
            var tempList = posts.ToList();
            var missing  = new List <int>();

            await Task.Run(() => {
                var firstDate = DateTime.Now;
                var nextDate  = firstDate;

                int totalCount = tempList.Count();

                while (totalCount < MAX_POSTPONED + RESERVE)
                {
                    var thisDayDate  = nextDate;
                    var thisDayPosts = tempList.Where(i => UnixTimeConverter.ToDateTime(i.Date).Date == thisDayDate.Date).ToList();

                    foreach (var scheduleItem in schedule.Items)
                    {
                        if (totalCount >= MAX_POSTPONED + RESERVE)
                        {
                            break;
                        }

                        var scheduledDate =
                            ConvertScheduleItemToDateTime(new DateTime(thisDayDate.Year, thisDayDate.Month, thisDayDate.Day),
                                                          scheduleItem);

                        if (scheduledDate <= DateTime.Now)
                        {
                            continue;
                        }

                        var isTimeCorrectlyScheduled =
                            thisDayPosts.Any(i => IsTimeCorrectlyScheduled(i.Date, scheduleItem));

                        if (isTimeCorrectlyScheduled == false)
                        {
                            totalCount++;
                            missing.Add(UnixTimeConverter.ToUnix(scheduledDate));
                        }
                    }

                    nextDate = nextDate.AddDays(1);
                }

                missing.Sort((a, b) => a.CompareTo(b));

                return(missing);
            });

            return(missing);
        }
Exemplo n.º 2
0
        //todo: put this somewhere else
        public bool IsDateMatchTheSchedule(int unixTime, Schedule schedule)
        {
            var dateTime = UnixTimeConverter.ToDateTime(unixTime);

            return(schedule.Items.Any(i => i.Hour == dateTime.Hour && i.Minute == dateTime.Minute));
        }
Exemplo n.º 3
0
        public bool IsTimeCorrectlyScheduled(int unixTime, ScheduleItem scheduleItem)
        {
            var dateTime = UnixTimeConverter.ToDateTime(unixTime);

            return(new ScheduleItem(dateTime).Equals(scheduleItem));
        }