Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            notificationList = Notification.GetNotifications();
            InitNotificationSendDateDictionary();

            while (true)
            {
                foreach (Notification notification in notificationList)
                {
                    double currentValue = Measurement.GetCurrentValue(MeasurementType.GetMeasurementTypes()
                                                                      .Find(x => x.name == notification.measurement_type).id, notification.tunnel.id);

                    DateTime currentDateTime = DateTime.Now;

                    if (notification.condition == "<")
                    {
                        if (currentValue < notification.value)
                        {
                            if ((currentDateTime - notificationSendDate[notification.id]).TotalMinutes > notification.repeat_after)
                            {
                                string messageText = $"W tunelu {notification.tunnel.name} wartość" +
                                                     $" {notification.measurement_type} " +
                                                     $"nie może byc mniejsze od {notification.value} a jest równe = {currentValue}";

                                try {
                                    new MailSending(notification.receivers).SendMessage(messageText);
                                } catch (Exception e) {
                                    Console.WriteLine(e);
                                }


                                notificationSendDate[notification.id] = currentDateTime;
                            }
                        }
                    }
                    else if (notification.condition == ">")
                    {
                        if (currentValue > notification.value)
                        {
                            if ((currentDateTime - notificationSendDate[notification.id]).TotalMinutes > notification.repeat_after)
                            {
                                string messageText = $"W tunelu {notification.tunnel.name} wartość" +
                                                     $" {notification.measurement_type} " +
                                                     $"nie może byc większe od {notification.value} a jest równe = {currentValue}";

                                try {
                                    new MailSending(notification.receivers).SendMessage(messageText);
                                } catch (Exception e) {
                                    Console.WriteLine(e);
                                }

                                notificationSendDate[notification.id] = currentDateTime;
                            }
                        }
                    }
                }

                Thread.Sleep(30000);
            }
        }
Ejemplo n.º 2
0
 public IActionResult GetMeasurementTypes()
 {
     return(new ObjectResult(MeasurementType.GetMeasurementTypes()));
 }