Example #1
0
        void TimeElapsed(object sender, ElapsedEventArgs e)
        {
            _longTimer++;

            if (_longTimer >= 60)
            {
                _longTimer = 0;
                AlarmTools.TimeElapsedMinute(sender, e);
            }
        }
Example #2
0
        public void UpdateVariableSingle(string name, float currentValue, DateTime timeStamp)
        {
            if (_time == null)
            {
                _longTimer      = DateTime.UtcNow.Second;
                _time           = new Timer(1000);
                _time.Elapsed  += TimeElapsed;
                _time.AutoReset = true;
                _time.Start();
            }

            ServiceVariable serviceVariable;

            //ako postoji variabla pod imenom na servisu updejtaj vrijednost ako ne postoji kreiraj
            try
            {
                serviceVariable = (from v in ServiceVariables
                                   where v.VariableDto.VariableName == name
                                   select v).First();
                serviceVariable.VariableDto.CurrentValue = currentValue.ToString(CultureInfo.InvariantCulture);
            }
            catch (Exception)
            {
                var variableDto = new VariableDto
                {
                    CurrentValue = currentValue.ToString(CultureInfo.InvariantCulture),
                    VariableName = name,
                };
                serviceVariable = new ServiceVariable(variableDto);
                ServiceVariables.Add(serviceVariable);
            }

            using (var context = new PowerMonitoringModelContainer())
            {
                //ako ne postoji entity na sevicu pogledaj dali variajbla postoji u bazi ako ne postoji kreiraj
                // provaj je naći u bazi pod imenom ako ne postoji kreiraj
                Variable variableEnty;
                try
                {
                    variableEnty = (from v in context.VariableSet
                                    where v.Name == name
                                    select v).First();
                }
                catch (Exception)
                {
                    variableEnty = Variable.CreateVariable(-1, name, _singleTypeString, true);
                    context.AddToVariableSet(variableEnty);
                    context.SaveChanges();
                }

                if (variableEnty == null)
                {
                    return;
                }

                //logiranje
                if (variableEnty.DataLoggingEnabled)
                {
                    if (variableEnty.Type == _singleTypeString)
                    {
                        variableEnty.SingleLogSet.Add(SingleLog.CreateSingleLog(-1, currentValue, timeStamp, -1));
                    }
                    if (variableEnty.Type == _doubleTypeString)
                    {
                        variableEnty.DoubleLogSet.Add(DoubleLog.CreateDoubleLog(-1, currentValue, timeStamp, -1));
                    }
                }
                context.SaveChanges();

                AlarmConfig alarmConfiguration = variableEnty.AlarmConfigSet;
                if (alarmConfiguration == null)
                {
                    return;
                }

                //High
                if (AlarmTools.UpdateAlarmAndReturnIsActive(currentValue, alarmConfiguration, "HI", alarmConfiguration.HI_LevelChange, alarmConfiguration.HI_Enable, AlarmTools.UsporediHi, context) == false)
                {
                    AlarmTools.RemoveLowerAlarmIfHigherLevelExist(context, alarmConfiguration, "HI", "HIHI");
                }
                else
                {
                    AlarmTools.UpdateAcknowladgeFromHigherLevelIfExist(alarmConfiguration, "HI", "HIHI");
                }

                if (AlarmTools.UpdateAlarmAndReturnIsActive(currentValue, alarmConfiguration, "HIHI", alarmConfiguration.HIHI_LevelChange, alarmConfiguration.HIHI_Enable, AlarmTools.UsporediHi, context))
                {
                    AlarmTools.RemoveAlarmIfExist(context, alarmConfiguration, "HI");
                }

                //Low
                if (AlarmTools.UpdateAlarmAndReturnIsActive(currentValue, alarmConfiguration, "LO", alarmConfiguration.LO_LevelChange, alarmConfiguration.LO_Enable, AlarmTools.UsporediLo, context) == false)
                {
                    AlarmTools.RemoveLowerAlarmIfHigherLevelExist(context, alarmConfiguration, "LO", "LOLO");
                }
                else
                {
                    AlarmTools.UpdateAcknowladgeFromHigherLevelIfExist(alarmConfiguration, "LO", "LOLO");
                }
                if (AlarmTools.UpdateAlarmAndReturnIsActive(currentValue, alarmConfiguration, "LOLO", alarmConfiguration.LOLO_LevelChange, alarmConfiguration.LOLO_Enabled, AlarmTools.UsporediLo, context))
                {
                    AlarmTools.RemoveAlarmIfExist(context, alarmConfiguration, "LO");
                }

                context.SaveChanges();
            }
        }