private ATCustomerDetail GetCustomerDetails(string DeviceId) { ATCustomerDetail cDetail = new ATCustomerDetail(); try { DataTable dt = new DataTable(); dt = Data.GetData(DataBase.Alert, CommandType.StoredProcedure, "A_GetCustomerDetail", new SqlParameter[] { new SqlParameter("DeviceId", DeviceId) }); cDetail = dt.AsEnumerable().Select(row => new ATCustomerDetail() { UserId = Convert.ToString(row["UserId"]), Username = Convert.ToString(row["Username"]), FirstName = Convert.ToString(row["FirstName"]), LastName = Convert.ToString(row["LastName"]), Address_AddressLine1 = Convert.ToString(row["Address_AddressLine1"]), Address_AddressLine2 = Convert.ToString(row["Address_AddressLine2"]), Address_AddressLine3 = Convert.ToString(row["Address_AddressLine3"]), Address_City = Convert.ToString(row["Address_City"]), Address_State = Convert.ToString(row["Address_State"]), Address_Country = Convert.ToString(row["Address_Country"]), Address_PostalCode = Convert.ToString(row["Address_PostalCode"]), PhoneNo = Convert.ToString(row["PhoneNo"]), Email = Convert.ToString(row["Email"]), WebSite = Convert.ToString(row["WebSite"]), CompanyName = Convert.ToString(row["CompanyName"]), Status = Convert.ToString(row["Status"]), Parent = Convert.ToString(row["Parent"]), Discriminator = Convert.ToString(row["Discriminator"]), SMSBalance = Convert.ToInt32(row["SMSBalance"]), EMAILBalance = Convert.ToInt32(row["EMAILBalance"]), NOTIFICATIONBalance = Convert.ToInt32(row["NOTIFICATIONBalance"]), IsAccountExpired = Convert.ToBoolean(row["IsAccountExpired"]) } ).FirstOrDefault(); } catch (Exception ex) { } return(cDetail); }
private ATCustomerDetail SaveCustomerDetails(string UserId, int EMAILBalance, int SMSBalance, int NOTIFICATIONBalance) { ATCustomerDetail cDetail = new ATCustomerDetail(); try { Data.StoreData_ExecuteNonQuery(DataBase.Alert, CommandType.StoredProcedure, "A_StoreCustomerNotificationCount", new SqlParameter[] { new SqlParameter("UserId", UserId), new SqlParameter("SMSBalance", SMSBalance), new SqlParameter("EMAILBalance", EMAILBalance), new SqlParameter("NOTIFICATIONBalance", NOTIFICATIONBalance) }); } catch (Exception ex) { } return(cDetail); }
private ATCustomerDetail SaveCustomerDetails(string UserId, int EMAILBalance, int SMSBalance, int NOTIFICATIONBalance) { ATCustomerDetail cDetail = new ATCustomerDetail(); try { Data.StoreData_ExecuteNonQuery(DataBase.Alert, CommandType.StoredProcedure, "A_StoreCustomerNotificationCount", new SqlParameter[] { new SqlParameter("UserId", UserId), new SqlParameter("SMSBalance", SMSBalance), new SqlParameter("EMAILBalance", EMAILBalance), new SqlParameter("NOTIFICATIONBalance", NOTIFICATIONBalance) }); } catch (Exception ex) { } return cDetail; }
private ATCustomerDetail GetCustomerDetails(string DeviceId) { ATCustomerDetail cDetail = new ATCustomerDetail(); try { DataTable dt = new DataTable(); dt = Data.GetData(DataBase.Alert, CommandType.StoredProcedure, "A_GetCustomerDetail", new SqlParameter[] { new SqlParameter("DeviceId", DeviceId) }); cDetail = dt.AsEnumerable().Select(row => new ATCustomerDetail() { UserId = Convert.ToString(row["UserId"]), Username = Convert.ToString(row["Username"]), FirstName = Convert.ToString(row["FirstName"]), LastName = Convert.ToString(row["LastName"]), Address_AddressLine1 = Convert.ToString(row["Address_AddressLine1"]), Address_AddressLine2 = Convert.ToString(row["Address_AddressLine2"]), Address_AddressLine3 = Convert.ToString(row["Address_AddressLine3"]), Address_City = Convert.ToString(row["Address_City"]), Address_State = Convert.ToString(row["Address_State"]), Address_Country = Convert.ToString(row["Address_Country"]), Address_PostalCode = Convert.ToString(row["Address_PostalCode"]), PhoneNo = Convert.ToString(row["PhoneNo"]), Email = Convert.ToString(row["Email"]), WebSite = Convert.ToString(row["WebSite"]), CompanyName = Convert.ToString(row["CompanyName"]), Status = Convert.ToString(row["Status"]), Parent = Convert.ToString(row["Parent"]), Discriminator = Convert.ToString(row["Discriminator"]), SMSBalance = Convert.ToInt32(row["SMSBalance"]), EMAILBalance = Convert.ToInt32(row["EMAILBalance"]), NOTIFICATIONBalance = Convert.ToInt32(row["NOTIFICATIONBalance"]), IsAccountExpired = Convert.ToBoolean(row["IsAccountExpired"]) } ).FirstOrDefault(); } catch (Exception ex) { } return cDetail; }
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); }
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); }