//读取实时数据插值 public static List <PValue> ReadDataInterval(string tagname, DateTime startdate, DateTime enddate, int interval) { ErrorFlag = false; ErrorInfo = ""; List <PValue> results = new List <PValue>(); DBInterface.RTDBInterface.LongPI.RTDbHelper rtdbhelperpi = null; DBInterface.RTDBInterface.LongPGIM.RTDbHelper rtdbhelperpgim = null; DBInterface.RTDBInterface.LongXIANDB.RTDbHelper rtdbhelperxiandb = null; DBInterface.RTDBInterface.RTDbHelper rtdbhelper = null; //特别注意上面,如果在上面的位置不是给null,而是用new实例化。则某种数据库就会被两个对象初始化。 //这样会造成问题!!! //出现问题的现象是:比如PI数据库, //——1、运行rtdbhelperpi = new DBInterface.RTDBInterface.LongPI.RTDbHelper()时,不执行任何操作,但是RTDBInterface.LongPI.RTDbHelper第一次执行时,会创建一个静态的rtdbhelper //——2、运行rtdbhelper = new DBInterface.RTDBInterface.RTDbHelper()时,该构造函数,会创建非静态rtdbhelper,对静态rtdbhelper造成干扰。使的静态rtdbhelper中的pihelper指向发生变化。 try { //每次执行,都是在新的线程中,这个方式,PGIM会不会有问题,要测试 //关于异常处理方式的说明: //——总体原则1:不在底层helper层处理异常,将异常放到DAO层处理。 if (APPConfig.rtdb_Type == "PI") //PI数据库的情况下,使用PI长连接类 { rtdbhelperpi = new DBInterface.RTDBInterface.LongPI.RTDbHelper(); results = rtdbhelperpi.GetIntervalValuesFixInterval(tagname, startdate, enddate, interval); } else if (APPConfig.rtdb_Type == "PGIM") //PGIM数据库的情况下,使用PI长连接类 { rtdbhelperpgim = new DBInterface.RTDBInterface.LongPGIM.RTDbHelper(); results = rtdbhelperpgim.GetIntervalValuesFixInterval(tagname, startdate, enddate, interval); } else if (APPConfig.rtdb_Type == "XIANDB") { rtdbhelperxiandb = new DBInterface.RTDBInterface.LongXIANDB.RTDbHelper(); results = rtdbhelperxiandb.GetIntervalValuesFixInterval(tagname, startdate, enddate, interval); } else { rtdbhelper = new DBInterface.RTDBInterface.RTDbHelper(); results = rtdbhelper.GetIntervalValuesFixInterval(tagname, startdate, enddate, interval); } return(results); } catch (Exception ex) { //RTDBHelper在底层(pgimhelper、goldenhelper)对异常进行处理,将异常信息记录到rtdbhelper.Exception中,并将异常转发 //在这里,如果Exception不为null,则说明底层捕捉到了异常信息,应该将底层捕捉到的Exception计入log //如果Exception为null,则说明底层没有捕捉到异常信息。这里应该记录ex内容 ErrorFlag = true; if (APPConfig.rtdb_Type == "PI" && rtdbhelperpi.Exception != null) //PI数据库的情况下,使用PI长连接类 { ErrorInfo = rtdbhelperpi.Exception; } else if (APPConfig.rtdb_Type == "PGIM" && rtdbhelperpgim.Exception != null) //PGIM数据库的情况下,使用PI长连接类 { ErrorInfo = rtdbhelperpgim.Exception; } else if (APPConfig.rtdb_Type == "XIANDB" && rtdbhelperxiandb.Exception != null) { ErrorInfo = rtdbhelperxiandb.Exception; } else { ErrorInfo = ex.ToString(); } //log string messageStr; messageStr = String.Format("DAO层RTDBDAO.ReadData()错误:---------->") + Environment.NewLine; //logHelper.Error(messageStr); messageStr += String.Format("错误信息:{0}", ErrorInfo); logHelper.Error(messageStr); //实时数据库RTDB出现任何异常,返回null return(null); } }