コード例 #1
0
ファイル: DACWorker.cs プロジェクト: icprog/FS-SMISCloud
        private void LetsDoIt(DACTask t)
        {
            this.working = true;
            DACTaskResult result = null;

            if (_context != null && _context.IsAvaliable() && _context.Node != null)
            {
                try
                {
                    UpdateContext();
                    Log.Info("_context valid, start robot");
                    result          = new DACTaskExecutor(adapter, _sensorCollectMsgHandler).Run(t, _context);
                    result.ErrorMsg = "OK";
                }
                catch (Exception ex)
                {
                    Log.ErrorFormat("DTU context : {0}--{1}, error {2}", t.DtuID, this._context != null && this._context.Node != null ? this._context.Node.DtuCode : string.Empty, ex.Message);
                    if (result == null)
                    {
                        result = new DACTaskResult
                        {
                            DtuCode   = _context.Node.DtuCode,
                            Task      = t,
                            ErrorCode = (int)Errors.ERR_UNKNOW,
                            ErrorMsg  = "FAILED",
                            Finished  = DateTime.Now
                        };
                        result.Task.Status = DACTaskStatus.FAIL;
                    }
                }
            }
            else
            {
                Log.Error("_context Busy, can't run.");
                int errcode;
                if (_context != null && _context.DtuConnection != null && _context.DtuConnection.IsOnline)
                {
                    errcode = (int)Errors.ERR_DTU_BUSY;
                }
                else if (_context != null && _context.DtuConnection != null && !_context.DtuConnection.IsOnline)
                {
                    errcode = (int)Errors.ERR_NOT_CONNECTED;
                }
                else
                {
                    errcode = (int)Errors.ERR_INVALID_DTU;
                }
                result = new FailedDACTaskResult(errcode, t);
            }
            if (t.Consumer != null)
            {
                t.Consumer(result);
            }
            this.working = false;
        }
コード例 #2
0
        private void LetsDoIt(ATTask atTask)
        {
            ExecuteResult result = null;

            if (_context.IsAvaliable())
            {
                ushort timeout = 10;
                Log.Info("_context valid, start robot");
                try
                {
                    result          = new ConfigCommandExecutor().Execute(task, _context, timeout);
                    result.ErrorMsg = "OK";
                }
                catch (Exception ex)
                {
                    Log.Error(ex.Message);
                    result.ErrorMsg = "FAILED";
                }
            }
            else
            {
                Log.Error("_context Busy, can't run.");
                result = new ExecuteResult
                {
                    IsOK      = false,
                    ErrorCode = (int)Errors.ERR_NOT_CONNECTED,
                    ErrorMsg  = "FAILED",
                    Task      = atTask,
                    Elapsed   = 0,
                    Finished  = DateTime.Now
                };
                foreach (var ac in atTask.AtCommands.AtCommands)
                {
                    ATCommandResult r = new ATCommandResult();
                    r.GetJsonResult(ac.ToATString());
                    result.AddAtResult(r);
                }
                result.Task.Status = DACTaskStatus.FAIL;
            }

            if (atTask.Consumer != null)
            {
                atTask.Consumer(result);
            }
            this.Stop();
        }