示例#1
0
 public ExceptionEventInfo(RuntimeErrorMessage message) : base(message.Id, EventType.Exception, message.Time)
 {
     this.Message       = message.Message;
     this.ExceptionType = message.Name;
     this.StackTrace    = message.StackTrace;
     this.Source        = message.Source;
 }
        private bool HandleRuntimeErrorMessage(RuntimeErrorMessage message)
        {
            ExceptionEventInfo exceptionEventInfo = new ExceptionEventInfo(message);

            _globalInfo.EventQueue.Enqueue(exceptionEventInfo);
            _testsMaintainer.FreeHost(message.Id);
            return(true);
        }
        private bool HandleRuntimeErrorMessage(RuntimeErrorMessage message)
        {
            // 阻塞足够时间后再执行,以保证其他状态数据的正确更新
            Thread.Sleep(500);
            // 接收到ExceptionMessage后只是释放Host,删除执行ExceptionEventInfo。因为状态维护模块会自动维护相关的信息
//            ExceptionEventInfo exceptionEventInfo = new ExceptionEventInfo(message);
//            _globalInfo.EventQueue.Enqueue(exceptionEventInfo);
            _testsMaintainer.FreeHost(message.Id);
            return(true);
        }
示例#4
0
        public void StartSlaveTask()
        {
            // 打印状态日志
            _context.LogSession.Print(LogLevel.Info, _context.SessionId, "Slave controller started.");

            _context.MessageTransceiver.StartReceive();
            _context.LogSession.Print(LogLevel.Debug, _context.SessionId, "Slave transceiver started.");

            _downlinkMsgProcessor = new DownlinkMessageProcessor(_context);

            _context.UplinkMsgProcessor.Start();

            _flowTaskThread = new Thread(TestTaskWork)
            {
                IsBackground = true,
                Name         = string.Format(Constants.TaskRootThreadNameFormat, _context.SessionId)
            };
            // TODO 配置运行时线程为STA模式以支持对SLAVE端显示界面的支持,目前该配置除了对COM组件的调用以外未发现有额外的影响
            _flowTaskThread.SetApartmentState(ApartmentState.STA);
            // 开始流程处理线程
            _flowTaskThread.Start();
            _context.FlowControlThread = _flowTaskThread;

            // 打印状态日志
            _context.LogSession.Print(LogLevel.Debug, _context.SessionId,
                                      $"Flow task thread started, thread:{_flowTaskThread.ManagedThreadId}");

            try
            {
                // 在主线程内开始侦听下行消息并处理
                _downlinkMsgProcessor.StartListen();
            }
            catch (Exception ex)
            {
                _context.LogSession.Print(LogLevel.Fatal, CommonConst.PlatformLogSession, ex,
                                          "TestflowRuntimeException caught.");
                // 发送异常错误信息
                RuntimeErrorMessage runtimeErrorMessage = new RuntimeErrorMessage(_context.SessionId, ex)
                {
                    Index = _context.MsgIndex
                };
                _context.UplinkMsgProcessor.SendMessage(runtimeErrorMessage, true);
            }
            finally
            {
                StopSlaveTask();
                _context.LogSession.Print(LogLevel.Info, _context.SessionId, "Slave controller  stopped.");
            }
        }
示例#5
0
        public void DoFlowTask()
        {
            try
            {
                // 配置心跳包生成委托
                Context.UplinkMsgProcessor.HeartbeatMsgGenerator = GetHeartBeatMessage;

                // 打印状态日志
                Context.LogSession.Print(LogLevel.Debug, Context.SessionId, $"{this.GetType().Name} task action started.");

                // 如果被取消则直接返回
                if (Context.Cancellation.IsCancellationRequested)
                {
                    // 打印状态日志
                    Context.LogSession.Print(LogLevel.Debug, Context.SessionId, $"{this.GetType().Name} task action aborted.");
                    return;
                }

                // 更新当前FlowTask
                SlaveFlowTaskBase.CurrentFlowTask = this;

                FlowTaskAction();

                // 打印状态日志
                Context.LogSession.Print(LogLevel.Debug, Context.SessionId, $"{this.GetType().Name} task action over.");
            }
            catch (ThreadAbortException ex)
            {
                Context.State = RuntimeState.Abort;
                Context.LogSession.Print(LogLevel.Warn, CommonConst.PlatformSession, ex, "Task aborted.");
                TaskAbortAction();
            }
            catch (Exception ex)
            {
                Context.State = RuntimeState.Error;
                // 失败后打印日志并发送错误信息
                Context.LogSession.Print(LogLevel.Fatal, CommonConst.PlatformLogSession, ex,
                                         "Runtime exception occured.");
                TaskErrorAction(ex);
                // 发送运行时异常错误
                RuntimeErrorMessage errorMessage = new RuntimeErrorMessage(Context.SessionId, ex)
                {
                    Index = Context.MsgIndex
                };
                Context.UplinkMsgProcessor.SendMessage(errorMessage, true);
            }
        }