Exemplo n.º 1
0
 /// <summary>构造函数
 ///
 /// </summary>
 public FrmCacheTablesSimpleQuery()
 {
     InitializeComponent();
     grdData.ShowCellToolTips    = false;
     grdData.AutoGenerateColumns = false;
     m_CacheTablesDAL            = GlobalHelp.GetResolve <IBseDAL <CacheTables> >();
     grdData.RowsAdded          += this.grdData_RowsAdded;
     grdData.RowPostPaint       += grdData_RowPostPaint;
     grdData.CellMouseEnter     += this.grdData_CellMouseEnter;
     grdData.CellMouseLeave     += this.grdData_CellMouseLeave;
     grdData.CellDoubleClick    += this.grdData_CellDoubleClick;
     toolTip.Draw += this.toolTip_Draw;
     DoInitData();
 }
Exemplo n.º 2
0
        private static void SynLocalCacheByCacheConfig(DataTable dtCacheTable)
        {
            string        strTableName  = dtCacheTable.Rows[0]["TableName"].ToString();
            string        strId         = dtCacheTable.Rows[0]["Id"].ToString();
            string        strConn       = dtCacheTable.Rows[0]["ConnectionString"].ToString();
            DatabaseTable databaseTable = CacheManager.GetDatabaseTable(strConn, SqlType.SqlServer, strTableName);

            if (databaseTable != null)
            {
                string strDdl = CacheManager.RunTableDdl(databaseTable, SqlType.SQLite);
                strDdl += "; SELECT 'ok'";
                IDbHelper helper = GlobalHelp.GetDataAccessSqliteHelper();
                helper.CreateCommand("DROP Table IF EXISTS [" + strTableName + "]");
                helper.ExecuteNonQuery();
                helper.CreateCommand(strDdl);
                DataTable dtCache = helper.ExecuteQuery();
                if (dtCache.Rows.Count > 0 && dtCache.Rows[0][0].ToString().Trim() == "ok")
                {
                    //删除本地缓存设置表数据
                    helper.CreateCommand("DELETE FROM CacheConfig WHERE TableName ='" + strTableName + "' ");
                    helper.ExecuteNonQuery();
                    //获取服务器缓存表数据,并同步至本地缓存数据库
                    IDbHelper helperSql = new MSSQLHelper(strConn);
                    helperSql.CreateCommand("SELECT * FROM " + strTableName + " with(nolock)");
                    DataTable dtBatch = helperSql.ExecuteQuery();
                    dtBatch.TableName = strTableName;
                    for (int i = 0; i < dtBatch.Columns.Count; i++)
                    {
                        dtBatch.Columns[i].AutoIncrement = false;
                    }
                    helper.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;
                    }
                    helper.BatchInsert(dtCacheTable);
                    if (!CacheManager.CacheDictionary.ContainsKey(strTableName))
                    {
                        CacheManager.CacheDictionary.Add(strTableName, strTableName);
                    }
                }
            }
        }
Exemplo n.º 3
0
 /// <summary>构造函数
 ///
 /// </summary>
 /// <param name=model" CacheSetting">对象</param>
 /// <param name="lstCacheSetting">对象集合</param>
 public FrmCacheSettingSimpleDialog(CacheSetting modelCacheSetting, List <CacheSetting> lstCacheSetting)
 {
     InitializeComponent();
     DoInitData();
     m_lstCacheSetting          = lstCacheSetting ?? new List <CacheSetting>();
     m_CacheSettingDAL          = GlobalHelp.GetResolve <IBseDAL <CacheSetting> >();
     this.dataNavigator.Visible = false;
     if (modelCacheSetting != null)
     {
         this.dataNavigator.Visible  = true;
         m_CacheSetting              = modelCacheSetting;
         this.dataNavigator.ListInfo = lstCacheSetting.Select(t => t.Id.ToString()).ToList();
         m_strIndex = lstCacheSetting.FindIndex(t => t.Id == m_CacheSetting.Id).ToString();
         this.dataNavigator.CurrentIndex = int.Parse(m_strIndex);
     }
 }
Exemplo n.º 4
0
 /// <summary>构造函数
 ///
 /// </summary>
 /// <param name=model" CacheTables">对象</param>
 /// <param name="lstCacheTables">对象集合</param>
 public FrmCacheTablesSimpleDialog(CacheTables modelCacheTables, List <CacheTables> lstCacheTables)
 {
     InitializeComponent();
     DoInitData();
     m_lstCacheTables           = lstCacheTables ?? new List <CacheTables>();
     m_CacheTablesDAL           = GlobalHelp.GetResolve <IBseDAL <CacheTables> >();
     this.dataNavigator.Visible = false;
     if (modelCacheTables != null)
     {
         this.dataNavigator.Visible = true;
         m_CacheTables = modelCacheTables;
         this.dataNavigator.ListInfo = lstCacheTables.Select(t => t.Id.ToString()).ToList();
         m_strIndex = lstCacheTables.FindIndex(t => t.Id == m_CacheTables.Id).ToString();
         this.dataNavigator.CurrentIndex = int.Parse(m_strIndex);
     }
 }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
 /// <summary>处理接受到的消息
 ///
 /// </summary>
 /// <param name="data"></param>
 /// <param name="responseChannel"></param>
 public static void Received(NetworkData data, IConnection responseChannel)
 {
     try
     {
         var message = MessageConverter.ToMessage(data);
         if (message.Command == Command.Send)
         {
             if (message.Content.Contains("join group successful"))
             {
                 return;
             }
             CacheMessageEntity entity       = JsonConvert.DeserializeObject <CacheMessageEntity>(message.Content);
             string             strKey       = entity.CacheKey;
             string             strOperation = entity.Operation;
             DataTable          dtCacheTable = entity.DataTableCache;
             //新增缓存配置,同步缓存
             if (strOperation == "Add")
             {
                 SynLocalCacheByCacheConfig(dtCacheTable);
             }
             //删除缓存配置,同步缓存
             else if (strOperation == "Delete")
             {
                 string    strTableName = dtCacheTable.Rows[0]["TableName"].ToString();
                 string    strId        = dtCacheTable.Rows[0]["Id"].ToString();
                 IDbHelper helper       = GlobalHelp.GetDataAccessSqliteHelper();
                 helper.CreateCommand("DELETE FROM CacheConfig WHERE Id=" + strId + "");
                 helper.ExecuteNonQuery();
                 helper.CreateCommand("DROP Table IF EXISTS [" + strTableName + "]");
                 helper.ExecuteNonQuery();
                 if (CacheManager.CacheDictionary.ContainsKey(strTableName))
                 {
                     CacheManager.CacheDictionary.Remove(strTableName);
                 }
             }
         }
     }
     catch (Exception)
     {
     }
 }
Exemplo n.º 8
0
        internal static string GetLocalCacheIds()
        {
            IDbHelper dbSqliteHelper = GlobalHelp.GetDataAccessSqliteHelper();
            string    strSql         = "Select Id from CacheConfig ";

            dbSqliteHelper.CreateCommand(strSql);
            //dbSqliteHelper.
            DataTable dt = dbSqliteHelper.ExecuteQuery();

            if (dt.Rows.Count > 0)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append(("("));
                foreach (DataRow dr in dt.Rows)
                {
                    sb.Append(dr["Id"]);
                    sb.Append(",");
                }
                sb.Remove(sb.Length - 1, 1);
                sb.Append((")"));
                return(sb.ToString());
            }
            return(string.Empty);
        }
Exemplo n.º 9
0
        /// <summary>获取缓存表配置
        ///
        /// </summary>
        /// <returns></returns>
        internal static List <CacheConfig> GetCacheStoreConfig()
        {
            IBseDAL <CacheConfig> cacheDal = GlobalHelp.GetResolve <IBseDAL <CacheConfig> >();

            return(cacheDal.GetListArray(""));
        }
Exemplo n.º 10
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);
                    }
                }
            }
        }