コード例 #1
0
        private void eWeLinkWachdog()
        {
            if (Wachdog || eWeRebootiong)
            {
                return;
            }
            Wachdog = true;
            Task.Run(() =>
            {
                for (int i = 0; i < WachdogDelay; i++)
                {
                    if (Status == IPStatus.Success || !InternetConnection)
                    {
                        goto EndWachdog;
                    }
                    Thread.Sleep(1000);
                }
                if (Status == IPStatus.Success || !InternetConnection)
                {
                    goto EndWachdog;
                }
                if (UserInformer.Alarm)
                {
                    UserInformer.SendMSG(Config.Name, "Ping: Worker offline");
                }

                WachingStop();
                eWeReboot();
                EndWachdog:
                Wachdog = false;
            });
        }
コード例 #2
0
        private void eWeReboot()
        {
            if (Config.eWeDevice != null && App.Ewelink != null)
            {
                if (eWeRebootiong)
                {
                    return;
                }
                eWeRebootiong = true;
                while (App.Live && eWeRebootiong)
                {
                    Task.Run(() =>
                    {
                        UserInformer.SendMSG(Config.Name, "eWeReboot");

                        EwelinkNet.Classes.SwitchDevice dev = null;
                        try
                        {
                            dev = App.Ewelink.Devices.
                                  Where(d => d.name == Config.eWeDevice).First()
                                  as EwelinkNet.Classes.SwitchDevice;
                        }
                        catch
                        {
                            eWeRebootiong = false;
                            UserInformer.SendMSG(Config.Name, "eWeReboot error");
                            return;
                        }

                        if (dev != null)
                        {
                            dev.TurnOff();
                            Thread.Sleep(8000);
                            dev.TurnOn();
                        }
                        else
                        {
                            eWeRebootiong = false;
                            UserInformer.SendMSG(Config.Name, "eWeReboot error");
                            return;
                        }
                    });

                    for (int i = 0; i < Config.eWeDelayTimeout; i++)
                    {
                        Thread.Sleep(1000);
                        if (Status == IPStatus.Success || !InternetConnection)
                        {
                            eWeRebootiong = false; return;
                        }
                    }
                }
            }
        }
コード例 #3
0
                public void StartWach()
                {
                    if (!HiveWach)
                    {
                        HiveWach = true;

                        if (!HiveWachdog)
                        {
                            HiveWachdog = true;
                            Task.Run(() =>
                            {
                                Thread.Sleep(HiveOSWachdogDelay * 1000);
                                CurrentHiveStatus = HiveStatus.Normal;
                                UserInformer.SendMSG(Config.Name, "Start hive wach");
                                BackToLoop:
                                while (CurrentHiveStatus == HiveStatus.Normal && InternetConnection)
                                {
                                    Thread.Sleep(1000);
                                }
                                if (InternetConnection)
                                {
                                    //задержка
                                    for (int n = 0; n < 100; n++)
                                    {
                                        if (CurrentHiveStatus == HiveStatus.Normal)
                                        {
                                            goto BackToLoop;
                                        }
                                        Thread.Sleep(100);
                                    }

                                    string msg = "";
                                    switch (CurrentHiveStatus)
                                    {
                                    case HiveStatus.LowHashrate:
                                        {
                                            msg = "Hive: Low hashrate";
                                        }
                                        break;

                                    case HiveStatus.WorkerOffline:
                                        {
                                            msg = "Hive: Worker offline";
                                        }
                                        break;
                                    }
                                    UserInformer.SendMSG(Config.Name, msg);
                                    Rig.eWeReboot();
                                }
                                HiveWachdog = false;
                            });
                        }
                        Task.Run(() =>
                        {
                            while (!App.HiveConnection)
                            {
                                Thread.Sleep(100);
                            }

                            while (HiveWach && InternetConnection)
                            {
                                var mi = HiveClient.GetWorkerInfo(Config.HiveFarmID.Value,
                                                                  Config.HiveWorkerID.Value);

                                if (mi != null)
                                {
                                    InformReceived?.Invoke(new RigInform
                                    {
                                        Indication      = true,
                                        InfHashrates    = mi.Value.Hashrates,
                                        InfTemperatures = mi.Value.Temperatures
                                    });

                                    // low hashrate wachdog
                                    if (Config.WachdogMinHashrate != null)
                                    {
                                        if (mi.Value.Hashrates.Length > 0)
                                        {
                                            CurrentHiveStatus =
                                                mi.Value.Hashrates.Sum() < Config.WachdogMinHashrate.Value ?
                                                HiveStatus.LowHashrate : HiveStatus.Normal;
                                        }
                                        else
                                        {
                                            CurrentHiveStatus = HiveStatus.LowHashrate;
                                        }
                                    }
                                    else
                                    {
                                        CurrentHiveStatus = HiveStatus.Normal;
                                    }
                                }
                                else
                                {
                                    InformReceived?.Invoke(new RigInform {
                                        Indication = false
                                    });

                                    CurrentHiveStatus = HiveStatus.WorkerOffline;

                                    goto EndHiveWach;
                                }

                                Thread.Sleep(new TimeSpan(0, 0, HiveOSRequestDelay));
                            }
                            EndHiveWach:
                            HiveWach = false;
                        });
                    }
                }