public async Task <RentOrder> ReceiveMessage(string queueReceive)
        {
            RentOrder rent     = null;
            bool      received = false;
            var       channel  = _connection.CreateModel();

            while (!received)
            {
                channel.QueueDeclare(queue: queueReceive,
                                     durable: false,
                                     exclusive: false,
                                     autoDelete: false,
                                     arguments: null);

                var consumer = new EventingBasicConsumer(channel);
                consumer.Received += async(model, ea) =>
                {
                    var body    = ea.Body;
                    var message = Encoding.UTF8.GetString(body);
                    Console.WriteLine("Received from worker {0}", message);
                    rent     = JsonConvert.DeserializeObject <RentOrder>(message);
                    received = true;
                };
                channel.BasicConsume(queue: queueReceive,
                                     autoAck: true,
                                     consumer: consumer);
            }
            return(await Task.FromResult <RentOrder>(rent));
        }
示例#2
0
 public User AddRent(RentOrder rent)
 {
     if (Balance > rent.TotalPayment)
     {
         Balance -= rent.TotalPayment;
         RentOrders.Add(rent);
         return(this);
     }
     else
     {
         // if null it mans that user doesn't have enough money
         return(null);
     }
 }
示例#3
0
 public User RemoveRent(RentOrder rent)
 {
     Balance += rent.TotalPayment;
     RentOrders.Remove(rent);
     return(this);
 }