Пример #1
0
 private void Disconnect()
 {
     timer1.Stop();
     Thread.Sleep(500);
     clusterClient.Disconnect();
     clusterClient = null;
     server.Stop();
 }
Пример #2
0
        public bool Connect()
        {
            buttonStart.Enabled = false;
            if (textBoxCallsign.Text.Length == 0)
            {
#pragma warning disable CA1303 // Do not pass literals as localized parameters
                MessageBox.Show("Need callsign!~", "QueueIt");
#pragma warning restore CA1303 // Do not pass literals as localized parameters
                buttonStart.Enabled = true;
                return false;
            }
            char[] sep = { ':' };
            var tokens = textBoxClusterServer.Text.Split(sep);
            if (tokens.Length > 0 && tokens.Length != 2)
            {
#pragma warning disable CA1303 // Do not pass literals as localized parameters
                MessageBox.Show("Bad format for cluster server", "ClusterServer");
#pragma warning restore CA1303 // Do not pass literals as localized parameters
                buttonStart.Enabled = true;
                return false;
            }
            string host = tokens[0];
            int port = Int32.Parse(tokens[1], CultureInfo.InvariantCulture);
            if (qrz != null) qrz.Dispose();
            qrz = new QRZ(textBoxCallsign.Text, textBoxPassword.Text);
            if (qrz == null || qrz.isOnline == false)
            {
                if (qrz != null) richTextBox1.AppendText("QRZ: " + qrz.xmlError + "\n");
                return false;
            }
            clusterClient = new ClusterClient(host, port, spotQueue, qrz)
            {
                rttyOffset = (float)numericUpDownRTTYOffset.Value
            };
            try
            {
#pragma warning disable CA1303 // Do not pass literals as localized parameters
                richTextBox1.AppendText("Trying to connect\n");
                richTextBox1.SelectionStart = richTextBox1.TextLength;
                richTextBox1.ScrollToCaret();
#pragma warning restore CA1303 // Do not pass literals as localized parameters
                Application.DoEvents();
                if (clusterClient.Connect(textBoxCallsign.Text, richTextBox1, clientQueue))
                {
                    //richTextBox1.AppendText("Connected\n");
                    timer1.Start();
#pragma warning disable CA1303 // Do not pass literals as localized parameters
                    buttonStart.Text = "Disconnect";
#pragma warning restore CA1303 // Do not pass literals as localized parameters
                              //richTextBox1.SelectionStart = richTextBox1.Text.Length;
                              //richTextBox1.ScrollToCaret();
                }
                else
                {
#pragma warning disable CA1303 // Do not pass literals as localized parameters
                    buttonStart.Text = "Start";
                    richTextBox1.AppendText("Connect failed....hmmm...no answer from cluster server?\n");
#pragma warning restore CA1303 // Do not pass literals as localized parameters
                }
                ReviewedSpottersSave(false);
                clusterClient.listBoxIgnore = listBoxIgnoredSpotters;
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
            {
                buttonStart.Enabled = true;
#pragma warning disable CA1303 // Do not pass literals as localized parameters
                buttonStart.Text = "Connect";
                MessageBox.Show(ex.Message, "QueueIt");
#pragma warning restore CA1303 // Do not pass literals as localized parameters
            }

            // Now start the server for Log4OM to get the spots from the queue
            if (Int32.TryParse(textBoxPortLocal.Text, out int qport))
            {
                if (server == null)
                {
                    server = new QServer(qport, clientQueue, spotQueue);
                    _ = Task.Run(() => server.Start());
#pragma warning disable CA1305 // Specify IFormatProvider
                    TimeIntervalForDump = Convert.ToInt32(comboBoxTimeInterval.SelectedItem);
                    TimeIntervalAfter = Convert.ToInt32(comboBoxTimeIntervalAfter.SelectedItem);
#pragma warning restore CA1305 // Specify IFormatProvider
                }
            }
            buttonStart.Enabled = true;
            return true;
        }