예제 #1
0
        private void DoRunProcess(byte[] sendData)
        {
            bool readerSuccess = false;
            bool success       = false;

            try
            {
                MessageStructure reader = null;
                MessageHead      head   = null;
                _stepTimer.StartTime();
                //Console.WriteLine("DoRunProcess:"+ indentify);
                _session.Proxy.SendAsync(sendData, data =>
                {
                    //  try
                    //  {
                    //      if (data.Length == 0) return true;
                    //      reader = new MessageStructure(data);
                    //      head = reader.ReadHeadGzip();
                    //      return head.Action.ToString() == Action;
                    //  }
                    //  catch (Exception ex)
                    //  {
                    //      TraceLog.WriteError("Step {0} error:{1}", Action, ex);
                    //      return false;
                    //  }
                    if (netReader.pushNetStream(data))
                    {
                        readerSuccess = true;
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                });

                if (CheckCompleted(head) && readerSuccess && DecodePacket(reader, head))
                {
                    success = true;
                    _stepTimer.Completed();
                }
                else
                {
                    Console.WriteLine(indentify + " acction error");
                }
            }
            catch (Exception ex)
            {
                _stepTimer.PushError(ex.Message);
            }
            finally
            {
                _stepTimer.StopTime();
            }

            if (success && ChildStep != null)
            {
                ChildStep.StartRun();
            }
        }
예제 #2
0
        private void DoRunProcess(byte[] sendData)
        {
            bool success = false;

            try
            {
                MessageStructure reader = null;
                MessageHead      head   = null;
                _stepTimer.StartTime();
                _session.Proxy.SendAsync(sendData, data =>
                {
                    try
                    {
                        if (data.Length == 0)
                        {
                            return(true);
                        }
                        reader = new MessageStructure(data);
                        head   = reader.ReadHeadGzip();
                        return(head.Action.ToString() == Action);
                    }
                    catch (Exception ex)
                    {
                        TraceLog.WriteError("Step {0} error:{1}", Action, ex);
                        return(false);
                    }
                });

                if (CheckCompleted(head) && DecodePacket(reader, head))
                {
                    success = true;
                    _stepTimer.Completed();
                }
            }
            catch (Exception ex)
            {
                _stepTimer.PushError(ex.Message);
            }
            finally
            {
                _stepTimer.StopTime();
            }

            if (success && ChildStep != null)
            {
                ChildStep.StartRun();
            }
        }
예제 #3
0
        internal static int RunStep(StringBuilder stepBuilder, List <ThreadSession> sessionList, TaskSetting setting, string stepName, int runtimes)
        {
            CaseStep[] caseList = new CaseStep[sessionList.Count];
            Task[]     taskList = new Task[sessionList.Count];
            StepTimer  st       = new StepTimer();

            st.Reset();
            st.StartTime();
            for (int i = 0; i < taskList.Length; i++)
            {
                ++cnt;
                var session  = sessionList[i];
                var caseStep = CaseStep.Create(setting.CaseStepTypeFormat, stepName, cnt);
                if (caseStep != null)
                {
                    caseStep.Runtimes = runtimes;
                    caseStep.Init(session, setting);
                    caseList[i] = caseStep;
                    //Console.WriteLine("Task.Factory.StartNew:" + cnt);
                    taskList[i] = Task.Factory.StartNew(caseStep.StartRun);
                }
            }
            if (setting.WaitTimeout == TimeSpan.Zero)
            {
                Task.WaitAll(taskList);
            }
            else
            {
                Task.WaitAll(taskList, setting.WaitTimeout);
            }
            st.Completed();
            st.DoResult();
            int errorCount = caseList.Sum(t => t.Timer.FailNum);

            DoStepResult(setting, stepBuilder, stepName, caseList, 0, st);
            return(errorCount);
        }
예제 #4
0
 internal static int RunStep(StringBuilder stepBuilder, List<ThreadSession> sessionList, TaskSetting setting, string stepName, int runtimes)
 {
     CaseStep[] caseList = new CaseStep[sessionList.Count];
     Task[] taskList = new Task[sessionList.Count];
     StepTimer st = new StepTimer();
     st.Reset();
     st.StartTime();
     for (int i = 0; i < taskList.Length; i++)
     {
         ++cnt;
         var session = sessionList[i];
         var caseStep = CaseStep.Create(setting.CaseStepTypeFormat, stepName,cnt);
         if (caseStep != null)
         {
             caseStep.Runtimes = runtimes;
             caseStep.Init(session,setting);
             caseList[i] = caseStep;
             //Console.WriteLine("Task.Factory.StartNew:" + cnt);
             taskList[i] = Task.Factory.StartNew(caseStep.StartRun);
         }
     }
     if (setting.WaitTimeout == TimeSpan.Zero)
     {
         Task.WaitAll(taskList);
     }
     else
     {
         Task.WaitAll(taskList, setting.WaitTimeout);
     }
     st.Completed();
     st.DoResult();
     int errorCount = caseList.Sum(t => t.Timer.FailNum);
     DoStepResult(setting,stepBuilder, stepName, caseList,0,st);
     return errorCount;
 }