Ejemplo n.º 1
0
        public void ProcessFiredAlerts()
        {
            // Get Generated alerts
            List<ATDevice> generatedAlerts = GetFiredAlerts(this.ProcessorId);

            generatedAlerts.ForEach(d =>
            {
                ATCustomerDetail customerDetail = new ATCustomerDetail();
                customerDetail = GetCustomerDetails(d.Id);

                if (customerDetail != null && customerDetail.IsAccountExpired == false)
                {
                    // Check for the particular customer is having message count (Email/SMS)
                    d.Alerts.ForEach(alert =>
                    {
                        try
                        {
                            // Get templates by its alert type from Global cached variable
                            AlertDelivery ed = new AlertDelivery();

                            // Get Email lists
                            ed.ToAddresses = GetFiredAlertsReceivers(alert.Id);
                            ed.ToAddresses = ed.ToAddresses ?? new List<AlertDeliveryNStatus>();

                            // TODO Get SMS lists

                            if (ed.ToAddresses.Count > 0)
                            {
                                try
                                {
                                    if (ed.ToAddresses.Where(m => m.MediumType == AlertMediumType.Email).ToList().Count > 0
                                    && customerDetail.EMAILBalance > 0)
                                    {
                                        ed.EmailContent = TemplateParser.GetEmailTemplateWithValues(alert.AlarmType, d);
                                        ed.SmtpSettings = new SmtpSettings();
                                        ed = new EmailAlert().SendMail(ed);
                                        customerDetail.EMAILBalance = customerDetail.EMAILBalance - ed.ToAddresses.Select(m => m.MediumType == AlertMediumType.Email && m.SentStatus == DeliveryStatus.Success).Count();
                                    }
                                }
                                catch (Exception ex)
                                {
                                }

                                try
                                {
                                    if (ed.ToAddresses.Where(m => m.MediumType == AlertMediumType.SMS).ToList().Count > 0
                                    && customerDetail.SMSBalance > 0)
                                    {
                                        ed.SmsContent = TemplateParser.GetSmsTemplateWithValues(alert.AlarmType, d);
                                        ed.SMSApiSettings = new SMSApiSettings();
                                        ed = new SmsAlert().SendMessage(ed);
                                        customerDetail.SMSBalance = customerDetail.SMSBalance - ed.ToAddresses.Select(m => m.MediumType == AlertMediumType.SMS && m.SentStatus == DeliveryStatus.Success).Count();
                                    }
                                }
                                catch (Exception ex)
                                {
                                }

                                StoreDeliverLog(d.Id, alert.Id, alert.AlarmType, ed);
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex);
                        }
                    });

                    SaveCustomerDetails(customerDetail.UserId, customerDetail.EMAILBalance, customerDetail.SMSBalance, customerDetail.NOTIFICATIONBalance);
                }

            });
            // Save status
            UpdateFiredAlerts(this.ProcessorId);
        }
Ejemplo n.º 2
0
        public void ProcessFiredAlerts()
        {
            // Get Generated alerts
            List <ATDevice> generatedAlerts = GetFiredAlerts(this.ProcessorId);

            generatedAlerts.ForEach(d =>
            {
                ATCustomerDetail customerDetail = new ATCustomerDetail();
                customerDetail = GetCustomerDetails(d.Id);

                if (customerDetail != null && customerDetail.IsAccountExpired == false)
                {
                    // Check for the particular customer is having message count (Email/SMS)
                    d.Alerts.ForEach(alert =>
                    {
                        try
                        {
                            // Get templates by its alert type from Global cached variable
                            AlertDelivery ed = new AlertDelivery();

                            // Get Email lists
                            ed.ToAddresses = GetFiredAlertsReceivers(alert.Id);
                            ed.ToAddresses = ed.ToAddresses ?? new List <AlertDeliveryNStatus>();

                            // TODO Get SMS lists

                            if (ed.ToAddresses.Count > 0)
                            {
                                try
                                {
                                    if (ed.ToAddresses.Where(m => m.MediumType == AlertMediumType.Email).ToList().Count > 0 &&
                                        customerDetail.EMAILBalance > 0)
                                    {
                                        ed.EmailContent = TemplateParser.GetEmailTemplateWithValues(alert.AlarmType, d);
                                        ed.SmtpSettings = new SmtpSettings();
                                        ed = new EmailAlert().SendMail(ed);
                                        customerDetail.EMAILBalance = customerDetail.EMAILBalance - ed.ToAddresses.Select(m => m.MediumType == AlertMediumType.Email && m.SentStatus == DeliveryStatus.Success).Count();
                                    }
                                }
                                catch (Exception ex)
                                {
                                }

                                try
                                {
                                    if (ed.ToAddresses.Where(m => m.MediumType == AlertMediumType.SMS).ToList().Count > 0 &&
                                        customerDetail.SMSBalance > 0)
                                    {
                                        ed.SmsContent     = TemplateParser.GetSmsTemplateWithValues(alert.AlarmType, d);
                                        ed.SMSApiSettings = new SMSApiSettings();
                                        ed = new SmsAlert().SendMessage(ed);
                                        customerDetail.SMSBalance = customerDetail.SMSBalance - ed.ToAddresses.Select(m => m.MediumType == AlertMediumType.SMS && m.SentStatus == DeliveryStatus.Success).Count();
                                    }
                                }
                                catch (Exception ex)
                                {
                                }

                                StoreDeliverLog(d.Id, alert.Id, alert.AlarmType, ed);
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex);
                        }
                    });

                    SaveCustomerDetails(customerDetail.UserId, customerDetail.EMAILBalance, customerDetail.SMSBalance, customerDetail.NOTIFICATIONBalance);
                }
            });
            // Save status
            UpdateFiredAlerts(this.ProcessorId);
        }