コード例 #1
0
ファイル: Program.cs プロジェクト: wardensky/wardensky-demo
        private static void consumer_Listener(IMessage message)
        {
            string taskId = string.Empty;

            try
            {
                ITextMessage msg = (ITextMessage)message;
                Dictionary <string, object> param = MqConsumer.ReadParaFromJson(msg.Text);


                if (msg.NMSType == "ModifyWirelessMode")
                {
                    string param1 = param["modeString"].ToString();
                    taskId = param["taskId"].ToString();
                    log.Info(string.Format("执行命令,参数是{0}", param1), taskId);
                    Thread.Sleep(1000 * 1);
                    WirelessModeOper.ModifyWirelessMode(param1);
                    MqAgentProducer.SendResponse(msg.NMSMessageId, true, "成功", "");
                }
            }
            catch (Exception ex)
            {
                log.Info(ex.Message);
            }
        }
コード例 #2
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);
                AgentApiAp apBll = ApFactory.GetAp(param["deviceModel"].ToString());
                projectId = param["projectId"].ToString();
                log.Info(msg.NMSMessageId, projectId);
                if (msg.NMSType == "PostWebRequest")
                {
                    string param1 = param["dns2"].ToString();
                    log.Info("执行命令,参数是" + param1, projectId);
                    Thread.Sleep(1000 * 3);

                    string url     = "http://192.168.0.1/goform/NetWorkSetupSave";
                    string param11 = string.Format("Go=index.htm&con-type=0&adsl-user=302000230640&adsl-pwd=36663381&ssid=sss&ssid-pwd=lizc580231&ipval=192.168.163.82&submask=255.255.255.0&gateway=192.168.163.1&dns1=114.114.114.114&dns2={0}", param1);
                    string ret     = HttpHelper.PostWebRequest(url, param11);

                    log.Info("回复消息,执行成功", projectId);
                    MqAgentProducer.SendResponse(msg.NMSMessageId, StepTestStatus.测试通过, "我已经成功执行了");
                }
                else if (msg.NMSType == "ModifySp")
                {
                    string   param1 = param["p1"].ToString();
                    SpHelper sp     = new SpHelper();
                    sp.ModifySp(param1);
                    log.Info("执行命令,参数是" + param1, projectId);
                    Thread.Sleep(1000 * 3);
                    WriteLogAndSendResponse(msg.NMSMessageId, "回复消息,我已经完成任务!", StepTestStatus.测试通过, "", projectId, param["caseId"].ToString(), param["stepId"].ToString());
                }
                else if (msg.NMSType == "InitApConfig")
                {
                    string        ip          = param["ip"].ToString();
                    string        user        = param["user"].ToString();
                    string        pwd         = param["password"].ToString();
                    List <string> commandList = ((Newtonsoft.Json.Linq.JArray)param["cfgCommand"]).Select(s => s.ToString()).ToList();
                    apBll.InitApConfig(ip, user, pwd, commandList);
                    Thread.Sleep(1000 * 3);
                    Dictionary <string, string> response = new Dictionary <string, string>();
                    WriteLogAndSendResponse(msg.NMSMessageId, "回复消息,我已经完成任务!", StepTestStatus.测试通过, "", projectId, param["caseId"].ToString(), param["stepId"].ToString());
                }
            }
            catch (Exception ex)
            {
                log.Info(ex.Message, projectId);
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: wardensky/wardensky-demo
        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);
            }
        }
コード例 #4
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);
                log.Info(msg.NMSMessageId, taskId);
                if (msg.NMSType == "command1")
                {
                    string param1 = param["param1"].ToString();
                    taskId = param["taskId"].ToString();
                    log.Info("执行命令,参数是" + param1, taskId);
                    Thread.Sleep(1000 * 3);
                    log.Info("回复消息,执行成功", taskId);
                    MqAgentProducer.SendResponse(msg.NMSMessageId, StepTestStatus.测试通过, "我已经成功执行了");
                }
            }
            catch (Exception ex)
            {
                log.Info(ex.Message, taskId);
            }
        }
コード例 #5
0
        private static void consumer_Listener(IMessage message)
        {
            ITextMessage msg       = (ITextMessage)message;
            string       projectId = string.Empty;
            string       caseId    = string.Empty;
            string       stepId    = string.Empty;

            try
            {
                Dictionary <string, object> param = MqConsumerBase.ReadMapFromJson(msg.Text);
                projectId = param["projectId"].ToString();
                caseId    = param["caseId"].ToString();
                stepId    = param["stepId"].ToString();
                string dev = param["deviceModel"].ToString();
                param.Remove("projectId");
                param.Remove("deviceModel");
                param.Remove("caseId");
                param.Remove("stepId");

                FormAgentManual form = new FormAgentManual(dev, param);
                DialogResult    dr   = form.ShowDialog();
                if (dr == DialogResult.Yes)
                {
                    //发送成功消息
                    MqAgentProducer.SendResponse(msg.NMSMessageId, StepTestStatus.测试通过, "AGENT_MANUAL完成测试,测试通过", projectId, caseId, stepId);
                }
                else
                {
                    MqAgentProducer.SendResponse(msg.NMSMessageId, StepTestStatus.测试未通过, "AGENT_MANUAL完成测试,测试未通过", projectId, caseId, stepId);
                }
            }
            catch (Exception ex)
            {
                MqAgentProducer.SendResponse(msg.NMSMessageId, StepTestStatus.测试异常, ex.ToString(), projectId, caseId, stepId);
            }
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: wardensky/wardensky-demo
 private static void WriteLogAndSendResponse(string msgId, string logMsg, StepTestStatus result, string resultMsg, string projectId, string caseId, string stepId)
 {
     log.Info(logMsg, msgId);
     testLog.Write(projectId, logMsg, caseId);
     MqAgentProducer.SendResponse(msgId, result, resultMsg, projectId, caseId, stepId);
 }
コード例 #7
0
ファイル: Program.cs プロジェクト: wardensky/wardensky-demo
        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);
            }
        }