Пример #1
0
        public void HandleDeivce(Object obj)
        {
            TcpClient client = (TcpClient)obj;
            var       stream = client.GetStream();
            string    imei   = String.Empty;
            string    data   = null;

            Byte[] bytes = new Byte[256];
            int    i;

            try
            {
                while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
                {
                    string hex = BitConverter.ToString(bytes);
                    data = Encoding.UTF8.GetString(bytes, 0, i);
                    Console.WriteLine("{1}, Queue {2}: Received: {0}", data, Thread.CurrentThread.ManagedThreadId, chatMessages.Count);


                    if (data != null)
                    {
                        List <long?> idList = MySQLClass.GetVKID();

                        //Read messages from PLUGIN CHAT -> Send TO BOT Community VK
                        foreach (long?id in idList)
                        {
                            //Add Message+ID to Queue
                            VKparams vkQ = new VKparams()
                            {
                                messageToSend = data,
                                vkID          = id
                            };

                            //Добавляем в конец очереди рассылки
                            chatMessages.Enqueue(vkQ);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: {0}", e.ToString());

                client.Close();
            }
            //finally { client.Close(); }
        }
Пример #2
0
        public void VKScheduler()
        {
            //LPListener lpl = new LPListener();
            key_linked.AddButton("Удалить привязку", null, LPListener.decine);
            MessageKeyboard keyboard_linked = key_linked.Build();

            //Очищать очередь сообщений - отправлять в ВК
            while (true)
            {
                try
                {
                    if (chatMessages.Count > 0)

                    {
                        //Берем элемент в начале очереди
                        VKparams el     = chatMessages.Peek();
                        string   msg    = el.messageToSend;
                        long?    vkid   = el.vkID;
                        bool     sended = false;
                        if (msg != null && vkid != null)
                        {
                            sended = SendMessage(msg, vkid, keyboard_linked, null);
                        }

                        if (sended == true)
                        {
                            el = chatMessages.Dequeue();
                        }

                        Thread.Sleep(delay * 1000);
                    }
                }
                catch (Exception ex)
                {
                    LPListener.ErrorLogging(ex);
                    LPListener.ReadError();
                }
            }
        }