Beispiel #1
0
        public void UpdateRows(string columnName, object value)
        {
            var alarmdef = AlarmDataSet.GetActiveAlarmDefinitionTable(group_name);

            for (int i = 0; i < alarmdef.Count; i++)
            {
                if (!alarmdef[i].IsVirtual)
                {
                    alarmdef[i][columnName] = value;
                }
            }
            alarmdef.Save();
        }
Beispiel #2
0
 public CountAlarm(AlarmDataSet.alarm_definitionRow row, string conditionColumnName)
     : base(row)
 {
     this.conditionColumnName = conditionColumnName;
     var m = Regex.Match(row.alarm_condition, Expression);
     if (m.Success)
     {
         limit = Convert.ToInt32(m.Groups["limit"].Value);
         equality = m.Groups["equality"].Value;
     }
     else
     {
         throw new ArgumentException("Invalid condition '"+row.alarm_condition+"' ");
     }
 }
Beispiel #3
0
 public LimitAlarm(AlarmDataSet.alarm_definitionRow row, string conditionColumnName)
     : base(row)
 {
     string condition = row[conditionColumnName].ToString();
     var m = Regex.Match(condition, Expression);
     if (m.Success)
     {
         m_alarmValue = Convert.ToDouble(m.Groups["value"].Value);
         m_alarmOperator = m.Groups["operator"].Value;
         customMessageVariables.Add("%limit_expression", m.Groups[0].Value);
     }
     else
     {
         throw new ArgumentException("Invalid condition '" + condition + "'");
     }
 }
Beispiel #4
0
        internal void ProcessGroup(DateTime t)
        {
            alarmCount = 0;
            clearCount = 0;
            var alarmdef = AlarmDataSet.GetActiveAlarmDefinitionTable(group_name);

            if (useHydrometCache)
            {
                AlarmDataSet.PreloadInstantHydrometData(alarmdef, t);
            }
            string emailMsg         = "";
            string txtMsg           = "";
            string emailMessageBody = "";
            string txtMessageBody   = "";

            foreach (var row in alarmdef)
            {
                if (row.enabled)
                {
                    if (!row.active)
                    {
                        Alarm alarmCondition = AlarmFactory(row, "alarm_condition");
                        if (alarmCondition.Check(t))
                        {                       // set the alarm.
                            if (!row.IsVirtual) // don't set active on 'virtual' alarms
                            {
                                row.active = true;
                            }
                            alarmCount++;
                            alarmCondition.CreateMessage(out emailMsg, out txtMsg);
                            txtMessageBody   += " " + txtMsg;
                            emailMessageBody += "<br/>Hydromet Notification: \n<br>" + emailMsg;
                        }
                    }
                    else
                    {                                  // check if alarm can be cleared.
                        if (row.clear_condition != "") // without clear condition you must manually clear that alarm
                        {
                            Alarm clearCondition = AlarmFactory(row, "clear_condition");
                            if (clearCondition.Check(t))
                            { // clear the alarm.
                                if (row.IsVirtual)
                                {
                                    throw new ApplicationException("Assertion.... unexpected virtual rows");
                                }
                                row.active = false;

                                emailMessageBody += " The Alarm condition below has been CLEARED<br/> ";
                                clearCondition.CreateMessage(out emailMsg, out txtMsg);
                                emailMessageBody += "<br/>Hydromet Notification: \n<br>" + emailMsg;
                                txtMessageBody   += txtMsg;
                                clearCount++;
                            }
                        }
                    }
                }
            }

            if (ProcessCount > 0 && sendEmail)
            {
                emailMessageBody += "\n\n <a href=\"https://www.usbr.gov/pn/hydromet/disclaimer.html\">provisional data disclaimer</a>";
                SendEmailNotice(AlarmDataSet.EmailAddresses(group_name), group_name, emailMessageBody, txtMessageBody);
            }
            // phone ??
            alarmdef.Save();
        }
Beispiel #5
0
        public static void PreloadInstantHydrometData(AlarmDataSet.alarm_definitionDataTable alarmdef)
        {
            // find all instant data, and largest hours_back, to make a single cache of data
            var cbttPcodes = (from row in alarmdef.AsEnumerable()
                         where row.database.ToLower() == "i"  // instant hydromet data
                         select row.cbtt.ToLower() + " " + row.pcode.ToLower()).Distinct().ToArray();

            if (cbttPcodes.Length == 0)
                return;

            // TO DO.  throw error if mixing quality and 'regular' data.
            //if (MixedQualityData(cbttPcodes))
            //{
            //    throw new ArgumentException("Error: quality and Mixing qual");
            //}

            var hours_back = (from row in alarmdef.AsEnumerable()
                              where row.database.ToLower() == "i"
                              select row.hours_back).Max();

            DateTime t1 = DateTime.Now.AddHours(-hours_back);
            DateTime t2 = DateTime.Now;
               // HydrometInstantSeries.KeepFlaggedData = true;

            var cache = new HydrometDataCache();
            cache.Add(String.Join(",", cbttPcodes).Split(','), t1, t2,
                HydrometHost.PN, Reclamation.TimeSeries.TimeInterval.Irregular, hours_back);

            HydrometInstantSeries.Cache = cache;
            Console.WriteLine(cbttPcodes);
        }
Beispiel #6
0
        private static Alarm AlarmFactory(AlarmDataSet.alarm_definitionRow row, string conditionColumnName)
        {
            string condition =row[conditionColumnName].ToString();

            if (Regex.IsMatch(condition, CountAlarm.Expression))
            {
                return new CountAlarm(row, conditionColumnName);
            }
            else if (Regex.IsMatch(condition, LimitAlarm.Expression))
            {
                return new LimitAlarm(row, conditionColumnName);
            }
            else if (Regex.IsMatch(condition, FlagAlarm.Expression))
            {
                return new FlagAlarm(row, conditionColumnName);
            }
            else if (Regex.IsMatch(condition, RogueMinimumFlow.Expression))
            {
                return new RogueMinimumFlow(row, conditionColumnName.ToLower()=="clear_condition");
            }
            else if (Regex.IsMatch(condition, RogueSystemState.Expression))
            {
                return new RogueSystemState(row);
            }

            throw new NotImplementedException("Invalid alarm condition " + row[conditionColumnName]);
        }