private void GetJsonresult(DACTask t, int errcode) { if (t.Sensors != null) { foreach (var s in t.Sensors) { this.AddSensorResult(new SensorAcqResult { Data = new SensorErrorData(s, errcode) }); } } }
private bool HasUnfinishedTask(uint dtuId, out DACTask t) { if (_rtasks.ContainsKey(dtuId)) { t = _rtasks[dtuId]; return(true); } else { t = null; return(false); } }
private DACTaskResult ExcuteLocalDacTask(DACTask task, DacTaskContext context) { DtuNode dtu = context.Node; DACTaskResult rslt = new DACTaskResult(); rslt.Task = task; rslt.Task.Status = DACTaskStatus.RUNNING; rslt.ErrorMsg = "OK"; rslt.StoragedTimeType = SensorAcqResultTimeType.SensorResponseTime; Stopwatch sw = new Stopwatch(); sw.Start(); var dtuConn = context.DtuConnection as FileDtuConnection; // 强转成FileDtuConnection if (dtuConn != null && dtuConn.Connect()) { try { foreach (Sensor si in dtu.Sensors) { if (!this.IsSensorRequired(context, task.Sensors, si)) { continue; } var result = this.RequestFileSensor(si, dtuConn);// 请求文件传感器 foreach (SensorAcqResult r in result) { rslt.AddSensorResult(r); } } this.CheckFileAndBackup(dtuConn.FilePath); } catch (System.Exception e) { rslt.ErrorCode = (int)Errors.ERR_NOT_CONNECTED; rslt.ErrorMsg = string.Format( "DTU:{0},FilePath:{1},Failed To Read the File,Msg:{2}", dtu.DtuCode, dtuConn.FilePath, e.Message); log.ErrorFormat( "dtu:{0} network={1},file={2},Failed To Read the File,Msg:{3}", dtu.DtuCode, dtu.NetworkType, dtuConn.FilePath, e.Message); } } else { rslt.ErrorCode = (int)Errors.ERR_NOT_CONNECTED; rslt.ErrorMsg = string.Format( "DTU:{0},FilePath:{1},File Not Exists", dtu.DtuCode, dtuConn != null ? dtuConn.FilePath : null); log.ErrorFormat("dtu:{0} network={1},file={2},File Not Exists", dtu.DtuCode, dtu.NetworkType, dtuConn != null ? dtuConn.FilePath : null); } sw.Stop(); rslt.Finished = System.DateTime.Now; rslt.Elapsed = sw.ElapsedMilliseconds; rslt.Task.Status = DACTaskStatus.DONE; context.DtuConnection.Disconnect(); return(rslt); }
// TODO internal static void SaveTask(DACTask task) { _dacTaskPool.Enqueue(task); }
internal void NewTask(DACTask t) { this.taskPool.Enqueue(t); }
// TODO 插队任务。 public bool TryJoinTask(DACTask newTask) { return(false); }
/// <summary> /// 处理 即时采集任务 /// </summary> /// <param name="tid"></param> /// <param name="dtuId">要采集的DTU</param> /// <param name="sensors">要采集的传感器,为空或Count=0时,指全部传感器。</param> /// <param name="consumer"></param> /// <param name="reactive">从数据库重新激活任务,默认=false</param> /// <returns> -1 </returns> public int ArrangeInstantTask(string tid, uint dtuId, IList <uint> sensors, TaskResultConsumer consumer, bool activeFromDB = false) { DtuNode dtu = null; DACTask task = this.CreateInstantDACTask(tid, dtuId, sensors, consumer, activeFromDB); if (task == null) { return(-1); //无法创建任务. } dtu = _dtus[dtuId]; bool ScheduleStarted = true; if (_schedule == null) { this.CreateSchedule(_dtus.Count); ScheduleStarted = false; } // Arrange an instant task to schedule string jobKey = GetJobKey(dtuId); JobKey jk = new JobKey(jobKey, JobGroup); if (_schedule.GetJobDetail(jk) != null) { Log.DebugFormat("Task already exist? {0}", jk); return(-1); } IJobDetail job = JobBuilder.Create <DTUDacJob>() .WithIdentity(jobKey, JobGroup) .Build(); AssignJobInfo(this, TaskType.INSTANT, job, tid, dtu, sensors, consumer, task.ID); ISimpleTrigger trigger = (ISimpleTrigger)TriggerBuilder.Create() .WithIdentity(string.Format("{0}{1}", InstantTrigger, dtu.DtuId), JobGroup) .WithSimpleSchedule(x => x .WithIntervalInSeconds(5000) .WithRepeatCount(1)) .StartNow() //.StartAt(DateBuilder.NextGivenMinuteDate(null, 10)) .Build(); _schedule.ScheduleJob(job, trigger); Console.WriteLine("Add job {1} {0}", DateTime.Now, job.Key.Name); if (!ScheduleStarted) { _schedule.Start(); } Log.DebugFormat("Instance DAC Job created: {0}, task.ID={1}", jobKey, task.ID); //try //{ // _schedule.TriggerJob(jk); //} //catch (Exception ex) //{ // OnInstantTaskFinished(new FailedDACTaskResult(Errors.ERR_NOT_CONNECTED) // { // Task = task, // Finished = DateTime.Now // }); // Log.Error(ex.Message); //} return(task.ID); }