예제 #1
0
        /// <summary>
        /// 保存最新服务状态
        /// </summary>
        /// <param name="servicestate">服务状态</param>
        /// <param name="serviceid">服务id</param>
        /// <param name="costTime">花费时间</param>
        /// <param name="serverAppType">链接服务监控时,是App还是web</param>
        /// <returns></returns>
        public async static Task SaveNewState(int servicestate, int serviceid, int?costTime = null, int?serverAppType = null)
        {
            using (var db = new BizDataContext())
            {
                var entity = await db.Set <T_HTZ_ServiceState>().Where(p => p.State == v_common.YesState && p.ObjectId == serviceid && p.ServiceType == serverAppType).FirstOrDefaultAsync();

                if (entity == null)
                {
                    entity                     = new T_HTZ_ServiceState();
                    entity.CreateTime          = DateTime.Now;
                    entity.HTZ_ServiceState_Id = await db.GetNextIdentity_IntAsync();

                    entity.ServiceState    = servicestate;
                    entity.ServiceType     = serverAppType;//链接服务监控时,是App还是web
                    entity.State           = v_common.YesState;
                    entity.ObjectId        = serviceid;
                    entity.RequestCostTime = costTime;
                    entity.UpdateTime      = entity.CreateTime;

                    await db.InsertAsync(entity);
                }
                else
                {
                    entity.UpdateTime      = DateTime.Now;
                    entity.ServiceState    = servicestate;
                    entity.RequestCostTime = costTime;

                    await db.UpdatePartialAsync(entity, p => new { p.UpdateTime, p.ServiceState, p.RequestCostTime });
                }
            }
        }
예제 #2
0
        public static async Task SaveServerDisks(BizDataContext db, v_server server)
        {
            var dbdisks = await db.Set <T_HTZ_ServerHardDisk>().Where(p => p.State == v_common.YesState && p.HTZ_ServerId == server.id).ToListAsync();

            foreach (var item in server.disks)
            {
                var disk = dbdisks.Where(p => p.HTZ_ServerHardDisk_Name == item.name && p.State == v_common.YesState).FirstOrDefault();

                if (disk == null)
                {
                    disk = new T_HTZ_ServerHardDisk();
                    disk.HTZ_ServerHardDisk_Name = item.name;
                    disk.CreateTime            = DateTime.Now;
                    disk.UpdateTime            = DateTime.Now;
                    disk.TotalCapacity         = (int)(item.Size / 1024 / 1024 / 1024);
                    disk.UserCapacity          = (int)(item.FreeSpace / 1024 / 1024 / 1024);
                    disk.State                 = v_common.YesState;
                    disk.UpdateTime            = disk.CreateTime;
                    disk.HTZ_ServerHardDisk_Id = await db.GetNextIdentity_IntAsync();

                    disk.HTZ_ServerId = server.id;

                    await db.InsertAsync(disk);
                }
                else
                {
                    disk.UpdateTime    = DateTime.Now;
                    disk.TotalCapacity = (int)(item.Size / 1024 / 1024 / 1024);
                    disk.UserCapacity  = (int)(item.FreeSpace / 1024 / 1024 / 1024);
                    await db.UpdatePartialAsync(disk, p => new { p.UpdateTime, p.TotalCapacity, p.UserCapacity });
                }
            }
        }
예제 #3
0
        private static async Task SaveServerLog(BizDataContext db, v_server server, int serverstate)
        {
            var log = new T_HTZ_ServerLog();

            log.CpuOccupancy     = server.cpu;
            log.CreateTime       = DateTime.Now;
            log.HTZ_ServerId     = server.id;
            log.HTZ_ServerLog_Id = await db.GetNextIdentity_IntAsync();

            if (server.totalmemory > 0)
            {
                log.MemoryOccupancy = (int)((1 - ((double)server.freememory / server.totalmemory)) * 100);
            }

            log.ServerState = serverstate;
            log.State       = v_common.YesState;

            await db.InsertAsync(log);
        }
예제 #4
0
        public async static Task SaveLivingIndexData(string html, XmlNode xmlRoot, BizDataContext db)
        {
            var rootNode = CommonHelper.GetRootNode(html);

            //获取对实体解析的配置节点
            var infoConfig = xmlRoot.SelectSingleNode("LivingIndexConfig");

            var date = DateTime.Now;


            var entity = new T_HTZ_LivingIndex();


            //解析应该包含多个子节点,每个子节点表示一个属性,这里进行循环赋值
            foreach (XmlNode property in infoConfig.ChildNodes)
            {
                entity = CommonHelper.GetProperty(entity, rootNode, property);
            }

            //查询天气数据
            var dbentity = (from a in db.Set<T_HTZ_LivingIndex>()

                            where a.CreateTime == DateTime.Now.Date

                            select a).FirstOrDefault();

            if (dbentity != null)
            {
                entity.HTZ_LivingIndex_Id = dbentity.HTZ_LivingIndex_Id;
                entity.CreateTime = dbentity.CreateTime;
                entity.UpdateTime = DateTime.Now;

                await db.UpdateAsync(entity);
            }
            else
            {
                entity.HTZ_LivingIndex_Id = db.GetNextIdentity_Int();
                entity.CreateTime = DateTime.Now.Date;

                await db.InsertAsync(entity);
            }

        }
예제 #5
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);
        }
예제 #6
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);
        }
예제 #7
0
        public async static Task SaveWeekData(string html, XmlNode xmlRoot, BizDataContext db)
        {
            var rootNode = CommonHelper.GetRootNode(html);

            //获取信息列表的配置节点
            var listConfig = xmlRoot.SelectSingleNode("ListConfig");

            //这里是为了最终找到modelListNodes变量的值,也就是列表
            //在此之前可能需要多次的剥离无效数据,因此使用了foreach循环
            //正常流程应该是多次SelectSingleNode后,进行一次SelectNodes,获取到列表
            HtmlNode modelNode = null;
            HtmlNodeCollection modelListNodes = null;
            foreach (XmlNode item in listConfig.ChildNodes)
            {
                if (modelNode == null)
                {
                    modelNode = rootNode;
                }

                if (item.Attributes["issingleselect"].Value.ToBool())
                {
                    //多次剥离无效数据
                    modelNode = modelNode.SelectSingleNode(item.Attributes["signstr"].Value);
                }
                else
                {
                    //最终获取到列表,此时应该循环结束
                    modelListNodes = modelNode.SelectNodes(item.Attributes["signstr"].Value);
                    break;
                }
            }

            //获取对实体解析的配置节点
            var infoConfig = xmlRoot.SelectSingleNode("WeatherConfig");

            var date = DateTime.Now;

            var weatherList = await db.Set<T_TemperatureHumidity>().Where(p => p.ActionDate >= DateTime.Now.Date).ToListAsync();

            //对上面获取到的列表循环处理
            foreach (HtmlNode info in modelListNodes)
            {

                T_TemperatureHumidity entity = new T_TemperatureHumidity();

                var detailUrl = string.Empty;

                //解析应该包含多个子节点,每个子节点表示一个属性,这里进行循环赋值
                foreach (XmlNode property in infoConfig.ChildNodes)
                {
                    entity = CommonHelper.GetProperty(entity, info, property);
                }

                entity.State = v_common.YesState;
                entity.ActionDate = date.Date;
                entity.ActionYear = date.Year.ToString();
                entity.CreateTime = DateTime.Now;

                var id = weatherList.Where(p => p.ActionDate == date.Date).Select(p => p.TemperatureHumidity_Id).FirstOrDefault();

                if (id > 0)
                {
                    entity.TemperatureHumidity_Id = id;
                    entity.UpdateTime = DateTime.Now;

                    await db.UpdatePartialAsync(entity, p => new { p.TemperatureStr, p.Wheather, p.Wind, p.WindDirection, p.UpdateTime });
                }
                else
                {
                    entity.TemperatureHumidity_Id = await db.GetNextIdentity_IntAsync();
                    await db.InsertAsync(entity);
                }

                date = date.AddDays(1);
            }
        }
예제 #8
0
        private async static Task SaveInfomationDetail(string pageSource, T_Information info, XmlNode infoNode, BizDataContext db, v_crawler crawler, string detailUrl)
        {
            var rootNode = CommonHelper.GetRootNode(pageSource);

            if (info != null)
            {
                var xmlRoot = infoNode.SelectSingleNode("DataDetail");

                var detailHost = new Regex(@"\S+/").Match(detailUrl).Value;

                //新闻解析应该包含多个子节点,每个子节点表示一个属性,这里进行循环赋值
                foreach (XmlNode property in xmlRoot.ChildNodes)
                {
                    info = CommonHelper.GetProperty(info, rootNode, property, detailHost);
                }


                var info_infotag = new T_InfoType_Information()
                {
                    InfoType_Information_Id = await db.GetNextIdentity_IntAsync(),
                    CreateTime    = DateTime.Now,
                    InformationId = info.Information_Id,
                    InfoTypeId    = crawler.infotype,
                };

                var informationcontent = new T_Information_Content()
                {
                    Information_Content_Id = await db.GetNextIdentity_IntAsync(),
                    Conent      = info.Content,
                    ContentType = (int)Information_Content_ContentTypeEnum.TextWords,

                    OrderIndex    = 0,
                    InformationId = info.Information_Id,
                    State         = 0,
                    CreateTime    = DateTime.Now,
                };

                info.ClassifyId  = (int)InfoSource.Crawler;
                info.PublishTime = info.CreateTime;
                info.IsTop       = false;



                if (!string.IsNullOrEmpty(informationcontent.Conent))
                {
                    var regex    = new Regex("<img.*?>");
                    var imgMtach = regex.Match(info.Content);
                    if (imgMtach.Success)
                    {
                        var img      = imgMtach.Value;
                        var srcMatch = new Regex("src=\".*?\"").Match(img);
                        if (srcMatch.Success)
                        {
                            var src = srcMatch.Value;

                            var att = new T_Attachment()
                            {
                                Attachment_ID = await db.GetNextIdentity_IntAsync(),
                                FilePath      = src,

                                State      = 0,
                                CreateTime = DateTime.Now,
                            };
                            await db.InsertAsync(att);
                        }
                    }

                    await db.InsertAsync(info);

                    await db.InsertAsync(info_infotag);

                    await db.InsertAsync(informationcontent);
                }
            }
        }