/// <summary> /// logs the messages reported by the devices /// </summary> /// <param name="progressString"></param> private void LogProgress(DeviceProgress progressReport) { if (progressReport.PType == ProgressType.TRACE) { // Console.WriteLine(progressReport.PMessage); _logger.LogDebug(progressReport.PMessage); } else if (progressReport.PType == ProgressType.INFO) { _logger.LogInformation(progressReport.PMessage); } else if (progressReport.PType == ProgressType.ALERT) { _logger.LogError(progressReport.PMessage); } }
/// <summary> /// 更新任务资源表。 更新设备明细到数据库 /// </summary> /// <param name="hwtask">模板部署任务</param> /// <param name="deployProgress">部署任务明细</param> /// <returns>完成的设备数量</returns> private int UpdateHWTaskResourceList(HWESightTask hwtask, DeployProgress deployProgress) { bool isFinsihed = false; int finishedCnt = 0; IList <HWTaskResource> resourceList = HWTaskResourceDal.Instance.FindTaskResourceByTaskId(hwtask.ID); Dictionary <string, DeviceProgress> dviDict = new Dictionary <string, DeviceProgress>(); if (deployProgress.DeviceDetails == null) { return(0); } DeviceProgress emptyDevicProcess = null; foreach (DeviceProgress deviceProgress in deployProgress.DeviceDetails) { if (string.IsNullOrEmpty(deviceProgress.DeviceDn))//如果dn为空,设备关闭或者删除的时候。 { emptyDevicProcess = deviceProgress; } else { dviDict[deviceProgress.DeviceDn.ToUpper()] = deviceProgress; } } foreach (HWTaskResource hwResource in resourceList) { DeviceProgress deviceProgress = null; if (dviDict.ContainsKey(hwResource.DN.ToUpper())) { deviceProgress = dviDict[hwResource.DN.ToUpper()]; hwResource.DeviceResult = deviceProgress.DeviceResult; hwResource.DeviceProgress = deviceProgress.Progress; hwResource.ErrorCode = deviceProgress.ErrorCode; hwResource.ErrorDetail = deviceProgress.ErrorDetail; hwResource.TaskType = ConstMgr.HWESightTask.TASK_TYPE_DEPLOY; hwResource.SyncStatus = hwtask.SyncStatus; hwResource.LastModifyTime = System.DateTime.Now; if (deviceProgress.Progress == 100) { finishedCnt++; } } else { if (emptyDevicProcess != null) { LogUtil.HWLogger.API.WarnFormat("System can't find this dn=[{0}], using the none dn message.", hwResource.DN); hwResource.DeviceResult = emptyDevicProcess.DeviceResult; hwResource.DeviceProgress = emptyDevicProcess.Progress; hwResource.ErrorCode = emptyDevicProcess.ErrorCode; hwResource.ErrorDetail = emptyDevicProcess.ErrorDetail; hwResource.TaskType = ConstMgr.HWESightTask.TASK_TYPE_DEPLOY; hwResource.SyncStatus = hwtask.SyncStatus; hwResource.LastModifyTime = System.DateTime.Now; if (emptyDevicProcess.Progress == 100) { finishedCnt++; } } else { LogUtil.HWLogger.API.WarnFormat("System can't find this dn=[{0}]", hwResource.DN); } } HWTaskResourceDal.Instance.UpdateEntity(hwResource); } if (resourceList.Count > 0) { return((finishedCnt * 100) / resourceList.Count); } else { return(0); } }