Пример #1
0
        public void Strat()
        {
            if (telnet.Connect() == false)
            {
                Console.WriteLine("connect fail ");
            }
            else
            {
                telnet.WaitStr("login");
                telnet.WriteLine("telnet");
                telnet.WaitStr("password");
                telnet.WriteLine("lijie1515");
                telnet.WaitStr("$");
                Console.WriteLine(telnet.GetAndMoveShowData());

                //Console.WriteLine("-------------------------------------------");
                //Console.WriteLine(telnet.SessionLog);
                //Console.WriteLine("-------------------------------------------");



                Console.WriteLine(telnet.GetAndMoveShowData());
                telnet.WriteLine("ls");
                telnet.WaitStr("$");
                Console.WriteLine(telnet.GetAndMoveShowData());

                Console.WriteLine("-------------------------------------------");
                Console.WriteLine(telnet.AllLogData);
                Console.WriteLine("-------------------------------------------");

                Console.ReadLine();
                telnet.OnMesageReport += telnet_OnMesageReport;
                for (int i = 0; i < 10; i++)
                {
                    telnet.WriteLine("netstat");
                }
                telnet.OnMesageReport -= telnet_OnMesageReport;

                Console.ReadLine();
                Console.WriteLine("******************************************");
                Console.WriteLine(telnet.DoRequest("ll", "$ "));
                Console.WriteLine("******************************************");
                Console.WriteLine(telnet.DoRequest("mkdir 123", "$ "));
                Console.WriteLine("******************************************");
                Console.WriteLine(telnet.DoRequest("ll", "$ "));
                Console.WriteLine("******************************************");

                Console.ReadLine();
                telnet.DisConnect();
            }
        }
Пример #2
0
        public MyExecutionDeviceResult ExecutionDeviceRun(ICaseExecutionContent yourExecutionContent, CaseActionActuator.delegateGetExecutiveData yourExecutiveDelegate, string sender, ActuatorStaticDataCollection yourActuatorStaticDataCollection, int caseId)
        {
            List <string>           errorList = new List <string>();
            string                  tempError = null;
            MyExecutionDeviceResult myResult  = new MyExecutionDeviceResult();

            myResult.staticDataResultCollection = new System.Collections.Specialized.NameValueCollection();

            //向UI推送执行过程信息
            Action <string, CaseActuatorOutPutType, string> ExecutiveDelegate = (innerSender, outType, yourContent) =>
            {
                if (yourExecutiveDelegate != null)
                {
                    yourExecutiveDelegate(innerSender, outType, yourContent);
                }
            };

            //处理执行错误(执行器无法执行的错误)
            Action <string> DealExecutiveError = (errerData) =>
            {
                if (errerData != null)
                {
                    ExecutiveDelegate(sender, CaseActuatorOutPutType.ExecutiveError, errerData);
                    errorList.Add(errerData);
                }
            };

            if (yourExecutionContent.MyCaseProtocol == CaseProtocol.telnet)
            {
                //在调用该函数前保证nowExecutionContent.ErrorMessage为空,且as一定成功
                MyTelnetExecutionContent nowExecutionContent = yourExecutionContent as MyTelnetExecutionContent;
                myResult.caseProtocol = CaseProtocol.telnet;
                myResult.caseTarget   = nowExecutionContent.MyExecutionTarget;
                myResult.startTime    = DateTime.Now.ToString("HH:mm:ss");
                StringBuilder tempCaseOutContent = new StringBuilder();

                System.Diagnostics.Stopwatch myWatch = new System.Diagnostics.Stopwatch();
                myWatch.Start();

                ExecutiveDelegate(sender, CaseActuatorOutPutType.ExecutiveInfo, string.Format("【ID:{0}】[telnet]Executive···", caseId));

                string nowTelnetCmd = nowExecutionContent.telnetContent.GetTargetContentData(yourActuatorStaticDataCollection, myResult.staticDataResultCollection, out tempError);
                if (tempError != null)
                {
                    DealExecutiveError(string.Format("this case get static data errer with [{0}]", nowExecutionContent.telnetContent.GetTargetContentData()));
                    tempCaseOutContent.AppendLine("error with static data");
                }
                else
                {
                    try
                    {
                        string tempResult = telnetShell.DoRequest(nowTelnetCmd);

                        ExecutiveDelegate(sender, CaseActuatorOutPutType.ExecutiveInfo, tempResult);
                        tempCaseOutContent.AppendLine(tempResult);
                    }
                    catch (Exception ex)
                    {
                        DealExecutiveError(ex.Message);
                        tempCaseOutContent.AppendLine(ex.Message);
                    }
                }

                myWatch.Stop();
                myResult.spanTime = myResult.requestTime = myWatch.ElapsedMilliseconds.ToString();

                myResult.backContent = tempCaseOutContent.ToString();
            }
            else
            {
                myResult.backContent = "error:your CaseProtocol is not Matching RunTimeActuator";
                DealExecutiveError(myResult.backContent);
            }


            if (errorList.Count > 0)
            {
                myResult.additionalError = errorList.MyToString("\r\n");
            }

            return(myResult);
        }