private void CreateNotifications() { var TimeNow = DateTime.Now.Hour; var CurrentTime = DateTime.Now.Hour; int ScheduleTime = -1; NotificationScheduleDB.RemoveSchedules(Deck); do { CurrentTime = (CurrentTime + Interval) % 24; if (CurrentTime >= Settings.NotificationStartTime && CurrentTime <= Settings.NotificationEndTime) { var Notification = new NotificationSchedule(Deck, CurrentTime, (GameType)GameSelection + 1); NotificationScheduleDB.AddSchedule(Notification); if (ScheduleTime < 0) { ScheduleTime = CurrentTime; } } } while (CurrentTime != CurrentTime); ScheduleAlarm(ScheduleTime); }
public void TestTriggerCreatorNormal() { //var loggerMoq = new Mock<ILogger>(); var quartzMock = new Mock <IScheduler>(); //var logger = loggerMoq.Object; var quartz = quartzMock.Object; var triggerCreator = new TriggerCreator(quartz); var notificationSchedule = new NotificationSchedule { SubscriberID = "*****@*****.**", NotificationType = "notificationType", RunOnSunday = false, RunOnMonday = false, RunOnTuesday = false, RunOnWednesday = false, RunOnThursday = false, RunOnFriday = true, RunOnSaturday = false, RunOnHour = 23, RunOnMinute = 15 }; var trigger = triggerCreator.FillTriggerAsync(notificationSchedule); trigger.Wait(); var itrigger = trigger.Result; // trigger can only look into the future, so need to set up the dates based on today: var today = System.DateTime.Today; // find next thursday: var thursday = today.AddDays(System.DayOfWeek.Thursday - today.DayOfWeek); if (thursday < today) { thursday = thursday.AddDays(7); } var friday = thursday.AddDays(1); var fridayNextWeek = friday.AddDays(7); // thursday 23:22 var referenceDate1 = new System.DateTime(thursday.Year, thursday.Month, thursday.Day, 23, 22, 0); // expect next friday, 23:15 var expectDate1 = new System.DateTime(friday.Year, friday.Month, friday.Day, 23, 15, 0); // friday 23:22 var referenceDate2 = new System.DateTime(friday.Year, friday.Month, friday.Day, 23, 22, 0); // expect next week friday 23:15 var expectDate2 = new System.DateTime(fridayNextWeek.Year, fridayNextWeek.Month, fridayNextWeek.Day, 23, 15, 0); Assert.AreEqual("*****@*****.**", itrigger.Key.Name); Assert.AreEqual("notificationType", itrigger.JobKey.Name); Assert.AreEqual <System.DateTimeOffset>(new System.DateTimeOffset(expectDate1), itrigger.GetFireTimeAfter(new System.DateTimeOffset(referenceDate1)).Value); Assert.AreEqual <System.DateTimeOffset>(new System.DateTimeOffset(expectDate2), itrigger.GetFireTimeAfter(new System.DateTimeOffset(referenceDate2)).Value); }
private Notification GetNotification(NotificationSchedule ScheduledNotification, PendingIntent ContentIntent) { Notification.Builder builder = new Notification.Builder(Application.Context) .SetContentTitle("Time to play!") .SetContentIntent(ContentIntent) .SetContentText(String.Format("Smash some {0} cards", ScheduledNotification.Deck.Name)) .SetSmallIcon(Resource.Drawable.icon) .SetAutoCancel(true); return(builder.Build()); }
private Bundle GetDataBundle(NotificationSchedule ScheduledNotification) { Bundle Data = new Bundle(); var DeckName = ScheduledNotification.Deck.Name; var DeckID = ScheduledNotification.DeckID; var Game = ScheduledNotification.Game; Data.PutString("DeckName", DeckName); Data.PutInt("ID", DeckID); Data.PutInt("Game", Game); return(Data); }
public static void NotificationSchedulMacker() { List <CorrectiveActionApproval> approvalList = new List <CorrectiveActionApproval>(); using (CorrectiveActionApprovalData data = new CorrectiveActionApprovalData()) { List <int> correctiveActionID = data.GetAll().Select(x => x.CorrectiveActionID).ToList(); List <int> correctiveActionIDDistinct = new List <int>(); foreach (int item in correctiveActionID) { if (!correctiveActionIDDistinct.Exists(x => x == item)) { correctiveActionIDDistinct.Add(item); } } foreach (int item in correctiveActionIDDistinct) { CorrectiveActionApproval approval = data.GetMany(x => x.IsApproved == false).First(); approvalList.Add(approval); } } using (NotificationScheduleData data = new NotificationScheduleData()) { foreach (CorrectiveActionApproval item in approvalList) { if (!data.Exists(x => x.CorrectiveActionApprovalID == item.CorrectiveActionApprovalID)) { DateTime newdatetime = DateTime.Now; NotificationSchedule notificationSchedule = new NotificationSchedule() { CorrectiveActionApprovalID = item.CorrectiveActionApprovalID, NotificationDate = null, StartDate = newdatetime, PeriodHours = 48, PeriodCount = 2, NotificationTypeID = 1, NextRunDate = newdatetime }; data.Add(notificationSchedule); } } data.Commit(); } }
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); }
public Event() { Notify = new NotificationSchedule(); }