Exemple #1
0
        private async Task HandleShipmentFulfilledEvent(ShipmentFulfilledEvent shipmentFulfilledEvent)
        {
            if (shipmentFulfilledEvent.FactoryId == _configuration.Factorino.FactoryId)
            {
                _logger.Debug($"Shipment fulfilled, spawning resources and producing event...");
                if (_state.PendingShipments.ContainsKey(shipmentFulfilledEvent.EntityId))
                {
                    try
                    {
                        var shipment = _state.PendingShipments[shipmentFulfilledEvent.EntityId];
                        await _rcon.SendCommandAsync($"/factorino_import {JsonConvert.SerializeObject(shipment.ToDTO())}");

                        await _producer.ProduceAsync(new ShipmentReceivedEvent(shipment.ShipmentId, _configuration.Factorino.FactoryId, null));

                        _state.PendingShipments.Remove(shipmentFulfilledEvent.EntityId);
                    }
                    catch (Exception e)
                    {
                        _logger.Error(e, $"Could not spawn shipment {shipmentFulfilledEvent.EntityId}!");
                    }
                }
                else
                {
                    _logger.Error($"Expected to find shipment with ID {shipmentFulfilledEvent.EntityId} in pending shipments, but could not find it!");
                }
            }
        }
        public Task Handle(ShipmentFulfilledEvent evnt)
        {
            var shipment = _dbContext.Shipments.FirstOrDefault(s => s.ShipmentId == evnt.EntityId);

            if (shipment != null)
            {
                shipment.State = ShipmentState.Fulfilled;
            }
            return(Task.CompletedTask);
        }
Exemple #3
0
        public Task Handle(ShipmentFulfilledEvent evnt)
        {
            _state.HandledShipments.TryPeek(out var handledShipment);
            if (handledShipment == evnt.EntityId)
            {
                // If we've already handled this event through the evaluator,
                // we don't want to mess with inventory
                _state.HandledShipments.Dequeue();
                return(Task.CompletedTask);
            }

            var shipment = _state.Shipments[evnt.EntityId];

            foreach (var cart in shipment.Carts)
            {
                foreach (var stack in cart.Inventory)
                {
                    shipment.Owner.Inventory[stack.Name].Quantity -= stack.Count;
                }
            }

            shipment.State = ShipmentState.Fulfilled;
            return(Task.CompletedTask);
        }