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); }
//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)); }