/// <summary>
        /// 更新IIS缓存中指定Id记录
        /// </summary>
        /// <param name="model">记录实体</param>
        public void SetModelForCache(DataAccess.Model.ErrorLog model)
        {
            //从缓存中读取记录列表
            var list = GetList();

            //从缓存中删除记录
            DelCache(model.Id);
            //添加记录
            list.Add(model);
        }
Exemple #2
0
        /// <summary>
        /// 给实体赋值
        /// </summary>
        /// <param name="model">实体</param>
        /// <param name="colName">列名</param>
        /// <param name="value">值</param>
        public void SetModelValue(DataAccess.Model.ErrorLog model, string colName, object value)
        {
            if (model == null || string.IsNullOrEmpty(colName))
            {
                return;
            }

            //返回指定条件的实体
            switch (colName)
            {
            case "Id":
                model.Id = (int)value;
                break;

            case "ErrTime":
                model.ErrTime = (DateTime)value;
                break;

            case "BrowserVersion":
                model.BrowserVersion = (string)value;
                break;

            case "BrowserType":
                model.BrowserType = (string)value;
                break;

            case "Ip":
                model.Ip = (string)value;
                break;

            case "PageUrl":
                model.PageUrl = (string)value;
                break;

            case "ErrMessage":
                model.ErrMessage = (string)value;
                break;

            case "ErrSource":
                model.ErrSource = (string)value;
                break;

            case "StackTrace":
                model.StackTrace = (string)value;
                break;

            case "HelpLink":
                model.HelpLink = (string)value;
                break;

            case "Type":
                model.Type = ConvertHelper.Ctinyint(value);
                break;
            }
        }
Exemple #3
0
        /// <summary>
        /// 给实体赋值
        /// </summary>
        /// <param name="model">实体</param>
        /// <param name="dic">列名与值</param>
        public void SetModelValue(DataAccess.Model.ErrorLog model, Dictionary <string, object> dic)
        {
            if (model == null || dic == null)
            {
                return;
            }

            //遍历字典,逐个给字段赋值
            foreach (var d in dic)
            {
                SetModelValue(model, d.Key, d.Value);
            }
        }
Exemple #4
0
        /// <summary>
        /// 返回实体中指定字段名的值
        /// </summary>
        /// <param name="model">实体</param>
        /// <param name="colName">获取的字段名</param>
        /// <returns></returns>
        private object GetFieldValue(DataAccess.Model.ErrorLog model, string colName)
        {
            if (model == null || string.IsNullOrEmpty(colName))
            {
                return(null);
            }
            //返回指定的列值
            switch (colName)
            {
            case "Id":
                return(model.Id);

            case "ErrTime":
                return(model.ErrTime);

            case "BrowserVersion":
                return(model.BrowserVersion);

            case "BrowserType":
                return(model.BrowserType);

            case "Ip":
                return(model.Ip);

            case "PageUrl":
                return(model.PageUrl);

            case "ErrMessage":
                return(model.ErrMessage);

            case "ErrSource":
                return(model.ErrSource);

            case "StackTrace":
                return(model.StackTrace);

            case "HelpLink":
                return(model.HelpLink);

            case "Type":
                return(model.Type);
            }

            return(null);
        }
Exemple #5
0
        /// <summary>
        /// 更新IIS缓存中指定Id记录
        /// </summary>
        /// <param name="model">记录实体</param>
        public void SetModelForCache(DataAccess.Model.ErrorLog model)
        {
            if (model == null)
            {
                return;
            }

            //从缓存中删除记录
            DelCache(model.Id);

            //从缓存中读取记录列表
            var list = GetList();

            if (list == null)
            {
                list = new List <DataAccess.Model.ErrorLog>();
            }
            //添加记录
            list.Add(model);
        }
Exemple #6
0
        /// <summary>
        /// 将ErrorLog记录实体由普通的实体(DataAccess.Model.ErrorLog)转换为SubSonic插件生成的实体
        /// </summary>
        /// <param name="model">普通的实体(DataAccess.Model.ErrorLog)</param>
        /// <returns>ErrorLog</returns>
        public ErrorLog Transform(DataAccess.Model.ErrorLog model)
        {
            if (model == null)
            {
                return(null);
            }

            return(new ErrorLog
            {
                Id = model.Id,
                ErrTime = model.ErrTime,
                BrowserVersion = model.BrowserVersion,
                BrowserType = model.BrowserType,
                Ip = model.Ip,
                PageUrl = model.PageUrl,
                ErrMessage = model.ErrMessage,
                ErrSource = model.ErrSource,
                StackTrace = model.StackTrace,
                HelpLink = model.HelpLink,
                Type = model.Type,
            });
        }
Exemple #7
0
        /// <summary>
        /// 从IIS缓存中获取指定条件的记录
        /// </summary>
        /// <param name="conditionColName">条件列名</param>
        /// <param name="value">条件值</param>
        /// <returns>DataAccess.Model.ErrorLog</returns>
        public DataAccess.Model.ErrorLog GetModelForCache(string conditionColName, object value)
        {
            try
            {
                //从缓存中获取List
                var list = GetList();
                DataAccess.Model.ErrorLog           model      = null;
                Expression <Func <ErrorLog, bool> > expression = null;

                //返回指定条件的实体
                switch (conditionColName)
                {
                case "Id":
                    model      = list.SingleOrDefault(x => x.Id == (int)value);
                    expression = x => x.Id == (int)value;
                    break;

                case "ErrTime":
                    model      = list.SingleOrDefault(x => x.ErrTime == (DateTime)value);
                    expression = x => x.ErrTime == (DateTime)value;
                    break;

                case "BrowserVersion":
                    model      = list.SingleOrDefault(x => x.BrowserVersion == (string)value);
                    expression = x => x.BrowserVersion == (string)value;
                    break;

                case "BrowserType":
                    model      = list.SingleOrDefault(x => x.BrowserType == (string)value);
                    expression = x => x.BrowserType == (string)value;
                    break;

                case "Ip":
                    model      = list.SingleOrDefault(x => x.Ip == (string)value);
                    expression = x => x.Ip == (string)value;
                    break;

                case "PageUrl":
                    model      = list.SingleOrDefault(x => x.PageUrl == (string)value);
                    expression = x => x.PageUrl == (string)value;
                    break;

                case "ErrMessage":
                    model      = list.SingleOrDefault(x => x.ErrMessage == (string)value);
                    expression = x => x.ErrMessage == (string)value;
                    break;

                case "ErrSource":
                    model      = list.SingleOrDefault(x => x.ErrSource == (string)value);
                    expression = x => x.ErrSource == (string)value;
                    break;

                case "StackTrace":
                    model      = list.SingleOrDefault(x => x.StackTrace == (string)value);
                    expression = x => x.StackTrace == (string)value;
                    break;

                case "HelpLink":
                    model      = list.SingleOrDefault(x => x.HelpLink == (string)value);
                    expression = x => x.HelpLink == (string)value;
                    break;

                case "Type":
                    model      = list.SingleOrDefault(x => x.Type == (byte)value);
                    expression = x => x.Type == (byte)value;
                    break;

                default:
                    return(null);
                }

                if (model == null)
                {
                    //从数据库中读取
                    var tem = ErrorLog.SingleOrDefault(expression);
                    if (tem == null)
                    {
                        return(null);
                    }
                    else
                    {
                        //对查询出来的实体进行转换
                        model = Transform(tem);
                        SetModelForCache(model);
                        return(model);
                    }
                }
                else
                {
                    return(model);
                }
            }
            catch (Exception e)
            {
                //记录日志
                CommonBll.WriteLog("从IIS缓存中获取ErrorLog表记录时出现异常", e);

                return(null);
            }
        }