Ejemplo n.º 1
0
 public static void Run(IConnection connection)
 {
     using (var channel = connection.CreateModel())
     {
         using (var context = new SportEventsContext())
         {
             var events   = context.Set <SportEvent>();
             var consumer = new EventingBasicConsumer(channel);
             consumer.Received += (model, ea) =>
             {
                 var body       = ea.Body;
                 var sportEvent = Encoding.UTF8.GetString(body).ToSportEvent();
                 Console.WriteLine(sportEvent);
                 if (events.Contains(sportEvent))
                 {
                     context.Modify(sportEvent);
                 }
                 else
                 {
                     events.Add(sportEvent);
                 }
                 context.SaveChanges();
             };
             channel.BasicConsume(queue: "sport_events",
                                  autoAck: true,
                                  consumer: consumer);
             connection.ConnectionShutdown += (x, y) => { Environment.Exit(0); };
             Thread.Sleep(Timeout.Infinite);
         }
     }
 }
Ejemplo n.º 2
0
        public static void Modify(this SportEventsContext contextEvent, SportEvent sportEvent)
        {
            var result = contextEvent.Events.SingleOrDefault(b => b == sportEvent);

            if (result == null)
            {
                return;
            }
            result.Copy(sportEvent);
            contextEvent.SaveChanges();
        }