private void Client_OPCClientDataChangeEvent(object source, OPCClientDataChangeEventArgs e) { if (GlobalConfig.Global.PersistenceType == PersistenceType.Xml) { OnServiceLog("OPC读取数据不支持XML方式持久化"); return; } if (_config == null) { OnServiceLog("配置信息为空"); return; } List <ITag> tags = ConvertTagData(e); //CrossServerCache.TagCache.AddOrUpdateRange(tags); if (_config.OPCClientPersistence) { PersistenceType pt = GlobalConfig.Global.PersistenceType; if (pt == PersistenceType.CoreRT //|| pt == PersistenceType.Golden || pt == PersistenceType.eDNA) { #region 写入实时数据库 IDbContext rdb = null; try { rdb = DbContextPool.Pop(); if (rdb != null) { string tableName = "SSIOOpc"; rdb.WriteTags(tableName, e.TimeStamps, e.ItemNames, e.ItemValues); } } catch (Exception ex) { OnServiceLog(ex.Message); } finally { if (rdb != null) { DbContextPool.Push(rdb); } } OnServiceLog("OPC Client>>写入实时数据库操作完成。共:" + e.NumItems.ToString() + " 数据点。"); #endregion } else if (pt == PersistenceType.MySql || pt == PersistenceType.Oracle || pt == PersistenceType.SqlServer || pt == PersistenceType.Sqlite) { #region 写到关系数据库 if (_persistence == null) { _persistence = DataPersistenceFactory.CreateDataPersistence(pt); } ((BaseSqlPersistence)_persistence).PersistenceData("", tags); OnServiceLog("OPC Client>>写入关系数据库操作完成。共:" + e.NumItems.ToString() + " 数据点。"); #endregion } } else { string context = "OPC Client>>"; for (int i = 0; i < e.NumItems; i++) { context += String.Format("序号:{0},时间:{1},标签:{2},值:{3};", i.ToString(), e.TimeStamps[i].ToString("yyyy-MM-dd HH:mm:ss"), e.ItemNames[i], e.ItemValues[i].ToString()); } OnServiceLog(context); } }