private void SetResultState(out StepResult lastStepResult, out StatusReportType finalReportType,
                                    out FailedInfo failedInfo)
        {
            StepTaskEntityBase lastStep = StepTaskEntityBase.GetCurrentStep(this.Index, RootCoroutineId);

            lastStepResult = lastStep.Result;
            failedInfo     = null;
            this.State     = ModuleUtils.GetSequenceState(this._stepEntityRoot);
            switch (this.State)
            {
            case RuntimeState.Over:
            case RuntimeState.Success:
                finalReportType = StatusReportType.Over;
                break;

            case RuntimeState.Failed:
                finalReportType = StatusReportType.Failed;
                break;

            case RuntimeState.Timeout:
            case RuntimeState.Error:
                finalReportType = StatusReportType.Error;
                break;

            case RuntimeState.Abort:
                finalReportType = StatusReportType.Error;
                failedInfo      = new FailedInfo("Sequence aborted", FailedType.Abort);
                _context.LogSession.Print(LogLevel.Warn, Index, $"Sequence {Index} execution aborted");
                break;

            default:
                finalReportType = StatusReportType.Over;
                break;
            }
        }
Exemple #2
0
 public SMS(List <string> numbers, string msgContent, LevelType msgLevel, DateTime sendTime, StatusReportType statusReport)
 {
     Number       = numbers;
     Content      = msgContent;
     Level        = msgLevel;
     SendTime     = sendTime;
     StatusReport = statusReport;
     IsSplit      = true;
 }
Exemple #3
0
 public SequenceStatusInfo(int sequence, CallStack stack, StatusReportType type, RuntimeState sequenceState, StepResult result, FailedInfo failedInfo = null)
 {
     this.SequenceState = sequenceState;
     this.Sequence      = sequence;
     this.Stack         = stack;
     this.ReportType    = type;
     this.FailedInfo    = failedInfo;
     this.Time          = DateTime.Now;
     this.Result        = result;
 }
        private void FillFinalExceptionReportInfo(Exception ex, out StatusReportType finalReportType,
                                                  out StepResult lastStepResult, out FailedInfo failedInfo)
        {
            if (ex is TaskFailedException)
            {
                TaskFailedException failedException = (TaskFailedException)ex;
                FailedType          failedType      = failedException.FailedType;
                this.State      = ModuleUtils.GetRuntimeState(failedType);
                finalReportType = ModuleUtils.GetReportType(failedType);
                lastStepResult  = ModuleUtils.GetStepResult(failedType);
                failedInfo      = new FailedInfo(ex, failedType);
                _context.LogSession.Print(LogLevel.Info, Index, "Step force failed.");
            }
            else if (ex is TestflowAssertException)
            {
                this.State      = RuntimeState.Failed;
                finalReportType = StatusReportType.Failed;
                lastStepResult  = StepResult.Failed;
                failedInfo      = new FailedInfo(ex, FailedType.AssertionFailed);
                _context.LogSession.Print(LogLevel.Error, Index, "Assert exception catched.");
            }
            else if (ex is ThreadAbortException)
            {
                this.State      = RuntimeState.Abort;
                finalReportType = StatusReportType.Error;
                lastStepResult  = StepResult.Abort;
                failedInfo      = new FailedInfo(ex, FailedType.Abort);
                _context.LogSession.Print(LogLevel.Warn, Index, $"Sequence {Index} execution aborted");
            }
            else if (ex is TestflowException)
            {
                this.State      = RuntimeState.Error;
                finalReportType = StatusReportType.Error;
                lastStepResult  = StepResult.Error;
                failedInfo      = new FailedInfo(ex, FailedType.RuntimeError);
                _context.LogSession.Print(LogLevel.Error, Index, ex, "Inner exception catched.");
            }
            else
            {
                this.State      = RuntimeState.Error;
                finalReportType = StatusReportType.Error;
                lastStepResult  = StepResult.Error;
                failedInfo      = new FailedInfo(ex, FailedType.RuntimeError);
                _context.LogSession.Print(LogLevel.Error, Index, ex, "Runtime exception catched.");
            }
//            else if (ex is TargetInvocationException)
//            {
//                this.State = RuntimeState.Failed;
//                finalReportType = StatusReportType.Failed;
//                lastStepResult = StepResult.Failed;
//                failedInfo = new FailedInfo(ex.InnerException, FailedType.TargetError);
//                _context.LogSession.Print(LogLevel.Error, Index, ex, "Invocation exception catched.");
//            }
        }
Exemple #5
0
        string GetStatusReport(StatusReportType a)
        {
            string str = "";

            switch (a)
            {
            case StatusReportType.Enabled:
                str = "发送";
                break;

            case StatusReportType.Disable:
                str = "不发送";
                break;

            case StatusReportType.Push:
                str = "推送";
                break;
            }
            return(str);
        }
Exemple #6
0
        public int GetReportStatus(StatusReportType statustype)
        {
            int status = 0;

            if (statustype == StatusReportType.Created)
            {
                status = 1;
            }
            if (statustype == StatusReportType.Saved)
            {
                status = 2;
            }
            if (statustype == StatusReportType.Completed)
            {
                status = 3;
            }
            if (statustype == StatusReportType.Submitted)
            {
                status = 4;
            }
            return(status);
        }
        public void Invoke(bool forceInvoke = false)
        {
            FailedInfo       failedInfo      = null;
            StepResult       lastStepResult  = StepResult.NotAvailable;
            StatusReportType finalReportType = StatusReportType.Failed;

            try
            {
                this.State = RuntimeState.Running;
                SequenceStatusInfo startStatusInfo = new SequenceStatusInfo(Index, _stepEntityRoot.GetStack(),
                                                                            StatusReportType.Start, RuntimeState.Running, StepResult.NotAvailable)
                {
                    ExecutionTime  = DateTime.Now,
                    ExecutionTicks = -1,
                    CoroutineId    = RootCoroutineId
                };
                _context.StatusQueue.Enqueue(startStatusInfo);

                StepTaskEntityBase stepEntity = _stepEntityRoot;
                do
                {
                    stepEntity.Invoke(forceInvoke);
                } while (null != (stepEntity = stepEntity.NextStep));
                SetResultState(out lastStepResult, out finalReportType, out failedInfo);
            }
            catch (TaskFailedException ex)
            {
                // 停止失败的step的计时
                StepTaskEntityBase currentStep = StepTaskEntityBase.GetCurrentStep(Index, RootCoroutineId);
                currentStep?.EndTiming();
                FillFinalExceptionReportInfo(ex, out finalReportType, out lastStepResult, out failedInfo);
                // 如果抛出TargetInvokcationException到当前位置则说明内部没有发送错误事件
                if (null != currentStep && currentStep.Result == StepResult.NotAvailable)
                {
                    currentStep.SetStatusAndSendErrorEvent(lastStepResult, failedInfo);
                }
            }
            catch (TestflowAssertException ex)
            {
                // 停止失败的step的计时
                StepTaskEntityBase currentStep = StepTaskEntityBase.GetCurrentStep(Index, RootCoroutineId);
                currentStep?.EndTiming();
                FillFinalExceptionReportInfo(ex, out finalReportType, out lastStepResult, out failedInfo);
                // 如果抛出TargetInvokcationException到当前位置则说明内部没有发送错误事件
                if (null != currentStep && currentStep.Result == StepResult.NotAvailable)
                {
                    currentStep.SetStatusAndSendErrorEvent(lastStepResult, failedInfo);
                }
            }
            catch (ThreadAbortException ex)
            {
                // 停止失败的step的计时
                StepTaskEntityBase currentStep = StepTaskEntityBase.GetCurrentStep(Index, RootCoroutineId);
                currentStep?.EndTiming();
                FillFinalExceptionReportInfo(ex, out finalReportType, out lastStepResult, out failedInfo);
                // Abort异常不会在内部处理,需要在外部强制抛出
                currentStep?.SetStatusAndSendErrorEvent(lastStepResult, failedInfo);
            }
            catch (TargetInvocationException ex)
            {
                // 停止失败的step的计时
                StepTaskEntityBase currentStep = StepTaskEntityBase.GetCurrentStep(Index, RootCoroutineId);
                currentStep?.EndTiming();
                FillFinalExceptionReportInfo(ex.InnerException, out finalReportType, out lastStepResult, out failedInfo);
                // 如果抛出TargetInvokcationException到当前位置则说明内部没有发送错误事件
                if (null != currentStep && currentStep.Result == StepResult.NotAvailable)
                {
                    currentStep.SetStatusAndSendErrorEvent(lastStepResult, failedInfo);
                }
            }
            catch (TestflowLoopBreakException ex)
            {
                // 停止失败的step的计时
                StepTaskEntityBase currentStep = StepTaskEntityBase.GetCurrentStep(Index, RootCoroutineId);
                currentStep?.EndTiming();
                // 如果包含内部异常,则说明发生了运行时错误,记录错误信息。
                if (null != ex.InnerException)
                {
                    FillFinalExceptionReportInfo(ex.InnerException, out finalReportType, out lastStepResult,
                                                 out failedInfo);
                    // 如果抛出TargetInvokcationException到当前位置则说明内部没有发送错误事件
                    if (null != currentStep && currentStep.BreakIfFailed)
                    {
                        currentStep.SetStatusAndSendErrorEvent(lastStepResult, failedInfo);
                    }
                }
                // 只是流程控制,记录结果信息后退出
                else
                {
                    SetResultState(out lastStepResult, out finalReportType, out failedInfo);
                }
            }
            catch (Exception ex)
            {
                // 停止失败的step的计时
                StepTaskEntityBase currentStep = StepTaskEntityBase.GetCurrentStep(Index, RootCoroutineId);
                currentStep?.EndTiming();
                FillFinalExceptionReportInfo(ex, out finalReportType, out lastStepResult, out failedInfo);
                // 如果抛出Exception到当前位置则说明内部没有发送错误事件
                if (null != currentStep && currentStep.BreakIfFailed)
                {
                    currentStep.SetStatusAndSendErrorEvent(lastStepResult, failedInfo);
                }
            }
            finally
            {
                StepTaskEntityBase currentStep = StepTaskEntityBase.GetCurrentStep(Index, RootCoroutineId);
                // 发送结束事件,包括所有的ReturnData信息
                SequenceStatusInfo overStatusInfo = new SequenceStatusInfo(Index, currentStep.GetStack(),
                                                                           finalReportType, this.State, StepResult.Over, failedInfo)
                {
                    ExecutionTime  = DateTime.Now,
                    CoroutineId    = RootCoroutineId,
                    ExecutionTicks = 0
                };
                overStatusInfo.WatchDatas = _context.VariableMapper.GetReturnDataValues(_sequence);
                this._context.StatusQueue.Enqueue(overStatusInfo);

                _context.VariableMapper.ClearSequenceVariables(_sequence);
                this._stepEntityRoot = null;
                // 将失败步骤职责链以后的step标记为null
                currentStep.NextStep = null;
            }
        }