Exemple #1
0
    public override void Execute(IList <object> line)
    {
        if (line == null || line.Count < 3)
        {
            RigEx.WriteLineColors("Bot Id parametr error ".AddTimeStamp(), ConsoleColor.DarkRed);
            return;
        }
        if (line[1].ToString().ToLower() != TeleSettings.MyName)
        {
            return;
        }

        int curVersion;

        if (GetVersionString(line, out curVersion))
        {
            if (!gSheet.Data.VersionIsLiquid(curVersion, gSheet.NewVersion))
            {
                return;
            }
            else
            {
                RigEx.WriteLineColors($"Google Sheet you use last version: {curVersion}", ConsoleColor.Green);
            }
        }
        else
        {
            RigEx.WriteLineColors("Google Sheet cannot read cur version from C", ConsoleColor.Red);
        }
    }
Exemple #2
0
        public MainClass()
        {
            _handler += new MainClass.EventHandler(Handler);
            AppDomain.CurrentDomain.ProcessExit += (s, e) => { OnProcessExit(s, new EventType {
                    msg = "Quit"
                }); };
            SetConsoleCtrlHandler(_handler, true);
            settings   = new SettingsData();
            controller = new Controller(settings);

            Sheet = new GSheet(controller);
            RigEx.WriteLineColors($"servise:\tGoogle Sheet\t- {Sheet != null}".AddTimeStamp(), Sheet != null ? ConsoleColor.DarkGreen : ConsoleColor.Red);
            bool initBiosDone = controller.TelegramUser.Any() && controller.ServerList.Any();

            RigEx.WriteLineColors($"servise:\tGoogle Reader\t- {initBiosDone}".AddTimeStamp(), initBiosDone ? ConsoleColor.DarkGreen : ConsoleColor.Red);
            sensors = new SensorService(controller);
            RigEx.WriteLineColors($"servise:\tSensors\t\t- {sensors != null}".AddTimeStamp(), sensors != null ? ConsoleColor.DarkGreen : ConsoleColor.Red);
            alarmSensors = new AlarmData(controller);
            RigEx.WriteLineColors($"servise:\tAlarmSensors\t- {alarmSensors != null}".AddTimeStamp(), alarmSensors != null ? ConsoleColor.DarkGreen : ConsoleColor.Red);
            tbot = new TelegramBot(controller);
            RigEx.WriteLineColors($"servise:\tTelegramBot\t- {tbot != null}".AddTimeStamp(), tbot != null ? ConsoleColor.DarkGreen : ConsoleColor.Red);
            difficulty = new MineDifficulty(controller);
            RigEx.WriteLineColors($"servise:\tWhat To Mine\t- {difficulty != null}".AddTimeStamp(), difficulty != null ? ConsoleColor.DarkGreen : ConsoleColor.Red);
            miner = new Miner(controller);
            RigEx.WriteLineColors($"servise:\tMiner \t- {miner != null}".AddTimeStamp(), miner != null ? ConsoleColor.DarkGreen : ConsoleColor.Red);
        }
Exemple #3
0
        public void Execute(JsonData jd)
        {
            RigEx.WriteLineColors($"Command change miner {srv.Ctrl.CurMiner} to {jd.Value} ".AddTimeStamp(), ConsoleColor.Yellow);
            var serv = srv.Ctrl.Miners.FirstOrDefault(i => i.Name == jd.Value);

            if (serv != null)
            {
                if (srv.Ctrl.CurMiner.Name != serv.Name)
                {
                    srv.Ctrl.MinerCommand(CurrentMinerCommand.ChangeAndRunMiner, jd);
                }
                else if (!srv.Ctrl.MinerStatus)
                {
                    srv.Ctrl.MinerCommand(CurrentMinerCommand.LounchMiner);
                }
                else
                {
                    RigEx.WriteLineColors($"Warning Change miner - Already Running {serv.Name}".AddTimeStamp(), ConsoleColor.DarkYellow);
                    srv.SendMsg($"{serv.Name} : already running");
                }
            }
            else
            {
                RigEx.WriteLineColors($"Warning Change miner - canot fount miner {jd.Value}".AddTimeStamp(), ConsoleColor.DarkRed);
            }
        }
Exemple #4
0
    public override void Execute(IList <object> line)
    {
        if (line == null || line.Count < 2)
        {
            RigEx.WriteLineColors("CoinName parametr error ".AddTimeStamp(), ConsoleColor.DarkRed);
            return;
        }

        int id;

        if (!int.TryParse(line[2].ToString(), out id))
        {
            Console.WriteLine($"line {line[0]} senver name {line[1]} do not have id as int {line[2]} ");
        }

        string serverName = line[1].ToString().ToLower();
        var    newSheed   = new ServerInfo(id, serverName, true);

        if (serverName.Contains(GShSettings.PCname))
        {
            gSheet.MyPage.MyServerSheetId = newSheed;
        }
        else if (!gSheet.Data.ServersSheetId.Any(o => o.Name.Contains(serverName)))
        {
            gSheet.Data.ServersSheetId.Add(newSheed);
        }
    }
Exemple #5
0
        private void Start()
        {
            try
            {
                minerProcess = Process.Start(startInfo);
//                minerProcess.WaitForExit();
//                if (ctrl.MinerStatus)
//                {
//                    RigEx.WriteLineColors("WaitForExit ".AddTimeStamp(), ConsoleColor.DarkCyan);
//                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error lounch {startInfo.FileName}: {e.Message} ");
            }
            while (true)
            {
                Thread.Sleep(1000);
                if (ctrl.MinerStatus && minerProcess.HasExited)
                {
                    RigEx.WriteLineColors($"relaunching miner: {ctrl.CurMiner.Name}".AddTimeStamp(), ConsoleColor.DarkCyan);
                    LaunchMiner();
                    return;
                }
            }
        }
Exemple #6
0
        public void SendPingErrorList(List <IToken> errors)
        {
            foreach (IToken token in errors)
            {
                InlineKeyboardButton[][] testInlinekeyBoard = new InlineKeyboardButton[1][];
                testInlinekeyBoard[0]    = new InlineKeyboardButton[1];
                testInlinekeyBoard[0][0] = new InlineKeyboardButton {
                    Text = $"stop ping", CallbackData = $"{TCmdType.stopPing}:{token.Name}"
                };

                InlineKeyboardMarkup keyboardInlineMarkUp = new InlineKeyboardMarkup(testInlinekeyBoard);
                try
                {
                    foreach (IToken user in Ctrl.TelegramUser)
                    {
                        try
                        {
                            Bot.Client?.SendTextMessageAsync(user.Id, $"Error {token.Name}", replyMarkup: keyboardInlineMarkUp);
                        }
                        catch (Exception e)
                        {
                            RigEx.WriteLineColors($"cannot send ping error {user.Id} message:Error {token.Name} e:{e.Message}".AddTimeStamp(), ConsoleColor.Red);
                        }
                    }
                }
                catch (Exception e)
                {
                    RigEx.WriteLineColors($"cannot send ping error message:Error {token.Name} e:{e.Message}".AddTimeStamp(), ConsoleColor.DarkRed);
                }
            }
        }
Exemple #7
0
        public Dictionary <string, double> GetDifficulty()
        {
            using (var client = new WebClient())
            {
                var json = client.DownloadString(JsonUrlWhattomine);
                blob = JsonConvert.DeserializeObject <MineBlob>(json);
            }
            Dictionary <string, double> difficultyDictionary = new Dictionary <string, double>();

            foreach (ICoin coin in ctrl.GetCoins)
            {
                if (!blob["coins"].ContainsKey(coin.Name))
                {
                    RigEx.WriteLineColors($"{coin.Name} not found in WotToMine.com", ConsoleColor.DarkRed);
                    continue;
                }
                var blockReward  = blob["coins"][coin.Name].BlockReward;
                var blocksPerDay = blob["coins"][coin.Name].BlockTime;// * 24;//block count in day,
                var netHash      = blob["coins"][coin.Name].NetHash;
                var proff        = blob["coins"][coin.Name].Profitability;

                string result = $"Rew: {blockReward} time: {blocksPerDay} nH: {netHash} = {86400 / blocksPerDay * blockReward / netHash * coin.Hashrate}";
                RigEx.WriteLineColors($"{coin.Name}: \trew {blockReward} \tt:{blocksPerDay} \tnh {netHash} \t= {86400 / blocksPerDay * blockReward / netHash * coin.Hashrate} / {proff}", ConsoleColor.Cyan);
                double reward = 86400 / blocksPerDay * blockReward / netHash * coin.Hashrate;
                difficultyDictionary.Add(coin.Name, reward);
            }
            return(difficultyDictionary);
        }
Exemple #8
0
 public override void Execute(IList <object> line)
 {
     if (line[1] == null || line[1].ToString() == string.Empty)
     {
         RigEx.WriteLineColors("Google Sheet cannot read miner name from  B".AddTimeStamp(), ConsoleColor.Red);
     }
     gSheet.Data.MinersList.Add(new MinerInfo(line[1].ToString(), line[2].ToString()));
 }
Exemple #9
0
        public void Execute()
        {
            RigEx.WriteLineColors($"Command  {Name}", ConsoleColor.Yellow);
            var    d    = srv.Ctrl.GetDiffucalty();
            string diff = d.Aggregate(String.Empty, (current, d1) => current + $"\n{d1.Key}:\t{d1.Value}");

            srv.SendMsg(diff);
        }
Exemple #10
0
 private void CheckList()
 {
     if (data.MyPage.MyServerSheetId == null)
     {
         RigEx.WriteLineColors($"ERROR: not found Sheet Id for this PC will write on Default page".AddTimeStamp(), ConsoleColor.Red);
         data.MyPage.MyServerSheetId = new ServerInfo();
     }
 }
Exemple #11
0
 public async void Execute(JsonData jd)
 {
     RigEx.WriteLineColors("Command send screen".AddTimeStamp(), ConsoleColor.Yellow);
     srv.Ctrl.CreateScreenShot();
     foreach (var user in srv.Ctrl.TelegramUser)
     {
         await Bot.Client?.SendPhotoAsync(user.Id, System.IO.File.OpenRead(MainClass.ScreenPath));
     }
 }
Exemple #12
0
        private void AddNewAlarmSensor(ISensorProperty s)
        {
            RigEx.WriteLineColors($"sensor detected: {s.Name} =>   {s.Dictionary.Keys.Last().ToString()}".AddTimeStamp(), ConsoleColor.DarkGray);
            var alarmsensor = new AlarmSensor(s, ctrl);

            alarmsensor.AlarmAction      += OnAlarmAction;
            alarmsensor.StopMiningAction += OnStopMiningAction;
            ctrl.GetAlarmdata.AddifNew(alarmsensor);
        }
Exemple #13
0
 public override void Execute(IList <object> line)
 {
     if (line == null || line.Count < 2)
     {
         RigEx.WriteLineColors("CoinName parametr error ".AddTimeStamp(), ConsoleColor.DarkRed);
         return;
     }
     gSheet.Data.UserToKen.Add(GetUserTokenFromLine(line));
 }
Exemple #14
0
 public bool VersionIsLiquid(int curVersion, int newversion)
 {
     if (newversion > curVersion)
     {
         RigEx.WriteLineColors($"start Update Version curent: {curVersion} to last version: {newversion}", ConsoleColor.Green);
         RunLauncher();
         return(false);
     }
     return(true);
 }
Exemple #15
0
        public Miner(IMiningCtrl minerCtrl)
        {
            ctrl = minerCtrl;
            var minerName = RigEx.Read(RigEx.Lastminer);

            RigEx.WriteLineColors($"Last miner is: {minerName}".AddTimeStamp(), ConsoleColor.DarkCyan);
            ChangeAndRunMinerAction(minerName);
            ctrl.ButtonChangeAndRunMinerAction += ChangeAndRunMinerAction;
            ctrl.MinerActivityAction           += OnMinerActivityAction;
        }
Exemple #16
0
        private IList <IList <object> > GetComandLineFrom(string sheetId)
        {
            var comandline = GetRange($"{sheetId}!A2:F2");

            if (comandline == null)
            {
                RigEx.WriteLineColors($"cannot read ComandLine A2:Z2 from{sheetId}", ConsoleColor.DarkRed);
            }
            return(comandline);
        }
Exemple #17
0
    private static string GetSpreadsheetId()
    {
        string path = Path.GetFullPath(Path.Combine(Path.Combine(System.Reflection.Assembly.GetEntryAssembly().Location, @"..\..\"), "sheetId.txt"));

        if (!File.Exists(path))
        {
            RigEx.WriteLineColors($"Cannot faund file {path} ", ConsoleColor.Red);
            return(String.Empty);
        }
        return(File.ReadAllText(path));
    }
Exemple #18
0
 public async void ChangeAndRunMinerAction(IEventArgs minerName)
 {
     if (minerName != null && !string.IsNullOrEmpty(minerName.Value))
     {
         await ChangeAndRunMinerAction(minerName.Value);
     }
     else
     {
         RigEx.WriteLineColors("miner ChangeMiner => miner is null ", ConsoleColor.DarkRed);
     }
 }
Exemple #19
0
 private void OnStopMiningAction(IAlarmSensor sensor)
 {
     if (ctrl.MinerStatus && sensor.AlarmType == AlarmType.High)
     {
         RigEx.WriteLineColors($"Stop miner {sensor.Sensor.Name}=> {sensor.SensorType} :{sensor.Sensor.Dictionary[sensor.SensorType]} - {sensor.AlarmType}".AddTimeStamp(), ConsoleColor.Magenta);
         ctrl.SetMinigActivityStatus(false);
     }
     else if (!ctrl.MinerStatus && sensor.AlarmType == AlarmType.Low)
     {
         RigEx.WriteLineColors($"Start miner {sensor.Sensor.Name}=> {sensor.SensorType} :{sensor.Sensor.Dictionary[sensor.SensorType]} - {sensor.AlarmType}".AddTimeStamp(), ConsoleColor.Magenta);
         ctrl.SetMinigActivityStatus(true);
     }
 }
Exemple #20
0
 public override void Execute(IList <object> line)
 {
     if (line == null || line.Count < 3)
     {
         RigEx.WriteLineColors("Bot Id parametr error ".AddTimeStamp(), ConsoleColor.DarkRed);
         return;
     }
     if (line[1].ToString().ToLower() != TeleSettings.MyName)
     {
         return;
     }
     gSheet.Data.BotId = line[2].ToString();
 }
Exemple #21
0
 public async void SendMsg(string msg)
 {
     try
     {
         foreach (var token in Ctrl.TelegramUser)
         {
             await Bot.Client?.SendTextMessageAsync(token.Id, $"{msg}");
         }
     }
     catch (Exception e)
     {
         RigEx.WriteLineColors($"Telegram Send:{msg}\nError: {e.Message}".AddTimeStamp(), ConsoleColor.DarkRed);
     }
 }
Exemple #22
0
        private void LaunchCommandLine(IEventArgs minerName = null)
        {
            if (ctrl?.CurMiner == null)
            {
                RigEx.WriteLineColors("LaunchMiner : current miner is null".AddTimeStamp(), ConsoleColor.Red);
                return;
            }
            startInfo.CreateNoWindow  = true;
            startInfo.UseShellExecute = true;
            startInfo.FileName        = ctrl.CurMiner.Path;
            startInfo.WindowStyle     = ProcessWindowStyle.Normal;

            LaunchMiner();
        }
Exemple #23
0
 public JsonData(string jsonValue)
 {
     string[] data = jsonValue.Split(':');
     if (data == null || data.Length < 1)
     {
         RigEx.WriteLineColors($"Cannot convert value {jsonValue}".AddTimeStamp(), ConsoleColor.Red);
         return;
     }
     if (!Enum.TryParse(data[0], out type))
     {
         RigEx.WriteLineColors($"Cannot convert callback {data[0]}", ConsoleColor.Red);
         return;
     }
     Value = data.Length > 1 ? data[1] : String.Empty;
 }
Exemple #24
0
        private void OnAlarmAction(IAlarmSensor sensor)
        {
            var alarm = $"{Icons.ring} Alarm {sensor.SensorType.Icon()}: {sensor.Sensor.Dictionary[sensor.SensorType]} - {sensor.AlarmType.Icon()}";

            try
            {
                foreach (IToken token in Ctrl.TelegramUser)
                {
                    Bot.Client?.SendTextMessageAsync(token.Id, alarm, replyMarkup: GetAlarmInlinekeyBoard(sensor.SensorType));
                }
            }
            catch (Exception e)
            {
                RigEx.WriteLineColors($"Telegram Error: {e.Message}".AddTimeStamp(), ConsoleColor.DarkRed);
            }
        }
Exemple #25
0
 private void OnMinerActivityAction()
 {
     if (ctrl.MinerStatus != IsActive)
     {
         if (ctrl.MinerStatus)
         {
             RigEx.WriteLineColors("Launch miner ".AddTimeStamp(), ConsoleColor.DarkCyan);
             LaunchCommandLine();
         }
         else
         {
             RigEx.WriteLineColors("Stop miner ".AddTimeStamp(), ConsoleColor.DarkCyan);
             Destroy();
         }
     }
 }
Exemple #26
0
 public void Execute()
 {
     RigEx.WriteLineColors($"Command {Name}".AddTimeStamp(), ConsoleColor.Cyan);
     try
     {
         foreach (IToken token in srv.Ctrl.TelegramUser)
         {
             Bot.Client?.SendTextMessageAsync(token.Id, srv?.CurMiner?.Name, replyMarkup: srv.GetMinersInlinekeyBoard());
         }
     }
     catch (Exception e)
     {
         RigEx.WriteLineColors($"Telegram Send message Error: {e.Message}".AddTimeStamp(), ConsoleColor.DarkRed);
         throw;
     }
 }
Exemple #27
0
    public override void Execute(IList <object> line)
    {
        if (line == null || line.Count < 2)
        {
            RigEx.WriteLineColors("CoinName parametr error ".AddTimeStamp(), ConsoleColor.DarkRed);
            return;
        }
        int hashRate;

        int.TryParse(line[2].ToString(), out hashRate);
        hashRate = hashRate == 0 ? 1 : hashRate;
        string coinName = line[1].ToString();
        var    coin     = new Coin(coinName, hashRate);

        gSheet.Data.CoinsList.AddOrReplase(coin);
    }
Exemple #28
0
    public override void Execute(IList <object> line)
    {
        if (line.Count < 2)
        {
            gSheet.Data.PingDelayMillisec = 240000; // 4 min
            return;
        }
        int minutes = 4;

        if (!int.TryParse(line[1]?.ToString(), out minutes))
        {
            RigEx.WriteLineColors("ping alarm: can not parse to int from B colum ", ConsoleColor.Red);
        }
        minutes = minutes == 0 ? 4 : minutes;
        gSheet.Data.PingDelayMillisec = minutes * 60000;
    }
Exemple #29
0
        public async Task Destroy()
        {
            if (minerThread != null)
            {
                try
                {
                    minerThread.Abort(startInfo);
                    minerThread.DisableComObjectEagerCleanup();
                    minerThread = null;
                }
                catch (Exception e)
                {
                    RigEx.WriteLineColors($"Destroy miner Thread: cannot Abort Thread {e.Message}".AddTimeStamp(),
                                          ConsoleColor.DarkRed);
                }
            }
            if (minerProcess != null)
            {
                try
                {
                    minerProcess.Kill();
                    minerThread = null;
                }
                catch (Exception e)
                {
                    RigEx.WriteLineColors($"Destroy miner Process: cannot kill process {e.Message}".AddTimeStamp(),
                                          ConsoleColor.DarkRed);
                }

                var processes = Process.GetProcesses().ToList();
                var cc        = processes.Where(i => i.ProcessName.StartsWith("ccminer") ||
                                                i.ProcessName.StartsWith("excavator") ||
                                                i.ProcessName.StartsWith("ethminer") ||
                                                i.ProcessName.StartsWith("nheqminer") ||
                                                i.ProcessName.StartsWith("sgminer") ||
                                                i.ProcessName.StartsWith("xmrig") ||
                                                i.ProcessName.StartsWith("xmr-stak-cpu")).ToList();
                if (cc != null)
                {
                    for (int i = 0; i < cc.Count(); i++)
                    {
                        RigEx.WriteLineColors($"miner: {cc[i].ProcessName}", ConsoleColor.Cyan);
                        cc[i].Kill();
                    }
                }
            }
        }
Exemple #30
0
        protected void SendRequests()
        {
            var busr = new BatchUpdateSpreadsheetRequest {
                Requests = request
            };

            try
            {
                var t = page.Service.Spreadsheets.BatchUpdate(busr, page.SpreadsheetId);
                //t.Execute();
                t.ExecuteAsStream();
            }
            catch (Exception e)
            {
                RigEx.WriteLineColors($"Exeption to send request{e.Message}".AddTimeStamp(), ConsoleColor.Red);
            }
        }