public bool Create(SysExceptionModel model)
 {
     try
     {
         if (exceptionRepository.IsExist(model.Id))
         {
             return(false);
         }
         SysException entity = new SysException
         {
             Id         = ResultHelper.NewId,
             HelpLink   = model.HelpLink,
             Message    = model.Message,
             Source     = model.Source,
             StackTrace = model.StackTrace,
             TargetSite = model.TargetSite,
             Data       = model.Data,
             CreateTime = model.CreateTime
         };
         return(exceptionRepository.Create(entity) == 1);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Esempio n. 2
0
 public int Create(SysExceptionModel entity)
 {
     using (SysExceptionContext db = new SysExceptionContext())
     {
         db.sysExceptions.Add(entity);
         return(db.SaveChanges());
     }
 }
        /// <summary>
        /// 校验Excel数据,这个方法一般用于重写校验逻辑
        /// </summary>
        public virtual bool CheckImportData(string fileName, List <SysExceptionModel> list, ref ValidationErrors errors)
        {
            var targetFile = new FileInfo(fileName);

            if (!targetFile.Exists)
            {
                errors.Add("导入的数据文件不存在");
                return(false);
            }

            var excelFile = new ExcelQueryFactory(fileName);

            //对应列头
            excelFile.AddMapping <SysExceptionModel>(x => x.HelpLink, "帮助连接");
            excelFile.AddMapping <SysExceptionModel>(x => x.Message, "异常信息");
            excelFile.AddMapping <SysExceptionModel>(x => x.Source, "来源类库");
            excelFile.AddMapping <SysExceptionModel>(x => x.StackTrace, "堆栈");
            excelFile.AddMapping <SysExceptionModel>(x => x.TargetSite, "目标站点");
            excelFile.AddMapping <SysExceptionModel>(x => x.Data, "程序集");
            excelFile.AddMapping <SysExceptionModel>(x => x.CreateTime, "发生时间");

            //SheetName
            var excelContent = excelFile.Worksheet <SysExceptionModel>(0);
            int rowIndex     = 1;

            //检查数据正确性
            foreach (var row in excelContent)
            {
                var errorMessage = new StringBuilder();
                var entity       = new SysExceptionModel();
                entity.Id         = row.Id;
                entity.HelpLink   = row.HelpLink;
                entity.Message    = row.Message;
                entity.Source     = row.Source;
                entity.StackTrace = row.StackTrace;
                entity.TargetSite = row.TargetSite;
                entity.Data       = row.Data;
                entity.CreateTime = row.CreateTime;

                //=============================================================================
                if (errorMessage.Length > 0)
                {
                    errors.Add(string.Format(
                                   "第 {0} 列发现错误:{1}{2}",
                                   rowIndex,
                                   errorMessage,
                                   "<br/>"));
                }
                list.Add(entity);
                rowIndex += 1;
            }
            if (errors.Count > 0)
            {
                return(false);
            }
            return(true);
        }
Esempio n. 4
0
        /// <summary>
        /// 添加异常记录
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Insert(SysExceptionModel model)
        {
            StringBuilder sql = new StringBuilder();

            sql.AppendLine("INSERT INTO SYS_EXCEPTION");
            sql.AppendLine("  (EX_ID,");
            sql.AppendLine("   EX_HELPLINK,");
            sql.AppendLine("   EX_MESSAGE,");
            sql.AppendLine("   EX_SOURCE,");
            sql.AppendLine("   EX_STACK,");
            sql.AppendLine("   EX_TARGET,");
            sql.AppendLine("   EX_DATA,");
            sql.AppendLine("   EX_NAMESPACE,");
            sql.AppendLine("   EX_CLASS,");
            sql.AppendLine("   EX_METHOD,");
            sql.AppendLine("   EX_TYPE,");
            sql.AppendLine("   EX_DESC,");
            sql.AppendLine("   CREATE_USER,");
            sql.AppendLine("   LM_USER)");
            sql.AppendLine("VALUES");
            sql.AppendLine("  ($EX_ID,");
            sql.AppendLine("   $EX_HELPLINK,");
            sql.AppendLine("   $EX_MESSAGE,");
            sql.AppendLine("   $EX_SOURCE,");
            sql.AppendLine("   $EX_STACK,");
            sql.AppendLine("   $EX_TARGET,");
            sql.AppendLine("   $EX_DATA,");
            sql.AppendLine("   $EX_NAMESPACE,");
            sql.AppendLine("   $EX_CLASS,");
            sql.AppendLine("   $EX_METHOD,");
            sql.AppendLine("   $EX_TYPE,");
            sql.AppendLine("   $EX_DESC,");
            sql.AppendLine("   $CREATE_USER,");
            sql.AppendLine("   $LM_USER)");
            SQLParameter[] parms =
            {
                new SQLParameter("EX_ID",        typeof(string), model.EX_ID),
                new SQLParameter("EX_HELPLINK",  typeof(string), model.EX_HELPLINK),
                new SQLParameter("EX_MESSAGE",   typeof(string), model.EX_MESSAGE),
                new SQLParameter("EX_SOURCE",    typeof(string), model.EX_SOURCE),
                new SQLParameter("EX_STACK",     typeof(string), model.EX_STACK),
                new SQLParameter("EX_TARGET",    typeof(string), model.EX_TARGET),
                new SQLParameter("EX_DATA",      typeof(string), model.EX_DATA),
                new SQLParameter("EX_NAMESPACE", typeof(string), model.EX_NAMESPACE),
                new SQLParameter("EX_CLASS",     typeof(string), model.EX_CLASS),
                new SQLParameter("EX_METHOD",    typeof(string), model.EX_METHOD),
                new SQLParameter("EX_TYPE",      typeof(string), model.EX_TYPE),
                new SQLParameter("EX_DESC",      typeof(string), model.EX_DESC),
                new SQLParameter("CREATE_USER",  typeof(string), model.CREATE_USER),
                new SQLParameter("LM_USER",      typeof(string), model.LM_USER)
            };
            int result = DB.CustomExecuteWithReturn(new SQLParamCondition(sql.ToString(), parms));

            return(result);
        }
Esempio n. 5
0
        public ActionResult Details(string id)
        {
            SysException      entity = exceptionBLL.GetById(id);
            SysExceptionModel info   = new SysExceptionModel()
            {
                Id         = entity.Id,
                HelpLink   = entity.HelpLink,
                Message    = entity.Message,
                Source     = entity.Source,
                StackTrace = entity.StackTrace,
                TargetSite = entity.TargetSite,
                Data       = entity.Data,
                CreateTime = entity.CreateTime,
            };

            return(View(info));
        }
Esempio n. 6
0
        public ActionResult Details(string id)
        {
            SysExceptionModel entity = exceptionBLL.GetById(id);

            //SysExceptionModel info = new SysExceptionModel()
            //{
            //    Id = entity.Id,
            //    HelpLink = entity.HelpLink,
            //    Message = entity.Message,
            //    Source = entity.Source,
            //    StackTrace = entity.StackTrace,
            //    TargetSite = entity.TargetSite,
            //    Data = entity.Data,
            //    CreateTime = entity.CreateTime,
            //};
            return(View(entity));
        }
Esempio n. 7
0
        public virtual SysExceptionModel GetById(string id)
        {
            if (IsExist(id))
            {
                SysException      entity = m_Rep.GetById(id);
                SysExceptionModel model  = new SysExceptionModel();
                model.Id         = entity.Id;
                model.HelpLink   = entity.HelpLink;
                model.Message    = entity.Message;
                model.Source     = entity.Source;
                model.StackTrace = entity.StackTrace;
                model.TargetSite = entity.TargetSite;
                model.Data       = entity.Data;
                model.CreateTime = entity.CreateTime;

                return(model);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 8
0
 /// <summary>
 /// 加入异常日志
 /// </summary>
 /// <param name="ex">异常</param>
 public static void WriteException(Exception ex)
 {
     try
     {
         using (SysExceptionContext db = new SysExceptionContext())
         {
             SysExceptionModel model = new SysExceptionModel()
             {
                 Id         = ResultHelper.NewId,
                 HelpLink   = ex.HelpLink,
                 Message    = ex.Message,
                 Source     = ex.Source,
                 StackTrace = ex.StackTrace,
                 TargetSite = ex.TargetSite.ToString(),
                 Assembly   = ex.Data.ToString(),
                 CreateTime = ResultHelper.NowTime
             };
             db.sysExceptions.Add(model);
             db.SaveChanges();
         }
     }
     catch (Exception ep)
     {
         try
         {
             //异常失败写入txt
             string path    = @"~/exceptionLog.txt";
             string txtPath = System.Web.HttpContext.Current.Server.MapPath(path);//获取绝对路径
             using (StreamWriter sw = new StreamWriter(txtPath, true, Encoding.Default))
             {
                 sw.WriteLine((ex.Message + "|" + ex.StackTrace + "|" + ep.Message + "|" + DateTime.Now.ToString()).ToString());
                 sw.Dispose();
                 sw.Close();
             }
             return;
         }
         catch { return; }
     }
 }
Esempio n. 9
0
        /// <summary>
        /// 修改一个实体
        /// </summary>
        /// <param name="errors">持久的错误信息</param>
        /// <param name="model">模型</param>
        /// <returns>是否成功</returns>
        public virtual bool Edit(ref ValidationErrors errors, SysExceptionModel model)
        {
            try
            {
                SysException entity = m_Rep.GetById(model.Id);
                if (entity == null)
                {
                    errors.add(Suggestion.Disable);
                    return(false);
                }
                entity.Id         = model.Id;
                entity.HelpLink   = model.HelpLink;
                entity.Message    = model.Message;
                entity.Source     = model.Source;
                entity.StackTrace = model.StackTrace;
                entity.TargetSite = model.TargetSite;
                entity.Data       = model.Data;
                entity.CreateTime = model.CreateTime;



                if (m_Rep.Edit(entity))
                {
                    return(true);
                }
                else
                {
                    errors.add(Suggestion.EditFail);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                errors.add(ex.Message);
                ExceptionHandler.WriteException(ex);
                //ExceptionHander.WriteException(ex);
                return(false);
            }
        }
Esempio n. 10
0
        public virtual bool Create(ref ValidationErrors errors, SysExceptionModel model)
        {
            try
            {
                SysException entity = m_Rep.GetById(model.Id);
                if (entity != null)
                {
                    errors.Add(Suggestion.PrimaryRepeat);
                    return(false);
                }
                entity            = new SysException();
                entity.Id         = model.Id;
                entity.HelpLink   = model.HelpLink;
                entity.Message    = model.Message;
                entity.Source     = model.Source;
                entity.StackTrace = model.StackTrace;
                entity.TargetSite = model.TargetSite;
                entity.Data       = model.Data;
                entity.CreateTime = model.CreateTime;


                if (m_Rep.Create(entity))
                {
                    return(true);
                }
                else
                {
                    errors.Add(Suggestion.InsertFail);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return(false);
            }
        }
Esempio n. 11
0
        public JsonResult Delete(string id)
        {
            SysExceptionModel model = exceptionBLL.GetById(id);

            if (!string.IsNullOrWhiteSpace(id))
            {
                if (exceptionBLL.Delete(ref errors, id))
                {
                    LogHandler.WriteServiceLog("虚拟用户", "Id:" + model.Id + ",Name:" + model.Data, "成功", "删除", "Exception");
                    return(Json(JsonHandler.CreateMessage(1, "删除成功"), JsonRequestBehavior.AllowGet));
                }
                else
                {
                    string ErrorCol = errors.Error;
                    LogHandler.WriteServiceLog("虚拟用户", "Id:" + model.Id + ",Name:" + model.Data + "," + ErrorCol, "失败", "删除", "Exception");
                    return(Json(JsonHandler.CreateMessage(0, "删除失败" + ErrorCol), JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                return(Json(JsonHandler.CreateMessage(0, "删除失败", "无效的实体"), JsonRequestBehavior.AllowGet));
            }
        }
Esempio n. 12
0
        public ActionResult Details(string id)
        {
            SysExceptionModel info = exceptionBLL.GetById(id);

            return(View(info));
        }
Esempio n. 13
0
        public ActionResult Details(string id)
        {
            SysExceptionModel entity = exceptionBLL.GetById(id);

            return(View(entity));
        }
        public JsonResult GetById(string exId)
        {
            SysExceptionModel model = _exceptionApp.GetById(exId);

            return(Json(model, JsonRequestBehavior.AllowGet));
        }