示例#1
0
        public ChartDataModel GetLineStateData(int?organId)
        {
            var            list   = new LineBusiness().GetAllItems();
            ChartDataModel result = new ChartDataModel(); //{ Titles = new List<string>(), Datas = new List<int>() };

            if (organId == null)                          //SysAdmin
            {
                var alarmcount  = list.FindAll(n => !n.ConnectState).Count;
                var normalcount = list.Count - alarmcount;
                result.Titles = new List <string> {
                    "报警线路", "正常线路"
                };
                result.Datas = new List <int> {
                    alarmcount, normalcount
                };
            }
            else
            {
                list = list.FindAll(n => n.OrganizationId == organId.Value);
                var alarmcount  = list.FindAll(n => !n.ConnectState).Count;
                var normalcount = list.Count - alarmcount;
                result.Titles = new List <string> {
                    "报警线路", "正常线路"
                };
                result.Datas = new List <int> {
                    alarmcount, normalcount
                };
            }
            return(result);
        }
示例#2
0
        public ChartDataModel GetAlarmData(int?organId)
        {
            var            list   = new AlarmBusiness().GetView();
            ChartDataModel result = new ChartDataModel(); //{ Titles = new List<string>(), Datas = new List<int>() };

            if (organId == null)                          //SysAdmin
            {
                var alarmcount  = list.Count();
                var normalcount = new LineBusiness().GetNormalLine(list.Select(n => n.LineId).ToArray()).Count();
                result.Titles = new List <string> {
                    "报警线路", "正常线路"
                };
                result.Datas = new List <int> {
                    alarmcount, normalcount
                };
            }
            else
            {
                //IEnumerable<AlarmModel> resultlist = list?.Where(n => n.OrganId == organId);
            }
            return(result);
        }
示例#3
0
        /// <summary>
        /// 返回结果,直接写入数据库(alarm,alarm_log,line)
        /// </summary>
        /// <param name="id">线路Id</param>
        /// <param name="pingState"></param>
        public void WriteAlarmToDB(int id, PingState pingState)
        {
            lock (_lock)
            {
                try
                {
                    if (!_catch.ContainsKey(id))
                    {
                        _catch.Add(id, new LineAlarmCache()
                        {
                            Alarm = null, Count = 0
                        });
                    }

                    if (!pingState.State)
                    {
                        _catch[id].Count++;
                        if (_catch[id].Alarm == null)
                        {
                            LineModel line = new LineBusiness().GetItem(id);
                            if (_catch[id].Count >= line.AlarmMax)
                            {
                                _catch[id].Alarm = new AlarmModel()
                                {
                                    AlarmCount = 1,
                                    Confirm    = false,
                                    FirstTime  = pingState.CollectTime,
                                    IP         = line.LineIP,
                                    LineId     = line.Id,
                                    LineName   = line.Name,
                                    OrganId    = line.OrganizationId,
                                    OrganName  = line.OrganizationName,
                                    State      = AlarmStateType.OnAlarm,
                                    LastTime   = pingState.CollectTime,
                                    Type       = AlarmType.LineNotConnected
                                };
                                //状态改为 正在告警
                                MonitorADOProvider.GetInstance().InsertAlarm(_catch[id].Alarm);
                                SendMessage?.Invoke(_catch[id].Alarm, line.SMSTelphone);
                            }
                        }
                        else
                        {
                            if (_catch[id].Alarm.Id == 0)
                            {
                                _catch[id].Alarm = MonitorADOProvider.GetInstance().GetLastestAlarm(id, AlarmType.LineNotConnected);
                            }
                            //更新次数和最后时间
                            MonitorADOProvider.GetInstance().UpdateAlarm(_catch[id].Alarm.Id, pingState.CollectTime);
                        }
                    }
                    else
                    {
                        if (_catch[id].Alarm != null)
                        {
                            if (_catch[id].Alarm.Id == 0)
                            {
                                _catch[id].Alarm = MonitorADOProvider.GetInstance().GetLastestAlarm(id, AlarmType.LineNotConnected);
                            }
                            LineModel line = MonitorADOProvider.GetInstance().GetLineModel(id);
                            MonitorADOProvider.GetInstance().RecoverAlarm(_catch[id].Alarm.Id, DateTime.Now, AlarmStateType.Recover);
                            SendMessage?.Invoke(_catch[id].Alarm, line.SMSTelphone);
                        }
                    }



                    //var alarm = _catch[id].Provider.GetLastestAlarm(id, AlarmType.LineNotConnected);
                    //if (!pingState.State)
                    //{
                    //    _catch[id].Count++;

                    //    //根据告警策略 更新 告警状态
                    //    if (alarm == null)
                    //    {
                    //        LineModel line = new LineBusiness().GetItem(id);
                    //        //肯定是有alarm的
                    //        if (_catch[id].Count >= line.AlarmMax)
                    //        {
                    //            alarm = new AlarmModel()
                    //            {
                    //                AlarmCount = 1,
                    //                Confirm = false,
                    //                FirstTime = pingState.CollectTime,
                    //                IP = line.LineIP,
                    //                LineId = line.Id,
                    //                LineName = line.Name,
                    //                OrganId = line.OrganizationId,
                    //                OrganName = line.OrganizationName,
                    //                State = AlarmStateType.OnAlarm,
                    //                LastTime = pingState.CollectTime,
                    //                Type = AlarmType.LineNotConnected
                    //            };
                    //            //状态改为 正在告警
                    //            _catch[id].Provider.InsertSync(alarm);
                    //            SendMessage?.Invoke(alarm, line.SMSTelphone);
                    //        }
                    //    }
                    //    else
                    //    {
                    //        //更新次数和最后时间
                    //        string condition = "AND Id = @Id";
                    //        string field = "AlarmCount=@AlarmCount,LastTime=@LastTime";
                    //        _catch[id].Provider.UpdateSync(condition, field, new { Id = alarm.Id, AlarmCount = alarm.AlarmCount + 1, LastTime = pingState.CollectTime });
                    //    }
                    //}
                    //else
                    //{
                    //    if (alarm != null)
                    //    {
                    //        LineModel line = new LineBusiness().GetItem(id);
                    //        alarm.RecoverDate = pingState.CollectTime;
                    //        alarm.State = AlarmStateType.Recover;
                    //        //alarm.AlarmCount = _catch[id].Count;
                    //        _catch[id].Provider.AddRecoverDate(alarm);
                    //        SendMessage?.Invoke(alarm, line.SMSTelphone);
                    //    }
                    //}
                }
                catch (Exception ex)
                {
                }
            }
        }