Ejemplo n.º 1
0
        public NotificationDateValidationInfo DecideNotificationTimeValidation(NotificationDefinition notificationDefinition, NotificationOptions notificationOptions, DateTime now, DateTime requestDate)
        {
            bool     isValid     = false;
            DateTime startTime   = new DateTime();
            DateTime endTime     = new DateTime();
            var      lastNow     = now.AddMinutes(notificationDefinition.SendStartDuration);
            var      lastNowTime = lastNow.TimeOfDay;

            if (NotificationDateValidator.IsExistSchedule(notificationDefinition))
            {
                foreach (var scheduleItem in notificationDefinition.Schedules)
                {
                    if (scheduleItem.StartTime < scheduleItem.EndTime)
                    {
                        var tempEndDate = new DateTime(lastNow.Year, lastNow.Month, lastNow.Day, scheduleItem.EndTime.Hours, scheduleItem.EndTime.Minutes, scheduleItem.EndTime.Seconds);
                        var minEndTime = new DateTime[] { now.AddMinutes(notificationDefinition.SendEndDuration), tempEndDate }.Min();
                        if (lastNowTime.IsBetween(scheduleItem.StartTime, scheduleItem.EndTime) && scheduleItem.Days.Contains((int)lastNow.DayOfWeek))
                        {
                            startTime = lastNow;
                            endTime   = minEndTime;
                            isValid   = true;
                            break;
                        }
                    }
                }
            }

            return(NotificationDateValidator.SetValidDateInfos(startTime, endTime, isValid));
        }
Ejemplo n.º 2
0
        public NotificationDateValidationInfo DecideNotificationTimeValidation(NotificationDefinition notificationDefinition, NotificationOptions notificationOptions, DateTime now, DateTime requestDate)
        {
            bool     isValid   = false;
            DateTime startTime = new DateTime();
            DateTime endTime   = new DateTime();
            //lastNow degerini kullaniyoruz. DateTime.Now'a eklenen sure ile gun bilgisi degisebilir
            var lastNow     = now.AddMinutes(notificationDefinition.SendStartDuration);
            var lastNowTime = lastNow.TimeOfDay;

            if (NotificationDateValidator.IsExistSchedule(notificationDefinition))
            {
                foreach (var scheduleItem in notificationDefinition.Schedules)
                {
                    if (scheduleItem.StartTime < scheduleItem.EndTime)
                    {
                        var residualMinutes = scheduleItem.StartTime.Subtract(now.TimeOfDay).TotalMinutes;
                        residualMinutes = Math.Abs(residualMinutes);

                        if (residualMinutes < notificationDefinition.SendEndDuration && scheduleItem.Days.Contains((int)lastNow.DayOfWeek))
                        {
                            startTime = lastNow.AddMinutes(residualMinutes);
                            endTime   = lastNow.AddMinutes(notificationDefinition.SendEndDuration);
                            isValid   = true;
                            break;
                        }
                    }
                }
            }

            return(NotificationDateValidator.SetValidDateInfos(startTime, endTime, isValid));
        }
Ejemplo n.º 3
0
        public NotificationDateValidationInfo DecideNotificationTimeValidation(NotificationDefinition notificationDefinition, NotificationOptions notificationOptions, DateTime now, DateTime requestDate)
        {
            bool     isValid   = false;
            DateTime startTime = new DateTime();
            DateTime endTime   = new DateTime();

            NotificationDateValidationInfo validDateInfo = new NotificationDateValidationInfo();

            validDateInfo.SendStartTime = startTime;
            validDateInfo.SendEndTime   = endTime;
            validDateInfo.isValid       = isValid;

            var        lastNow = now.AddMinutes(notificationDefinition.SendStartDuration);
            int        today   = (int)lastNow.DayOfWeek;
            List <int> combinedScheduleDays = new List <int>();
            int        scheduleLoopCount    = 0;

            if (NotificationDateValidator.GetSchedulingWaitingStatus(notificationDefinition))
            {
                if (NotificationDateValidator.IsExistSchedule(notificationDefinition))
                {
                    foreach (var scheduleItem in notificationDefinition.Schedules)
                    {
                        scheduleLoopCount++;
                        if (notificationDefinition.Schedules.Count == 1)
                        {
                            if (!scheduleItem.Days.Contains(today))    // 1,2,3,4,5,6,0
                            {
                                validDateInfo = SetStartAndEndTime(scheduleItem.Days.ToList(), scheduleItem, today, lastNow, startTime, endTime, isValid, notificationDefinition);
                            }
                        }
                        else
                        {
                            if (notificationDefinition.Schedules.Count > 1)
                            {
                                if (!scheduleItem.Days.Contains(today))
                                {
                                    combinedScheduleDays = combinedScheduleDays.Union(scheduleItem.Days.ToList()).ToList();
                                    if (scheduleLoopCount == notificationDefinition.Schedules.Count)
                                    {
                                        validDateInfo = SetStartAndEndTime(combinedScheduleDays, scheduleItem, today, lastNow, startTime, endTime, isValid, notificationDefinition);
                                    }
                                }
                                else
                                {
                                    break;// O gün takvimde varsa bu class'dan çýk yoluna devam et, burayla iþin yok
                                }
                            }
                        }
                    }
                }
            }


            return(validDateInfo);
        }
Ejemplo n.º 4
0
        public static bool IsOutOfScheduleRequest(NotificationDefinition notificationDefinition, DateTime requestDate, DateTime now)
        {
            var lastNow     = now.AddMinutes(notificationDefinition.SendStartDuration);
            var lastNowTime = lastNow.TimeOfDay;
            int today       = (int)lastNow.DayOfWeek;

            bool result = true;

            if (NotificationDateValidator.IsExistSchedule(notificationDefinition))
            {
                foreach (var scheduleItem in notificationDefinition.Schedules)
                {
                    bool isDayExistInSchedule    = false;
                    bool isNowValidScheduletTime = false;

                    if (scheduleItem.StartTime == scheduleItem.EndTime)
                    {
                        isNowValidScheduletTime = true;
                    }

                    if (scheduleItem.StartTime < scheduleItem.EndTime)
                    {
                        if (lastNowTime.IsBetween(scheduleItem.StartTime, scheduleItem.EndTime))
                        {
                            isNowValidScheduletTime = true;
                        }
                    }

                    if (scheduleItem.StartTime > scheduleItem.EndTime)
                    {
                        if (!lastNowTime.IsBetween(scheduleItem.EndTime, scheduleItem.StartTime))
                        {
                            isNowValidScheduletTime = true;
                        }
                    }

                    if (scheduleItem.Days.Contains(today))
                    {
                        isDayExistInSchedule = true;
                    }

                    if (isNowValidScheduletTime && isDayExistInSchedule)
                    {
                        result = false;
                        break;
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 5
0
        public static DateTime ControlProcessTimeDayOut(NotificationOptions timeOptions, bool isValid, NotificationDefinition notificationDefinition, DateTime now)
        {
            var lastNow = now.AddMinutes(notificationDefinition.SendStartDuration);

            if (NotificationDateValidator.IsExistSchedule(notificationDefinition))
            {
                foreach (var scheduleItem in notificationDefinition.Schedules)
                {
                    if (isValid)
                    {
                        if (timeOptions.SendEndTime.Day != lastNow.Day && !scheduleItem.Days.Contains((int)timeOptions.SendEndTime.DayOfWeek))
                        {
                            //endTime hesabi yapilirken bir sonraki gune gecildi
                            //ve bir sonraki gun valid gunlerden degil ise bir onceki gunun 23:59'u end time'dir.
                            timeOptions.SendEndTime = new DateTime(lastNow.Year, lastNow.Month, lastNow.Day, 23, 59, 59);
                        }
                    }
                }
            }

            return(timeOptions.SendEndTime);
        }
Ejemplo n.º 6
0
        public NotificationDateValidationInfo DecideNotificationTimeValidation(NotificationDefinition notificationDefinition, NotificationOptions notificationOptions, DateTime now, DateTime requestDate)
        {
            bool     isValid   = false;
            DateTime startTime = new DateTime();
            DateTime endTime   = new DateTime();

            var lastNow = now.AddMinutes(notificationDefinition.SendStartDuration);

            if (NotificationDateValidator.IsExistSchedule(notificationDefinition))
            {
                foreach (var scheduleItem in notificationDefinition.Schedules)
                {
                    if (scheduleItem.StartTime == scheduleItem.EndTime && scheduleItem.Days.Contains((int)lastNow.DayOfWeek))
                    {
                        startTime = lastNow;
                        endTime   = startTime.AddMinutes(notificationDefinition.SendEndDuration);
                        isValid   = true;
                        break;
                    }
                }
            }

            return(NotificationDateValidator.SetValidDateInfos(startTime, endTime, isValid));
        }
Ejemplo n.º 7
0
        //Takvim saatleri dýþýnda öncesinde ve sonrasýnda gelen istekleri yönet
        public NotificationDateValidationInfo DecideNotificationTimeValidation(NotificationDefinition notificationDefinition, NotificationOptions notificationOptions, DateTime now, DateTime requestDate)
        {
            bool     isValid   = false;
            DateTime startTime = new DateTime();
            DateTime endTime   = new DateTime();
            //lastNow degerini kullaniyoruz. DateTime.Now'a eklenen sure ile gun bilgisi degisebilir
            var      lastNow     = now.AddMinutes(notificationDefinition.SendStartDuration);
            var      lastNowTime = lastNow.TimeOfDay;
            TimeSpan midNight    = new TimeSpan(23, 59, 59);

            if (NotificationDateValidator.IsExistSchedule(notificationDefinition))
            {
                if (NotificationDateValidator.GetSchedulingWaitingStatus(notificationDefinition))
                {
                    foreach (var scheduleItem in notificationDefinition.Schedules)
                    {
                        if (!lastNowTime.IsBetween(scheduleItem.StartTime, scheduleItem.EndTime))
                        {
                            //16:00-21:00 takvimi için ör istek saati : 15:00
                            //08:00-17:00 takvimi için ör istek saati : 07:00
                            if (lastNowTime < scheduleItem.StartTime)
                            {
                                var newDate = new DateTime(now.Year, now.Month, now.Day, 00, 00, 00);
                                startTime = newDate + scheduleItem.StartTime;
                                endTime   = startTime.AddMinutes(notificationDefinition.SendEndDuration);
                                isValid   = true;
                                break;
                            }


                            if (lastNowTime > scheduleItem.EndTime)
                            {
                                //16:00-21:00 takvimi için ör istek saati : 22:00
                                //08:00-17:00 takvimi için ör istek saati : 18:00
                                if (lastNowTime.IsBetween(scheduleItem.EndTime, midNight))
                                {
                                    var newDate = new DateTime(now.Year, now.Month, now.Day, 00, 00, 00);
                                    newDate   = newDate.AddDays(1);
                                    startTime = newDate + scheduleItem.StartTime;
                                    endTime   = startTime.AddMinutes(notificationDefinition.SendEndDuration);
                                    isValid   = true;
                                    break;
                                }


                                //16:00-21:00 takvimi için ör istek saati : 00:00 'dan sonra 16:00'a kadar. Ör: 00:40 veya 02:00
                                //08:00-17:00 takvimi için ör istek saati : 00:00 'dan sonra 08:00'a kadar. Ör: 00:40 veya 02:00
                                if (lastNowTime.IsLessThanOrEquals(midNight))
                                {
                                    var newDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 00, 00, 00);
                                    startTime = newDate + scheduleItem.StartTime;
                                    endTime   = startTime.AddMinutes(notificationDefinition.SendEndDuration);
                                    isValid   = true;
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            return(NotificationDateValidator.SetValidDateInfos(startTime, endTime, isValid));
        }