public static string SendResponse(string messageId, StepTestStatus result, string message) { Dictionary <string, object> param = new Dictionary <string, object>(); param.Add("result", result); param.Add("msg", message); param.Add("correlationId", messageId); string ret = MqProducerQueue.GetInst().SendJsonMessage(MqConst.RESPONSE_Q, null, param, null); return(ret); }
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); } }
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); }
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); } }
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); } }