Ejemplo n.º 1
0
        public static string testStatus  = "";      //实时数据库DAO层专用,用于多实时数据库实现
        #endregion
        //实时数据库连接测试
        public static bool connectTest()
        {
            ErrorFlag = false;
            ErrorInfo = "";
            try
            {
                rtdbConnStr = (APPConfig.rtdb_connString);


                if (APPConfig.rtdb_Type == "PI")                                                                                  //PI数据库的情况下,使用长连接类
                {
                    DBInterface.RTDBInterface.LongPI.RTDbHelper rtdbhelperpi = new DBInterface.RTDBInterface.LongPI.RTDbHelper(); //如果出现“类型初始值设定项引发异常”的错误,请检查RTDbType、RTDbConnection两个静态参数的设置是否正确。尤其是改为xml配置时,如果配置不正确,则或报出该错误。
                    testStatus = rtdbhelperpi.ConnTest();
                }
                else if (APPConfig.rtdb_Type == "PGIM") //PGIM数据库的情况下,使用长连接类
                {
                    DBInterface.RTDBInterface.LongPGIM.RTDbHelper rtdbhelperpgim = new DBInterface.RTDBInterface.LongPGIM.RTDbHelper();
                    testStatus = rtdbhelperpgim.ConnTest();
                }
                else if (APPConfig.rtdb_Type == "XIANDB") //XIANDB数据库的情况下,使用长连接类
                {
                    DBInterface.RTDBInterface.LongXIANDB.RTDbHelper rtdbhelperxiandb = new DBInterface.RTDBInterface.LongXIANDB.RTDbHelper();
                    testStatus = rtdbhelperxiandb.ConnTest();
                }
                else if (APPConfig.rtdb_Type == "TOM") //XIANDB数据库的情况下,使用长连接类
                {
                    DBInterface.RTDBInterface.LongTOM.RTDbHelper rtdbhelpertom = new DBInterface.RTDBInterface.LongTOM.RTDbHelper();
                    testStatus = rtdbhelpertom.ConnTest();
                }
                else
                {
                    DBInterface.RTDBInterface.RTDbHelper rtdbhelper = new DBInterface.RTDBInterface.RTDbHelper();
                    testStatus = rtdbhelper.ConnTest();
                }

                return(true);
            }
            catch (Exception ex)
            {
                ErrorInfo = ex.ToString();

                string messageStr;
                messageStr = String.Format("DAO层connectTest()错误:---------->") + Environment.NewLine;
                //logHelper.Error(messageStr);
                messageStr += String.Format("详细错误信息:" + ex.ToString());
                logHelper.Error(messageStr);
                return(false);
            }
        }
Ejemplo n.º 2
0
        public void rtdbTestTomGetData()
        {
            DateTime start = new DateTime(2015, 5, 1, 0, 0, 0);
            DateTime end   = new DateTime(2015, 5, 1, 0, 2, 0);

            //TOMHelper helper = new TOMHelper();
            // String info=helper.Logon();
            // bool status=helper.isLogOn;
            //Console.WriteLine("连接信息" + info + "----状态:" + status);
            DBInterface.RTDBInterface.LongTOM.RTDbHelper helper = new DBInterface.RTDBInterface.LongTOM.RTDbHelper();
            List <PValue> pvalues  = helper.GetRawValues("test.tag01", start, end);
            List <PValue> pvalues2 = helper.GetRawValues("test.tag02", start, end);
            List <PValue> pvalues3 = helper.GetRawValues("test.tag03", start, end);
            List <PValue> pvalues4 = helper.GetRawValues("test.tag04", start, end);
            List <PValue> pvalues5 = helper.GetRawValues("test.tag05", start, end);
            List <PValue> pvalues6 = helper.GetRawValues("test.tag06", start, end);

            foreach (PValue p in pvalues)
            {
                Console.WriteLine(p.Timestamp + " " + p.Value);
            }


            foreach (PValue p in pvalues2)
            {
                Console.WriteLine(p.Timestamp + " " + p.Value);
            }

            foreach (PValue p in pvalues3)
            {
                Console.WriteLine(p.Timestamp + " " + p.Value);
            }

            foreach (PValue p in pvalues4)
            {
                Console.WriteLine(p.Timestamp + " " + p.Value);
            }

            foreach (PValue p in pvalues5)
            {
                Console.WriteLine(p.Timestamp + " " + p.Value);
            }

            foreach (PValue p in pvalues6)
            {
                Console.WriteLine(p.Timestamp + " " + p.Value);
            }
        }
Ejemplo n.º 3
0
        //读取实时数据原始值
        public static List <PValue> ReadData(string tagname, DateTime startdate, DateTime enddate)
        {
            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.LongTOM.RTDbHelper    rtdbhelpertom    = null;
            DBInterface.RTDBInterface.RTDbHelper            rtdbhelper       = null;

            int errorcount = 0;     //错误统计计数

            //特别注意上面,如果在上面的位置不是给null,而是用new实例化。则某种数据库就会被两个对象初始化。
            //这样会造成问题!!!
            //出现问题的现象是:比如PI数据库,
            //——1、运行rtdbhelperpi = new DBInterface.RTDBInterface.LongPI.RTDbHelper()时,不执行任何操作,但是RTDBInterface.LongPI.RTDbHelper第一次执行时,会创建一个静态的rtdbhelper
            //——2、运行rtdbhelper = new DBInterface.RTDBInterface.RTDbHelper()时,该构造函数,会创建非静态rtdbhelper,对静态rtdbhelper造成干扰。使的静态rtdbhelper中的pihelper指向发生变化。
beginRead:
            try
            {
                //每次执行,都是在新的线程中,这个方式,PGIM会不会有问题,要测试
                //关于异常处理方式的说明:
                //——总体原则1:不在底层helper层处理异常,将异常放到DAO层处理。

                if (APPConfig.rtdb_Type == "PI")        //PI数据库的情况下,使用PI长连接类
                {
                    rtdbhelperpi = new DBInterface.RTDBInterface.LongPI.RTDbHelper();
                    results      = rtdbhelperpi.GetRawValues(tagname, startdate, enddate);
                }
                else if (APPConfig.rtdb_Type == "PGIM") //PGIM数据库的情况下,使用PI长连接类
                {
                    rtdbhelperpgim = new DBInterface.RTDBInterface.LongPGIM.RTDbHelper();
                    results        = rtdbhelperpgim.GetRawValues(tagname, startdate, enddate);
                }
                else if (APPConfig.rtdb_Type == "XIANDB")
                {
                    rtdbhelperxiandb = new DBInterface.RTDBInterface.LongXIANDB.RTDbHelper();
                    results          = rtdbhelperxiandb.GetRawValues(tagname, startdate, enddate);
                }
                else if (APPConfig.rtdb_Type == "TOM")
                {
                    rtdbhelpertom = new DBInterface.RTDBInterface.LongTOM.RTDbHelper();
                    results       = rtdbhelpertom.GetRawValues(tagname, startdate, enddate);
                }
                else
                {
                    rtdbhelper = new DBInterface.RTDBInterface.RTDbHelper();
                    results    = rtdbhelper.GetRawValues(tagname, startdate, enddate);
                }

                return(results);
            }
            catch (Exception ex)
            {
                errorcount = errorcount + 1;
                if (errorcount > APPConfig.rtdb_maxrepeatonerror)
                {
                    //RTDBHelper在底层(pgimhelper、goldenhelper)对异常进行处理,将异常信息记录到rtdbhelper.Exception中,并将异常转发
                    //在这里,如果Exception不为null,则说明底层捕捉到了异常信息,应该将底层捕捉到的Exception计入log
                    //如果Exception为null,则说明底层没有捕捉到异常信息。这里应该记录ex内容
                    errorcount = 0;
                    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}次,跳过此次实时数据读取。错误信息:{1}", APPConfig.rtdb_maxrepeatonerror, ErrorInfo);
                    logHelper.Error(messageStr);
                    //实时数据库RTDB出现任何异常,返回null
                    return(null);
                }
                else
                {
                    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()错误,正在尝试第{0}次重新读取。错误信息:{1}", errorcount, ErrorInfo);
                    logHelper.Info(messageStr); //注意,未超过最大读取次数时,先记录info。超过后,才记录error
                    //等待设定的毫秒数
                    Thread.Sleep(APPConfig.rtdb_waitsecondonerror * 1000);
                    //重新读取
                    goto beginRead;
                }
            }
        }