You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lj_plc/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/Cache/CacheHelper.cs

152 lines
4.7 KiB
C#

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
{
/// <summary>
/// 数据缓存辅助类
/// </summary>
public class CacheHelper
{
#region 字段定义
private static List<Entity.AlarmInfo> _alarmInfoList; //用于按数据块、起始字、长度进行读取
private static List<Entity.SimpleAlarmInfo> _alarmBlockWordList; //数据块、地址字列表
private static List<Entity.PmtAlarmInfo> _pmtAlarmInfoList; //基础数据
#endregion
#region 报警参数
#region 缓存报警参数信息
/// <summary>
/// 缓存报警参数信息
/// </summary>
/// <param name="alarmInfoList">报警参数列表</param>
public static void CacheAlarmInfo()
{
_alarmInfoList = Alarm.AlarmHelper.GetBlockStartLengthList();
_pmtAlarmInfoList = Alarm.AlarmHelper.GetPmtAlarmInfoList();
_alarmBlockWordList = new List<Entity.SimpleAlarmInfo>();
foreach (Entity.PmtAlarmInfo entity in _pmtAlarmInfoList)
{
bool flag = false;
foreach (Entity.SimpleAlarmInfo info in _alarmBlockWordList)
{
if (entity.AlarmPLC == info.AlramPLC && entity.AlarmBlock == info.AlarmBlock && entity.AlarmAddress == info.AlarmAddress)
{
flag = true;
break;
}
}
if (!flag)
{
Entity.SimpleAlarmInfo newEntity = new Entity.SimpleAlarmInfo();
newEntity.AlramPLC = entity.AlarmPLC;
newEntity.AlarmBlock = entity.AlarmBlock;
newEntity.AlarmAddress = entity.AlarmAddress;
newEntity.AlarmBit = entity.AlarmBit.ToString();
_alarmBlockWordList.Add(newEntity);
}
}
}
#endregion
#region 清空缓存的报警参数信息
/// <summary>
/// 清空缓存的报警参数信息
/// </summary>
public static void ClearAlarmInfo()
{
_alarmInfoList = null;
_pmtAlarmInfoList = null;
_alarmBlockWordList = null;
}
#endregion
#region 从缓存获取所有报警参数扩展实体列表
/// <summary>
/// 从缓存获取所有报警参数扩展实体列表
/// </summary>
/// <returns></returns>
public static List<Entity.AlarmInfo> AlarmInfoList
{
get
{
if (_alarmInfoList == null)
{
CacheAlarmInfo();
}
return _alarmInfoList;
}
}
#endregion
#region 从缓存获取数据块和报警地址字列表
/// <summary>
/// 从缓存获取数据块和报警地址字列表
/// </summary>
/// <returns></returns>
public static List<Entity.SimpleAlarmInfo> BlockWordList
{
get
{
if (_pmtAlarmInfoList == null)
{
CacheAlarmInfo();
}
return _alarmBlockWordList;
}
}
#endregion
#region 从缓存获取报警参数实体信息
/// <summary>
/// 从缓存获取报警参数实体信息
/// </summary>
/// <param name="alarmPLC">报警参数PLC</param>
/// <param name="alarmBlock">报警参数数据块</param>
/// <param name="alarmAddress">报警参数地址字</param>
/// <param name="alarmBit">报警参数数据位</param>
/// <returns>返回对应的报警参数实体对象</returns>
public static Entity.PmtAlarmInfo GetPmtAlarmInfoFromCache(string alarmPLC, string alarmBlock, int alarmAddress, int alarmBit)
{
if (_pmtAlarmInfoList == null)
{
CacheAlarmInfo();
}
foreach(Entity.PmtAlarmInfo entity in _pmtAlarmInfoList)
{
if (entity.AlarmPLC == alarmPLC && entity.AlarmBlock == alarmBlock && entity.AlarmAddress == alarmAddress && entity.AlarmBit == alarmBit)
{
return entity;
}
}
return null;
}
#endregion
#endregion
}
}