Exemplo n.º 1
0
        public ActionResult CreateAnalogRegisterAlert(AnalogRegisterAlert alert)
        {
            if (ModelState.IsValid)
            {
                var areg = findAnalogReg(alert.AnalogRegisterId);
                areg.Alerts.Add(alert);
                db.SaveChanges();

                return redirectToEdit(areg, "");
            }
            return View(alert);
        }
Exemplo n.º 2
0
 private void checkAnalogAlert(AnalogRegisterAlert alert, RegisterFeedback feedback, AnalogRegister reg)
 {
     var scaledValue = reg.BuildScaledValue(feedback);
     switch (alert.Type)
     {
         case AnalogRegisterAlertType.GreaterThan:
             if (!alert.Alerted && scaledValue > alert.Value)
             {
                 alert.Alerted = true;
                 m_context.SaveChanges();
                 sendEmail(alert.EmailSubject, buildAnalogBody(alert, reg, scaledValue), alert.getEmailsList());
             }
             else if (alert.Alerted && scaledValue < alert.Value)
             {
                 alert.Alerted = false;
                 m_context.SaveChanges();
                 sendEmail(alert.EmailSubject, buildAnalogBody(alert, reg, scaledValue), alert.getEmailsList());
             }
             break;
         case AnalogRegisterAlertType.LessThan:
             if (!alert.Alerted && scaledValue < alert.Value)
             {
                 alert.Alerted = true;
                 m_context.SaveChanges();
                 sendEmail(alert.EmailSubject, buildAnalogBody(alert, reg, scaledValue), alert.getEmailsList());
             }
             else if (alert.Alerted && scaledValue > alert.Value)
             {
                 alert.Alerted = false;
                 m_context.SaveChanges();
                 sendEmail(alert.EmailSubject, buildAnalogBody(alert, reg, scaledValue), alert.getEmailsList());
             }
             break;
         case AnalogRegisterAlertType.EqualTo:
             if (!alert.Alerted && scaledValue == alert.Value)
             {
                 alert.Alerted = true;
                 m_context.SaveChanges();
                 sendEmail(alert.EmailSubject, buildAnalogBody(alert, reg, scaledValue), alert.getEmailsList());
             }
             else if (alert.Alerted && scaledValue != alert.Value)
             {
                 alert.Alerted = false;
                 m_context.SaveChanges();
                 sendEmail(alert.EmailSubject, buildAnalogBody(alert, reg, scaledValue), alert.getEmailsList());
             }
             break;
         default:
             break;
     }
 }
Exemplo n.º 3
0
 private string buildAnalogBody(AnalogRegisterAlert alert, AnalogRegister register, float value)
 {
     var builder = new StringBuilder();
     if (alert.Alerted)
     {
         builder.AppendLine(alert.EmailBody);
     }
     else
     {
         builder.AppendLine("No longer in an alerted state.");
     }
     builder.AppendLine("Device: ");
     builder.AppendLine(register.Device.SerialNumber);
     builder.AppendLine("Register: ");
     builder.AppendLine(register.Alias);
     builder.AppendLine("Value: ");
     builder.AppendLine(value.ToString());
     return builder.ToString();
 }
Exemplo n.º 4
0
 public ActionResult CreateAnalogRegisterAlert(int id)
 {
     var regAlert = new AnalogRegisterAlert();
     regAlert.AnalogRegisterId = id;
     return View("EditAnalogRegisterAlert", regAlert);
 }
Exemplo n.º 5
0
 public ActionResult EditAnalogRegisterAlert(AnalogRegisterAlert alert)
 {
     if (ModelState.IsValid)
     {
         db.Entry(alert).State = EntityState.Modified;
         db.SaveChanges();
     }
     var aReg = findAnalogReg(alert.AnalogRegisterId);
     return redirectToEdit(aReg, "");
 }