Example #1
0
 public void turnOff()
 {
     Task.Run(() =>
     {
         using (var db = new SimpleScadaContext())
         {
             db.Data.AddRange(data);
             db.SaveChanges();
         }
     });
 }
Example #2
0
        public void alarmHandling(DateTime actualTime, Variables variable)
        {
            if (variable.Alarm == true)
            {
                switch (variable.Type)
                {
                case "BOOL":
                    if (alarmInList == null && readBoolValue(variable.Source).Equals("True"))
                    {
                        alarmInList.Add(new AlarmList()
                        {
                            TimeReceived = actualTime.ToShortDateString() + " " + actualTime.ToLongTimeString(), VariableName = variable.Name, AlarmValue = 1, Text = variable.AlarmText, Active = true
                        });
                    }
                    else if (alarmInList != null)
                    {
                        if (alarmInList.Any(p => p.VariableName.Equals(variable.Name)) == false && readBoolValue(variable.Source).Equals("True"))
                        {
                            alarmInList.Add(new AlarmList()
                            {
                                TimeReceived = actualTime.ToShortDateString() + " " + actualTime.ToLongTimeString(), VariableName = variable.Name, AlarmValue = 1, Text = variable.AlarmText, Active = true
                            });
                        }
                        else if (alarmInList.Any(p => p.VariableName.Equals(variable.Name)) == true && readBoolValue(variable.Source).Equals("False"))
                        {
                            var tempAlarm = alarmInList.First(p => p.VariableName.Equals(variable.Name)) as AlarmList;

                            using (var db = new SimpleScadaContext())
                            {
                                db.AlarmHistory.Add(new AlarmHistory()
                                {
                                    TimeReceived    = tempAlarm.TimeReceived,
                                    TimeAcknowledge = actualTime.ToShortDateString() + " " + actualTime.ToLongTimeString(),
                                    VariableName    = tempAlarm.VariableName,
                                    Text            = tempAlarm.Text,
                                    AlarmValue      = tempAlarm.AlarmValue
                                });
                                db.SaveChanges();
                            }

                            alarmInList.Remove(tempAlarm);
                        }
                    }
                    break;


                default:
                    break;
                }
            }
        }