Beispiel #1
0
        private void ApriSchermataCompra(bool UsernameScelto)
        {
            if (!UsernameScelto)
            {
                formCompra   f = new formCompra(Channel, Connection);
                DialogResult r = f.ShowDialog();
                if (r == System.Windows.Forms.DialogResult.OK)
                {
                    this.NumCartelle = f.Compra.NumCartelle;
                    this.Saldo       = f.Compra.Saldo;
                    this.Username    = f.Compra.Username;

                    lblNome.Text  = this.Username;
                    lblConto.Text = this.Saldo.ToString("0.00") + "€";
                    DichiaraCode();

                    var props = Channel.CreateBasicProperties();
                    props.Headers = new Dictionary <string, object>();
                    props.Headers.Add("Oggetto", 1);
                    props.Headers.Add("NumCartelle", NumCartelle);
                    byte[] body = Encoding.UTF8.GetBytes(Username);
                    Channel.BasicPublish("CS" + Username, "", props, body);
                }
                else
                {
                    AvvisaTabellone = false;
                    this.Close();
                }
            }
            else
            {
                formCompra   f = new formCompra(Channel, Connection, Saldo, Username, true);
                DialogResult r = f.ShowDialog();
                if (r == System.Windows.Forms.DialogResult.OK)
                {
                    this.NumCartelle = f.Compra.NumCartelle;
                    this.Saldo       = f.Compra.Saldo;
                    lblConto.Text    = this.Saldo.ToString("0.00") + "€";
                    pnlRiquadroCartelle.Controls.Clear();

                    var props = Channel.CreateBasicProperties();
                    props.Headers = new Dictionary <string, object>();
                    props.Headers.Add("Oggetto", 1);
                    props.Headers.Add("NumCartelle", NumCartelle);
                    byte[] body = Encoding.UTF8.GetBytes(Username);
                    Channel.BasicPublish("CS" + Username, "", props, body);
                }
                else
                {
                    Invia("CS" + Username, 2, Username);
                    AvvisaTabellone = false;
                    this.Close();
                }
            }
        }
Beispiel #2
0
        private void btnConferma_Click(object sender, EventArgs e)
        {
            if (!UsernameScelto)
            {
                Channel.ExchangeDeclare("qRichieste", "direct", false, false, null);
                Channel.QueueDeclare("qRichieste", false, false, false, null);
                Channel.QueueBind("qRichieste", "qRichieste", "", null);
                Channel.QueueDeclare("Try" + Username, false, false, false, null);
                Channel.ExchangeDeclare("Try" + Username, ExchangeType.Direct, false, false, null);
                Channel.QueueBind("Try" + Username, "Try" + Username, "");
                var consumer = new EventingBasicConsumer(Channel);

                var props = Channel.CreateBasicProperties();

                var correlationId = Guid.NewGuid().ToString();
                props.CorrelationId = correlationId;
                props.Headers       = new Dictionary <string, object>();
                props.Headers.Add("Oggetto", 0);

                consumer.Received += (model, ea) =>
                {
                    var body     = ea.Body;
                    var response = Encoding.UTF8.GetString(body);
                    if (ea.BasicProperties.CorrelationId == correlationId)
                    {
                        this.BeginInvoke((MethodInvoker) delegate()
                        {
                            int codice = Int32.Parse(response);
                            Channel.QueueDelete("Try" + Username);
                            if (codice == 0)
                            {
                                formCompra f   = (formCompra)this.Parent;
                                f.DialogResult = DialogResult.OK;
                                f.Close();
                            }
                            else
                            {
                                lblVerifica.ForeColor = Color.Red;
                                if (codice == 1)
                                {
                                    lblVerifica.Text = "Lobby piena!";
                                }
                                else
                                {
                                    lblVerifica.Text = "Username già in uso!";
                                }
                                this.btnAggiungi.Enabled = true;
                                this.btnConferma.Enabled = true;
                                this.btnRimuovi.Enabled  = true;
                            }
                        });
                    }
                };
                var messageBytes = Encoding.UTF8.GetBytes(Username);
                Channel.BasicPublish("qRichieste", "", props, messageBytes);

                Channel.BasicConsume(consumer: consumer, queue: "Try" + Username, autoAck: true);

                this.btnAggiungi.Enabled = false;
                this.btnConferma.Enabled = false;
                this.btnRimuovi.Enabled  = false;
            }
            else
            {
                formCompra f = (formCompra)this.Parent;
                f.DialogResult = DialogResult.OK;
                f.Close();
            }
        }