using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using System.IO; using System.Reflection; using System.Xml.Serialization; using ICSharpCode.Core; using Mesnac.Basic; using Mesnac.Codd.Session; namespace Mesnac.Action.ChemicalWeighing.Cache { /// /// 数据缓存辅助类 /// public class CacheHelper { #region 字段定义 private static List _alarmInfoList; //用于按数据块、起始字、长度进行读取 private static List _alarmBlockWordList; //数据块、地址字列表 private static List _pmtAlarmInfoList; //基础数据 #endregion #region 报警参数 #region 缓存报警参数信息 /// /// 缓存报警参数信息 /// /// 报警参数列表 public static void CacheAlarmInfo() { _alarmInfoList = Alarm.AlarmHelper.GetBlockStartLengthList(); _pmtAlarmInfoList = Alarm.AlarmHelper.GetPmtAlarmInfoList(); _alarmBlockWordList = new List(); foreach (Entity.PmtAlarmInfo entity in _pmtAlarmInfoList) { Entity.SimpleAlarmInfo newEntity = new Entity.SimpleAlarmInfo(); newEntity.AlramPLC = entity.AlarmPLC; newEntity.AlarmBlock = entity.AlarmBlock; newEntity.Alarm_Alias = entity.AlarmAlias; _alarmBlockWordList.Add(newEntity); } } #endregion #region 清空缓存的报警参数信息 /// /// 清空缓存的报警参数信息 /// public static void ClearAlarmInfo() { _alarmInfoList = null; _pmtAlarmInfoList = null; _alarmBlockWordList = null; } #endregion #region 从缓存获取所有报警参数扩展实体列表 /// /// 从缓存获取所有报警参数扩展实体列表 /// /// public static List AlarmInfoList { get { if (_alarmInfoList == null) { CacheAlarmInfo(); } return _alarmInfoList; } } #endregion #region 从缓存获取数据块和报警地址字列表 /// /// 从缓存获取数据块和报警地址字列表 /// /// public static List BlockWordList { get { if (_pmtAlarmInfoList == null) { CacheAlarmInfo(); } return _alarmBlockWordList; } } #endregion #region 从缓存获取报警参数实体信息 /// /// 从缓存获取报警参数实体信息 /// /// 报警参数PLC /// 报警参数数据块 /// 报警参数地址字 /// 报警参数数据位 /// 返回对应的报警参数实体对象 public static Entity.PmtAlarmInfo GetPmtAlarmInfoFromCache(string alarmPLC, string alarmBlock, string alarmAlias) { if (_pmtAlarmInfoList == null) { CacheAlarmInfo(); } foreach(Entity.PmtAlarmInfo entity in _pmtAlarmInfoList) { if (entity.AlarmPLC == alarmPLC && entity.AlarmBlock == alarmBlock && entity.AlarmAlias == alarmAlias) { return entity; } } return null; } #endregion #endregion } }