예제 #1
0
        public async static Task SendErrorMessage(BizDataContext db, CrawlerException e)
        {
            string msg = string.Format("{0},发生了异常,异常信息为:<br/>{1}<br/>更多信息请打开高新区智慧生活后台查看。", e.servicename, e.exceptionbrief);

            var handlers = await db.Set <T_HTZ_ExceptionHandler>().Where(p => p.ServiceType == e.crawlertype && p.State == v_common.YesState).ToListAsync();

            var nearLog = await db.Set <T_HTZ_ExceptionHandlerLog>().Where(p => p.ObjectId == e.serviceid && p.State == v_common.YesState).OrderByDescending(p => p.HTZ_ExceptionHandlerLog_Id).FirstOrDefaultAsync();

            if (nearLog != null && nearLog.CreateTime > DateTime.Now.AddHours(-8))
            {
                return;
            }

            var mails = handlers.Where(p => !string.IsNullOrEmpty(p.Email)).Select(p => p.Email).ToArray();

            if (mails.Length < 1)
            {
                return;
            }

            var mail = new MyMailManager();

            mail.SetMailMessageAndSend(msg, mails);

            var log = new T_HTZ_ExceptionHandlerLog();

            log.CreateTime   = DateTime.Now;
            log.HandlerIdStr = string.Join(",", handlers.Select(p => p.HTZ_ExceptionHandler_Id).ToArray());
            log.HTZ_ExceptionHandlerLog_Id = await db.GetNextIdentity_IntAsync();

            log.Message     = msg;
            log.MessageType = (int)HTZ_ExceptionHandlerLog_MessageTypeEnum.Mail;
            log.ObjectId    = e.serviceid;
            log.State       = v_common.YesState;
            await db.InsertAsync(log);
        }
예제 #2
0
        /// <summary>
        /// 保存异常信息
        /// </summary>
        /// <returns></returns>
        public async static Task SaveException(CrawlerException e)
        {
            using (var db = new BizDataContext())
            {
                var his = new T_HTZ_ExceptionHistory();

                his.CreateTime              = DateTime.Now;
                his.ExceptionBreif          = e.exceptionbrief;
                his.ExceptionMessage        = e.exceptionmessage;
                his.HTZ_ExceptionHistory_Id = await db.GetNextIdentity_IntAsync();

                his.IsRead      = false;
                his.ServiceId   = e.serviceid;
                his.State       = v_common.YesState;
                his.StatusCode  = e.statuscode;
                his.ServiceType = e.serverAppType;//链接服务监控时,是App还是web

                await db.InsertAsync(his);

                await SendErrorMessage(db, e);
            }

            await SaveNewState((int)HTZ_ServiceState_ServiceStateEnum.Wrong, e.serviceid, null, e.serverAppType);
        }