Example #1
0
 public ActionResult CreateAnalog(AnalogRegister register)
 {
     if (ModelState.IsValid)
     {
         RegisterFactory.CreateAnalogRegister(register.DeviceId, register.Alias, register.Description, register.RegisterNumber, register.EngineeringUnit, register.ScalingFactor, register.SignednessType);
         return RedirectToAction("Edit", "Device", new { id = register.DeviceId });
     }
     return View(register);
 }
Example #2
0
 public static AnalogRegister CreateAnalogRegister(int devID, string alias, string description, int registerNumber, string engineeringUnit, float scalingFactor, Signedness signedness)
 {
     using (var context = new DynapowerCloudMonitoringDbContext())
     {
         var dev = context.Devices.Find(devID);
         var analogRegister = new AnalogRegister()
         {
             RegisterNumber = registerNumber,
             Alias = alias,
             Description = description,
             DeviceId = dev.Id,
             EngineeringUnit = engineeringUnit,
             ScalingFactor = scalingFactor,
             SignednessType = signedness
         };
         dev.Registers.Add(analogRegister);
         context.SaveChanges();
         return analogRegister;
     }
 }
Example #3
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;
     }
 }
Example #4
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();
 }
Example #5
0
 public ActionResult CreateAnalog(int deviceID)
 {
     var aReg = new AnalogRegister();
     aReg.DeviceId = deviceID;
     return redirectToEdit(aReg);
 }
Example #6
0
 public ActionResult EditRegister(AnalogRegister register)
 {
     if (ModelState.IsValid)
     {
         return updateRegister(register);
     }
     return View(register);
 }
Example #7
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;
 }