예제 #1
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;
     }
 }
예제 #2
0
 private ChannelDataPoints getAnalogFeedbacks(AnalogRegister reg, IEnumerable<RegisterFeedback> feedbacks)
 {
     var dataPoints = new List<SensorCloud.Point>(feedbacks.Count());
     foreach (var feedback in feedbacks)
     {
         dataPoints.Add(new SensorCloud.Point(feedback.ReadAt, reg.BuildScaledValue(feedback)));
     }
     var channelID = reg.RegisterNumber.ToString();
     var channelAndPoints = new ChannelDataPoints()
     {
         ChannelID = channelID,
         DataPoints = dataPoints
     };
     return channelAndPoints;
 }