Ejemplo n.º 1
0
        /// <summary>
        /// On timer elapse handler.
        /// </summary>
        /// <remarks>
        /// The main idea of this handler is to get GPU load values in order to
        /// make decision on restart supervised app. First we get all GPU load
        /// valuers and show them to user. After we calculate lowest one and if
        /// calculated value lowerer than the theshold supervised app restarts.
        /// We have 5 attempts.
        /// </remarks>
        private void OnElapse()
        {
            var hasInet = utilMgr.IsOnline();

            Output.Write(hasInet ? "Internet ok; " : "No internrt; ", ConsoleColor.Cyan);

            var gpus = computer.Hardware.Where(x => x.HardwareType == HardwareType.GpuNvidia || x.HardwareType == HardwareType.GpuAti);

            foreach (var gpu in gpus)
            {
                gpu.Update();
                var load = gpu.Sensors.FirstOrDefault(x => x.SensorType == SensorType.Load);
                var tmpr = gpu.Sensors.FirstOrDefault(x => x.SensorType == SensorType.Temperature);
                Output.Write($"gpu{Regex.Match(gpu.Identifier.ToString(), @"\d+").Value}(ld={load?.Value}%, t={tmpr?.Value} C);  ", ConsoleColor.Cyan);
            }
            Output.WriteLine();

            var minLoad = computer.Hardware.Min(x => x.Sensors.FirstOrDefault(y => y.SensorType == SensorType.Load)?.Value);

            if (minLoad < args.GpuLoadThreshold)
            {
                Output.WriteLine($"GPU LOAD {minLoad}%, THERESHOLD {args.GpuLoadThreshold}! RESTART MINER IN {--iteration}", ConsoleColor.Red);
            }
            else if (hasInet)
            {
                iteration = MaxItertions;
            }

            if (!hasInet)
            {
                Output.WriteLine($"NO INTERNET CONNECTION! RESTART MINER IN {--iteration}", ConsoleColor.Red);
            }
            else if (minLoad > args.GpuLoadThreshold)
            {
                iteration = MaxItertions;
            }

            if (iteration > 0)
            {
                return;
            }

            timer.Enabled = false;

            Output.Write("RESTARTING MINER...", ConsoleColor.Yellow);
            utilMgr.RestartProcess(supervisedProcess);
            Output.WriteLine(" OK!", ConsoleColor.Green);

            timer.Enabled = true;
            iteration     = MaxItertions;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Here is the behaviour logic depending on internet connection status.
        /// </summary>
        private void InternetActions()
        {
            if (!args.CheckInet)
            {
                return;
            }
            var hasInet = utilMgr.IsOnline();

            if (!isStopped)
            {
                Output.Write(hasInet ? "Internet ok; " : "No internrt; ", ConsoleColor.Cyan);
            }
            if (hasInet)
            {
                checkInetIterations = MaxItertions;
            }
            else if (!isStopped)
            {
                Output.WriteLine($"NO INTERNET CONNECTION! STOPPING MINER IN {--checkInetIterations}", ConsoleColor.Red);
            }
            if (checkInetIterations <= 0)
            {
                if (!isStopped)
                {
                    utilMgr.StopProcess(supervisedProcess);
                    Output.WriteLine("Miner stopped", ConsoleColor.Yellow);
                }
                isStopped = true;
            }
            else if (isStopped)
            {
                utilMgr.StartProcess(supervisedProcess);
                Output.WriteLine("Miner started", ConsoleColor.Yellow);
                isStopped = false;
            }
        }