Ejemplo n.º 1
0
        public void InspectAlert(Alert alert)
        {
            bool condionAns      = socialMediaManager.VerifyCondition(alert);
            int  notificationNmr = 1;

            if (condionAns == true)
            {
                AlertType type = alert.Type;
                if (type != AlertType.mail)
                {
                    //TODO controleer of notification al in database is opgenomen
                    if (!alertRepository.NotificationExists(alert.AlertId))
                    {
                        Notification notification = new Notification()
                        {
                            NotificationId = notificationNmr, DateTime = DateTime.Now, Alert = alert
                        };
                        alertRepository.CreateNotification(notification);
                        alert.Notifications.Add(notification);
                        //TODO klopt niet, moet een user wel als attribuut in Alert opgenomen worden?
                        alertRepository.UpdateAlert(alert);
                        notificationNmr++;
                    }
                }
                if (type != AlertType.notification)
                {
                    this.SendMail(alert);
                }
            }
        }
        private void CompareNrOfPostsWithSelf(Alert alert)
        {
            int tweetAmount    = socialMediaRepository.ReadNrOfPostsFromItem(alert.Item, DateTime.Now, DateTime.Now.AddHours(-FREQUENTIE));
            int oldTweetAmount = socialMediaRepository.ReadNrOfPostsFromItem(alert.Item, DateTime.Now.AddHours(-FREQUENTIE), DateTime.Now.AddHours(-(FREQUENTIE * 2)));

            if (alert.ConditionPerc > 100)
            {
                if (tweetAmount >= oldTweetAmount * (alert.ConditionPerc / 100))
                {
                    if (!alertRepository.NotificationExists(alert.AlertId))
                    {
                        Notification notification = new Notification()
                        {
                            DateTime = DateTime.Now, Alert = alert
                        };
                        notification.Content = String.Format("Er wordt meer over {0} gepraat op sociale media", alert.Item.Name);
                        alertRepository.CreateNotification(notification);
                        alert.Notifications.Add(notification);
                        alertRepository.UpdateAlert(alert);
                        SendAlert(alert, notification);
                    }
                }
            }
            else
            {
                if (tweetAmount <= oldTweetAmount * (alert.ConditionPerc / 100))
                {
                    if (!alertRepository.NotificationExists(alert.AlertId))
                    {
                        Notification notification = new Notification()
                        {
                            DateTime = DateTime.Now, Alert = alert
                        };
                        notification.Content = String.Format("Er wordt minder over {0} gepraat op sociale media", alert.Item.Name);
                        alertRepository.CreateNotification(notification);
                        alert.Notifications.Add(notification);
                        alertRepository.UpdateAlert(alert);
                        SendAlert(alert, notification);
                    }
                }
            }
        }