public async Task Execute(IJobExecutionContext context)
        {
            var success = long.TryParse(context.Trigger.Description, out var triggerId);

            if (!success)
            {
                return;
            }
            var consumerNotificationSettingsIds = TriggerNotificationsObserver.GetIds(triggerId);

            if (consumerNotificationSettingsIds is null)
            {
                throw new Exception($"The trigger with id: {triggerId} doesn't exist in the {nameof(TriggerNotificationsObserver)}");
            }
            var emailsData = await _databaseRequests.GetNotificationRecipientsAsync(consumerNotificationSettingsIds);

            var consumerNotificationSettingsFromEmails = emailsData.Select(x => x.ConsumerNotificationSetting).ToList();
            var preparedEmails = emailsData.Select(x => new BoundEmailModel(x)).ToList();
            await EmailService.SendBoundEmails(preparedEmails);

            var markedAsCompletedConsumerNotificationSettings = ITCraftFrame.CustomMapper.MapList <ConsumerNotificationSetting, ConsumerNotificationSettingModel>(consumerNotificationSettingsFromEmails);

            markedAsCompletedConsumerNotificationSettings.ForEach(x => x.StatusId = 3);
            await _databaseRequests.UpdateAsync(markedAsCompletedConsumerNotificationSettings);
        }
Esempio n. 2
0
        public async Task Execute(IJobExecutionContext context)
        {
            var success = long.TryParse(context.Trigger.Description, out var triggerId);

            if (!success)
            {
                return;
            }
            var consumerNotificationSettingsIds = TriggerNotificationsObserver.GetIds(triggerId);
            var emailsData = await _databaseRequests.GetNotificationRecipientsAsync(consumerNotificationSettingsIds);

            var preparedEmails = emailsData.Select(x => new BoundEmailModel(x)).ToList();
            await EmailService.SendBoundEmails(preparedEmails);
        }
Esempio n. 3
0
        private static async void Start(string[] args)
        {
            await QuartzScheduler.StartScheduler();

            var _databaseRequests = new DatabaseRequests();
            var notifications     = await _databaseRequests.GetNotificationsAsync();

            TriggerNotificationsObserver.SetUpTriggerNotificationObserver(notifications);

            var triggersAndJobs = GetJobs(notifications);
            var TAJForNotificationJobsUpdater = SetUpNotificationJobsUpdater();

            await QuartzScheduler.ScheduleJobs(triggersAndJobs);

            TriggerNotificationsObserver.AddEvent();

            await QuartzScheduler.ScheduleJob(TAJForNotificationJobsUpdater.Item1, TAJForNotificationJobsUpdater.Item2);
        }
Esempio n. 4
0
        private static IReadOnlyDictionary <IJobDetail, IReadOnlyCollection <ITrigger> > GetJobs(IEnumerable <SimpleTriggerModel> notifications)
        {
            var triggers        = new List <ITrigger>();
            var triggersAndJobs = new Dictionary <IJobDetail, IReadOnlyCollection <ITrigger> >();
            var repeatTypes     = notifications.Select(x => x.RepeatType).Distinct();

            foreach (Repeat repeatType in repeatTypes)
            {
                var job = QuartzJob.CreateJob(repeatType);
                var notificationsOfType = notifications.Where(x => x.RepeatType == repeatType);
                foreach (var notification in notificationsOfType)
                {
                    var triggerId = TriggerNotificationsObserver.GetTriggerId(notification);
                    var trigger   = QuartzTrigger.CreateTrigger(notification.DateStart, notification.RepeatType, triggerId.ToString());//notification.TriggerId.ToString());
                    triggers.Add(trigger);
                }
                triggersAndJobs.Add(job, triggers.ToList());
                triggers.Clear();
            }

            return(triggersAndJobs);
        }
Esempio n. 5
0
        public async Task Execute(IJobExecutionContext context)
        {
            var notifications = await _databaseRequests.GetNotificationsAsync();

            TriggerNotificationsObserver.CompareAndUpdate(notifications);
        }
Esempio n. 6
0
        public static void Test1()
        {
            void DisplayTriggers()
            {
                foreach (var trigger in TriggerNotificationsObserver._triggersInfo)
                {
                    Console.WriteLine($"{trigger.TriggerId} -> {trigger.DateStart} -> {trigger.RepeatType} -> {string.Join(",", trigger.ConsumerNotificationSettingIds)}");
                }
            }

            var date1 = DateTime.Now;
            var date2 = date1.AddDays(1);
            var date3 = date2.AddDays(1);
            var date4 = date3.AddDays(1);

            var setupTriggers = new List <SimpleTriggerModel>()
            {
                new SimpleTriggerModel()
                {
                    DateStart  = date1,
                    RepeatType = Repeat.Once,
                    ConsumerNotificationSettingIds = new List <int>()
                    {
                        1, 2, 3
                    }
                },
                new SimpleTriggerModel()
                {
                    DateStart  = date1,
                    RepeatType = Repeat.Every6Month,
                    ConsumerNotificationSettingIds = new List <int>()
                    {
                        10, 11, 12
                    }
                },
                new SimpleTriggerModel()
                {
                    DateStart  = date2,
                    RepeatType = Repeat.EveryWeek,
                    ConsumerNotificationSettingIds = new List <int>()
                    {
                        100, 101, 102
                    }
                }
            };
            var updateTriggers = new List <SimpleTriggerModel>()
            {
                new SimpleTriggerModel()
                {
                    DateStart  = date1,
                    RepeatType = Repeat.Once,
                    ConsumerNotificationSettingIds = new List <int>()
                    {
                        1, 2, 3, 4, 5, 6
                    }
                },
                new SimpleTriggerModel()
                {
                    DateStart  = date1,
                    RepeatType = Repeat.Every6Month,
                    ConsumerNotificationSettingIds = new List <int>()
                    {
                        10
                    }
                },
//                new SimpleTriggerModel() {
//                    DateStart = date2,
//                    RepeatType = Repeat.EveryWeek,
//                    ConsumerNotificationSettingIds = new List<int>() {100, 101, 102}
//                }
                new SimpleTriggerModel()
                {
                    DateStart  = date3,
                    RepeatType = Repeat.EveryYear,
                    ConsumerNotificationSettingIds = new List <int>()
                    {
                        1000, 10001
                    }
                },
            };

            // no new triggers
//            var updateTriggers2 = new List<SimpleTriggerModel>() {
//                new SimpleTriggerModel() {
//                    DateStart = date1,
//                    RepeatType = Repeat.Once,
//                    ConsumerNotificationSettingIds = new List<int>() {1, 2, 3}
//                },
//                new SimpleTriggerModel() {
//                    DateStart = date1,
//                    RepeatType = Repeat.Every6Month,
//                    ConsumerNotificationSettingIds = new List<int>() {10, 11, 12}
//                },
//                new SimpleTriggerModel() {
//                    DateStart = date2,
//                    RepeatType = Repeat.EveryWeek,
//                    ConsumerNotificationSettingIds = new List<int>() {100, 101, 102}
//                }
//            };
            TriggerNotificationsObserver.SetUpTriggerNotificationObserver(setupTriggers);
            Console.WriteLine("Settuped triggers...");
            DisplayTriggers();
            TriggerNotificationsObserver.AddEvent();
            TriggerNotificationsObserver.CompareAndUpdate(updateTriggers);
            Console.WriteLine("Updated triggers...");
            DisplayTriggers();
        }