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); }
internal static void SaveTaskResult(DACTaskResult result) { _dacTaskResultPool.Enqueue(result); }