Esempio n. 1
0
        private void BtnLogOut_Click(object sender, EventArgs e)
        {
            LogInForm l = new LogInForm();

            this.Hide();
            l.ShowDialog();
            this.Close();
        }
Esempio n. 2
0
        private void BtnRegister_Click(object sender, EventArgs e)
        {
            try
            {
                string username = txtUsernameReg.Text;
                string password = txtPassReg.Text;
                var    factory  = new ConnectionFactory()
                {
                    HostName = "localhost"
                };
                using (var connection = factory.CreateConnection())
                    using (var channel = connection.CreateModel())
                    {
                        channel.ExchangeDeclare(exchange: "registerResponse", type: "direct");

                        var queueName = channel.QueueDeclare().QueueName;

                        channel.QueueBind(queue: queueName,
                                          exchange: "registerResponse",
                                          routingKey: queueName);

                        Console.WriteLine(" [*] Waiting for logs.");

                        var  consumer = new EventingBasicConsumer(channel);
                        bool primio   = false;
                        var  messageR = "";
                        consumer.Received += (model, ea) =>
                        {
                            var body1    = ea.Body;
                            var message1 = Encoding.UTF8.GetString(body1);
                            messageR = message1;
                            primio   = true;
                        };

                        channel.BasicConsume(queue: queueName,
                                             autoAck: true,
                                             consumer: consumer);
                        var message = "username:"******": password:"******": routingKey:" + queueName;
                        var body    = Encoding.UTF8.GetBytes(message);
                        channel.BasicPublish(exchange: "registerCall",
                                             routingKey: "register",
                                             basicProperties: null,
                                             body: body);
                        while (!primio)
                        {
                            ;
                        }
                        if (messageR.Length < 30)
                        {
                            MessageBox.Show(messageR.ToString());
                            LogInForm log = new LogInForm();
                            this.Hide();
                            this.Close();
                            log.ShowDialog();
                        }
                        else
                        {
                            MessageBox.Show(messageR.ToString());
                        }
                    };
            }
            catch (Exception ec)
            {
                MessageBox.Show(ec.Message);
            }
        }