Exemplo n.º 1
0
        /// <summary>
        /// </summary>
        /// <param name="dtus">所有DTU信息</param>
        /// <param name="utasks">未完成的实时采集任务(存储于数据库中,以DTUID为key)</param>
        public DACTaskManager(IDtuServer dtuServer, IList <DtuNode> dtus, IList <DACTask> utasks, DtuType type = DtuType.Gprs)
        {
            OnDTUConnectionStatusChanged = null;
            this._dtuServer = dtuServer;
            DACTaskPersistent.Init();
            foreach (DtuNode d in dtus)
            {
                _dtus[d.DtuId]         = d;
                _dtuCodeMap[d.DtuCode] = d;
            }
            Log.DebugFormat("{0} dtus ready to work.", _dtus.Count);
            DtuType = type;
            if (DtuType.Gprs == type)
            {
                dtuServer.OnConnectStatusChanged += OnConnectionStatusChanged;
            }

            _adapterManager = SensorAdapterManager.InitializeManager();

            if (utasks != null)
            {
                foreach (DACTask t in utasks)
                {
                    if (t.DtuID == 0)
                    {
                        continue;
                    }
                    _rtasks[t.DtuID] = t;
                    ArrangeInstantTask(t.TID, t.DtuID, t.Sensors, null, true);
                }
            }
        }
Exemplo n.º 2
0
        DACTask CreateInstantDACTask(string tid, uint dtuId, IList <uint> sensors, TaskResultConsumer consumer, bool activeFromDB)
        {
            if (DtuType == Model.DtuType.Com)
            {
                Log.ErrorFormat("COM dtu doesn't support instance task.");
                return(null);
            }
            DACTask task = null;

            if (activeFromDB)
            {
                if (HasUnfinishedTask(dtuId, out task))
                {
                    return(task);
                }
            }
            else
            {
                if (!_dtus.ContainsKey(dtuId))
                {
                    return(null);
                }
                task = new DACTask(tid, dtuId, sensors, TaskType.INSTANT, null);
                DACTaskPersistent.SaveTaskImmedate(task);
                _rtasks[dtuId] = task;
            }
            return(task);
        }
Exemplo n.º 3
0
 public void Stop()
 {
     _schedule.Shutdown();
     foreach (DACWorker w in _workers.Values)
     {
         w.Stop();
     }
     _schedule.Clear();
     _workers.Clear();
     DACTaskPersistent.Stop();
     ATTaskPersistent.Stop();
 }
Exemplo n.º 4
0
 // 即时采集任务固定回调, 用于处理数据库任务记录
 private static void OnInstantTaskFinished(DACTaskResult result)
 {
     //
     Log.DebugFormat("OnInstaceTaskFinished :t={0}, r={1}, status={2}", result.Task.ID, result.ErrorCode, result.Task.Status);
     DACTaskPersistent.SaveTaskResult(result);
     if (result.Task.Status == DACTaskStatus.DONE)
     {
         uint    dtuId = result.Task.DtuID;
         DACTask task;
         if (_rtasks.ContainsKey(dtuId))
         {
             _rtasks.TryRemove(dtuId, out task);
         }
         TryRemoveJob(dtuId);
         Console.WriteLine("remove job {1} {0}", DateTime.Now, dtuId);
     }
 }