Esempio n. 1
0
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="serverPKID">ID</param>
        /// <param name="address">地址:格式 IP地址;登录名;密码;数据库;数据库类型</param>
        /// <param name="updateRate"></param>
        /// <param name="deviceTagParams"></param>
        /// <param name="callback"></param>
        private void Initial(Int64 serverPKID, string address, int updateRate,
                             List <DeviceTagParam> deviceTagParams, DataChangeEventHandler callback)
        {
            pkid = serverPKID;
            string[] connStrings = address.Split('|');  //分隔符

            #region 初始化参数

            DbType           = EmDbType.SqlServer;
            ConnectionString = address;

            #region 数据库类型及连接语句

            if (connStrings.Count() >= 2)
            {
                ConnectionString = connStrings[1];

                string sdbtype = connStrings[0].ToLower();
                if (sdbtype == "access")
                {
                    DbType = EmDbType.Access;
                }
                if (sdbtype == "oracle")
                {
                    DbType = EmDbType.Oracle;
                }
                if (sdbtype == "mysql")
                {
                    DbType = EmDbType.MySql;
                }
            }

            if (connStrings.Count() >= 5) //分开的数据库连接数据
            {
                if (!string.IsNullOrEmpty(connStrings[2]) && !string.IsNullOrEmpty(connStrings[3]) &&
                    !string.IsNullOrEmpty(connStrings[4]))
                {
                    ConnectionString = DBFactory.BuildConnStr(DbType, connStrings[1], connStrings[2], connStrings[3],
                                                              connStrings[4]);
                }
            }

            #endregion

            MainConn = DBFactory.NewConnection(DbType, ConnectionString); //连接语句

            Callback = callback;                                          //设置回调函数

            DeviceTags = deviceTagParams;                                 //标签

            #endregion

            CustomProtocol   = (connStrings.Length >= 6) ? connStrings[5] : ""; //自定义协议
            ProtocolVariable = (connStrings.Length >= 7) ? connStrings[6] : ""; //自定义协议参数
        }