Exemple #1
0
        private void UpdateListView(ListView lw)
        {
            if (lw.SelectedItems.Count > 0 && lw == WhichListView() && Path.GetFileName(lw.SelectedItems[0].Text) != lw.SelectedItems[0].Text)
            {
                if (lw == listView1)
                {
                    rootLeft = lw.SelectedItems[0].Text;
                }
                else
                {
                    rootRight = lw.SelectedItems[0].Text;
                }
            }

            ListE(lw).Update(Root(lw));
            lw.Items.Clear();

            foreach (ListViewItem item in ListE(lw).list)
            {
                lw.Items.Add(item);
                if ((item.Index % 2) == 0)
                {
                    item.BackColor = data.color1;
                }
                else
                {
                    item.BackColor = data.color2;
                }
                item.ForeColor = data.fontColor;
            }

            TB tb = new TB(() => {
                if (lw == listView1)
                {
                    return(textBox4);
                }
                return(textBox5);
            });

            tb.Invoke().Text = Root(lw);

            if (lw == listView1)
            {
                watcherLeft.Path = rootLeft;
                watcherLeft.EnableRaisingEvents = true;
            }
            else
            {
                watcherRight.Path = rootRight;
                watcherRight.EnableRaisingEvents = true;
            }
        }
Exemple #2
0
        public void Start()
        {
            try
            {
                listener = new TcpListener(MyIp, Convert.ToInt32(port));
                listener.Start();

                byte[] data = new byte[1024];
                while (flag)
                {
                    mytcpclient = listener.AcceptTcpClient();
                    stream      = mytcpclient.GetStream();
                    do
                    {
                        CountBytes = stream.Read(data, 0, data.Length);
                        builder2.Append(Encoding.Unicode.GetString(data, 0, CountBytes));
                    }while (stream.DataAvailable);
                    TB.Invoke((MethodInvoker)(delegate() { TB.AppendText(Environment.NewLine + " Подключился " + builder2.ToString()); }));
                    data = null;

                    DateTime DTime = DateTime.Now;

                    data = Encoding.Unicode.GetBytes(DTime.ToString());
                    TB.Invoke((MethodInvoker)(delegate() { TB.AppendText(Environment.NewLine + " Отправляем - " + DTime.ToString()); }));

                    stream.Write(data, 0, data.Length);
                    builder2.Clear();
                }
                stream.Close();
                listener.Stop();
                Thread.ResetAbort();
            }
            catch (Exception ex)
            {
                //TB.AppendText(Environment.NewLine + "Отключаемся");
                if (stream != null)
                {
                    stream.Close();
                }
            }
        }
        public void CONNZAP()
        {
            try
            {
                Btn.Invoke((MethodInvoker)(delegate() { Btn.Enabled = false; }));
                client = new TcpClient(address, port); //подключаемся
                stream = client.GetStream();           //открываем поток

                {
                    data = Encoding.Unicode.GetBytes(Environment.UserName); //имя залогиневшего пользователя конвертим в массив байт
                    stream.Write(data, 0, data.Length);                     //отправляем массив байт по сети

                    do
                    {
                        CountBytes = stream.Read(data, 0, data.Length);
                        builder.Append(Encoding.Unicode.GetString(data, 0, CountBytes));
                    }while (stream.DataAvailable);
                    TB.Invoke((MethodInvoker)(delegate() { TB.AppendText(Environment.NewLine + " Получили от сервера - " + builder.ToString()); }));
                    builder.Clear();
                    Btn.Invoke((MethodInvoker)(delegate() { Btn.Enabled = true; }));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Не удалось установить соединение, проверьте параметры подключения и брандмауэр на предмет блокировки порта" + ex, "Ошибка соединения", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                if (client != null)
                {
                    client.Close();
                }
            }
            finally
            {
                if (client != null)
                {
                    client.Close();
                }
                Btn.Invoke((MethodInvoker)(delegate() { Btn.Enabled = true; }));
            }
        }
Exemple #4
0
        private void Form1_Shown(object sender, EventArgs e)
        {
            this.Size     = new Size(400, 800);
            this.Location = new Point(0, 0);
            InitializeControls();
            {
                Thread thread = new Thread(() =>
                {
                    while (true)
                    {
                        StringBuilder s = new StringBuilder();
                        foreach (var sh in socketHandlers)
                        {
                            s.AppendLine(sh.status);
                        }
                        s.AppendLine(status);
                        if (s.ToString() != LBL.Text)
                        {
                            LBL.Invoke(new Action(() => { LBL.Text = s.ToString(); }));
                        }
                        Thread.Sleep(10);
                    }
                });
                thread.IsBackground = true;
                thread.Start();
            }
            {
                Thread thread = new Thread(() =>
                {
                    while (true)
                    {
                        PBX.Invoke(new Action(() => { PBX.Image = (AIaction == '0' ? Properties.Resources.buttonLight : Properties.Resources.buttonDark); }));
                        TB.Invoke(new Action(() =>
                        {
                            int target = ((int)Math.Round(AIpressButtonPossibility * 1000.0) - TB.Value);
                            if (target > 0)
                            {
                                TB.Value += (int)Math.Ceiling(target * 0.2);
                            }
                            if (target < 0)
                            {
                                TB.Value += (int)Math.Floor(target * 0.2);
                            }
                            Application.DoEvents();
                        }));
                        Thread.Sleep(20);
                    }
                    ;
                });
                thread.IsBackground = true;
                thread.Start();
            }
            try
            {
                comport = new SerialPort("COM3", 115200, Parity.None, 8, StopBits.One);
                comport.DataReceived += Comport_DataReceived;
                if (!comport.IsOpen)
                {
                    comport.Open();
                }
            }
            catch (Exception error)
            {
                status += $"\r\nArduino doesn't connected, restart the program to try again\r\nError:\r\n{error}";
            }
            for (int i = 1; i <= socketCount; i++)
            {
                socketHandlers.Add(new MessageSender(port + i));
            }
            socketHandlers.Add(new MessageSender(port));
            MessageReceiver receiver = new MessageReceiver(aiPort);

            receiver.msgReceived += Receiver_msgReceived;
            receiver.Start();
        }