Exemplo n.º 1
0
 public AtCommandWorker(ATTask task, DacTaskContext context)
 {
     this.task     = task;
     this._source  = new CancellationTokenSource();
     this._token   = this._source.Token;
     this._context = context;
 }
Exemplo n.º 2
0
        public int ArrangeInstantTask(string tid, uint dtuId, JObject[] cmdobjs, ATTaskResultConsumer consumer)
        {
            ATTask task = new ATTask(tid, dtuId, cmdobjs, TaskType.INSTANT, consumer);

            ATTaskPersistent.Init();
            ATTaskPersistent.SaveTaskImmedate(task);
            task.Consumer += OnAtInstantTaskFinished;
            DacTaskContext context = null;

            if (_workers.ContainsKey(dtuId))
            {
                if (!IsWorkerAvaliable(_workers[dtuId]))
                {
                    _workers[dtuId].Stop();
                }
                context = _workers[dtuId].GetContext();
            }
            else
            {
                context = CreateContext(dtuId);
            }
            var atworker = new AtCommandWorker(task, context);

            atworker.StartWork();
            return(task.ID);
        }
Exemplo n.º 3
0
 internal static void SaveTaskImmedate(ATTask task)
 {
     try
     {
         DbAccessorHelper.AtDbAccessor.SaveInstantTask(task);
     }
     catch (Exception ex)
     {
         log.ErrorFormat("SaveATTaskImmedate Failed! : -- {0}", ex.Message);
     }
 }
Exemplo n.º 4
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();
        }