private static void treatBadBloodPatient(object o) { bool sendMail = true; InputData input = o as InputData; if (input.BShowWindowBox) { DialogResult ret = MessageBoxEx.Show(Properties.ResStrings.strAlertBlood, Properties.ResStrings.strAlertDetected, MessageBoxButtons.YesNo, MessageBoxIcon.Stop, 10000); if (ret == DialogResult.No) { sendMail = false; } } if (sendMail) { MainDBClass db = new MainDBClass(); if (db.OpenDB()) { smtpInfo smtp = db.getSmtpInfo(true); alertInfo alert = db.getAlertInfo(AlertType.AT_Bad_Blood_Patient, true); db.CloseDB(); if ((alert != null) && (smtp != null)) { createAndSendMail(alert, smtp, input.Device, input.UTC, input.SpareData); } } } }
public bool AddAlertInfo(alertInfo alert) { switch (useDb) { case dbUsedType.db_SqlLite: return(sqliteProvider.AddAlertInfo(alert)); case dbUsedType.db_SqlServer: return(sqlServerProvider.AddAlertInfo(alert)); } return(false); }
private void buttonSaveAlert_Click(object sender, EventArgs e) { try { if (comboBoxAlertType.SelectedIndex >= 0) { selAlert = (AlertType)comboBoxAlertType.SelectedIndex; selAlertInfo = new alertInfo(); selAlertInfo.AlertName = selAlert.ToString(); selAlertInfo.RecipientList = textBoxMailToList.Text; selAlertInfo.CCRecipientList = textBoxCCList.Text; selAlertInfo.BCCRecipientList = textBoxBCCList.Text; selAlertInfo.MailSubject = textBoxMailSubject.Text; selAlertInfo.AlertMessage = richTextBox.Text; selAlertInfo.bActive = checkBoxAlertActive.Checked; if (selAlert == AlertType.AT_Remove_Tag_Max_Time) { if (checkedListBox.CheckedIndices.Count > 0) { selAlertInfo.alertData = textBoxAlert.Text; for (int i = 0; i < checkedListBox.CheckedIndices.Count; i++) { selAlertInfo.alertData += ";" + DeviceArray[checkedListBox.CheckedIndices[i]].SerialRFID; } } } else { selAlertInfo.alertData = textBoxAlert.Text; } db.DeleteAlert(selAlertInfo); db.AddAlertInfo(selAlertInfo); MessageBox.Show(ResStrings.strAlertSaved, ResStrings.strAlertManagmentInfo, MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception exp) { ErrorMessage.ExceptionMessageBox.Show(exp); } }
private void buttonTestAlert_Click(object sender, EventArgs e) { try { if (comboBoxAlertType.SelectedIndex >= 0) { selAlert = (AlertType)comboBoxAlertType.SelectedIndex; selAlertInfo = new alertInfo(); selAlertInfo.AlertName = selAlert.ToString(); selAlertInfo.RecipientList = textBoxMailToList.Text; selAlertInfo.CCRecipientList = textBoxCCList.Text; selAlertInfo.BCCRecipientList = textBoxBCCList.Text; selAlertInfo.MailSubject = textBoxMailSubject.Text; selAlertInfo.AlertMessage = richTextBox.Text; selAlertInfo.bActive = checkBoxAlertActive.Checked; if (selAlert == AlertType.AT_Remove_Tag_Max_Time) { if (checkedListBox.SelectedIndices.Count > 0) { selAlertInfo.alertData = textBoxAlert.Text; for (int i = 0; i < checkedListBox.SelectedIndices.Count; i++) { selAlertInfo.alertData += ";" + DeviceArray[checkedListBox.SelectedIndices[i]].SerialRFID; } } } else { selAlertInfo.alertData = textBoxAlert.Text; } createAndSendMail(selAlertInfo, smtp); } } catch (Exception exp) { ErrorMessage.ExceptionMessageBox.Show(exp); } }
private static void treatValueRemoved(object o) { InputData input = o as InputData; if (input.BShowWindowBox) { MessageBoxEx.Show(Properties.ResStrings.strAlertValue, Properties.ResStrings.strAlertDetected, MessageBoxButtons.OK, MessageBoxIcon.Stop, 10000); } MainDBClass db = new MainDBClass(); if (db.OpenDB()) { smtpInfo smtp = db.getSmtpInfo(true); alertInfo alert = db.getAlertInfo(AlertType.AT_Limit_Value_Exceed, true); db.CloseDB(); if ((alert != null) && (smtp != null)) { createAndSendMail(alert, smtp, input.Device, input.UTC, input.SpareData); } } }
private void createAndSendMail(alertInfo alert, smtpInfo smtp) { bool mailcreated = false; //create the mail message MailMessage mail = null; string mailbody = null; mailcreated = true; mail = new MailMessage(); //set the addresses mail.From = new MailAddress(smtp.sender); string[] recpt = alert.RecipientList.Split(';'); foreach (string str in recpt) { mail.To.Add(str.Trim()); } if (!string.IsNullOrEmpty(alert.BCCRecipientList)) { string[] bcc = alert.BCCRecipientList.Split(';'); foreach (string str in bcc) { mail.Bcc.Add(str.Trim()); } } if (!string.IsNullOrEmpty(alert.CCRecipientList)) { string[] cc = alert.CCRecipientList.Split(';'); foreach (string str in cc) { mail.CC.Add(str.Trim()); } } string subject = alert.MailSubject; subject = subject.Replace("\n", "<br/>"); mail.Subject = subject; string body = alert.AlertMessage; body = body.Replace("\n", "<br/>"); mailbody = body; /*Attachment data = new Attachment(path); * mail.Attachments.Add(data);*/ if (mailcreated) { //first we create the Plain Text part AlternateView plainView = AlternateView.CreateAlternateViewFromString(mailbody, null, "text/plain"); //then we create the Html part //to embed images, we need to use the prefix 'cid' in the img src value //the cid value will map to the Content-Id of a Linked resource. //thus <img src='cid:companylogo'> will map to a LinkedResource with a ContentId of 'companylogo' AlternateView htmlView; htmlView = AlternateView.CreateAlternateViewFromString(mailbody + "<br />", null, "text/html"); //add the views mail.AlternateViews.Add(plainView); mail.AlternateViews.Add(htmlView); //send the message SmtpClient SmtpServer = new SmtpClient(smtp.smtp); SmtpServer.Port = smtp.port; if (smtp.bUseSSL) { SmtpServer.EnableSsl = true; } SmtpServer.Credentials = new System.Net.NetworkCredential(smtp.login, smtp.pwd); SmtpServer.Send(mail); MessageBox.Show(Properties.ResStrings.strAlertTestOk, Properties.ResStrings.stralertTestInfo, MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void getAlert(AlertType selAlert) { try { selAlertInfo = db.getAlertInfo(selAlert, false); if (selAlertInfo != null) { textBoxMailToList.Text = selAlertInfo.RecipientList; textBoxCCList.Text = selAlertInfo.CCRecipientList; textBoxBCCList.Text = selAlertInfo.BCCRecipientList; textBoxMailSubject.Text = selAlertInfo.MailSubject; richTextBox.Text = selAlertInfo.AlertMessage; checkBoxAlertActive.Checked = selAlertInfo.bActive; switch (selAlertInfo.type) { case AlertType.AT_Door_Open_Too_Long: case AlertType.AT_Max_Fridge_Temp: case AlertType.AT_Stock_Limit: textBoxAlert.Text = selAlertInfo.alertData; break; case AlertType.AT_Remove_Tag_Max_Time: if (selAlertInfo.alertData.Contains(';')) { string[] data = selAlertInfo.alertData.Split(';'); textBoxAlert.Text = data[0]; checkedListBox.ClearSelected(); if (data.Length > 2) { for (int i = 1; i < data.Length; i++) { for (int loop = 0; loop < DeviceArray.Length; loop++) { if (DeviceArray[loop].SerialRFID == data[i]) { checkedListBox.SetItemChecked(loop, true);; break; } } } } } break; default: textBoxAlert.Text = null; break; } } else { textBoxMailToList.Text = null; textBoxCCList.Text = null; textBoxBCCList.Text = null; textBoxMailSubject.Text = null; richTextBox.Text = null; checkBoxAlertActive.Checked = false; textBoxAlert.Text = null; } } catch (Exception exp) { ErrorMessage.ExceptionMessageBox.Show(exp); } }
static void Main(string[] args) { WebRequest wr = WebRequest.Create("https://fogos.pt/new/fires"); wr.Method = "GET"; wr.Proxy = GetProxy(); WebResponse response = wr.GetResponse(); var sr = new StreamReader(response.GetResponseStream()); var myStr = sr.ReadToEnd(); JObject jo = JObject.Parse(myStr); string xml = string.Empty; if (jo.Value <bool>("success")) { JArray data = jo.Value <JArray>("data"); alert oAlert = new alert(); oAlert.identifier = Guid.NewGuid().ToString(); oAlert.msgType = alertMsgType.Alert; oAlert.scope = alertScope.Public; oAlert.sender = "https://fogos.pt"; oAlert.sent = DateTime.UtcNow; oAlert.status = alertStatus.Actual; List <alertInfo> infoList = new List <alertInfo>(); foreach (var item in data) { alertInfo info = new alertInfo(); info.category = new[] { alertInfoCategory.Fire }; info.certainty = alertInfoCertainty.Observed; info.description = item.Value <string>("location"); info.language = "pt-PT"; info.description = string.Format("Status:{0}-Homens:{1}-M.Aereos:{2}", item.Value <string>("status"), item.Value <string>("man"), item.Value <string>("aerial")); if (item.Value <bool>("important")) { info.description += item.Value <string>("extra"); } int raio = 0; switch (item.Value <string>("statusCode")) { case "10": case "9": info.severity = alertInfoSeverity.Minor; break; case "8": case "7": info.severity = alertInfoSeverity.Moderate; raio = 1; break; case "5": info.severity = alertInfoSeverity.Severe; raio = 3; if (item.Value <bool>("important")) { info.severity = alertInfoSeverity.Extreme; raio = 5; } break; } info.@event = "Ocorrencia"; info.urgency = alertInfoUrgency.Immediate; info.expires = DateTime.Now.AddDays(1); info.web = "https://fogos.pt"; List <alertInfoArea> areaList = new List <alertInfoArea>(); alertInfoArea area = new alertInfoArea(); area.circle = new[] { string.Format("{0},{1} {2}", item.Value <string>("lat"), item.Value <string>("lng"), raio) }; area.areaDesc = info.description; areaList.Add(area); info.area = areaList.ToArray(); infoList.Add(info); // break; } oAlert.info = infoList.ToArray(); XmlSerializer xmlSerializer = new XmlSerializer(typeof(alert)); using (StringWriter xw = new Utf8StringWriter()) { xmlSerializer.Serialize(xw, oAlert); xml = xw.ToString(); } } Console.Write(xml); Console.ReadKey(); }
private static void createAndSendMail(alertInfo alert, smtpInfo smtp, DeviceInfo device, UserClassTemplate utc, string spareData) { bool mailcreated = false; //create the mail message MailMessage mail = null; string mailbody = null; mailcreated = true; mail = new MailMessage(); //set the addresses mail.From = new MailAddress(smtp.sender); string[] recpt = alert.RecipientList.Split(';'); foreach (string str in recpt) { mail.To.Add(str.Trim()); } if (!string.IsNullOrEmpty(alert.BCCRecipientList)) { string[] bcc = alert.BCCRecipientList.Split(';'); foreach (string str in bcc) { mail.Bcc.Add(str.Trim()); } } if (!string.IsNullOrEmpty(alert.CCRecipientList)) { string[] cc = alert.CCRecipientList.Split(';'); foreach (string str in cc) { mail.CC.Add(str.Trim()); } } /* mail.Subject = alert.MailSubject + " " + device.DeviceName + " [S/N:" + device.SerialRFID + "]"; * mailbody = string.Empty; * * mailbody += "Alert type : <B>" + alert.AlertMessage + "</B><br />"; * mailbody += "Alert date : <B>" + DateTime.Now.ToLongDateString() + " at " + DateTime.Now.ToLongTimeString() + "</B><br />"; * mailbody += "Alert on device : <B>" + device.DeviceName + " [s/n: " + device.SerialRFID + "]" + "</B><br />"; * * switch (alert.type) * { * case AlertType.AT_Door_Open_Too_Long: * case AlertType.AT_Finger_Alert: * mailbody += "Alert generated by user : <B>" + utc.firstName + " " + utc.lastName + "</B><br />"; * break; * case AlertType.AT_Remove_Too_Many_Items: * case AlertType.AT_Limit_Value_Exceed: * mailbody += "Alert generated by user : <B>" + utc.firstName + " " + utc.lastName + "</B><br />"; * mailbody += "User removed <B>" + spareData + "</B><br />"; * break; * } */ string subject = alert.MailSubject; subject = subject.Replace("\n", "<br/>"); if (device != null) { subject = subject.Replace("[READERNAME]", device.DeviceName); subject = subject.Replace("[READERSERIAL]", device.SerialRFID); } if (utc != null) { subject = subject.Replace("[USERNAME]", utc.firstName + " " + utc.lastName); } subject = subject.Replace("[DATE]", DateTime.Now.ToLongDateString() + " at " + DateTime.Now.ToLongTimeString()); mail.Subject = subject; string body = alert.AlertMessage; body = body.Replace("\n", "<br/>"); if (device != null) { body = body.Replace("[READERNAME]", device.DeviceName); body = body.Replace("[READERSERIAL]", device.SerialRFID); } if (utc != null) { body = body.Replace("[USERNAME]", utc.firstName + " " + utc.lastName); } body = body.Replace("[DATE]", DateTime.Now.ToLongDateString() + " at " + DateTime.Now.ToLongTimeString()); body += "<br />"; switch (alert.type) { case AlertType.AT_Remove_Too_Many_Items: case AlertType.AT_Limit_Value_Exceed: body += "<br />User removed " + spareData + "<br />"; break; case AlertType.AT_Max_Fridge_Temp: body += "<br />" + spareData + "<br />"; break; case AlertType.AT_Remove_Tag_Max_Time: string[] dt = spareData.Split(';'); if (dt != null) { int nbTag = dt.Length - 1; body += "<br />All the following " + nbTag + " tag(s) have been removed from device than more " + dt[0] + " Minutes<br />"; for (int i = 1; i < dt.Length; i++) { body += " <br /> " + dt[i]; } } break; case AlertType.AT_Stock_Limit: string[] spData = spareData.Split(';'); if (spData != null) { for (int i = 0; i < spData.Length; i += 2) { body += "<br />Product " + spData[i] + " reach low stock limit : " + spData[i + 1] + " Left"; } } break; case AlertType.AT_DLC_Expired: /* string[] dt2 = spareData.Split(';'); * * if (dt2!= null) * { * int nbTag = dt2.Length - 1; * body += "<br />All the following " + nbTag + " product(s) have overtake their date of use<br />"; * * for (int i = 1; i < dt2.Length; i++) * body += " <br /> " + dt2[i]; * } */ break; case AlertType.AT_Bad_Blood_Patient: string[] dt3 = spareData.Split(';'); if (dt3 != null) { string patient = dt3[0]; body += "<br />The following blood bags removed are not for patient " + patient + "<br />"; for (int i = 1; i < dt3.Length; i++) { body += " <br /> " + dt3[i]; } } break; } mailbody = body; /*Attachment data = new Attachment(path); * mail.Attachments.Add(data);*/ if (mailcreated) { //first we create the Plain Text part AlternateView plainView = AlternateView.CreateAlternateViewFromString(mailbody, null, "text/plain"); //then we create the Html part //to embed images, we need to use the prefix 'cid' in the img src value //the cid value will map to the Content-Id of a Linked resource. //thus <img src='cid:companylogo'> will map to a LinkedResource with a ContentId of 'companylogo' AlternateView htmlView; htmlView = AlternateView.CreateAlternateViewFromString(mailbody + "<br />", null, "text/html"); //add the views mail.AlternateViews.Add(plainView); mail.AlternateViews.Add(htmlView); //send the message SmtpClient SmtpServer = new SmtpClient(smtp.smtp); SmtpServer.Port = smtp.port; if (smtp.bUseSSL) { SmtpServer.EnableSsl = true; } SmtpServer.Credentials = new System.Net.NetworkCredential(smtp.login, smtp.pwd); SmtpServer.Send(mail); } }