示例#1
0
        public static void InitCfgData(string key, string jsonCallEnity)
        {
            try
            {
                var    index          = key.IndexOf(CacheManager.MAIN_KEY_SPLIT_CHAR);
                string cacheKeyPrefix = index >= 0 ? key.Substring(0, index) : key;
                MemcachedUpdateSetConfigDAL    configDAL    = new MemcachedUpdateSetConfigDAL();
                MemcachedUpdateSetConfigEntity configEngity = configDAL.Select(string.Format("CacheKeyPrefix='{0}'", cacheKeyPrefix));
                if (configEngity == null)
                {
                    configEngity = new MemcachedUpdateSetConfigEntity();
                    configEngity.CacheKeyPrefix      = cacheKeyPrefix;
                    configEngity.DataChange_LastTime = DateTime.Now;
                    configEngity.FreMin         = 0;//数据库默认
                    configEngity.IsJobActByMin  = 0;
                    configEngity.UpdateHourSpan = KeyMinuteManager.DefaultMinute;
                    configDAL.Insert(configEngity);
                }

                MemcachedUpdateRuleDAL    ruleDAL    = new MemcachedUpdateRuleDAL();
                MemcachedUpdateRuleEntity ruleEntity = ruleDAL.Select(string.Format("CacheKey='{0}'", key));
                if (ruleEntity == null)
                {
                    ruleEntity                     = new MemcachedUpdateRuleEntity();
                    ruleEntity.CacheKey            = key;
                    ruleEntity.CacheKeyPrefix      = cacheKeyPrefix;
                    ruleEntity.ConditionEntityJson = jsonCallEnity;
                    ruleEntity.DataChange_LastTime = DateTime.Now;
                    ruleEntity.IsJobActByMin       = configEngity.IsJobActByMin;
                    ruleEntity.LastUpdateTime      = DateTime.Now;
                    ruleEntity.UpdateHourSpan      = configEngity.UpdateHourSpan;
                    ruleDAL.Insert(ruleEntity);
                }

                MemcachedGetFrequencyDAL    freqDAL    = new MemcachedGetFrequencyDAL();
                MemcachedGetFrequencyEntity freqEntity = freqDAL.Select(string.Format("CacheKey='{0}'", key));
                if (freqEntity == null)
                {
                    freqEntity                     = new MemcachedGetFrequencyEntity();
                    freqEntity.CacheKey            = key;
                    freqEntity.CacheKeyPrefix      = cacheKeyPrefix;
                    freqEntity.DataChange_LastTime = DateTime.Now;
                    freqEntity.FreMin              = configEngity.FreMin;
                    freqEntity.FreCount            = 1;
                    freqEntity.LastGetDateTime     = DateTime.Now;
                    freqDAL.Insert(freqEntity);
                }
            }
            catch (Exception ex)
            {
                Logging.HHLogHelperV2.ERRORGlobalException(ex);
            }
        }
        /// <summary>
        /// 根据一条数据记录创建实体对象
        /// </summary>
        public static MemcachedUpdateRuleEntity CreateEntity(DataRow dr)
        {
            MemcachedUpdateRuleEntity ent = new MemcachedUpdateRuleEntity();

            if (dr["MemcachedUpdateRuleId"] != DBNull.Value)
            {
                ent.MemcachedUpdateRuleId = int.Parse(dr["MemcachedUpdateRuleId"].ToString());
            }
            if (dr["CacheKey"] != DBNull.Value)
            {
                ent.CacheKey = (string)dr["CacheKey"];
            }
            if (dr["LastUpdateTime"] != DBNull.Value)
            {
                ent.LastUpdateTime = DateTime.Parse(dr["LastUpdateTime"].ToString());
            }
            if (dr["UpdateHourSpan"] != DBNull.Value)
            {
                ent.UpdateHourSpan = int.Parse(dr["UpdateHourSpan"].ToString());
            }
            if (dr["CacheKeyPrefix"] != DBNull.Value)
            {
                ent.CacheKeyPrefix = (string)dr["CacheKeyPrefix"];
            }
            if (dr["IsJobActByMin"] != DBNull.Value)
            {
                ent.IsJobActByMin = int.Parse(dr["IsJobActByMin"].ToString());
            }
            if (dr["ConditionEntityJson"] != DBNull.Value)
            {
                ent.ConditionEntityJson = (string)dr["ConditionEntityJson"];
            }
            if (dr["IsMainKey"] != DBNull.Value)
            {
                ent.IsMainKey = int.Parse(dr["IsMainKey"].ToString());
            }
            if (dr["ProcessIP"] != DBNull.Value)
            {
                ent.ProcessIP = (string)dr["ProcessIP"];
            }
            if (dr["UpdateLockTime"] != DBNull.Value)
            {
                ent.UpdateLockTime = DateTime.Parse(dr["UpdateLockTime"].ToString());
            }
            if (dr["DataChange_LastTime"] != DBNull.Value)
            {
                ent.DataChange_LastTime = DateTime.Parse(dr["DataChange_LastTime"].ToString());
            }
            return(ent);
        }
 /// <summary>
 /// 根据一条数据记录创建实体对象
 /// </summary>
 public static MemcachedUpdateRuleEntity CreateEntity(DataRow dr)
 {
     MemcachedUpdateRuleEntity ent = new MemcachedUpdateRuleEntity();
     if(dr["MemcachedUpdateRuleId"] != DBNull.Value)ent.MemcachedUpdateRuleId = int.Parse(dr["MemcachedUpdateRuleId"].ToString());            
     if(dr["CacheKey"] != DBNull.Value)ent.CacheKey = (string)dr["CacheKey"];
     if(dr["LastUpdateTime"] != DBNull.Value)ent.LastUpdateTime = DateTime.Parse(dr["LastUpdateTime"].ToString());            
     if(dr["UpdateHourSpan"] != DBNull.Value)ent.UpdateHourSpan = int.Parse(dr["UpdateHourSpan"].ToString());
     if(dr["CacheKeyPrefix"] != DBNull.Value)ent.CacheKeyPrefix = (string)dr["CacheKeyPrefix"];            
     if(dr["IsJobActByMin"] != DBNull.Value)ent.IsJobActByMin = int.Parse(dr["IsJobActByMin"].ToString());
     if(dr["ConditionEntityJson"] != DBNull.Value)ent.ConditionEntityJson = (string)dr["ConditionEntityJson"];            
     if(dr["IsMainKey"] != DBNull.Value)ent.IsMainKey = int.Parse(dr["IsMainKey"].ToString());
     if(dr["ProcessIP"] != DBNull.Value)ent.ProcessIP = (string)dr["ProcessIP"];            
     if(dr["UpdateLockTime"] != DBNull.Value)ent.UpdateLockTime = DateTime.Parse(dr["UpdateLockTime"].ToString());            
     if(dr["DataChange_LastTime"] != DBNull.Value)ent.DataChange_LastTime = DateTime.Parse(dr["DataChange_LastTime"].ToString());
     return ent;
 }
        /// <summary>
        /// 根据条件获取一个实体对象
        /// </summary>
        public MemcachedUpdateRuleEntity Select(string where)
        {
            DbCommand cmd = DB.DbProviderFactory.CreateCommand();

            cmd.CommandText = "select * from MemcachedUpdateRule with(nolock) where " + where;
            cmd.CommandType = System.Data.CommandType.Text;

            DataSet ds = DB.ExecuteDataSet(cmd);

            if (ds.Tables[0].Rows.Count == 0)
            {
                return(null);
            }

            DataRow dr = ds.Tables[0].Rows[0];

            return(MemcachedUpdateRuleEntity.CreateEntity(dr));
        }
        public bool Insert(MemcachedUpdateRuleEntity entity)
        {
            DbCommand cmd = DB.DbProviderFactory.CreateCommand();

            cmd.CommandText = "spA_MemcachedUpdateRule_i";
            cmd.CommandType = System.Data.CommandType.StoredProcedure;

            DB.AddOutParameter(cmd, "@MemcachedUpdateRuleId", DbType.Int32, entity.MemcachedUpdateRuleId);
            if (entity.CacheKey != null)
            {
                DB.AddInParameter(cmd, "@CacheKey", DbType.AnsiString, entity.CacheKey);
            }
            if (entity.LastUpdateTime.Year != 1)
            {
                DB.AddInParameter(cmd, "@LastUpdateTime", DbType.DateTime, entity.LastUpdateTime);
            }
            DB.AddInParameter(cmd, "@UpdateHourSpan", DbType.Int32, entity.UpdateHourSpan);
            if (entity.CacheKeyPrefix != null)
            {
                DB.AddInParameter(cmd, "@CacheKeyPrefix", DbType.AnsiString, entity.CacheKeyPrefix);
            }
            DB.AddInParameter(cmd, "@IsJobActByMin", DbType.Int32, entity.IsJobActByMin);
            if (entity.ConditionEntityJson != null)
            {
                DB.AddInParameter(cmd, "@ConditionEntityJson", DbType.AnsiString, entity.ConditionEntityJson);
            }
            DB.AddInParameter(cmd, "@IsMainKey", DbType.Int32, entity.IsMainKey);
            if (entity.ProcessIP != null)
            {
                DB.AddInParameter(cmd, "@ProcessIP", DbType.AnsiString, entity.ProcessIP);
            }
            if (entity.UpdateLockTime.Year != 1)
            {
                DB.AddInParameter(cmd, "@UpdateLockTime", DbType.DateTime, entity.UpdateLockTime);
            }
            if (entity.DataChange_LastTime.Year != 1)
            {
                DB.AddInParameter(cmd, "@DataChange_LastTime", DbType.DateTime, entity.DataChange_LastTime);
            }
            bool b = (int)DB.ExecuteNonQuery(cmd) == 0 ? true : false;

            entity.MemcachedUpdateRuleId = int.Parse(DB.GetParameterValue(cmd, "@MemcachedUpdateRuleId").ToString());
            return(b);
        }
        /// <summary>
        /// 根据主键获取一个实体对象
        /// </summary>
        public MemcachedUpdateRuleEntity Select(int MemcachedUpdateRuleId)
        {
            DbCommand cmd = DB.DbProviderFactory.CreateCommand();

            cmd.CommandText = "select * from MemcachedUpdateRule with(nolock) where MemcachedUpdateRuleId=@MemcachedUpdateRuleId";
            cmd.CommandType = System.Data.CommandType.Text;

            DB.AddInParameter(cmd, "MemcachedUpdateRuleId", DbType.Int32, MemcachedUpdateRuleId);
            DataSet ds = DB.ExecuteDataSet(cmd);

            if (ds.Tables[0].Rows.Count == 0)
            {
                return(null);
            }

            DataRow dr = ds.Tables[0].Rows[0];

            return(MemcachedUpdateRuleEntity.CreateEntity(dr));
        }
示例#7
0
 public static void UpdateTime(int ruleId, string processIP)
 {
     try
     {
         MemcachedUpdateRuleDAL    dal    = new MemcachedUpdateRuleDAL();
         MemcachedUpdateRuleEntity entity = dal.Select(ruleId);
         if (entity != null)
         {
             entity.LastUpdateTime      = DateTime.Now;
             entity.DataChange_LastTime = DateTime.Now;
             entity.ProcessIP           = processIP;
             entity.UpdateLockTime      = DateTime.Now;
             dal.Update(entity);
         }
     }
     catch (Exception ex)
     {
         Logging.HHLogHelperV2.ERRORGlobalException(ex);
     }
 }
        public List <MemcachedUpdateRuleEntity> GetJobUpdateData(int mod, int remainder)
        {
            DbCommand cmd = DB.DbProviderFactory.CreateCommand();
            string    sql = string.Format(@"SELECT TOP 1000 A.MemcachedUpdateRuleId, A.CacheKey,A.CacheKeyPrefix, A.ConditionEntityJson FROM MemcachedUpdateRule AS A
INNER JOIN MemcachedGetFrequency AS B ON A.CacheKeyPrefix=B.CacheKeyPrefix
INNER JOIN MemcachedUpdateSetConfig AS C ON A.CacheKeyPrefix=C.CacheKeyPrefix
WHERE B.FreCount>C.FreMin AND DATEDIFF(mi,A.LastUpdateTime,GETDATE())>=C.UpdateHourSpan
AND MemcachedUpdateRuleId % {0}={1} ORDER BY C.UpdateHourSpan ASC, B.FreCount DESC,A.LastUpdateTime DESC;", mod, remainder);

            cmd.CommandText = sql;
            cmd.CommandType = System.Data.CommandType.Text;
            DataSet ds = DB.ExecuteDataSet(cmd);

            List <MemcachedUpdateRuleEntity> list = new List <MemcachedUpdateRuleEntity>();

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                MemcachedUpdateRuleEntity ent = new MemcachedUpdateRuleEntity();
                if (dr["MemcachedUpdateRuleId"] != DBNull.Value)
                {
                    ent.MemcachedUpdateRuleId = int.Parse(dr["MemcachedUpdateRuleId"].ToString());
                }
                if (dr["CacheKey"] != DBNull.Value)
                {
                    ent.CacheKey = (string)dr["CacheKey"];
                }
                if (dr["CacheKeyPrefix"] != DBNull.Value)
                {
                    ent.CacheKeyPrefix = (string)dr["CacheKeyPrefix"];
                }
                if (dr["ConditionEntityJson"] != DBNull.Value)
                {
                    ent.ConditionEntityJson = (string)dr["ConditionEntityJson"];
                }
                list.Add(ent);
            }
            return(list);
        }
        public List<MemcachedUpdateRuleEntity> GetJobUpdateData(int mod, int remainder)
        {
            DbCommand cmd = DB.DbProviderFactory.CreateCommand();
            string sql = string.Format(@"SELECT TOP 1000 A.MemcachedUpdateRuleId, A.CacheKey,A.CacheKeyPrefix, A.ConditionEntityJson FROM MemcachedUpdateRule AS A
INNER JOIN MemcachedGetFrequency AS B ON A.CacheKeyPrefix=B.CacheKeyPrefix
INNER JOIN MemcachedUpdateSetConfig AS C ON A.CacheKeyPrefix=C.CacheKeyPrefix
WHERE B.FreCount>C.FreMin AND DATEDIFF(mi,A.LastUpdateTime,GETDATE())>=C.UpdateHourSpan
AND MemcachedUpdateRuleId % {0}={1} ORDER BY C.UpdateHourSpan ASC, B.FreCount DESC,A.LastUpdateTime DESC;", mod, remainder);

            cmd.CommandText = sql;
            cmd.CommandType = System.Data.CommandType.Text;
            DataSet ds = DB.ExecuteDataSet(cmd);

            List<MemcachedUpdateRuleEntity> list = new List<MemcachedUpdateRuleEntity>();
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                MemcachedUpdateRuleEntity ent = new MemcachedUpdateRuleEntity();
                if (dr["MemcachedUpdateRuleId"] != DBNull.Value) ent.MemcachedUpdateRuleId = int.Parse(dr["MemcachedUpdateRuleId"].ToString());
                if (dr["CacheKey"] != DBNull.Value) ent.CacheKey = (string)dr["CacheKey"];
                if (dr["CacheKeyPrefix"] != DBNull.Value) ent.CacheKeyPrefix = (string)dr["CacheKeyPrefix"];
                if (dr["ConditionEntityJson"] != DBNull.Value) ent.ConditionEntityJson = (string)dr["ConditionEntityJson"];
                list.Add(ent);
            }
            return list;
        }
        public bool Update(MemcachedUpdateRuleEntity entity)
        {
            DbCommand cmd = DB.DbProviderFactory.CreateCommand();
            cmd.CommandText = "spA_MemcachedUpdateRule_u";
            cmd.CommandType = System.Data.CommandType.StoredProcedure;

            DB.AddInParameter(cmd, "@MemcachedUpdateRuleId", DbType.Int32, entity.MemcachedUpdateRuleId);
            if (entity.CacheKey != null) DB.AddInParameter(cmd, "@CacheKey", DbType.AnsiString, entity.CacheKey);
            if (entity.LastUpdateTime.Year != 1) DB.AddInParameter(cmd, "@LastUpdateTime", DbType.DateTime, entity.LastUpdateTime);
            DB.AddInParameter(cmd, "@UpdateHourSpan", DbType.Int32, entity.UpdateHourSpan);
            if (entity.CacheKeyPrefix != null) DB.AddInParameter(cmd, "@CacheKeyPrefix", DbType.AnsiString, entity.CacheKeyPrefix);
            DB.AddInParameter(cmd, "@IsJobActByMin", DbType.Int32, entity.IsJobActByMin);
            if (entity.ConditionEntityJson != null) DB.AddInParameter(cmd, "@ConditionEntityJson", DbType.AnsiString, entity.ConditionEntityJson);
            DB.AddInParameter(cmd, "@IsMainKey", DbType.Int32, entity.IsMainKey);
            if (entity.ProcessIP != null) DB.AddInParameter(cmd, "@ProcessIP", DbType.AnsiString, entity.ProcessIP);
            if (entity.UpdateLockTime.Year != 1) DB.AddInParameter(cmd, "@UpdateLockTime", DbType.DateTime, entity.UpdateLockTime);
            if (entity.DataChange_LastTime.Year != 1) DB.AddInParameter(cmd, "@DataChange_LastTime", DbType.DateTime, entity.DataChange_LastTime);
            return DB.ExecuteNonQuery(cmd) == 0 ? true : false;
        }
示例#11
0
        public static void InitCfgData(string key, string jsonCallEnity)
        {
            try
            {
                var index=key.IndexOf(CacheManager.MAIN_KEY_SPLIT_CHAR);
                string cacheKeyPrefix = index >= 0 ? key.Substring(0, index) : key;
                MemcachedUpdateSetConfigDAL configDAL = new MemcachedUpdateSetConfigDAL();
                MemcachedUpdateSetConfigEntity configEngity = configDAL.Select(string.Format("CacheKeyPrefix='{0}'", cacheKeyPrefix));
                if (configEngity == null)
                {
                    configEngity = new MemcachedUpdateSetConfigEntity();
                    configEngity.CacheKeyPrefix = cacheKeyPrefix;
                    configEngity.DataChange_LastTime = DateTime.Now;
                    configEngity.FreMin = 0;//数据库默认
                    configEngity.IsJobActByMin = 0;
                    configEngity.UpdateHourSpan = KeyMinuteManager.DefaultMinute;
                    configDAL.Insert(configEngity);
                }

                MemcachedUpdateRuleDAL ruleDAL = new MemcachedUpdateRuleDAL();
                MemcachedUpdateRuleEntity ruleEntity = ruleDAL.Select(string.Format("CacheKey='{0}'", key));
                if (ruleEntity == null)
                {
                    ruleEntity = new MemcachedUpdateRuleEntity();
                    ruleEntity.CacheKey = key;
                    ruleEntity.CacheKeyPrefix = cacheKeyPrefix;
                    ruleEntity.ConditionEntityJson = jsonCallEnity;
                    ruleEntity.DataChange_LastTime = DateTime.Now;
                    ruleEntity.IsJobActByMin = configEngity.IsJobActByMin;
                    ruleEntity.LastUpdateTime = DateTime.Now;
                    ruleEntity.UpdateHourSpan = configEngity.UpdateHourSpan;
                    ruleDAL.Insert(ruleEntity);
                }

                MemcachedGetFrequencyDAL freqDAL = new MemcachedGetFrequencyDAL();
                MemcachedGetFrequencyEntity freqEntity = freqDAL.Select(string.Format("CacheKey='{0}'", key));
                if (freqEntity == null)
                {
                    freqEntity = new MemcachedGetFrequencyEntity();
                    freqEntity.CacheKey = key;
                    freqEntity.CacheKeyPrefix = cacheKeyPrefix;
                    freqEntity.DataChange_LastTime = DateTime.Now;
                    freqEntity.FreMin = configEngity.FreMin;
                    freqEntity.FreCount = 1;
                    freqEntity.LastGetDateTime = DateTime.Now;
                    freqDAL.Insert(freqEntity);
                }
            }
            catch(Exception ex)
            {
                Logging.HHLogHelperV2.ERRORGlobalException(ex);
            }
        }