public void RegisterHandler <T>(IConsume <T> handler) where T : class, Event
 {
     if (_registry.ContainsKey(typeof(T)))
     {
         _registry[typeof(T)] += e => handler.Consume(e as T);
     }
     else
     {
         _registry.Add(typeof(T), e => handler.Consume(e as T));
     }
 }
Exemplo n.º 2
0
    public void UseItem(int selected)
    {
        if (activeFilter == Item.Categories.Misc || activeFilter == Item.Categories.Ammo)
        {
            GD.Print("Nothing to do with these.");
            return;
        }
        ItemData dat             = itemData[selected];
        Actor    player          = Session.session.player;
        int      playerItemIndex = player.IndexOf(dat.type, dat.name);

        switch (activeFilter)
        {
        case Item.Categories.Weapons:
            player.EquipItem(playerItemIndex);
            break;

        case Item.Categories.Apparel:
            player.EquipItem(playerItemIndex);
            break;

        case Item.Categories.Aid:
            ItemData retrieved  = player.RetrieveItem(playerItemIndex);
            IConsume consumable = Item.FromData(retrieved) as IConsume;
            if (consumable != null)
            {
                consumable.Consume(player);
            }
            break;
        }


        RefreshInventory();
        RefreshStashItemInfo();
    }
Exemplo n.º 3
0
 public bool Consume(IMessage message)
 {
     //TODO: Hack, find a better way
     if (message.GetType() == typeof(TMessage))
     {
         return(consumer.Consume((TMessage)message));
     }
     return(true);
 }
Exemplo n.º 4
0
        public bool Consume(TMessage message)
        {
            var value = random.NextDouble();

            if (value <= chanceToFail)
            {
                return(true);
            }
            return(nextStep.Consume(message));
        }
 private void PublishIfNecessary()
 {
     if (_count == _builder.length)
     {
         _count = 0;
         _channel.Consume(new OneGenerationOfCellStatesAggregated
         {
             grid = _builder.Build()
         });
     }
 }
Exemplo n.º 6
0
 public void Consume(LivingNeighborsOfDeadCellCounted eventData)
 {
     if (eventData.livingNeighbors == 3)
     {
         _cellLivedChannel.Consume(new CellLived
         {
             position = eventData.position
         });
     }
     else
     {
         _cellDiedChannel.Consume(new CellDied
         {
             position = eventData.position
         });
     }
 }
Exemplo n.º 7
0
        public bool Consume(OrderReadyToCook message)
        {
            if (message.Order.TimeToLive < DateTime.Now)
            {
                Logger.Error("Order dropped. Id {0}", message.Order.Id);
                TopicPubSub.Instance.Publish(message.CorrelationId, new OrderDropped()
                {
                    Order = message.Order
                });
            }
            else
            {
                return(nextStep.Consume(message));
            }

            return(true);
        }
 private void StartProcessingMessages()
 {
     while (true)
     {
         TMessage message;
         if (messagesToProcess.TryDequeue(out message))
         {
             if (!consumer.Consume(message))
             {
                 messagesToProcess.Enqueue(message);
             }
         }
         else
         {
             Thread.Sleep(100);
         }
     }
 }
Exemplo n.º 9
0
 public void Consume(GenerationCompleted eventData)
 {
     foreach (var cell in eventData.grid)
     {
         var numberLiving = cell.Neighbors().Count(n => n.value);
         if (cell.value)
         {
             _liveCellEventHandler.Consume(new LivingNeighborsOfLiveCellCounted
             {
                 livingNeighbors = numberLiving,
                 position        = cell.position
             });
         }
         else
         {
             _deadCellEventHandler.Consume(new LivingNeighborsOfDeadCellCounted
             {
                 livingNeighbors = numberLiving,
                 position        = cell.position
             });
         }
     }
 }
 public void DeliverOne()
 {
     _handler.Consume(_eventQueue.Dequeue());
 }