Exemple #1
0
        /// <summary>
        /// 根据配置文件判断数据库类型
        /// </summary>
        /// <returns>0--oracle,1--sqlserver</returns>
        private int GetDatabaseType()
        {
            int nRet = -1;

            try
            {
                string configStr = INIOperator.INIGetStringValue(BaseDefine.CONFIG_FILE_PATH_ENV, BaseDefine.CONFIG_SECTION_CONFIG,
                                                                 BaseDefine.CONFIG_KEY_SQLORACLE, string.Empty);
                if (!string.IsNullOrEmpty(configStr))
                {
                    nRet = int.Parse(configStr);
                }
            }
            catch (Exception e)
            {
                Log.GetLogger().ErrorFormat("catch an error : {0}", e.Message);
            }

            return(nRet);
        }
Exemple #2
0
        private bool InitDevices()
        {
            dicCars.Clear();

            //获取 SDK Build
            if (!GetSDKBuildVersion())
            {
                return(false);
            }

            //窗口初始化(看不懂是什么作用,这里先翻译C++代码)
            int    kch   = 0;
            int    count = 4;
            string key   = string.Empty;

            m_dispalyShow[4] = BaseMethod.INIGetIntValue(BaseDefine.CONFIG_FILE_PATH_DISPLAY, BaseDefine.CONFIG_SECTION_CONFIG,
                                                         BaseDefine.CONFIG_KEY_VIDEOWND, 1);
            for (int i = 0; i < count; i++)
            {
                key = string.Format("{0}{1}", BaseDefine.CONFIG_KEY_DISPLAY, i + 1);
                m_dispalyShow[i] = BaseMethod.INIGetIntValue(BaseDefine.CONFIG_FILE_PATH_DISPLAY, BaseDefine.CONFIG_SECTION_CONFIG,
                                                             key, i);
                kch += m_dispalyShow[i];
            }
            if (kch != 6)
            {
                for (int i = 0; i < count; i++)
                {
                    key = string.Format("{0}{1}", BaseDefine.CONFIG_KEY_DISPLAY, i + 1);
                    string value = i.ToString();
                    INIOperator.INIWriteValue(BaseDefine.CONFIG_FILE_PATH_DISPLAY, BaseDefine.CONFIG_SECTION_CONFIG, key, value);
                    m_dispalyShow[i] = i;
                }
            }
            Log.GetLogger().InfoFormat("子窗口配置[%d,%d,%d,%d],音频窗口[%d]", m_dispalyShow[0], m_dispalyShow[1],
                                       m_dispalyShow[2], m_dispalyShow[3], m_dispalyShow[4]);

            //合码器初始化
            int nNum = BaseMethod.INIGetIntValue(BaseDefine.CONFIG_FILE_PATH_CAR, BaseDefine.CONFIG_SECTION_JMQ,
                                                 BaseDefine.CONFIG_KEY_NUM, 0);   //合码器数量
            int nEven = BaseMethod.INIGetIntValue(BaseDefine.CONFIG_FILE_PATH_DISPLAY, BaseDefine.CONFIG_SECTION_CONFIG,
                                                  BaseDefine.CONFIG_KEY_EVEN, 0); //是否隔行合码
            int nKskm = BaseMethod.INIGetIntValue(BaseDefine.CONFIG_FILE_PATH_ENV, BaseDefine.CONFIG_SECTION_CONFIG,
                                                  BaseDefine.CONFIG_KEY_KSKM, 0); //考试科目
            int nWnd2 = BaseMethod.INIGetIntValue(BaseDefine.CONFIG_FILE_PATH_DISPLAY, BaseDefine.CONFIG_SECTION_CONFIG,
                                                  BaseDefine.CONFIG_KEY_WND2, 1); //画面二状态
            int nHMQ = BaseMethod.INIGetIntValue(BaseDefine.CONFIG_FILE_PATH_ENV, BaseDefine.CONFIG_SECTION_CONFIG,
                                                 BaseDefine.CONFIG_KEY_HMQ, 0);   //配置的是合码器还是解码器

            if (0 == nNum)
            {
                Log.GetLogger().ErrorFormat("合码器数量为0,请检查配置文件");
                return(false);
            }
            Log.GetLogger().InfoFormat("读取到 {0} 台合码器,EVEN = {1}, 科目{2},画面2={3}", nNum, nEven, nKskm, nWnd2);

            string errorMsg = string.Empty;

            for (int i = 1; i <= nNum; i++)
            {
                string strConf = INIOperator.INIGetStringValue(BaseDefine.CONFIG_FILE_PATH_CAR, BaseDefine.CONFIG_SECTION_JMQ,
                                                               i.ToString(), string.Empty);
                string[] confArray = BaseMethod.SplitString(strConf, BaseDefine.SPLIT_CHAR_COMMA, out errorMsg);
                if (!string.IsNullOrEmpty(errorMsg) || confArray.Length != 4)
                {
                    Log.GetLogger().ErrorFormat("合码器配置错误,请检查配置文件。section = {0}, key = {1}", BaseDefine.CONFIG_SECTION_JMQ, i.ToString());
                    return(false);
                }

                string ipAddress = confArray[0]; //合码器地址
                string user      = confArray[1]; //用户名
                string password  = confArray[2]; //密码
                string port      = confArray[3]; //端口
                if (string.IsNullOrEmpty(ipAddress) || string.IsNullOrEmpty(user) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(port))
                {
                    Log.GetLogger().ErrorFormat("合码器配置错误,请检查配置文件。section = {0}, key = {1}", BaseDefine.CONFIG_SECTION_JMQ, i.ToString());
                    return(false);
                }
                Log.GetLogger().InfoFormat("准备对合码器 {0} 进行初始化,ip={1}, port={2}, user={3}, password={4}", i, ipAddress, port, user, password);

                //登录设备
                if (!InitHMQ(ipAddress, user, password, port))
                {
                    return(false);
                }

                int    displayChanCount = (1 == nHMQ) ? m_struDecAbility.struDviInfo.byChanNums : m_struDecAbility.struBncInfo.byChanNums;
                string sectionJMQ       = string.Format("JMQ{0}", i);
                for (int j = 0; j < displayChanCount; j++)   //DVI、BNC 个数循环
                {
                    if ((1 == nEven) && (j % 2 == 1))
                    {
                        continue;
                    }

                    string keyBNC = string.Format("BNC{0}", j + 1); //从 1 开始
                    int    nKch   = BaseMethod.INIGetIntValue(BaseDefine.CONFIG_FILE_PATH_CAR, sectionJMQ, keyBNC, -1);
                    if (-1 == nKch)                                 //没有配置
                    {
                        Log.GetLogger().InfoFormat("合码器 JMQ{0} 的 BNC 通道 {1} 处于空闲,可以配置。", i, keyBNC);
                        continue;
                    }

                    //检查通道配置及初始化
                    if (1 == nHMQ)
                    {
                        if (!CheckDVIChan(nKch, j)) //合码器
                        {
                            Log.GetLogger().ErrorFormat("通道检测及初始化错误,考车号={0},DVI={1}", nKch, j);
                        }
                    }
                    else
                    {
                        if (!CheckBNCChan(nKch, j)) //解码器
                        {
                            Log.GetLogger().ErrorFormat("通道检测及初始化错误,考车号={0},BNC={1}", nKch, j);
                        }
                    }
                }
            }

            return(true);
        }
Exemple #3
0
        /// <summary>
        /// 读取配置文件里的数据库连接字符串
        /// 配置文件config.ini里的数据库连接字符串加过盐,这里解析时需要将每个字符“-1”后,再进行翻转
        /// </summary>
        /// <returns></returns>
        private string GetConnectionString()
        {
            string retConnectionStr = string.Empty;

            //try
            //{
            //    string configStr = INIOperator.INIGetStringValue(BaseDefine.CONFIG_FILE_PATH_CONFIG, BaseDefine.CONFIG_SECTION_SQLLINK,
            //        BaseDefine.CONFIG_KEY_ServerPZ, string.Empty);
            //    if (!string.IsNullOrEmpty(configStr))
            //    {
            //        foreach (char c in configStr.ToCharArray())
            //        {
            //            int nC = (int)c;
            //            retConnectionStr = (char)(nC - 1) + retConnectionStr;
            //        }
            //    }
            //}
            //catch(Exception e)
            //{
            //    Log.GetLogger().ErrorFormat("catch an error : {0}", e.Message);
            //}
            //Log.GetLogger().InfoFormat("connection string after decode : {0}", retConnectionStr);
            ////配置文件里的数据库连接字符串包含"Provider=SQLOLEDB;",这在C#代码中不适用,这里去除该字段
            //if (0 == retConnectionStr.IndexOf("Provider=SQLOLEDB;"))
            //{
            //    retConnectionStr = retConnectionStr.Substring(18);
            //}
            //Log.GetLogger().InfoFormat("connection string after delete : {0}", retConnectionStr);

            try
            {
                string encodeAddress = INIOperator.INIGetStringValue(BaseDefine.CONFIG_FILE_PATH_DB,
                                                                     BaseDefine.CONFIG_SECTION_CONFIG, BaseDefine.CONFIG_KEY_DBADDRESS, "");
                string encodeUsername = INIOperator.INIGetStringValue(BaseDefine.CONFIG_FILE_PATH_DB,
                                                                      BaseDefine.CONFIG_SECTION_CONFIG, BaseDefine.CONFIG_KEY_USERNAME, "");
                string encodePassword = INIOperator.INIGetStringValue(BaseDefine.CONFIG_FILE_PATH_DB,
                                                                      BaseDefine.CONFIG_SECTION_CONFIG, BaseDefine.CONFIG_KEY_PASSWORD, "");
                string encodeInstance = INIOperator.INIGetStringValue(BaseDefine.CONFIG_FILE_PATH_DB,
                                                                      BaseDefine.CONFIG_SECTION_CONFIG, BaseDefine.CONFIG_KEY_INSTANCE, "");
                if (string.IsNullOrEmpty(encodeAddress) || string.IsNullOrEmpty(encodeUsername) || string.IsNullOrEmpty(encodePassword) ||
                    string.IsNullOrEmpty(encodeInstance))
                {
                    Log.GetLogger().ErrorFormat("数据库配置存在异常");
                    return(retConnectionStr);
                }

                string dbAddress  = BekUtils.Util.Base64Util.Base64Decode(encodeAddress);
                string dbUsername = BekUtils.Util.Base64Util.Base64Decode(encodeUsername);
                string dbPassword = BekUtils.Util.Base64Util.Base64Decode(encodePassword);
                string dbInstance = BekUtils.Util.Base64Util.Base64Decode(encodeInstance);
                if (string.IsNullOrEmpty(dbAddress) || string.IsNullOrEmpty(dbUsername) || string.IsNullOrEmpty(dbPassword) ||
                    string.IsNullOrEmpty(dbInstance))
                {
                    Log.GetLogger().ErrorFormat("数据库配置存在异常");
                    return(retConnectionStr);
                }

                int dbType = BaseMethod.INIGetIntValue(BaseDefine.CONFIG_FILE_PATH_ENV, BaseDefine.CONFIG_SECTION_CONFIG,
                                                       BaseDefine.CONFIG_KEY_SQLORACLE, 0);
                if (1 == dbType)
                {
                    //SQL
                    retConnectionStr = string.Format(BaseDefine.DB_CONN_FORMAT_SQL, dbAddress, dbInstance, dbUsername, dbPassword);
                }
                else
                {
                    //ORACLE
                    retConnectionStr = string.Format(BaseDefine.DB_CONN_FORMAT_ORACLE, dbUsername, dbPassword, dbAddress, dbInstance);
                }
            }
            catch (Exception e)
            {
                Log.GetLogger().ErrorFormat("catch an error : {0}", e.Message);
            }

            return(retConnectionStr);
        }