Ejemplo n.º 1
0
        public void Connect()
        {
            try
            {
                ipPoint = new IPEndPoint(IPAddress.Parse(IPaddrServer), port);
                socket  = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

                socket.Connect(ipPoint);

                FermaMessage message = new FermaMessage();
                message.NameFerma = ferma.name;
                message.Date      = DateTime.Now;
                message.Priority  = 2;
                message.Text      = "app FermaMonitoring запущена!";
                //message.Type = "system";

                ferma.listMessage.Add(message);

                isConnect = true;

                Console.WriteLine(message);
            }
            catch (Exception ex)
            {
                Console.WriteLine(DateTime.Now.ToString() + " :" + ferma.name + " Error in Connect SocketTcpClient : " + ex.Message);
                isConnect = false;
                Thread.Sleep(5000);
            }
        }
Ejemplo n.º 2
0
        public void ReciveCommand()
        {
            while (true)
            {
                if (isConnect)
                {
                    try
                    {
                        byte[]        data    = new byte[4096]; // буфер для ответа
                        StringBuilder builder = new StringBuilder();
                        int           bytes   = 0;              // количество полученных байт

                        do
                        {
                            bytes = socket.Receive(data, data.Length, 0);
                            builder.Append(Encoding.Unicode.GetString(data, 0, bytes));
                            Console.WriteLine(DateTime.Now.ToString() + " Ferma.TcpClient.ReciveCommand - try to recive command" + data);
                        } while (socket.Available > 0);

                        string json = builder.ToString();

                        if (json != "")
                        {
                            //Console.WriteLine(DateTime.Now.ToString() + " :" + ferma.name + " Ferma.TcpClient.ReciveCommand recived command from server : " + builder.ToString());

                            isConnect = true;

                            FermaMessage message = JsonConvert.DeserializeObject <FermaMessage>(json);

                            if (message.Type == "command")
                            {
                                ferma.command = message.Text;
                            }
                        }
                        else
                        {
                            isConnect = false;
                        }
                    }
                    catch (Exception ex)
                    {
                        isConnect = false;
                        Console.WriteLine(DateTime.Now.ToString() + " :" + ferma.name + " Error in ReciveCommand SocketTcpClient : " + ex.Message);
                        //ferma.listMessage.Add("Сервер был перезапушен!");
                    }
                }
                else
                {
                    Connect();
                }
                Thread.Sleep(100);
            }
        }
Ejemplo n.º 3
0
        private void SendConnect()
        {
            FermaMessage message = new FermaMessage();

            message.NameFerma = ferma.name;
            //message.Date = DateTime.Now;
            message.Priority = 1;
            message.Text     = "online";
            message.Type     = "system";

            SendData(message);
        }
Ejemplo n.º 4
0
        public override void Excecute()
        {
            ferma.StopMiner();
            FermaMessage message = new FermaMessage();

            message.NameCommand = nameCommand;
            message.NameFerma   = ferma.name;
            message.Date        = DateTime.Now;
            message.Priority    = 3;
            message.Text        = ferma.currentMiner.name + " майнер остановлен!";
            ferma.listMessage.Add(message);

            ferma.command = "";
        }
Ejemplo n.º 5
0
        public override void Excecute()
        {
            ferma.UpDateGPUInformation();
            //ferma.DisplayGPUInformation();
            //ferma.tcpClient.SendData(ferma.hw.GetGPUFermaTemp());
            ferma.UpdateProcessMiner();

            FermaMessage message = new FermaMessage();

            message.NameCommand = nameCommand;
            message.NameFerma   = ferma.name;
            message.Date        = DateTime.Now;
            message.Priority    = 3;
            message.Text        = ferma.GetGPUFermaCont();
            ferma.listMessage.Add(message);

            ferma.command = "";
        }
Ejemplo n.º 6
0
        public void UpDateGPUInformation()
        {
            string mesVideoCard = "";

            foreach (var videocard in listVideoCard.ToArray())
            {
                videocard.UpDateSens();
                try
                {
                    int i = 0;
                    while (i < videocard.listMessage.Count)
                    {
                        string mes = videocard.listMessage[i];
                        if (mes != "")
                        {
                            mesVideoCard = mesVideoCard + mes + "\n";
                            videocard.listMessage.Remove(mes);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(DateTime.Now.ToString() + " error in UpDateGPUInformation count of element >");
                    break;
                }
            }

            if (mesVideoCard != "")
            {
                FermaMessage message = new FermaMessage();
                //message.NameCommand = name;
                message.NameFerma = name;
                message.Date      = DateTime.Now;
                message.Priority  = 1;

                message.Text = mesVideoCard;

                listMessage.Add(message);
            }
        }
Ejemplo n.º 7
0
        public int SendData(FermaMessage message)
        {
            int result = 0;

            if ((isConnect) && (message != null) && (!sendBusy))
            {
                sendBusy = true;
                string serialized = JsonConvert.SerializeObject(message);
                try
                {
                    byte[] data = Encoding.Unicode.GetBytes(serialized);
                    result = socket.Send(data);
                    //Console.WriteLine(DateTime.Now.ToString() + " Ferma.TcpClient.SendData " + message);
                    Thread.Sleep(50);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(DateTime.Now.ToString() + " :" + ferma.name + " Error in SendData : " + ex.Message);
                    isConnect = false;
                }
                sendBusy = false;
            }
            return(result);
        }
Ejemplo n.º 8
0
        public override void Excecute()
        {
            if (ferma.currentMiner.name != nameMiner)
            {
                ferma.currentMiner.name = nameMiner;
                ferma.ChangeCurMiner();
            }
            else
            {
                FermaMessage message = new FermaMessage();
                message.NameCommand = nameCommand;
                message.NameFerma   = ferma.name;
                message.Date        = DateTime.Now;
                message.Priority    = 3;
                message.Text        = nameMiner + " майнер уже выбран!";

                ferma.listMessage.Add(message);
            }

            if (!ferma.firststartMiner)
            {
                ferma.StartCurrentMiner(firstStart: false);
            }
            else
            {
                FermaMessage message = new FermaMessage();
                message.NameCommand = nameCommand;
                message.NameFerma   = ferma.name;
                message.Date        = DateTime.Now;
                message.Priority    = 3;
                message.Text        = nameMiner + " отложенный запуск майнера!";
                ferma.listMessage.Add(message);
            }

            ferma.command = "";
        }
Ejemplo n.º 9
0
        public void StartCurrentMiner(bool firstStart)
        {
            bool curMinerStart = false;
            bool switchMiner   = false;

            UpdateProcessMiner();

            firststartMiner = firstStart;

            if (currentMiner.process != null)
            {
                curMinerStart = true;
            }

            if (!curMinerStart)
            {
                FermaMessage message;

                foreach (Miner miner in listMiner)
                {
                    if ((miner.process != null) & (miner.name != currentMiner.name))
                    {
                        switchMiner = true;
                        miner.process.Kill();

                        message = new FermaMessage();
                        //message.NameCommand = name;
                        message.NameFerma = name;
                        message.Date      = DateTime.Now;
                        message.Priority  = 2;
                        message.Text      = miner.name + " майнер остановлен!";

                        //Console.WriteLine(message);

                        listMessage.Add(message);
                    }
                }

                if (firstStart)
                {
                    message = new FermaMessage();
                    //message.NameCommand = name;
                    message.NameFerma = name;
                    message.Date      = DateTime.Now;
                    message.Priority  = 2;
                    message.Text      = currentMiner.name + " запуск через " + (delayStartMiner / 60000) + " м";

                    listMessage.Add(message);
                    Thread.Sleep(delayStartMiner); // задержка времени перед первым запуском майнера
                    firststartMiner = false;
                }
                else
                if (switchMiner)
                {
                    Thread.Sleep(5000);
                }


                Process.Start(currentMiner.path, currentMiner.arg);

                message = new FermaMessage();
                //message.NameCommand = name;
                message.NameFerma = name;
                message.Date      = DateTime.Now;
                message.Priority  = 2;
                message.Text      = currentMiner.name + " майнер запущен!";

                //Console.WriteLine(message);

                listMessage.Add(message);
            }
            else
            {
                firststartMiner = false;
            }
        }