/// <summary> /// 缓冲区注册 /// </summary> /// <param name="key"></param> /// <param name="statment"></param> /// <param name="bufType"></param> /// <returns></returns> public bool RegBufferInf(string key, string statment, BufType bufType, Boolean isEncrypt, Dictionary <string, object> pars) { if (_bufInf == null) { _bufInf = CreateBufTabInf(); ////如果存在缓冲区配置文件,则直接进行读取 //if (File.Exists(_bufDir + BUF_CONFIG_FILE_NAME) == true) //{ // _bufInf.ReadXml(_bufDir + BUF_CONFIG_FILE_NAME); //} } //如果存在相同的值,则退出 if (HasReg(key)) { throw new UserException("该键值已经存在,不能重复注册。"); } DataRow drBufInf = _bufInf.NewRow(); string strPars = ""; if (pars != null) { strPars = SerialObjectToString(pars); } drBufInf[BUF_FIELD_KEY] = key; drBufInf[BUF_FIELD_STATEMENT] = statment; drBufInf[BUF_FIELD_PARS] = strPars; drBufInf[BUF_FIELD_TYPE] = (int)bufType; drBufInf[BUF_FIELD_VER] = BUF_DEFAULT_VER_TAG; string sec = ""; using (Encrypt crypt = new Encrypt(key + BUF_CFG_ENCRYPT_KEY)) { if (isEncrypt == true) { sec = crypt.EncryptStr(BUF_SECURITY_TAG); } else { sec = crypt.EncryptStr(BUF_NOSECURITY_TAG); } } drBufInf[BUF_FIELD_SEC] = sec; _bufInf.Rows.Add(drBufInf); return(true); }
/// <summary> /// 刷新缓冲区 /// </summary> /// <param name="key"></param> /// <param name="version"></param> /// <param name="onRefreshBuffer"></param> public void RefreshBuffer(string key, int version, RefreshBufferEvent onRefreshBuffer) { if (_bufInf == null) { return; } //取得对应的缓冲信息 DataRow drBuf = _bufInf.Select(BUF_FIELD_KEY + "='" + key + "'")[0]; BufType bufType = (BufType)Convert.ToInt16(drBuf[BUF_FIELD_TYPE]); string statment = Convert.ToString(drBuf[BUF_FIELD_STATEMENT]); string pars = Convert.ToString(drBuf[BUF_FIELD_PARS]); string sec = ""; //如果不缓冲,则退出 if (bufType == BufType.BufNone) { return; } //读取缓冲区的加密状态配置 using (Encrypt crypt = new Encrypt(key + BUF_CFG_ENCRYPT_KEY)) { sec = crypt.DecryptStr(Convert.ToString(drBuf[BUF_FIELD_SEC])); } bool cusRead = false; DataTable dtData = null; if (onRefreshBuffer != null) { dtData = onRefreshBuffer(key, statment, _db, cusRead); } if (cusRead == false) { //从数据库读取数据 dtData = ReadDataFromDB(statment, pars); } if (dtData == null) { return; } dtData.TableName = key; WriteTableToDiskBuf(key, dtData, ((sec == BUF_NOSECURITY_TAG) ? false : true)); if (bufType == BufType.BufToMem) { AddDataToMem(key, dtData); } //更新缓冲区版本信息 if (version != BUF_DEFAULT_VER_TAG) { //刷新数据后,回写缓冲区版本信息 drBuf[BUF_FIELD_VER] = version; } }
/// <summary> /// 从缓冲区查询数据 /// </summary> /// <param name="key"></param> /// <param name="bufVer"></param> /// <param name="hasCopy"></param> /// <param name="onRefreshBuffer"></param> /// <returns></returns> public DataTable QueryBuffer(string key, int bufVer, bool hasCopy, RefreshBufferEvent onRefreshBuffer) { if (_bufInf == null) { throw new UserException("缓冲区信息对象无效,对象不能为 null。"); } if (HasReg(key) == false) { throw new UserException("未注册的缓冲区数据查询。"); } //取得对应的缓冲信息 DataRow drBuf = _bufInf.Select(BUF_FIELD_KEY + "='" + key + "'")[0]; BufType bufType = (BufType)Convert.ToInt16(drBuf[BUF_FIELD_TYPE]); int version = (int)Convert.ToInt16(drBuf[BUF_FIELD_VER]); string statment = Convert.ToString(drBuf[BUF_FIELD_STATEMENT]); string pars = Convert.ToString(drBuf[BUF_FIELD_PARS]); string sec = ""; string bufFilePath = GetBufFilePath(key); //读取缓冲区的加密状态配置 using (Encrypt crypt = new Encrypt(key + BUF_CFG_ENCRYPT_KEY)) { sec = crypt.DecryptStr(Convert.ToString(drBuf[BUF_FIELD_SEC])); } if (bufType == BufType.BufToMem) { //从内存中读取数据 //如果本地内存中不存在,或者缓冲版本与当前程序版本不同,则重新刷新缓冲区数据 if ((_memBuf == null) || (_memBuf.Tables.Contains(key) == false)) { if (File.Exists(bufFilePath) == false || bufVer > version) { RefreshBuffer(key, bufVer, onRefreshBuffer); } else { //从本地读取缓冲数据 DataTable dtData = SecurityReadFileToDataBuf(key, sec, bufVer, onRefreshBuffer); if (dtData == null) { return(null); } AddDataToMem(key, dtData); } } //如果数据未缓冲到内存中,则返回null if ((_memBuf == null) || (_memBuf.Tables.Contains(key) == false)) { return(null); } //使用clone方式,返回新的datatable对象 if (hasCopy) { return(_memBuf.Tables[key].Copy()); } else { return(_memBuf.Tables[key]); } } else if (bufType == BufType.BufToDisk) { //从本地文件中读取数据 //如果本地文件不存在,或者缓冲版本与当前程序版本不同,则重新刷新缓冲区数据 if (File.Exists(bufFilePath) == false || bufVer > version) { RefreshBuffer(key, bufVer, onRefreshBuffer); } //从本地文件读取数据 return(SecurityReadFileToDataBuf(key, sec, bufVer, onRefreshBuffer)); } else { return(ReadDataFromDB(statment, pars)); } }
/// <summary> /// 缓冲区注册 /// </summary> /// <param name="key"></param> /// <param name="statment"></param> /// <param name="bufType"></param> /// <param name="isEncrypt"></param> /// <returns></returns> public bool RegBufferInf(string key, string statment, BufType bufType, Boolean isEncrypt) { return(RegBufferInf(key, statment, bufType, isEncrypt, null)); }
/// <summary> /// 注册缓冲区信息 /// </summary> /// <param name="key"></param> /// <param name="statment"></param> /// <param name="bufType"></param> /// <returns></returns> public bool RegBufferInf(string key, string statment, BufType bufType) { return(RegBufferInf(key, statment, bufType, false, null)); }
/// <summary> /// 缓冲区注册 /// </summary> /// <param name="key"></param> /// <param name="statment"></param> /// <param name="bufType"></param> /// <param name="pars"></param> /// <returns></returns> public bool RegBufferInf(string key, string statment, BufType bufType, Dictionary <string, object> pars) { return(RegBufferInf(key, statment, bufType, false, pars)); }
public static Color GetColor(BufType bt) { return(bufColors[(int)bt]); }
public static Color GetColor(BufType bt) { return bufColors[(int)bt]; }
public USOCounter(int PLCAddr) { _PLCAddr = PLCAddr; buffer = BufType.USO; }
public void SetState(BufType b) { this.buf = b; }
public void SetMemento(Memento m) { Buf = m.GetState(); }