コード例 #1
0
ファイル: RegisterController.cs プロジェクト: Osceus/Cobra
 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);
 }
コード例 #2
0
ファイル: RegisterFactory.cs プロジェクト: Osceus/Cobra
 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;
     }
 }
コード例 #3
0
ファイル: FeedbackHandler.cs プロジェクト: Osceus/Cobra
 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;
     }
 }
コード例 #4
0
ファイル: FeedbackHandler.cs プロジェクト: Osceus/Cobra
 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();
 }
コード例 #5
0
ファイル: RegisterController.cs プロジェクト: Osceus/Cobra
 public ActionResult CreateAnalog(int deviceID)
 {
     var aReg = new AnalogRegister();
     aReg.DeviceId = deviceID;
     return redirectToEdit(aReg);
 }
コード例 #6
0
ファイル: RegisterController.cs プロジェクト: Osceus/Cobra
 public ActionResult EditRegister(AnalogRegister register)
 {
     if (ModelState.IsValid)
     {
         return updateRegister(register);
     }
     return View(register);
 }
コード例 #7
0
ファイル: SensorCloudPusher.cs プロジェクト: Osceus/Cobra
 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;
 }