Esempio n. 1
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 });
                }
            }
        }
Esempio n. 2
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 });
                }
            }
        }
Esempio n. 3
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);
            }
        }