private void SendPing(string ip)
        {
            if (!string.IsNullOrEmpty(ip))
            {
                btnPingPrimary.Enabled = btnPingSecondary.Enabled = false;

                TaskEx.Run(() =>
                {
                    PingResult pingResult = PingHelper.PingHost(ip);
                    MessageBox.Show(pingResult.ToString(), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                },
                           () =>
                {
                    btnPingPrimary.Enabled = btnPingSecondary.Enabled = true;
                });
            }
        }
Exemple #2
0
        private static void consumer_Listener(IMessage message)
        {
            string taskId = string.Empty;

            try
            {
                ITextMessage msg = (ITextMessage)message;
                Dictionary <string, object> param      = MqConsumerBase.ReadMapFromJson(msg.Text);
                IPerfApiStation             stationBll = StationFactory.GetStation(param["deviceModel"].ToString());
                log.Info(msg.NMSMessageId, taskId);
                if (msg.NMSType == "Ping")
                {
                    string ip = param["ip"].ToString();
                    int    num;
                    if (!int.TryParse(param["pingnum"].ToString(), out num))
                    {
                        log.Error("pingnum 参数异常!");
                    }
                    List <IPStatus> statusList = PingHelper.PingHost(ip, num);
                    double          PacketLoss = statusList.Where(p => p == IPStatus.Success).Count() / num;
                    bool            isSucess   = false;
                    if (PacketLoss > 0.5)
                    {
                        isSucess = true;
                    }
                    MqAgentProducer.SendResponse(msg.NMSMessageId, StepTestStatus.测试通过, "完成任务 丢包率:" + (1 - PacketLoss), param["projectId"].ToString(), param["caseId"].ToString(), param["stepId"].ToString());
                }

                else if (msg.NMSType == "ModifyWirelessMode")
                {
                    string param1 = param["modeString"].ToString();
                    taskId = param["taskId"].ToString();
                    log.Info(string.Format("执行命令,参数是{0}", param1), taskId);
                    Thread.Sleep(1000 * 1);
                    stationBll.ModifyWirelessMode(param1);
                    MqAgentProducer.SendResponse(msg.NMSMessageId, StepTestStatus.测试通过, "成功", param["projectId"].ToString(), param["caseId"].ToString(), param["stepId"].ToString());
                }
            }
            catch (Exception ex)
            {
                log.Info(ex.Message, taskId);
            }
        }
Exemple #3
0
        private void SendPing(string ip)
        {
            if (!string.IsNullOrEmpty(ip))
            {
                btnPingPrimary.Enabled = btnPingSecondary.Enabled = false;

                BackgroundWorker bw = new BackgroundWorker();

                bw.DoWork += (sender, e) =>
                {
                    PingResult pingResult = PingHelper.PingHost(ip);
                    MessageBox.Show(pingResult.ToString(), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                };

                bw.RunWorkerCompleted += (sender, e) =>
                {
                    btnPingPrimary.Enabled = btnPingSecondary.Enabled = true;
                };

                bw.RunWorkerAsync();
            }
        }
Exemple #4
0
        private static void consumer_Listener(IMessage message)
        {
            string projectId = string.Empty;

            try
            {
                ITextMessage msg = (ITextMessage)message;
                Dictionary <string, object> param      = MqConsumerBase.ReadMapFromJson(msg.Text);
                AgentApiStation             stationBll = StationFactory.GetStation(param["deviceModel"].ToString());
                projectId = param["projectId"].ToString();
                log.Info(msg.NMSMessageId, projectId);
                StepTestStatus stepTestStatus = StepTestStatus.测试通过;
                if (msg.NMSType == "Ping")
                {
                    string ip = param["ip"].ToString();
                    double packetLoss;
                    if (!Double.TryParse(param["pingnum"].ToString(), out packetLoss))
                    {
                        log.Error("丢包率限值参数异常!");
                    }

                    int num;
                    if (!int.TryParse(param["pingnum"].ToString(), out num))
                    {
                        log.Error("pingnum 参数异常!");
                    }
                    List <IPStatus> statusList = PingHelper.PingHost(ip, num);
                    double          PacketLoss = 1 - statusList.Where(p => p == IPStatus.Success).Count() / num;
                    if (PacketLoss > 0.1)
                    {
                        stepTestStatus = StepTestStatus.测试未通过;
                    }
                    MqAgentProducer.SendResponse(msg.NMSMessageId, stepTestStatus, "完成任务 丢包率:" + (1 - PacketLoss), projectId, param["caseId"].ToString(), param["stepId"].ToString());
                }

                else if (msg.NMSType == "ModifyWirelessMode")
                {
                    string param1 = param["modeString"].ToString();
                    log.Info(string.Format("执行命令,参数是{0}", param1), projectId);
                    Thread.Sleep(1000 * 1);
                    try
                    {
                        stationBll.ModifyWirelessMode(param1);
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex.Message);
                        stepTestStatus = StepTestStatus.测试异常;
                    }
                    MqAgentProducer.SendResponse(msg.NMSMessageId, stepTestStatus, "成功", param["projectId"].ToString(), param["caseId"].ToString(), param["stepId"].ToString());
                }
                else if (msg.NMSType == "UpStation")
                {
                    string ssid = param["ssid"].ToString();
                    string pwd  = param["password"].ToString();
                    stationBll.UpStation(ssid, pwd);
                    Thread.Sleep(1000 * 3);
                    MqAgentProducer.SendResponse(msg.NMSMessageId, StepTestStatus.测试通过, "回复消息,我已经完成任务!", projectId, param["caseId"].ToString(), param["stepId"].ToString());
                }
            }
            catch (Exception ex)
            {
                log.Info(ex.Message, projectId);
            }
        }