Esempio n. 1
0
        public async Task <HealthCheckResult> CheckAsync(CancellationToken cancellationToken = default)
        {
            var timer = CheckTimer.Start();

            try
            {
                var matchContent = _options.ExpectedContent != null;

                var completionOption = matchContent
                    ? HttpCompletionOption.ResponseContentRead
                    : HttpCompletionOption.ResponseHeadersRead;

                using (var response = await HttpClient
                                      .GetAsync(_uri, completionOption, cancellationToken)
                                      .ConfigureAwait(false))
                {
                    string contentString = null;

                    // if we need to match the content, read it while still timing
                    if (matchContent)
                    {
                        contentString = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
                    }

                    // all work has been finished, so stop the timer
                    var timing = timer.Stop();

                    if (!response.IsSuccessStatusCode)
                    {
                        return(TimedHealthCheckResult.Unhealthy(timing, response.ReasonPhrase));
                    }

                    if (timing > _options.UnhealthyThreshold)
                    {
                        return(TimedHealthCheckResult.Degraded(timing));
                    }

                    if (!matchContent)
                    {
                        return(TimedHealthCheckResult.Healthy(timing));
                    }

                    // need to match the response content
                    if (_options.ExpectedContent.Equals(contentString))
                    {
                        return(TimedHealthCheckResult.Healthy(timing));
                    }

                    return(HealthCheckResult.Degraded("Response content does not match expected content"));
                }
            }
            catch (Exception ex)
            {
                return(TimedHealthCheckResult.Unhealthy(timer.Stop(), ex));
            }
        }
Esempio n. 2
0
        public async Task <HealthCheckResult> CheckAsync(CancellationToken cancellationToken = default)
        {
            var timer = CheckTimer.Start();

            try
            {
                var servers   = GetServers().ToList();
                var pingTasks = new List <Task <TimeSpan> >();

                foreach (var s in servers)
                {
                    if (!s.IsConnected)
                    {
                        continue;
                    }

                    pingTasks.Add(s.PingAsync());
                }

                var connectedMsg = $"{pingTasks.Count}/{servers.Count} redis servers connected";

                //Nothing connected
                if (pingTasks.Count == 0)
                {
                    return(HealthCheckResult.Unhealthy(connectedMsg));
                }

                //Get the average ping times
                var pingResults = await Task.WhenAll(pingTasks).ConfigureAwait(false);

                var avg = TimeSpan.FromTicks(Convert.ToInt64(pingResults.Average(p => p.Ticks)));

                //Some connected
                if (pingTasks.Count != servers.Count)
                {
                    return(TimedHealthCheckResult.Degraded(avg, connectedMsg));
                }

                //All connected
                //Check timing
                if (avg > _options.UnhealthyThreshold)
                {
                    return(TimedHealthCheckResult.Degraded(avg));
                }

                //All good
                return(TimedHealthCheckResult.Healthy(avg));
            }
            catch (Exception ex)
            {
                return(TimedHealthCheckResult.Unhealthy(timer.Stop(), ex));
            }
        }
Esempio n. 3
0
        public void DoTimer(TimeSpan delay)
        {
            if (!m_Enable)
            {
                return;
            }

            if (m_Timer != null)
            {
                m_Timer.Stop();
            }

            m_End   = DateTime.UtcNow + delay;
            m_Timer = new CheckTimer(this, delay);
            m_Timer.Start();
        }
Esempio n. 4
0
 private void CheckTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
 {
     lock (checkTimerLock)
     {
         // If timer is disposed then return;
         if (CheckTimer == null)
         {
             return;
         }
         CheckAll();
     }
     if (CheckTimer.Interval != 5000)
     {
         CheckTimer.Interval = 5000;
     }
     CheckTimer.Start();
 }
Esempio n. 5
0
        public async Task <HealthCheckResult> CheckAsync(CancellationToken cancellationToken = default)
        {
            var timer = CheckTimer.Start();

            try
            {
                using (var conn = GetConnection(_connectionString))
                {
                    await conn.OpenAsync(cancellationToken).ConfigureAwait(false);

                    return(TimedHealthCheckResult.Healthy(timer.Stop()));
                }
            }
            catch (Exception ex)
            {
                return(TimedHealthCheckResult.Unhealthy(timer.Stop(), ex));
            }
        }
Esempio n. 6
0
        private void Form1_Load(object sender, EventArgs e)
        {
            Hide();
            ShowInTaskbar = false;

            MyNotifyIcon.ContextMenuStrip = MyContextMenuStrip;
            MyNotifyIcon.Icon             = new Icon("image/icon.ico");

            Schedule           = new ScheduleData();
            CurrentStudentList = new List <Student>();

            Schedule.PutBellList(File.ReadAllText("data/BellList.txt"));
            Schedule.PutGroupSchedule(File.ReadAllText("data/GroupSchedule.txt"));
            Schedule.PutGroupList("data/groups/");

            CheckTimer_Tick(sender, e);
            CheckTimer.Start();
            //    Schedule.ShowData();
        }
Esempio n. 7
0
        protected override void Initialization()
        {
            #region 用来检查新邮件的本地函数
            void CheckNewMail()
            {
                var NewMails = MailClient.ToArrayAsync().Result();

                foreach (var item in NewMails.Except(OldMail, FastRealize.EqualityComparer <IMailServed>(x => x.Data)))
                {
                    Delegate?.Invoke(MailClient, item);
                }
                OldMail = NewMails;
            }

            #endregion
            OldMail         = MailClient.ToArrayAsync().Result();
            CheckTimer      = CreateTimer.Timer(CheckInterval, null);
            CheckTimer.Due += CheckNewMail;
            CheckTimer.Start();
        }
Esempio n. 8
0
        public MainForm(string[] args)
        {
            InitializeComponent();

            try
            {
                //初始化日志
                Settings.Xlog = new XLog(CreatPath(@"\logs"), 1000);
            }
            catch
            {
                Settings.LogException("日志系统异常!可能无法写入日志");
            }

            try
            {
                //初始化配置
                InitSettings();
            }catch (Exception e1)
            {
                ShowTrace("初始化配置出现异常!");
                Settings.LogException(e1);
            }


            //检测是否自动启动,如果自启动并设置自退出则提示用户(此处仅提示)
            CheckAutoStart(args);

            //初始化插件列表
            InitGrid();

            Settings.Xlog.Add("插件列表加载完毕", "系统日志");

            //初始化自动定期检测计时器
            CheckTimer.Interval = 3600;
            CheckTimer.Start();
            Settings.Xlog.Add("自动定期检测计时器启动", "系统日志");
        }
Esempio n. 9
0
 void CheckAsync()
 {
     try
     {
         if (!IsSuspended())
         {
             CheckAll();
         }
     }
     catch (Exception)
     {
     }
     if (CheckTimer == null)
     {
         return;
     }
     // If check time is not every 5 seconds then...
     if (CheckTimer.Interval != 5000)
     {
         // Reset check to every 5 seconds.
         CheckTimer.Interval = 5000;
     }
     CheckTimer.Start();
 }
Esempio n. 10
0
        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);

            int version = reader.ReadInt();

            switch (version)
            {
            case 5:
            {
                SaveFlag flags = (SaveFlag)reader.ReadEncodedInt();

                if (GetSaveFlag(flags, SaveFlag.SpellEffect))
                {
                    m_Identified    = reader.ReadBool();
                    m_Effect        = (SpellEffect)reader.ReadEncodedInt();
                    m_EffectCharges = reader.ReadEncodedInt();
                }
                else
                {
                    m_Identified    = false;
                    m_Effect        = SpellEffect.None;
                    m_EffectCharges = 0;
                }

                if (GetSaveFlag(flags, SaveFlag.Resource))
                {
                    m_Resource = (CraftResource)reader.ReadEncodedInt();
                }
                else
                {
                    m_Resource = DefaultResource;
                }

                if (GetSaveFlag(flags, SaveFlag.Attributes))
                {
                    m_AosAttributes = new AosAttributes(this, reader);
                }
                else
                {
                    m_AosAttributes = new AosAttributes(this);
                }

                if (GetSaveFlag(flags, SaveFlag.ClothingAttributes))
                {
                    m_AosClothingAttributes = new AosArmorAttributes(this, reader);
                }
                else
                {
                    m_AosClothingAttributes = new AosArmorAttributes(this);
                }

                if (GetSaveFlag(flags, SaveFlag.SkillBonuses))
                {
                    m_AosSkillBonuses = new AosSkillBonuses(this, reader);
                }
                else
                {
                    m_AosSkillBonuses = new AosSkillBonuses(this);
                }

                if (GetSaveFlag(flags, SaveFlag.Resistances))
                {
                    m_AosResistances = new AosElementAttributes(this, reader);
                }
                else
                {
                    m_AosResistances = new AosElementAttributes(this);
                }

                if (GetSaveFlag(flags, SaveFlag.MaxHitPoints))
                {
                    m_MaxHitPoints = reader.ReadEncodedInt();
                }

                if (GetSaveFlag(flags, SaveFlag.HitPoints))
                {
                    m_HitPoints = reader.ReadEncodedInt();
                }

                if (GetSaveFlag(flags, SaveFlag.Crafter))
                {
                    m_Crafter = reader.ReadMobile();
                }

                if (GetSaveFlag(flags, SaveFlag.Quality))
                {
                    m_Quality = (ClothingQuality)reader.ReadEncodedInt();
                }
                else
                {
                    m_Quality = ClothingQuality.Regular;
                }

                if (GetSaveFlag(flags, SaveFlag.StrReq))
                {
                    m_StrReq = reader.ReadEncodedInt();
                }
                else
                {
                    m_StrReq = -1;
                }

                if (GetSaveFlag(flags, SaveFlag.PlayerConstructed))
                {
                    m_PlayerConstructed = true;
                }

                break;
            }

            case 4:
            {
                m_Resource = (CraftResource)reader.ReadInt();

                goto case 3;
            }

            case 3:
            {
                m_AosAttributes         = new AosAttributes(this, reader);
                m_AosClothingAttributes = new AosArmorAttributes(this, reader);
                m_AosSkillBonuses       = new AosSkillBonuses(this, reader);
                m_AosResistances        = new AosElementAttributes(this, reader);

                goto case 2;
            }

            case 2:
            {
                m_PlayerConstructed = reader.ReadBool();
                goto case 1;
            }

            case 1:
            {
                m_Crafter = reader.ReadMobile();
                m_Quality = (ClothingQuality)reader.ReadInt();
                break;
            }

            case 0:
            {
                m_Crafter = null;
                m_Quality = ClothingQuality.Regular;
                break;
            }
            }

            if (version < 2)
            {
                m_PlayerConstructed = true;                 // we don't know, so, assume it's crafted
            }
            if (version < 3)
            {
                m_AosAttributes         = new AosAttributes(this);
                m_AosClothingAttributes = new AosArmorAttributes(this);
                m_AosSkillBonuses       = new AosSkillBonuses(this);
                m_AosResistances        = new AosElementAttributes(this);
            }

            if (version < 4)
            {
                m_Resource = DefaultResource;
            }

            if (m_MaxHitPoints == 0 && m_HitPoints == 0)
            {
                m_HitPoints = m_MaxHitPoints = Utility.RandomMinMax(InitMinHits, InitMaxHits);
            }

            Mobile parent = Parent as Mobile;

            if (parent != null)
            {
                if (Core.AOS)
                {
                    m_AosSkillBonuses.AddTo(parent);
                }

                AddStatBonuses(parent);
                parent.CheckStatTimers();

                if (m_Effect != SpellEffect.None && m_EffectCharges > 0 && SpellCastEffect.IsRepeatingEffect(m_Effect))
                {
                    m_Timer = new CheckTimer(this);
                    m_Timer.Start();
                }
            }
        }
Esempio n. 11
0
 private void FormCheck_Load(object sender, EventArgs e)
 {
     FillCheck();
     CheckTimer.Start();
 }
Esempio n. 12
0
 /// <summary>
 /// Метод старта проверки времени и автозапуска проигрывателя
 /// </summary>
 public static void StartScheduler()
 {
     CheckTime(null, null);
     CheckTimer.Start();
 }
        public void DoTimer( TimeSpan delay )
        {
            if ( !m_Enable )
                return;

            if ( m_Timer != null )
                m_Timer.Stop();

            m_End = DateTime.Now + delay;

            m_Timer = new CheckTimer( this, delay );
            m_Timer.Start();
        }
Esempio n. 14
0
 /// <summary>
 /// Démarre la surveillance.
 /// </summary>
 public void Start()
 {
     Started = true;
     CheckConnection();
     CheckTimer.Start();
 }