/// <summary> /// 更新组选区 /// </summary> public ARESULT UpdateGroupSelectionConfig(string data) { GroupSelectionUpdateParam gupdate = JsonUtils.ObjectFromJson <GroupSelectionUpdateParam>(data); if (gupdate == null) { return(ARESULT.E_FAIL); } GroupAlarmConfig alramconfig = JsonUtils.ObjectFromJson <GroupAlarmConfig>(gupdate.mData); if (alramconfig == null) { return(ARESULT.E_FAIL); } SelectionGroup selectionGroup = null; lock (mSelectionGroups) { foreach (SelectionGroup item in mSelectionGroups) { if (item.mId == gupdate.mId) { selectionGroup = item; break; } } } if (selectionGroup == null) { return(ARESULT.E_FAIL); } #region 更新告警设置 lock (selectionGroup) { // 暂停温度处理线程 mProcessingWorker.Pause(); if (!selectionGroup.mAlarmConfig.mMaxTempConfig.Equals(alramconfig.mMaxTempConfig)) { // 正在告警时, 结束当前告警 if (selectionGroup.mAlarmInfo.mMaxTempAlarm.mAlarmStatus == AlarmStatus.Alarming) { UpdateAlarmInfo( (int)AlarmMode.GroupSelection, (int)GroupAlarmType.MaxTemperature, selectionGroup.mId, selectionGroup.Serialize(), selectionGroup.mAlarmInfo.mMaxTempAlarm); } selectionGroup.mAlarmConfig.mMaxTempConfig = alramconfig.mMaxTempConfig; selectionGroup.mAlarmInfo.mMaxTempAlarm.Reset(); } if (!selectionGroup.mAlarmConfig.mMaxTempeRiseConfig.Equals(alramconfig.mMaxTempeRiseConfig)) { if (selectionGroup.mAlarmInfo.mMaxTempRiseAlarmInfo.mAlarmStatus == AlarmStatus.Alarming) { UpdateAlarmInfo( (int)AlarmMode.GroupSelection, (int)GroupAlarmType.MaxTempRise, selectionGroup.mId, selectionGroup.Serialize(), selectionGroup.mAlarmInfo.mMaxTempRiseAlarmInfo); } selectionGroup.mAlarmConfig.mMaxTempeRiseConfig = alramconfig.mMaxTempeRiseConfig; selectionGroup.mAlarmInfo.mMaxTempRiseAlarmInfo.Reset(); } if (!selectionGroup.mAlarmConfig.mMaxTempDifConfig.Equals(alramconfig.mMaxTempDifConfig)) { if (selectionGroup.mAlarmInfo.mMaxTempDifAlarmInfo.mAlarmStatus == AlarmStatus.Alarming) { UpdateAlarmInfo( (int)AlarmMode.GroupSelection, (int)GroupAlarmType.MaxTempDif, selectionGroup.mId, selectionGroup.Serialize(), selectionGroup.mAlarmInfo.mMaxTempDifAlarmInfo); } selectionGroup.mAlarmConfig.mMaxTempDifConfig = alramconfig.mMaxTempDifConfig; selectionGroup.mAlarmInfo.mMaxTempDifAlarmInfo.Reset(); } if (!selectionGroup.mAlarmConfig.mRelativeTempDifConfig.Equals(alramconfig.mRelativeTempDifConfig)) { if (selectionGroup.mAlarmInfo.mRelativeTempDifAlarmInfo.mAlarmStatus == AlarmStatus.Alarming) { UpdateAlarmInfo( (int)AlarmMode.GroupSelection, (int)GroupAlarmType.RelativeTempDif, selectionGroup.mId, selectionGroup.Serialize(), selectionGroup.mAlarmInfo.mRelativeTempDifAlarmInfo); } selectionGroup.mAlarmConfig.mRelativeTempDifConfig = alramconfig.mRelativeTempDifConfig; selectionGroup.mAlarmInfo.mRelativeTempDifAlarmInfo.Reset(); } // 取消暂停 mProcessingWorker.Resume(); } #endregion return(GroupSelectionDAO.UpdateGroupSelection(selectionGroup.mId, selectionGroup.Serialize())); }
/// <summary> /// 删除选区 /// </summary> /// <param name="id">选区索引</param> /// <returns>是否成功</returns> public ARESULT RemoveSelection(long id) { try { if (ARESULT.AFAILED(SelectionDAO.RemoveSelection(id))) { return(ARESULT.E_FAIL); } bool continueFlag = false; lock (mSelectionGroups) { foreach (SelectionGroup groupSelection in mSelectionGroups) { lock (groupSelection) { for (int i = 0; i < groupSelection.mSelectionIds.Count; i++) { if (groupSelection.mSelectionIds[i] == id) { ClearSelectionGroupAlarm(groupSelection); if (groupSelection.mSelectionIds.Count == 1) { GroupSelectionDAO.RemoveGroupSelection(groupSelection.mId); mSelectionGroups.Remove(groupSelection); } else { for (int k = i; k < groupSelection.mSelectionIds.Count - 1; k++) { groupSelection.mSelectionIds[k] = groupSelection.mSelectionIds[k + 1]; } string data = groupSelection.Serialize(); if (data != null) { GroupSelectionDAO.UpdateGroupSelection(groupSelection.mId, data); } } continueFlag = true; break; } } } if (continueFlag) { break; } } } lock (mSelections) { foreach (Selection selection in mSelections) { lock (selection) { if (selection.mSelectionId == id) { ClearSelectionAlarm(selection); mSelections.Remove(selection); return(ARESULT.S_OK); } } } } return(ARESULT.E_FAIL); } catch (Exception e) { Tracker.LogE(e); return(ARESULT.E_FAIL); } }