Esempio n. 1
0
        internal static Dictionary <string, string> GetCacheDictinary()
        {
            m_dicCache = new Dictionary <string, string>();
            IDbHelper dbHelper = GlobalHelp.GetDataAccessHelper();
            string    strSql   = "Select Distinct TableName from CacheConfig ";

            dbHelper.CreateCommand(strSql);
            DataTable dt = dbHelper.ExecuteQuery();

            if (dt.Rows.Count > 0)
            {
                string strCacheTableName = dt.Rows[0][0].ToString();
                m_dicCache.Add(strCacheTableName, strCacheTableName);
            }
            return(m_dicCache);
        }
Esempio n. 2
0
        /// <summary>判断是否开启缓存
        ///
        /// </summary>
        /// <returns></returns>
        private static int GetAllowCache()
        {
            IDbHelper helper = GlobalHelp.GetDataAccessHelper();

            helper.CreateCommand("Select SetText From CacheSetting Where SetKey='AllowCache'");
            string strResult = helper.ExecuteScalar();

            if (strResult != string.Empty)
            {
                bool blnReturn;
                if (bool.TryParse(strResult, out blnReturn))
                {
                    return(blnReturn?1:0);
                }
                return(0);
            }
            return(0);
        }
Esempio n. 3
0
        /// <summary>同步缓存
        ///
        /// </summary>
        public static void SynCache()
        {
            IDbHelper helperSqlServer = GlobalHelp.GetDataAccessHelper();
            IDbHelper helperSqlite    = GlobalHelp.GetDataAccessSqliteHelper();
            string    strSql          = "Select * from CacheConfig";
            string    strIds          = GetLocalCacheIds();

            if (strIds != string.Empty)
            {
                strSql = strSql + " where Id  not in(" + strIds + ") ";
            }
            helperSqlServer.CreateCommand(strSql);
            DataTable dtCacheTable = helperSqlServer.ExecuteQuery();

            if (dtCacheTable.Rows.Count <= 0)
            {
                return;
            }
            foreach (DataRow dr in dtCacheTable.Rows)
            {
                string        strTableName  = dr["TableName"].ToString();
                string        strId         = dr["Id"].ToString();
                string        strConn       = dr["ConnectionString"].ToString();
                DatabaseTable databaseTable = GetDatabaseTable(strConn, SqlType.SqlServer, strTableName);
                if (databaseTable != null)
                {
                    #region 创建本地脚本
                    string strDdl = RunTableDdl(databaseTable, SqlType.SQLite);
                    strDdl += "; SELECT 'ok'";
                    helperSqlite.CreateCommand("DROP Table IF EXISTS [" + strTableName + "]");
                    helperSqlite.ExecuteNonQuery();
                    helperSqlite.CreateCommand(strDdl);
                    DataTable dtCache = helperSqlite.ExecuteQuery();
                    #endregion
                    if (dtCache.Rows.Count > 0 && dtCache.Rows[0][0].ToString().Trim() == "ok")
                    {
                        //删除本地缓存设置表数据
                        helperSqlite.CreateCommand("DELETE FROM CacheConfig WHERE TableName ='" + strTableName + "' ");
                        helperSqlite.ExecuteNonQuery();
                        //获取服务器缓存表数据,并同步至本地缓存数据库
                        IDbHelper helperTemp = new MSSQLHelper(strConn);
                        helperTemp.CreateCommand("SELECT * FROM " + strTableName + " with(nolock)");
                        DataTable dtBatch = helperTemp.ExecuteQuery();
                        dtBatch.TableName = strTableName;
                        for (int i = 0; i < dtBatch.Columns.Count; i++)
                        {
                            dtBatch.Columns[i].AutoIncrement = false;
                        }
                        helperSqlite.BatchInsert(dtBatch);
                        //同步本地缓存设置表数据
                        dtCacheTable.TableName = "CacheConfig";
                        for (int i = 0; i < dtCacheTable.Columns.Count; i++)
                        {
                            dtCacheTable.Columns[i].AutoIncrement = false;
                        }
                        for (int i = 0; i < dtCacheTable.Rows.Count; i++)
                        {
                            dtCacheTable.Rows[i]["ConnectionString"] = string.Empty;
                        }
                        helperSqlite.BatchInsert(dtCacheTable);
                    }
                }
            }
        }