Exemplo n.º 1
0
 public AopResult Begin(AopEnum action)
 {
     AopResult ar = AopResult.Continue;
     if (outerAop != null)
     {
         ar = outerAop.Begin(action, Para);
         if (ar == AopResult.Return)
         {
             return ar;
         }
     }
     if (AppConfig.Cache.IsAutoCache && !IsTxtDataBase) // ֻҪ����ֱ�ӷ���
     {
         isHasCache = AutoCache.GetCache(action, Para); //�ҿ���û��Cache
     }
     if (isHasCache)  //�ҵ�Cache
     {
         if (outerAop == null || ar == AopResult.Default)//��ִ��End
         {
             return AopResult.Return;
         }
         return AopResult.Break;//�ⲿAop˵������Ҫִ��End
     }
     else // û��Cache��Ĭ�Ϸ���
     {
         return ar;
     }
 }
Exemplo n.º 2
0
 public void End(AopEnum action, AopInfo aopInfo)
 {
     OutMsg("操作结果:" + aopInfo.IsSuccess);
     OutMsg("操作表名:" + aopInfo.TableName);
     OutMsg("操作参数:" + aopInfo.Where);
     OutMsg("----------------操作结束:" + action);
 }
Exemplo n.º 3
0
        public AopResult Begin(AopEnum action, AopInfo aopInfo)
        {
            try
            {
                StringBuilder sb = new StringBuilder();
                switch (action)
                {
                case AopEnum.Delete:
                    sb.AppendFormat("数据被删除,删除条件为:{0}", aopInfo.Where);
                    break;
                }

                if (!string.IsNullOrWhiteSpace(sb.ToString()))
                {
                    using (EditLog log = new EditLog())
                    {
                        log.TableName = aopInfo.TableName;
                        log.KeyID     = Convert.ToString(aopInfo.Row.PrimaryCell.Value);
                        log.Content   = sb.ToString();
                        log.UserID    = UserAuth.UserID;
                        log.EditTime  = DateTime.Now;
                        log.Insert(InsertOp.None);
                    }
                }
            }
            catch (Exception err)
            {
                Log.WriteLogToTxt("AopError:" + err.Message);
            }
            return(AopResult.Default);
        }
Exemplo n.º 4
0
        public AopResult Begin(AopEnum action, AopInfo aopInfo)
        {
            Console.WriteLine("开始方法:我已经拦截到用了方法");
            AopResult ar = AopResult.Continue;

            return(ar);
        }
Exemplo n.º 5
0
 public void End(AopEnum action, AopInfo aopInfo)
 {
     if (action == AopEnum.Select)
     {
         Console.WriteLine("结束方法:我已经拦截到用了选择方法");
     }
 }
Exemplo n.º 6
0
        public AopResult Begin(AopEnum action, AopInfo aopInfo)
        {
            try
            {
                StringBuilder sb = new StringBuilder();
                switch (action)
                {
                    case AopEnum.Delete:
                        sb.AppendFormat("数据被删除,删除条件为:{0}", aopInfo.Where);
                        break;
                }

                if (!string.IsNullOrWhiteSpace(sb.ToString()))
                {
                    using (EditLog log = new EditLog())
                    {
                        log.TableName = aopInfo.TableName;
                        log.KeyID = Convert.ToString(aopInfo.Row.PrimaryCell.Value);
                        log.Content = sb.ToString();
                        log.UserID = UserAuth.UserID;
                        log.EditTime = DateTime.Now;
                        log.Insert(InsertOp.None);
                    }
                }
            }
            catch (Exception err)
            {
                Log.WriteLogToTxt("AopError:" + err.Message);
            }
            return AopResult.Default;
        }
Exemplo n.º 7
0
        public AopResult Begin(AopEnum action)
        {
            AopResult ar = AopResult.Continue;

            if (outerAop != null && (aopOp == AopOp.OpenAll || aopOp == AopOp.OnlyOuter))
            {
                ar = outerAop.Begin(action, Para);
                if (ar == AopResult.Return)
                {
                    return(ar);
                }
            }
            if (aopOp == AopOp.OpenAll || aopOp == AopOp.OnlyInner)
            {
                if (AppConfig.Cache.IsAutoCache && !IsTxtDataBase)   // 只要不是直接返回
                {
                    isHasCache = AutoCache.GetCache(action, Para);   //找看有没有Cache
                }
                if (isHasCache)                                      //找到Cache
                {
                    if (outerAop == null || ar == AopResult.Default) //不执行End
                    {
                        return(AopResult.Return);
                    }
                    return(AopResult.Break);//外部Aop说:还需要执行End
                }
            }
            return(ar);// 没有Cache,默认返回
        }
Exemplo n.º 8
0
        //注意,我把这类库的生成目录指向了Aop_Demo的目录。
        //如果路径有误,可以改(项目属性=》生成=》输出路径)
        //这样你们就不用手工把生成的MyAopForDemo.dll Copy到 Aop_Demo项目的Debug目录下了

        //想让dll自动生成到另一个项目下,最方便是通过项目引用,不过Aop通常都是动态加载,项目之前没有引用关系,这里怕引用误导了大伙。

        public AopResult Begin(AopEnum action, AopInfo aopInfo)
        {
            OutMsg("----------------现在开始操作:" + action);
            OutMsg("表名:" + aopInfo.TableName);
            OutMsg("Where:" + aopInfo.Where);

            return(AopResult.Continue);//让执行继续了,返回有四种状态
        }
Exemplo n.º 9
0
        static bool IsCanRemoveCache(AopEnum action, AopInfo aopInfo)
        {
            if (IngoreCacheColumns.Count > 0)
            {
                string databaseName = string.Empty;
                if (action == AopEnum.ExeNonQuery)
                {
                    if (aopInfo.IsProc || !aopInfo.ProcName.ToLower().StartsWith("update "))
                    {
                        return(true);
                    }
                    databaseName = aopInfo.MProc.DataBase;
                }
                else
                {
                    databaseName = aopInfo.MAction.DataBase;
                }
                string tableName = aopInfo.TableName;
                if (string.IsNullOrEmpty(tableName))
                {
                    List <string> tableNames = SqlFormat.GetTableNamesFromSql(aopInfo.ProcName);
                    if (tableNames == null || tableNames.Count != 1)//多个表的批量语句也不处理。
                    {
                        return(true);
                    }
                    tableName = tableNames[0];
                }
                //获取被更新的字段名,
                string[] columns = null;
                if (IngoreCacheColumns.ContainsKey(tableName))
                {
                    columns = IngoreCacheColumns[tableName].ToLower().Split(',');
                }
                else if (IngoreCacheColumns.ContainsKey(databaseName + "." + tableName))
                {
                    columns = IngoreCacheColumns[databaseName + "." + tableName].ToLower().Split(',');
                }
                if (columns != null)                                                  //拿到要忽略的列。
                {
                    List <string> updateColumns = GetChangedColumns(action, aopInfo); //拿到已更新的列
                    if (columns.Length >= updateColumns.Count)
                    {
                        List <string> ignoreColumns = new List <string>(columns.Length);
                        ignoreColumns.AddRange(columns);

                        foreach (string item in updateColumns)
                        {
                            if (!ignoreColumns.Contains(item))
                            {
                                return(true);//只要有一个不存在。
                            }
                        }
                        return(false);//全都不存在
                    }
                }
            }
            return(true);
        }
Exemplo n.º 10
0
        private static bool IsCanOperateCache(AopEnum action, AopInfo para)
        {
            if (para.IsTransaction) // 事务中,读数据时,处理读缓存是无法放置共享锁的情况
            {
                //判断事务等级,如果不是最低等级,则事务的查询不处理缓存
                switch (action)//处理查询 动作
                {
                case AopEnum.Exists:
                case AopEnum.Fill:
                case AopEnum.GetCount:
                case AopEnum.Select:
                    if (para.MAction.dalHelper.TranLevel != System.Data.IsolationLevel.ReadUncommitted)
                    {
                        return(false);
                    }
                    break;

                case AopEnum.ExeMDataTable:
                case AopEnum.ExeMDataTableList:
                case AopEnum.ExeScalar:
                    if (para.MProc.dalHelper.TranLevel != System.Data.IsolationLevel.ReadUncommitted)
                    {
                        return(false);
                    }
                    break;
                }
            }
            List <string> tables = GetRelationTables(para);

            if (tables != null && tables.Count > 0)
            {
                foreach (string tableName in tables)
                {
                    if (NoCacheTables.Contains(tableName))
                    {
                        return(false);
                    }
                    string baseKey = GetBaseKey(para, tableName);
                    string delKey  = "DeleteAutoCache:" + baseKey;
                    if (_MemCache.Contains(delKey))
                    {
                        return(false);
                    }
                }
            }
            return(true);
            // string delKey = "DeleteAutoCache:" + baseKey;
            // return !_MemCache.Contains(delKey);
            //if (baseKey.Contains(".ActionV") || baseKey.Contains(".ProcS"))
            //{

            //    return true;
            //}
            //TimeSpan ts = DateTime.Now - _MemCache.Get<DateTime>("Del:" + baseKey);
            //return ts.TotalSeconds > 6;//5秒内无缓存。
        }
Exemplo n.º 11
0
 public void End(AopEnum action)
 {
     if (outerAop != null)
     {
         outerAop.End(action, Para);
     }
     if (!isHasCache && !IsTxtDataBase)
     {
         AutoCache.SetCache(action, Para); //找看有没有Cache
     }
 }
Exemplo n.º 12
0
 public void End(AopEnum action)
 {
     if (outerAop != null && (aopOp == AopOp.OpenAll || aopOp == AopOp.OnlyOuter))
     {
         outerAop.End(action, Para);
     }
     if (aopOp == AopOp.OpenAll || aopOp == AopOp.OnlyInner)
     {
         if (!isHasCache && !IsTxtDataBase && Para.IsSuccess) //Select内部调用了GetCount,GetCount的内部isHasCache为true影响了
         {
             AutoCache.SetCache(action, Para);                //找看有没有Cache
         }
     }
 }
Exemplo n.º 13
0
 private AopResult SetAopResult(AopEnum action)
 {
     if (_aop.IsLoadAop)
     {
         _aop.Para.MProc    = this;
         _aop.Para.ProcName = _procName;
         _aop.Para.IsProc   = _isProc;
         if (dalHelper.Com != null)
         {
             _aop.Para.DBParameters = dalHelper.Com.Parameters;
         }
         _aop.Para.IsTransaction = dalHelper.isOpenTrans;
         return(_aop.Begin(action));
     }
     return(AopResult.Default);
 }
Exemplo n.º 14
0
        private static List <string> GetChangedColumns(AopEnum action, AopInfo aopInfo)
        {
            List <string> columns    = new List <string>();
            string        expression = string.Empty;

            if (action == AopEnum.Update)
            {
                foreach (MDataCell item in aopInfo.Row)
                {
                    if (item.State == 2 && !item.Struct.IsPrimaryKey)
                    {
                        columns.Add(item.ColumnName.ToLower());
                    }
                }
                expression = aopInfo.UpdateExpression;
            }
            else if (action == AopEnum.ExeNonQuery && !aopInfo.IsProc)
            {
                string sql      = aopInfo.ProcName.ToLower();
                int    setStart = sql.IndexOf(" set ");
                int    whereEnd = sql.IndexOf(" where ");
                if (whereEnd < setStart)
                {
                    expression = sql.Substring(setStart + 5);
                }
                else
                {
                    expression = sql.Substring(setStart + 5, whereEnd - setStart + 5);
                }
            }
            if (!string.IsNullOrEmpty(expression))
            {
                string[] items = expression.ToLower().Split(',');
                foreach (string item in items)
                {
                    if (item.IndexOf('=') > -1)
                    {
                        string column = item.Split('=')[0];
                        if (!columns.Contains(column))
                        {
                            columns.Add(column);
                        }
                    }
                }
            }
            return(columns);
        }
Exemplo n.º 15
0
        private static string GetKey(AopEnum action, AopInfo aopInfo, string baseKey)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(baseKey);
            switch (action)
            {
            case AopEnum.ExeNonQuery:
            case AopEnum.Insert:
            case AopEnum.Update:
            case AopEnum.Delete:
                return(sb.ToString());
            }

            #region Key1:DBType
            sb.Append(".");
            sb.Append(action);
            if (aopInfo.DBParameters != null && aopInfo.DBParameters.Count > 0)
            {
                foreach (DbParameter item in aopInfo.DBParameters)
                {
                    sb.Append(item.ParameterName);
                    sb.Append(item.Value);
                }
            }
            if (aopInfo.CustomDbPara != null)
            {
                foreach (AopCustomDbPara item in aopInfo.CustomDbPara)
                {
                    sb.Append(item.ParaName);
                    sb.Append(item.Value);
                }
            }
            if (aopInfo.SelectColumns != null)
            {
                foreach (object item in aopInfo.SelectColumns)
                {
                    sb.Append(item);
                    sb.Append(item);
                }
            }
            #endregion

            switch (action)
            {
            case AopEnum.ExeMDataTableList:
            case AopEnum.ExeMDataTable:
            case AopEnum.ExeScalar:
                sb.Append(aopInfo.IsProc);
                sb.Append(aopInfo.ProcName);
                break;

            case AopEnum.Exists:
            case AopEnum.Fill:
            case AopEnum.GetCount:
                sb.Append(aopInfo.Where);
                break;

            case AopEnum.Select:
                sb.Append(aopInfo.PageIndex);
                sb.Append(aopInfo.PageSize);
                sb.Append(aopInfo.Where);
                break;
            }

            return(StaticTool.GetHashKey(sb.ToString()));
        }
Exemplo n.º 16
0
 private static string GetKey(AopEnum action, AopInfo aopInfo)
 {
     return(GetKey(action, aopInfo, GetBaseKey(aopInfo)));
 }
Exemplo n.º 17
0
        private static CacheManage _MemCache = CacheManage.Instance;   //有可能使用MemCache操作

        internal static bool GetCache(AopEnum action, AopInfo aopInfo) //Begin
        {
            switch (action)
            {
            case AopEnum.ExeNonQuery:
            case AopEnum.Insert:
            case AopEnum.Update:
            case AopEnum.Delete:
                return(false);
            }
            if (!IsCanOperateCache(aopInfo))
            {
                return(false);
            }
            string baseKey = GetBaseKey(aopInfo);
            //查看是否通知我移除
            string key = GetKey(action, aopInfo, baseKey);
            object obj = _MemCache.Get(key);

            switch (action)
            {
            case AopEnum.ExeMDataTableList:
                if (obj != null)
                {
                    List <MDataTable>           list = new List <MDataTable>();
                    Dictionary <string, string> jd   = JsonHelper.Split(obj.ToString());
                    if (jd != null && jd.Count > 0)
                    {
                        foreach (KeyValuePair <string, string> item in jd)
                        {
                            list.Add(MDataTable.CreateFrom(item.Value));
                        }
                    }
                    aopInfo.TableList = list;
                }
                break;

            case AopEnum.Select:
            case AopEnum.ExeMDataTable:
                if (obj != null)
                {
                    aopInfo.Table = MDataTable.CreateFrom(obj.ToString());
                }
                break;

            case AopEnum.ExeScalar:
                if (obj != null)
                {
                    aopInfo.ExeResult = obj;
                }
                break;

            case AopEnum.Fill:
                if (obj != null)
                {
                    MDataRow row = obj as MDataRow;
                    if (_MemCache.CacheType == CacheType.LocalCache)
                    {
                        row = row.Clone();
                    }
                    aopInfo.Row       = row;
                    aopInfo.IsSuccess = true;
                }
                break;

            case AopEnum.GetCount:
                if (obj != null)
                {
                    aopInfo.RowCount = int.Parse(obj.ToString());
                }
                break;

            case AopEnum.Exists:
                if (obj != null)
                {
                    aopInfo.ExeResult = obj;
                }
                break;
            }
            baseKey = key = null;
            return(obj != null);
        }
Exemplo n.º 18
0
        //private static List<string> _CacheTables = null;
        //internal static List<string> CacheTables
        //{
        //    get
        //    {
        //        if (_CacheTables == null)
        //        {
        //            _CacheTables = new List<string>();
        //            string tables = AppConfig.Cache.CacheTables.ToLower();
        //            if (!string.IsNullOrEmpty(tables))
        //            {
        //                _CacheTables.AddRange(tables.Split(','));
        //            }
        //        }
        //        return _CacheTables;
        //    }
        //    set
        //    {
        //        _CacheTables = value;
        //    }
        //}
        //private static List<string> _NoCacheTables = null;
        //internal static List<string> NoCacheTables
        //{
        //    get
        //    {
        //        if (_NoCacheTables == null)
        //        {
        //            _NoCacheTables = new List<string>();
        //            string tables = AppConfig.Cache.NoCacheTables.ToLower();
        //            if (!string.IsNullOrEmpty(tables))
        //            {
        //                _NoCacheTables.AddRange(tables.Split(','));
        //            }
        //        }
        //        return _NoCacheTables;
        //    }
        //    set
        //    {
        //        _NoCacheTables = value;
        //    }
        //}
        private static bool IsCanOperateCache(AopEnum action, AopInfo para)
        {
            if (para.IsTransaction) // 事务中,读数据时,处理读缓存是无法放置共享锁的情况
            {
                //判断事务等级,如果不是最低等级,则事务的查询不处理缓存
                switch (action)//处理查询 动作
                {
                case AopEnum.Exists:
                case AopEnum.Fill:
                case AopEnum.GetCount:
                case AopEnum.Select:
                case AopEnum.SelectList:
                    if (para.MAction.dalHelper.TranLevel != System.Data.IsolationLevel.ReadUncommitted)
                    {
                        return(false);
                    }
                    break;

                case AopEnum.ExeMDataTable:
                case AopEnum.ExeMDataTableList:
                case AopEnum.ExeScalar:
                case AopEnum.ExeList:
                    if (para.MProc.dalHelper.TranLevel != System.Data.IsolationLevel.ReadUncommitted)
                    {
                        return(false);
                    }
                    break;
                }
            }
            List <string> tables = GetRelationTables(para);

            if (tables != null && tables.Count > 0)
            {
                string cacheTables    = "," + AppConfig.Cache.CacheTables + ",";//demo.Aa
                string nNoCacheTables = "," + AppConfig.Cache.NoCacheTables + ",";
                foreach (string tableName in tables)
                {
                    if (cacheTables.Length > 2)
                    {
                        if (cacheTables.IndexOf("," + tableName + ",", StringComparison.OrdinalIgnoreCase) == -1 &&
                            cacheTables.IndexOf(para.DataBase + "." + tableName + ",", StringComparison.OrdinalIgnoreCase) == -1)
                        {
                            return(false);
                        }
                    }
                    else if (nNoCacheTables.Length > 2)
                    {
                        if (nNoCacheTables.IndexOf("," + tableName + ",", StringComparison.OrdinalIgnoreCase) > -1 ||
                            nNoCacheTables.IndexOf(para.DataBase + "." + tableName + ",", StringComparison.OrdinalIgnoreCase) > -1)
                        {
                            return(false);
                        }
                    }
                    string baseKey = GetBaseKey(para, tableName);
                    string delKey  = "DeleteAutoCache:" + baseKey;
                    if (_AutoCache.Contains(delKey))
                    {
                        return(false);
                    }
                }
            }
            return(true);
            // string delKey = "DeleteAutoCache:" + baseKey;
            // return !_MemCache.Contains(delKey);
            //if (baseKey.Contains(".ActionV") || baseKey.Contains(".ProcS"))
            //{

            //    return true;
            //}
            //TimeSpan ts = DateTime.Now - _MemCache.Get<DateTime>("Del:" + baseKey);
            //return ts.TotalSeconds > 6;//5秒内无缓存。
        }
Exemplo n.º 19
0
 public void End(AopEnum action, AopInfo aopInfo)
 {
 }
Exemplo n.º 20
0
        internal static void SetCache(AopEnum action, AopInfo aopInfo)//End
        {
            if (!IsCanOperateCache(aopInfo))
            {
                return;
            }
            string baseKey = GetBaseKey(aopInfo);

            switch (action)
            {
            case AopEnum.ExeNonQuery:
            case AopEnum.Insert:
            case AopEnum.Update:
            case AopEnum.Delete:
                if (aopInfo.IsSuccess || aopInfo.RowCount > 0)
                {
                    if (action == AopEnum.Update || action == AopEnum.ExeNonQuery)
                    {
                        //检测是否指定忽略的列名(多数据库的指定?{XXX.XXX})
                        if (!IsCanRemoveCache(action, aopInfo))
                        {
                            return;
                        }
                    }
                    ReadyForRemove(baseKey);
                }
                return;
            }


            if (_MemCache.CacheType == CacheType.LocalCache && _MemCache.Count > 5000000)//数量超过500万
            {
                return;
            }
            string key = GetKey(action, aopInfo, baseKey);
            int    flag;                         //0 正常;1:未识别;2:不允许缓存

            SetBaseKeys(aopInfo, key, out flag); //存档Key,后续缓存失效 批量删除
            if (flag == 2)
            {
                return;                                          //
            }
            double cacheTime = AppConfig.Cache.DefaultCacheTime; // Math.Abs(12 - DateTime.Now.Hour) * 60 + DateTime.Now.Second;//缓存中午或到夜里1点

            if (flag == 1 || aopInfo.PageIndex > 2)              // 后面的页数,缓存时间可以短一些
            {
                cacheTime = 2;                                   //未知道操作何表时,只缓存2分钟(比如存储过程等语句)
            }
            switch (action)
            {
            case AopEnum.ExeMDataTableList:
                if (IsCanCache(aopInfo.TableList))
                {
                    JsonHelper js = new JsonHelper(false, false);
                    foreach (MDataTable table in aopInfo.TableList)
                    {
                        js.Add(Guid.NewGuid().ToString(), table.ToJson(true, true, RowOp.IgnoreNull, false, EscapeOp.No));
                    }
                    js.AddBr();
                    _MemCache.Set(key, js.ToString(), cacheTime);
                }
                break;

            case AopEnum.Select:
            case AopEnum.ExeMDataTable:
                if (IsCanCache(aopInfo.Table))
                {
                    _MemCache.Set(key, aopInfo.Table.ToJson(true, true, RowOp.IgnoreNull, false, EscapeOp.No), cacheTime);
                }
                break;

            case AopEnum.ExeScalar:
                _MemCache.Set(key, aopInfo.ExeResult, cacheTime);
                break;

            case AopEnum.Fill:
                _MemCache.Set(key, aopInfo.Row.Clone(), cacheTime);
                break;

            case AopEnum.GetCount:
                _MemCache.Set(key, aopInfo.RowCount, cacheTime);
                break;

            case AopEnum.Exists:
                _MemCache.Set(key, aopInfo.ExeResult, cacheTime);
                break;
            }
        }
Exemplo n.º 21
0
 private static string GetKey(AopEnum action, AopInfo aopInfo)
 {
     return GetKey(action, aopInfo, GetBaseKey(aopInfo));
 }
Exemplo n.º 22
0
        //End
        internal static void SetCache(AopEnum action, AopInfo aopInfo)
        {
            string baseKey = GetBaseKey(aopInfo);
            switch (action)
            {
                case AopEnum.ExeNonQuery:
                case AopEnum.Insert:
                case AopEnum.Update:
                case AopEnum.Delete:
                    if (aopInfo.IsSuccess || aopInfo.RowCount > 0)
                    {
                        ReadyForRemove(baseKey);
                    }
                    return;
            }

            //if (!IsCanOperateCache(baseKey))
            //{
            //    return;
            //}
            if (_MemCache.CacheType == CacheType.LocalCache && _MemCache.RemainMemoryPercentage < 15)//可用内存低于15%
            {
                return;
            }
            string key = GetKey(action, aopInfo, baseKey);
            int flag;//0 正常;1:未识别;2:不允许缓存
            SetBaseKeys(aopInfo, key, out flag);//存档Key,后续缓存失效 批量删除
            if (flag == 2)
            {
                return;//
            }
            double cacheTime = Math.Abs(12 - DateTime.Now.Hour) * 60 + DateTime.Now.Second;//缓存中午或到夜里1点
            if (flag == 1 || aopInfo.PageIndex > 2) // 后面的页数,缓存时间可以短一些
            {
                cacheTime = 2;//未知道操作何表时,只缓存2分钟(比如存储过程等语句)
            }
            switch (action)
            {
                case AopEnum.ExeMDataTableList:
                    if (IsCanCache(aopInfo.TableList))
                    {
                        JsonHelper js = new JsonHelper(false, false);
                        foreach (MDataTable table in aopInfo.TableList)
                        {
                            js.Add(table.TableName, table.ToJson(true, true, RowOp.IgnoreNull));
                        }
                        js.AddBr();
                        _MemCache.Set(key, js.ToString(), cacheTime);
                    }
                    break;
                case AopEnum.Select:
                case AopEnum.ExeMDataTable:
                    if (IsCanCache(aopInfo.Table))
                    {
                        _MemCache.Set(key, aopInfo.Table.ToJson(true, true, RowOp.IgnoreNull), cacheTime);
                    }
                    break;
                case AopEnum.ExeScalar:
                    _MemCache.Set(key, aopInfo.ExeResult, cacheTime);
                    break;
                case AopEnum.Fill:
                    _MemCache.Set(key, aopInfo.Row, cacheTime);
                    break;
                case AopEnum.GetCount:
                    _MemCache.Set(key, aopInfo.RowCount, cacheTime);
                    break;
            }
        }
Exemplo n.º 23
0
        private static string GetKey(AopEnum action, AopInfo aopInfo, string baseKey)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(baseKey);
            switch (action)
            {
                case AopEnum.ExeNonQuery:
                case AopEnum.Insert:
                case AopEnum.Update:
                case AopEnum.Delete:
                    return sb.ToString();
            }

            #region Key1:DBType
            sb.Append(".");
            sb.Append(action);
            if (aopInfo.DBParameters != null && aopInfo.DBParameters.Count > 0)
            {
                foreach (DbParameter item in aopInfo.DBParameters)
                {
                    sb.Append(item.ParameterName);
                    sb.Append(item.Value);
                }
            }
            if (aopInfo.CustomDbPara != null)
            {
                foreach (AopCustomDbPara item in aopInfo.CustomDbPara)
                {
                    sb.Append(item.ParaName);
                    sb.Append(item.Value);
                }
            }
            if (aopInfo.SelectColumns != null)
            {
                foreach (object item in aopInfo.SelectColumns)
                {
                    sb.Append(item);
                    sb.Append(item);
                }
            }
            #endregion

            switch (action)
            {
                case AopEnum.ExeMDataTableList:
                case AopEnum.ExeMDataTable:
                case AopEnum.ExeScalar:
                    sb.Append(aopInfo.IsProc);
                    sb.Append(aopInfo.ProcName);
                    break;
                case AopEnum.Fill:
                case AopEnum.GetCount:
                case AopEnum.Select:
                    sb.Append(aopInfo.PageIndex);
                    sb.Append(aopInfo.PageSize);
                    sb.Append(aopInfo.Where);
                    break;
            }
            return MD5.Get(sb.ToString());
        }
Exemplo n.º 24
0
        internal static void SetCache(AopEnum action, AopInfo aopInfo)//End
        {
            string baseKey = GetBaseKey(aopInfo);

            switch (action)
            {
            case AopEnum.ExeNonQuery:
            case AopEnum.Insert:
            case AopEnum.Update:
            case AopEnum.Delete:
                if (aopInfo.IsSuccess || aopInfo.RowCount > 0)
                {
                    ReadyForRemove(baseKey);
                }
                return;
            }

            //if (!IsCanOperateCache(baseKey))
            //{
            //    return;
            //}
            if (_MemCache.CacheType == CacheType.LocalCache && _MemCache.RemainMemoryPercentage < 15)//可用内存低于15%
            {
                return;
            }
            string key = GetKey(action, aopInfo, baseKey);
            int    flag;                         //0 正常;1:未识别;2:不允许缓存

            SetBaseKeys(aopInfo, key, out flag); //存档Key,后续缓存失效 批量删除
            if (flag == 2)
            {
                return;                                                                     //
            }
            double cacheTime = Math.Abs(12 - DateTime.Now.Hour) * 60 + DateTime.Now.Second; //缓存中午或到夜里1点

            if (flag == 1 || aopInfo.PageIndex > 2)                                         // 后面的页数,缓存时间可以短一些
            {
                cacheTime = 2;                                                              //未知道操作何表时,只缓存2分钟(比如存储过程等语句)
            }
            switch (action)
            {
            case AopEnum.ExeMDataTableList:
                if (IsCanCache(aopInfo.TableList))
                {
                    JsonHelper js = new JsonHelper(false, false);
                    foreach (MDataTable table in aopInfo.TableList)
                    {
                        js.Add(Guid.NewGuid().ToString(), table.ToJson(true, true, RowOp.IgnoreNull));
                    }
                    js.AddBr();
                    _MemCache.Set(key, js.ToString(), cacheTime);
                }
                break;

            case AopEnum.Select:
            case AopEnum.ExeMDataTable:
                if (IsCanCache(aopInfo.Table))
                {
                    _MemCache.Set(key, aopInfo.Table.ToJson(true, true, RowOp.IgnoreNull), cacheTime);
                }
                break;

            case AopEnum.ExeScalar:
                _MemCache.Set(key, aopInfo.ExeResult, cacheTime);
                break;

            case AopEnum.Fill:
                _MemCache.Set(key, aopInfo.Row, cacheTime);
                break;

            case AopEnum.GetCount:
                _MemCache.Set(key, aopInfo.RowCount, cacheTime);
                break;
            }
        }
Exemplo n.º 25
0
 //Begin
 internal static bool GetCache(AopEnum action, AopInfo aopInfo)
 {
     switch (action)
     {
         case AopEnum.ExeNonQuery:
         case AopEnum.Insert:
         case AopEnum.Update:
         case AopEnum.Delete:
             return false;
     }
     if (!IsCanOperateCache(aopInfo))
     {
         return false;
     }
     string baseKey = GetBaseKey(aopInfo);
     //查看是否通知我移除
     string key = GetKey(action, aopInfo, baseKey);
     object obj = _MemCache.Get(key);
     switch (action)
     {
         case AopEnum.ExeMDataTableList:
             if (obj != null)
             {
                 List<MDataTable> list = new List<MDataTable>();
                 Dictionary<string, string> jd = JsonHelper.Split(obj.ToString());
                 if (jd != null && jd.Count > 0)
                 {
                     foreach (KeyValuePair<string, string> item in jd)
                     {
                         list.Add(MDataTable.CreateFrom(item.Value));
                     }
                 }
                 aopInfo.TableList = list;
             }
             break;
         case AopEnum.Select:
         case AopEnum.ExeMDataTable:
             if (obj != null)
             {
                 aopInfo.Table = MDataTable.CreateFrom(obj.ToString());
             }
             break;
         case AopEnum.ExeScalar:
             if (obj != null)
             {
                 aopInfo.ExeResult = obj;
             }
             break;
         case AopEnum.Fill:
             if (obj != null)
             {
                 MDataRow row = obj as MDataRow;
                 if (_MemCache.CacheType == CacheType.LocalCache)
                 {
                     row = row.Clone();
                 }
                 aopInfo.Row = row;
                 aopInfo.IsSuccess = true;
             }
             break;
         case AopEnum.GetCount:
             if (obj != null)
             {
                 aopInfo.RowCount = int.Parse(obj.ToString());
             }
             break;
     }
     baseKey = key = null;
     return obj != null;
 }
Exemplo n.º 26
0
Arquivo: Aop.cs Projeto: Angliy/Common
 public void End(AopEnum action, bool success, object id, params object[] aopInfo)
 {
 }
Exemplo n.º 27
0
 public void End(AopEnum action)
 {
     if (outerAop != null)
     {
         outerAop.End(action, Para);
     }
     if (!isHasCache && !IsTxtDataBase)
     {
         AutoCache.SetCache(action, Para); //�ҿ���û��Cache
     }
 }
Exemplo n.º 28
0
 public void End(AopEnum action, AopInfo aopInfo)
 {
 }
Exemplo n.º 29
0
Arquivo: Aop.cs Projeto: Angliy/Common
 public void Begin(AopEnum action, string objName, params object[] aopInfo)
 {
 }