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); }
public static NotificationDateValidationInfo SetValidDateInfos(DateTime startTime, DateTime endTime, bool isValid) { NotificationDateValidationInfo DateValidInfo = new NotificationDateValidationInfo(); DateValidInfo.SendStartTime = startTime; DateValidInfo.SendEndTime = endTime; DateValidInfo.isValid = isValid; return(DateValidInfo); }
public static bool CheckNotificationValidOptions(NotificationDefinition notificationDefinition, NotificationOptions notificationOptions, DateTime now, DateTime requestDate, out NotificationOptions validOptions) { var isValid = false; var lastNow = now.AddMinutes(notificationDefinition.SendStartDuration); var lastNowTime = lastNow.TimeOfDay; NotificationDateValidationInfo DateValidInfo = new NotificationDateValidationInfo(); foreach (var rule in Rules) { DateValidInfo = rule.DecideNotificationTimeValidation(notificationDefinition, notificationOptions, now, requestDate); if (DateValidInfo.isValid || IsRequestDateLessThanNow(notificationDefinition, requestDate, now)) { break; } } validOptions = new NotificationOptions() { SendStartTime = DateTime.MinValue, SendEndTime = DateTime.MinValue }; //Control if decision starttime expire options endTime if (!NotificationDateValidator.IsNotificationOptionsNullOrEmpty(notificationOptions) && notificationOptions.ControlWithNotificationSchedule) { if (!DateValidInfo.SendStartTime.IsLessThan(notificationOptions.SendEndTime) && DateValidInfo.SendStartTime != DateTime.MinValue) { return(isValid); } if (DateValidInfo.isValid) { validOptions.SendEndTime = notificationOptions.SendEndTime; } } validOptions.SendStartTime = DateValidInfo.SendStartTime; if (validOptions.SendEndTime == DateTime.MinValue) { validOptions.SendEndTime = DateValidInfo.SendEndTime; } isValid = DateValidInfo.isValid; //validOptions.SendEndTime = ControlProcessTimeDayOut(validOptions, isValid, notificationDefinition, now); return(isValid); }
public NotificationDateValidationInfo SetStartAndEndTime(List <int> days, NotificationSchedule scheduleItem, int today, DateTime lastNow, DateTime startTime, DateTime endTime, bool isValid, NotificationDefinition notificationDefinition) { NotificationDateValidationInfo validDateInfo = new NotificationDateValidationInfo(); var lastNowTime = lastNow.TimeOfDay; int daysOfWeek = 7; int counter = 0; int day = 0; while (day < daysOfWeek) { if (today < 6) { today++; } else { today = 0; } counter++;//Saysýn ki arada kaç gün var bilelim if (days.Contains(today)) { lastNow = lastNow.AddDays(counter); lastNowTime = lastNow.TimeOfDay; startTime = lastNow.Date + scheduleItem.StartTime; endTime = startTime.AddMinutes(notificationDefinition.SendEndDuration); isValid = true; break; } day++; } if (isValid) { validDateInfo.SendStartTime = startTime; validDateInfo.SendEndTime = endTime; validDateInfo.isValid = isValid; } return(validDateInfo); }