Exemplo n.º 1
0
        public void ExecAction()
        {
            log.Write(this.currentProject.Id, "执行action: " + this.currentStep.Command.Cmd, this.currentCase.Id);
            string ret = string.Empty;

            Thread.Sleep(this.currentStep.Command.Predelay * 1000);
            Dictionary <string, object> param = new Dictionary <string, object>();

            foreach (var inst in this.currentStep.Params.ParamList.ToLookup(s => s.Key))
            {
                if (inst.Count() != 1)
                {
                    param.Add(inst.Key, inst.Select(s =>
                    {
                        return(s.Value);
                    }).ToList());
                }
                else
                {
                    param.Add(inst.Key, inst.FirstOrDefault().Value);
                }
            }
            param.Add("projectId", this.currentProject.Id);
            param.Add("caseId", this.currentCase.Id);
            param.Add("stepId", this.currentStep.Id);
            param.Add("deviceModel", this.currentStep.TestDeviceModel);

            string msgId = MqMasterProducer.SendAction(this.currentStep.AgentType.ToString(), this.currentStep.Command.Cmd, param, this.currentStep.AgentFilter);

            log.Write(this.currentProject.Id, string.Format("发送消息给{0},其命令是{1}", this.currentStep.AgentType.ToString(), this.currentStep.Command.Cmd), this.currentCase.Id);
            this.dicReturnMsg.Add(msgId, new TestMsg(this.currentProject.Id, this.currentCase.Id, this.currentStep.Id));
            bool isResive = false;

            if (this.currentStep.Command.WaitResponse)
            {
                int count = 0;
                while (!isResive)
                {
                    Thread.Sleep(1000);
                    count++;
                    if (count > 3600)
                    {
                        this.Status = TestStatus.测试异常;
                        Console.WriteLine("超时");
                        break;
                    }
                    foreach (var obj in this.dicReturnMsg.Values)
                    {
                        if (!obj.HasReturn)
                        {
                            continue;
                        }
                        if (obj.StepId == this.currentStep.Id)
                        {
                            isResive = true;
                            break;
                        }
                    }
                }
            }
            Thread.Sleep(this.currentStep.Command.Postdelay * 1000);
        }
Exemplo n.º 2
0
        public string ExecAction()
        {
            if (this.currentStep.Id == 99)
            {
                this.Status = TaskStatus.测试完成;
                return(string.Empty);
            }
            log.Info("执行action: " + this.currentStep.StepAction.Name, this.currentTask.Id);
            string ret = string.Empty;

            Thread.Sleep(this.currentStep.StepAction.Predelay);
            Dictionary <string, object> param = new Dictionary <string, object>();

            foreach (var inst in this.currentStep.StepParams.ParamList.ToLookup(s => s.Key))
            {
                if (inst.Count() != 1)
                {
                    param.Add(inst.Key, inst.Select(s =>
                    {
                        return(s.Value);
                    }).ToList());
                }
                else
                {
                    param.Add(inst.Key, inst.FirstOrDefault().Value);
                }
            }
            param.Add("taskId", this.currentTask.Id);
            string msgId = MqMasterProducer.SendAction(this.currentStep.AgentName, this.currentStep.StepAction.Command, param, null);

            log.Info(string.Format("发送消息给{0},其命令是{1}", this.currentStep.AgentName, this.currentStep.StepAction.Command), this.currentTask.Id);
            if (!this.responseReturnDic.ContainsKey(msgId))
            {
                Response res = new Response();
                this.responseReturnDic.TryAdd(msgId, res);
                res.AgentName = this.currentStep.AgentName;
                res.Command   = this.currentStep.StepAction.Command;
                res.orgiMsgId = msgId;
            }
            if (this.currentStep.StepAction.WaitResponse)
            {
                while (true)
                {
                    Thread.Sleep(100);
                    bool isReturn = false;

                    if (this.msgReturnDic.TryGetValue(msgId, out isReturn) && isReturn)
                    {
                        break;
                    }
                }
            }
            Response response = null;

            if (this.responseReturnDic.TryGetValue(msgId, out response))
            {
                ret = response.Condition;
                if (!response.Result)
                {
                    log.Info("命令执行失败", this.currentScript.Id);
                    if (this.currentStep.StepAction.BreakOnFail)
                    {
                        this.Status = TaskStatus.测试异常;
                    }
                }
            }

            Thread.Sleep(this.currentStep.StepAction.Postdelay);
            return(ret);
        }