Exemple #1
0
        private void DoWork(object state)
        {
            //执行任务
            ServerStateEntity entity = new ServerStateEntity();
            var computer             = ComputerHelper.GetComputerInfo();

            entity.F_ARM     = computer.RAMRate;
            entity.F_CPU     = computer.CPURate;
            entity.F_IIS     = "0";
            entity.F_WebSite = _hostingEnvironment.ContentRootPath;
            new ServerStateService(_context).SubmitForm(entity).GetAwaiter().GetResult();
        }
Exemple #2
0
        /// <summary>
        /// 保存当前服务器状态
        /// </summary>
        public void RemindDemo()
        {
            DateTime nowtime = DateTime.Now;

            try
            {
                //保存数据
                ServerStateEntity entity = new ServerStateEntity();
                entity.F_ARM     = ServerStateHelper.GetUseARM();
                entity.F_CPU     = ServerStateHelper.GetCPU();
                entity.F_IIS     = ServerStateHelper.GetIISConnection();
                entity.F_WebSite = ServerStateHelper.GetSiteName();
                new ServerStateApp().SubmitForm(entity);
            }
            catch (Exception ex)
            {
                return;
            }
        }
        public void SubmitForm(ServerStateEntity entity)
        {
            var old = service.IQueryable(a => a.F_WebSite == entity.F_WebSite && a.F_Date == DateTime.Now.Date).FirstOrDefault();

            if (old != null)
            {
                entity.F_Id   = old.F_Id;
                entity.F_Date = old.F_Date;
                entity.F_Cout = old.F_Cout + 1;
                entity.F_ARM  = Math.Round(((old.F_ARM).ToDouble() * old.F_Cout + entity.F_ARM.ToDouble()) / entity.F_Cout, 2).ToString();
                entity.F_CPU  = Math.Round(((old.F_CPU).ToDouble() * old.F_Cout + entity.F_CPU.ToDouble()) / entity.F_Cout, 2).ToString();
                entity.F_IIS  = Math.Round(((old.F_IIS).ToDouble() * old.F_Cout + entity.F_IIS.ToDouble()) / entity.F_Cout, 0).ToString();
                service.Update(entity);
            }
            else
            {
                entity.F_Id   = Utils.GuId();
                entity.F_Cout = 1;
                entity.F_Date = DateTime.Now.Date;
                service.Insert(entity);
            }
        }
        public async Task <AlwaysResult> Start()
        {
            AlwaysResult obj = new AlwaysResult();

            try
            {
                ServerStateEntity entity = new ServerStateEntity();
                var computer             = ComputerHelper.GetComputerInfo();
                entity.F_ARM     = computer.RAMRate;
                entity.F_CPU     = computer.CPURate;
                entity.F_IIS     = "0";
                entity.F_WebSite = _hostingEnvironment.ContentRootPath;
                await _server.SubmitForm(entity);

                obj.state   = ResultType.success.ToString();
                obj.message = "服务器状态更新成功!";
            }
            catch (Exception ex)
            {
                obj.state   = ResultType.error.ToString();
                obj.message = "服务器状态更新失败!" + ex.Message;
            }
            return(obj);
        }