/// <summary> /// 更新选区 /// </summary> /// <param name="data">选区信息</param> /// <returns>是否成功</returns> public ARESULT UpdateSelection(string data) { SelectionUpdateParam update = JsonUtils.ObjectFromJson <SelectionUpdateParam>(data); if (update == null) { return(ARESULT.E_FAIL); } try { // 取出普通选区 Selection selection = GetSelection(update.mId); if (selection == null) { return(ARESULT.E_FAIL); } lock (selection) { // 判断选区是否改变 if (selection.Serialize().Equals(update.mData)) { return(ARESULT.S_OK); } // 清除选区告警 ClearSelectionAlarm(selection); // 反序列化 if (ARESULT.ASUCCEEDED(selection.Deserialize(update.mData))) { if (selection.mSelectionId != update.mId) { return(ARESULT.E_NOIMPL); } } else { return(ARESULT.E_INVALIDARG); } } // 判断普通选区是否关联选区组 lock (mSelectionGroups) { mSelectionGroups.ForEach(group => { // 清除选区组告警 if (group.InSelections(selection.mSelectionId)) { ClearSelectionGroupAlarm(group); } }); } return(SelectionDAO.UpdateSelection(update.mId, update.mData)); } catch (Exception e) { Tracker.LogE(e); return(ARESULT.E_FAIL); } }
/// <summary> /// 更新选区告警配置 /// </summary> public ARESULT UpdateSelectionConfig(string data) { SelectionConfigUpdate config = JsonUtils.ObjectFromJson <SelectionConfigUpdate>(data); if (config == null) { return(ARESULT.E_FAIL); } SelectionAlarmConfig alramconfig = JsonUtils.ObjectFromJson <SelectionAlarmConfig>(config.mData); if (config == null) { return(ARESULT.E_FAIL); } Selection selection = null; lock (mSelections) { foreach (Selection item in mSelections) { if (item.mSelectionId == config.mId) { selection = item; break; } } } if (selection == null) { return(ARESULT.E_FAIL); } #region 更新告警设置 lock (selection) { selection.mSelectionName = config.mName; // 暂停温度处理线程 mProcessingWorker.Pause(); if (!selection.mAlarmConfig.mMaxTempConfig.Equals(alramconfig.mMaxTempConfig)) { if (selection.mAlarmInfo.mMaxTempAlarmInfo.mAlarmStatus == AlarmStatus.Alarming) { UpdateAlarmInfo( (int)AlarmMode.Selection, (int)SelectionAlarmType.MaxTemp, selection.mSelectionId, selection.Serialize(), selection.mAlarmInfo.mMaxTempAlarmInfo); } selection.mAlarmConfig.mMaxTempConfig = alramconfig.mMaxTempConfig; selection.mAlarmInfo.mMaxTempAlarmInfo.Reset(); } if (!selection.mAlarmConfig.mMinTempConfig.Equals(alramconfig.mMinTempConfig)) { if (selection.mAlarmInfo.mMinTempAlarmInfo.mAlarmStatus == AlarmStatus.Alarming) { UpdateAlarmInfo( (int)AlarmMode.Selection, (int)SelectionAlarmType.MinTemp, selection.mSelectionId, selection.Serialize(), selection.mAlarmInfo.mMinTempAlarmInfo); } selection.mAlarmConfig.mMinTempConfig = alramconfig.mMinTempConfig; selection.mAlarmInfo.mMinTempAlarmInfo.Reset(); } if (!selection.mAlarmConfig.mAvgTempConfig.Equals(alramconfig.mAvgTempConfig)) { if (selection.mAlarmInfo.mAvgTempAlarmInfo.mAlarmStatus == AlarmStatus.Alarming) { UpdateAlarmInfo( (int)AlarmMode.Selection, (int)SelectionAlarmType.AvgTemp, selection.mSelectionId, selection.Serialize(), selection.mAlarmInfo.mAvgTempAlarmInfo); } selection.mAlarmConfig.mAvgTempConfig = alramconfig.mAvgTempConfig; selection.mAlarmInfo.mAvgTempAlarmInfo.Reset(); } // 取消暂停 mProcessingWorker.Resume(); } #endregion return(SelectionDAO.UpdateSelection(selection.mSelectionId, selection.Serialize())); }