public void CheckAlerts(NMSReportCommand nmsReportCommand, bool curStatusCheck)
        {
            //check route  error if a variable curStatusCheck is true
            if (curStatusCheck)
            {
                if (checkRouterError(nmsReportCommand)) return;
            }

            //Unknown Device
            if (checkUnknownDeviceAlert(nmsReportCommand)) return;

            //Alerts check
                checkLan1Alert(nmsReportCommand);
                checkLan2Alert(nmsReportCommand);
                //네트워크 상태 , Wire 와 Wireless 중 어느상태가 에러인지 불문명하여 일단 주석
                //checkNetworkAlert(nmsReportCommand);
                checkExtPowerAlert(nmsReportCommand);
                checkRssiAlert(nmsReportCommand);
                checkLowBatteryAlert(nmsReportCommand);
                checkDeviceIdErrorAlert(nmsReportCommand);
        }
        private void AddRowToAlertGrid(NMSReportCommand nmsReportCommand)
        {
            CelotMClient.Model.Device device = nmsReportCommand.Device;
            nms_reprot_t nms = nmsReportCommand.nms_reprot_t;

            int insertRowCount = this.alertGrid.Rows.Count;
            this.alertGrid.Rows.Insert(insertRowCount);

            SourceGrid.Cells.Views.ColumnHeader nameHeaderView1 = new SourceGrid.Cells.Views.ColumnHeader();
            DevAge.Drawing.VisualElements.ColumnHeader namebackHeader1 = new DevAge.Drawing.VisualElements.ColumnHeader();
            namebackHeader1.BackColor = Color.DarkSlateGray;
            nameHeaderView1.Background = namebackHeader1;
            nameHeaderView1.Border = cellBorder;
            nameHeaderView1.ForeColor = Color.White;
            nameHeaderView1.Font = new Font("굴림", 8, FontStyle.Regular);
            nameHeaderView1.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter;

            alertGrid[insertRowCount, 0] = new SourceGrid.Cells.Cell(device == null ? "" : device.Name);
            alertGrid[insertRowCount, 0].View = viewNormal;

            alertGrid[insertRowCount, 1] = new SourceGrid.Cells.Cell(device == null ? "" : device.Des);
            alertGrid[insertRowCount, 1].View = viewNormal;

            alertGrid[insertRowCount, 2] = new SourceGrid.Cells.Cell(device == null ? "" : device.GroupName);
            alertGrid[insertRowCount, 2].View = viewNormal;

            alertGrid[insertRowCount, 3] = new SourceGrid.Cells.Cell(device == null ? "" : device.SerialNo.ToString());
            alertGrid[insertRowCount, 3].View = viewNormal;

            alertGrid[insertRowCount, 4] = new SourceGrid.Cells.Cell(device == null ? "" : CelotUtility.ChangePhoneNumberToFormatString(device.PhoneNumber));
            alertGrid[insertRowCount, 4].View = viewNormal;

            alertGrid[insertRowCount, 5] = new SourceGrid.Cells.Cell(device == null ? "" : device.RouterIp);
            alertGrid[insertRowCount, 5].View = viewNormal;

            alertGrid[insertRowCount, 6] = new SourceGrid.Cells.Cell(nms == null ? "" : nms.header.session_id.ToString());
            alertGrid[insertRowCount, 6].View = viewNormal;

            alertGrid[insertRowCount, 7] = new SourceGrid.Cells.Cell(nms == null ? "" : nms.data.moduleband.ToString());
            alertGrid[insertRowCount, 7].View = viewNormal;

            alertGrid[insertRowCount, 8] = new SourceGrid.Cells.Cell(nms == null ? "" : nmsReportCommand.GetLanIPString());
            alertGrid[insertRowCount, 8].View = viewNormal;

            alertGrid[insertRowCount, 9] = new SourceGrid.Cells.Cell(nms == null ? "" : nmsReportCommand.GetWanIPString());
            alertGrid[insertRowCount, 9].View = viewNormal;

            alertGrid[insertRowCount, 10] = new SourceGrid.Cells.Cell(nms == null ? "" : nms.data.devicestatus.ToString());
            alertGrid[insertRowCount, 10].View = viewNormal;

            alertGrid[insertRowCount, 11] = new SourceGrid.Cells.Cell(nms == null ? "" : nms.data.vpnstatus.ToString());
            alertGrid[insertRowCount, 11].View = viewNormal;

            alertGrid[insertRowCount, 12] = new SourceGrid.Cells.Cell(nms == null ? "" : nms.data.wifistatus.ToString());
            alertGrid[insertRowCount, 12].View = viewNormal;

            alertGrid[insertRowCount, 13] = new SourceGrid.Cells.Cell(nms == null ? "" : nms.data.newsms.ToString());
            alertGrid[insertRowCount, 13].View = viewNormal;

            alertGrid[insertRowCount, 14] = new SourceGrid.Cells.Cell(nms == null ? "" : nms.data.sw_version);
            alertGrid[insertRowCount, 14].View = viewNormal;

            alertGrid[insertRowCount, 15] = new SourceGrid.Cells.Cell(nms == null ? "" : nms.data.external_power.ToString());
            alertGrid[insertRowCount, 15].View = viewNormal;

            alertGrid[insertRowCount, 16] = new SourceGrid.Cells.Cell(nms == null ? "" : nms.data.ext_device1[0].ToString());
            alertGrid[insertRowCount, 16].View = viewNormal;

            SignalBar signal = new SignalBar();
            signal.Dock = DockStyle.None;
            signal.Minimum = 0;
            signal.Maximum = 4;
            signal.BackColor = Color.SlateGray;

            if (nms != null)
            {
                signal.CurrentValue = nmsAlertManager.getRssiLevel(nms.data.modulesignal);
            }
            else
            {
                signal.CurrentValue = 0;
            }

            SourceGrid.Cells.Cell signalCell = new SourceGrid.Cells.Cell();
            alertGrid[insertRowCount, 17] = signalCell;
            alertGrid[insertRowCount, 17].View = viewNormal;
            SourceGrid.LinkedControlValue linkedControlValue = new SourceGrid.LinkedControlValue(signal, new SourceGrid.Position(insertRowCount, 17));
            alertGrid.LinkedControls.Add(linkedControlValue);

            alertGrid[insertRowCount, 18] = new SourceGrid.Cells.Cell((nms == null ? "" : nms.data.rpt_time.ToString()));
            alertGrid[insertRowCount, 18].View = viewNormal;

            alertGrid[insertRowCount, 19] = new SourceGrid.Cells.Cell((nms == null ? "" : nms.header.pro_ver.ToString()));
            alertGrid[insertRowCount, 19].View = nameHeaderView1;

            string currentTime = CelotUtility.ChangeStampStringToLocalFormat(nms.data.current_time);
            alertGrid[insertRowCount, 20] = new SourceGrid.Cells.Cell(currentTime);
            alertGrid[insertRowCount, 20].View = viewNormal;

            string resetTime = "";
            if (device != null && device.ResetTime != 0)
            {
                resetTime = CelotUtility.UnixTimeStampToDateString(device.ResetTime);
            }
            alertGrid[insertRowCount, 21] = new SourceGrid.Cells.Cell(resetTime);
            alertGrid[insertRowCount, 21].View = viewNormal;
        }
 public void checkRssiAlert(NMSReportCommand nmsReportCommand)
 {
     if (nmsReportCommand.nms_reprot_t == null) return;
     int rssiLevel = getRssiLevel(nmsReportCommand.nms_reprot_t.data.modulesignal);
     if (rssiLevel <= (int)RssiLevel.LEVEL_1)
     {
         AlertClass alertClass = new AlertClass();
         alertClass.AlertType = AlertType.RssiLevel;
         nmsReportCommand.DeviceAlertCassification = DeviceAlertCassification.ALERT;
         alertClass.AddErrorMessage("RSSI Level Error");
         RssiLeveErrCnt++;
         nmsReportCommand.AddAlert(alertClass);
     }
 }
 private bool checkUnknownDeviceAlert(NMSReportCommand nmsReportCommand)
 {
     if (nmsReportCommand.Device == null && nmsReportCommand.nms_reprot_t != null)
     {
         AlertClass alertClass = new AlertClass();
         alertClass.AlertType = AlertType.UnknownDevice;
         nmsReportCommand.DeviceAlertCassification = DeviceAlertCassification.UNKNOWN;
         alertClass.AddErrorMessage("Unknown Router");
         nmsReportCommand.AddAlert(alertClass);
         UnknownDeviceErrCnt++;
         return true;
     }
     return false;
 }
        //네트워크 상태가 Wire, Wireless 중 어떤 상태가 에러인지 불분명함
        public void checkNetworkAlert(NMSReportCommand nmsReportCommand)
        {
            if (nmsReportCommand.nms_reprot_t == null) return;
            NetworkState nState = (NetworkState)nmsReportCommand.nms_reprot_t.data.network_state;
            if (nState == NetworkState.WIRE)
            {
                AlertClass alertClass = new AlertClass();
                nmsReportCommand.DeviceAlertCassification = DeviceAlertCassification.ALERT;
                alertClass.AlertType = AlertType.Network;
                alertClass.AddErrorMessage("Wire");
                NetworkErrCnt++;
                nmsReportCommand.AddAlert(alertClass);
            }

            if (nState == NetworkState.WIRELESS)
            {
                AlertClass alertClass = new AlertClass();
                alertClass.AlertType = AlertType.Network;
                nmsReportCommand.DeviceAlertCassification = DeviceAlertCassification.ALERT;
                alertClass.AddErrorMessage("Wireless");
                NetworkErrCnt++;
                nmsReportCommand.AddAlert(alertClass);
            }
        }
        public bool checkRouterError(NMSReportCommand nmsReportCommand)
        {
            if (nmsReportCommand.Device != null)
            {
                Boolean isRouterError = false;
                DateTime compareTime;
                if (nmsReportCommand.nms_reprot_t == null)
                {
                    compareTime = CelotUtility.UnixTimeStampToDateTime(nmsReportCommand.Device.DeviceRegDate);
                    int result = DateTime.Compare(DateTime.Now, compareTime.AddMinutes(ApplicationConfig.Instance().NmsReportLimit));
                    if (result > 0)
                    {
                        isRouterError = true;
                    }
                }
                else
                {
                    compareTime = DateTime.ParseExact(nmsReportCommand.nms_reprot_t.data.current_time, "yyMMddHHmmss", null);
                    int result = DateTime.Compare(DateTime.Now, compareTime.AddMinutes(ApplicationConfig.Instance().NmsReportLimit));
                    if (result > 0)
                    {
                        isRouterError = true;
                    }
                }

                if (isRouterError)
                {
                    AlertClass alertClass = new AlertClass();
                    alertClass.AlertType = AlertType.Router;
                    alertClass.AddErrorMessage("No NMS Report");
                    nmsReportCommand.DeviceAlertCassification = DeviceAlertCassification.ABNORMAL;
                    nmsReportCommand.AddAlert(alertClass);
                    alertClass.AlertDuration = CelotUtility.getTimeAgo(compareTime);
                    RouterErrCnt++;
                    return true;
                }
                else
                {
                    return false;
                }
            }
            return false;
        }
 public void checkLowBatteryAlert(NMSReportCommand nmsReportCommand)
 {
     if (nmsReportCommand.nms_reprot_t == null) return;
     int lowBatteryLimit = ApplicationConfig.Instance().LowBatteryLimit;
     int battery = nmsReportCommand.nms_reprot_t.data.ext_device1[0];
     if (battery <= lowBatteryLimit)
     {
         AlertClass alertClass = new AlertClass();
         alertClass.AlertType = AlertType.LowBattery;
         alertClass.AddErrorMessage("Low Battery");
         nmsReportCommand.DeviceAlertCassification = DeviceAlertCassification.ALERT;
         alertClass.ErrorMessage = "Low Battery";
         LowBatteryErrCnt++;
         nmsReportCommand.AddAlert(alertClass);
     }
 }
 public void checkLan2Alert(NMSReportCommand nmsReportCommand)
 {
     if (nmsReportCommand.nms_reprot_t == null) return;
     EthernetStatus eStatus = (EthernetStatus)nmsReportCommand.nms_reprot_t.data.ethernet2_state;
     if (eStatus == EthernetStatus.ABNORMAL)
     {
         AlertClass alertClass = new AlertClass();
         nmsReportCommand.DeviceAlertCassification = DeviceAlertCassification.ALERT;
         alertClass.AlertType = AlertType.Lan2;
         alertClass.AddErrorMessage("Lan 2 Abnormal");
         Lan2ErrCnt++;
         nmsReportCommand.AddAlert(alertClass);
     }
 }
 public void checkExtPowerAlert(NMSReportCommand nmsReportCommand)
 {
     if (nmsReportCommand.nms_reprot_t == null) return;
     ExternalPower state = (ExternalPower)nmsReportCommand.nms_reprot_t.data.external_power;
     if (state == ExternalPower.ABNORMAL)
     {
         AlertClass alertClass = new AlertClass();
         alertClass.AlertType = AlertType.ExtPower;
         nmsReportCommand.DeviceAlertCassification = DeviceAlertCassification.ALERT;
         alertClass.AddErrorMessage("External Power Abnormal");
         ExtPowerErrCnt++;
         nmsReportCommand.AddAlert(alertClass);
     }
 }
        public void checkDeviceIdErrorAlert(NMSReportCommand nmsReportCommand)
        {
            if (nmsReportCommand.nms_reprot_t == null || nmsReportCommand.Device == null) return;
            AlertClass alertClass = new AlertClass();
            alertClass.AlertType = AlertType.DeviceIdError;
            nmsReportCommand.DeviceAlertCassification = DeviceAlertCassification.ALERT;
            alertClass.ErrorMessage = "";

            //아이피 불일치 조사
            if (!nmsReportCommand.Device.RouterIp.Equals(nmsReportCommand.GetLanIPString()))
            {
                alertClass.AddErrorMessage("Inconsistent IP");
            }

            //SMS 상태 불일지 조사
            if ((SmsSupport)nmsReportCommand.Device.SmsSupport == SmsSupport.SUPPORTED)
            {
                if (nmsReportCommand.nms_reprot_t.data.newsms < 0)
                {
                    alertClass.AddErrorMessage("Inconsistent SMS Status");
                }
            }
            else
            {
                if (nmsReportCommand.nms_reprot_t.data.newsms > 0)
                {
                    alertClass.AddErrorMessage("Inconsistent SMS Status");
                }
            }

            //와이파이 상태 불일치 조사
            if ((WifiSupport)nmsReportCommand.Device.WifiSupport== WifiSupport.SUPPORTED)
            {
                if (nmsReportCommand.nms_reprot_t.data.wifistatus != 1 && nmsReportCommand.nms_reprot_t.data.wifistatus != 0)
                {
                    alertClass.AddErrorMessage("Inconsistent Wifie Status");
                }
            }
            else
            {
                if (nmsReportCommand.nms_reprot_t.data.wifistatus == 1 || nmsReportCommand.nms_reprot_t.data.wifistatus == 0)
                {
                    alertClass.AddErrorMessage("Inconsistent Wifie Status");
                }
            }

            //VPN 상태 불일치 조사
            if ((VpnSupport)nmsReportCommand.Device.VpnSupport == VpnSupport.SUPPORTED)
            {
                if (nmsReportCommand.nms_reprot_t.data.vpnstatus != 1 && nmsReportCommand.nms_reprot_t.data.vpnstatus != 0)
                {
                    alertClass.AddErrorMessage("Inconsistent VPN Status");
                }
            }
            else
            {
                if (nmsReportCommand.nms_reprot_t.data.vpnstatus == 1 || nmsReportCommand.nms_reprot_t.data.vpnstatus == 0)
                {
                    alertClass.AddErrorMessage("Inconsistent Vpn Status");
                }
            }

            ////배터리 상태 불일치 조사
            //if ((BatterySupport)nmsReportCommand.Device.BatterySupport == BatterySupport.SUPPORTED)
            //{
            //    if (nmsReportCommand.nms_reprot_t.data.ext_device1[0] < 0)
            //    {
            //        alertClass.AddErrorMessage("Inconsistent Battery Status");
            //    }
            //}
            //else
            //{
            //    if (nmsReportCommand.nms_reprot_t.data.ext_device1[0] > 0)
            //    {
            //        alertClass.AddErrorMessage("Inconsistent Battery Status");
            //    }
            //}

            if (alertClass.ErrorMessage.Length > 0)
            {
                DeviceIdErrCnt++;
                nmsReportCommand.AddAlert(alertClass);
            }
        }
        private void AddDeviceToMap(NMSReportCommand nmsReportCommand)
        {
            CelotMClient.Model.Device device = nmsReportCommand.Device;
            nms_reprot_t nms = nmsReportCommand.nms_reprot_t;

            string routerName = device.Name;
            int serialNo = device.SerialNo;
            string number = CelotUtility.ChangePhoneNumberToFormatString(device.PhoneNumber);
            string des = device.Des;
            string latitude = device.Latitude;
            string longitude = device.Longitude;
            string routerIp = device == null ? "" : device.RouterIp;
            string lanIp = nms == null ? "": nmsReportCommand.GetLanIPString();
            string wanIp = nms == null ? "" : nmsReportCommand.GetWanIPString();
            string message = nmsReportCommand.GetAlertMessages() !=null ? nmsReportCommand.GetAlertMessages().Substring(1):"";
            string rssi = nms == null ? "" : String.Format("{0} ({1})", nms.data.modulesignal, this.alertManager.getRssiLevel(nmsReportCommand.nms_reprot_t.data.modulesignal ));
            string firmVersion = nms == null ? "" : nms.data.sw_version;
            string nmsVersion = nms == null ? "" : nms.header.pro_ver.ToString();

            int routerStatus = 0;
            switch(nmsReportCommand.DeviceAlertCassification){
                case DeviceAlertCassification.NORMAL:
                    routerStatus = 0;
                    break;
                case DeviceAlertCassification.ABNORMAL:
                    routerStatus = 1;
                    break;
                case DeviceAlertCassification.ALERT:
                    routerStatus = 2;
                    break;
            }

            this.webBrowser1.Document.InvokeScript(
                "addMarker", new object[] {
                    latitude,
                    longitude,
                    routerName,
                    des,
                    serialNo,
                    number,
                    rssi,
                    routerIp,
                    lanIp,
                    wanIp,
                    firmVersion,
                    nmsVersion,
                    message,
                    routerStatus
                }
            );
        }