コード例 #1
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);
            }
        }
コード例 #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);
                IPerfApiChariot             chariotBll = ChariotFactory.GetChariot(param["deviceModel"].ToString());

                log.Info(msg.NMSMessageId, taskId);
                if (msg.NMSType == "TestThroughput")
                {
                    taskId = param["taskId"].ToString();
                    string        param1      = param["param1"].ToString();
                    string        param2      = param["param2"].ToString();
                    string        param3      = param["param3"].ToString();
                    string        param4      = param["param4"].ToString();
                    string        param5      = param["param5"].ToString();
                    string        param6      = param["param6"].ToString();
                    string        ping        = "ping 127.0.0.1 -n 2 >nul";
                    List <string> commandList = new List <string>()
                    {
                        param1, ping, param2, ping, param3, ping, param4, ping, param5, ping, param6, ping + "&exit"
                    };
                    CmdHelper.SendCmdCommandList(commandList);
                    WriteLogAndSendResponse(msg.NMSMessageId, "回复消息,我已经完成任务!", StepTestStatus.测试通过, "", param["projectId"].ToString(), param["caseId"].ToString(), param["stepId"].ToString());
                }
                else if (msg.NMSType == "AnalysisResult")
                {
                    taskId = param["taskId"].ToString();
                    List <string> resultList = new List <string>();
                    string        filePath1  = param["FilePath1"].ToString();
                    //string filePath2 = param["FilePath2"].ToString();
                    //string filePath3 = param["FilePath3"].ToString();
                    resultList.Add(chariotBll.GetTestValue(filePath1));
                    //resultList.Add(AnalysisResult.GetTestValue(filePath2));
                    //resultList.Add(AnalysisResult.GetTestValue(filePath3));
                    string result = string.Join(",", resultList.ToArray());
                    WriteLogAndSendResponse(msg.NMSMessageId, "回复消息,我已经完成任务!", StepTestStatus.测试通过, "", param["projectId"].ToString(), param["caseId"].ToString(), param["stepId"].ToString());
                }
            }
            catch (Exception ex)
            {
                log.Info(ex.Message, taskId);
            }
        }
コード例 #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 consumer_Listener(IMessage message)
        {
            string projectId = string.Empty;
            string caseId    = string.Empty;

            try
            {
                ITextMessage msg = (ITextMessage)message;
                Dictionary <string, object> param = MqConsumerBase.ReadMapFromJson(msg.Text);
                IAgentApiIperf iperfBll           = IperfFactory.GetAp(param["deviceModel"].ToString());
                projectId = param["projectId"].ToString();
                log.Info(msg.NMSMessageId, projectId);
                if (msg.NMSType == "StartListen" | msg.NMSType == "StartSend")
                {
                    IPERF_PATH = param["FilePath"].ToString();
                    string cmd = param["cmd"].ToString();
                    if (msg.NMSType == "StartListen")
                    {
                        string        logpath = param["logpath"].ToString();
                        string        temp    = logpath.Remove(logpath.LastIndexOf("\\"));
                        DirectoryInfo di      = new DirectoryInfo(temp);
                        if (!di.Exists)
                        {
                            di.Create();
                        }
                        FileInfo fi = new FileInfo(logpath);
                        if (fi.Exists)
                        {
                            fi.MoveTo(fi.DirectoryName + @"\" + fi.LastWriteTime.ToString("yyyyMMddHHmm") + fi.Name);
                        }
                        cmd += " " + logpath;
                    }
                    iperfBll.StartLinten(IPERF_PATH, cmd);
                    WriteLogAndSendResponse(msg.NMSMessageId, "完成测试", StepTestStatus.测试通过, "", param["projectId"].ToString(), param["caseId"].ToString(), param["stepId"].ToString());
                }
                if (msg.NMSType == "AnalysisResult")
                {
                    if (!string.IsNullOrEmpty(IPERF_PATH))
                    {
                        ProcessHelper.KillProcessByFileName(IPERF_PATH);
                    }
                    List <string> resultList = new List <string>();
                    caseId = param["projectId"].ToString();
                    string     filePath1  = param["FilePath1"].ToString();
                    FileInfo   fi         = new FileInfo(filePath1);
                    TestResult testResult = resultBll.SelectFirstBy("CaseId", caseId);
                    bool       isFirst    = false;
                    if (testResult == null)
                    {
                        isFirst               = true;
                        testResult            = new TestResult();
                        testResult.ProjectId  = param["projectId"].ToString();
                        testResult.CaseId     = param["caseId"].ToString();
                        testResult.CreateTime = DateTime.Now;
                        testResult.IsPass     = true;
                        testResult.Result     = new List <double>();
                    }
                    TestCase       testCase   = projectBll.SelectById(testResult.ProjectId).CaseList.Where(s => s.Id == testResult.CaseId).FirstOrDefault();
                    StepTestStatus testStatus = StepTestStatus.测试通过;
                    string         reponseMsg = "回复消息 我已完成任务";
                    if (!fi.Exists)
                    {
                        testStatus        = StepTestStatus.测试异常;
                        reponseMsg        = "回复消息 测试未生成结果文件!";
                        testResult.IsPass = false;
                    }
                    else
                    {
                        int index = int.Parse(param["index"].ToString());
                        if (index > testCase.LimitList.Count && index <= 0)
                        {
                            testStatus        = StepTestStatus.测试异常;
                            reponseMsg        = "回复消息 测试时限值索引值与测试例中限值范围不符!";
                            testResult.IsPass = false;
                        }
                        else
                        {
                            double value = iperfBll.GetResult(filePath1);
                            if (value >= testCase.LimitList[index - 1])
                            {
                                testStatus = StepTestStatus.测试通过;
                                reponseMsg = "回复消息 测试通过,测试限值为" + value;
                                testResult.Result.Add(value);
                                testResult.IsPass = true;
                            }
                            else
                            {
                                testStatus        = StepTestStatus.测试未通过;
                                reponseMsg        = "回复消息 测试未通过,测试限值为" + value;
                                testResult.IsPass = false;
                            }
                        }
                    }
                    if (isFirst)
                    {
                        resultBll.Insert(testResult);
                    }
                    else
                    {
                        resultBll.UpdateBy("CaseId", testResult);
                    }

                    WriteLogAndSendResponse(msg.NMSMessageId, reponseMsg, testStatus, "", param["projectId"].ToString(), param["caseId"].ToString(), param["stepId"].ToString());
                }
            }
            catch (Exception ex)
            {
                log.Info(ex.Message, projectId);
                testLog.Write(projectId, ex.Message, caseId);
            }
        }
コード例 #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);
            }
        }
コード例 #8
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);
                IAgentApiChariot            chariotBll = ChariotFactory.GetChariot(param["deviceModel"].ToString());
                projectId = param["projectId"].ToString();
                log.Info(msg.NMSMessageId, projectId);
                if (msg.NMSType == "TestThroughput")
                {
                    string param1 = param["param1"].ToString();
                    //string param2 = param["param2"].ToString();
                    //string param3 = param["param3"].ToString();
                    string param4 = param["param4"].ToString();
                    ////string param5 = param["param5"].ToString();
                    ////string param6 = param["param6"].ToString();
                    string        ping        = "ping 127.0.0.1 -n 30 >nul";
                    List <string> commandList = new List <string>()
                    {
                        param1, ping, /* param2, ping, param3, ping,*/ param4, ping, /*param5, ping, param6, */ ping + "&exit"
                    };
                    CmdHelper.SendCmdCommandList(commandList);
                    WriteLogAndSendResponse(msg.NMSMessageId, "回复消息,我已经完成任务!", StepTestStatus.测试通过, "", param["projectId"].ToString(), param["caseId"].ToString(), param["stepId"].ToString());
                }
                else if (msg.NMSType == "AnalysisResult")
                {
                    List <string> resultList = new List <string>();
                    string        filePath1  = param["FilePath1"].ToString();
                    //string filePath2 = param["FilePath2"].ToString();
                    //string filePath3 = param["FilePath3"].ToString();
                    resultList.Add(chariotBll.GetTestValue(filePath1));
                    //resultList.Add(AnalysisResult.GetTestValue(filePath2));
                    //resultList.Add(AnalysisResult.GetTestValue(filePath3));
                    TestResult testResult = new TestResult();
                    testResult.ProjectId  = param["projectId"].ToString();
                    testResult.CaseId     = param["caseId"].ToString();
                    testResult.CreateTime = DateTime.Now;
                    testResult.IsPass     = true;
                    testResult.Result     = new List <double>();
                    TestCase       testCase   = caseBll.SelectById(testResult.CaseId);
                    StepTestStatus testStatus = StepTestStatus.测试通过;
                    string         reponseMsg = "回复消息 我已完成任务";
                    if (testCase.LimitList.Count != resultList.Count)
                    {
                        testStatus        = StepTestStatus.测试异常;
                        reponseMsg        = "回复消息 测试结果数量与限值数量不一致!";
                        testResult.IsPass = false;
                    }
                    else
                    {
                        for (int i = 0; i < testCase.LimitList.Count; i++)
                        {
                            double value = Convert.ToDouble(resultList[i]);
                            if (testCase.LimitList[i] > value)
                            {
                                testResult.IsPass = false;
                                testStatus        = StepTestStatus.测试未通过;
                            }
                            testResult.Result.Add(value);
                        }
                    }
                    resultBll.Insert(testResult);

                    WriteLogAndSendResponse(msg.NMSMessageId, reponseMsg, testStatus, "", param["projectId"].ToString(), param["caseId"].ToString(), param["stepId"].ToString());
                }
            }
            catch (Exception ex)
            {
                log.Info(ex.Message, projectId);
            }
        }