示例#1
0
 private Task HandleShipmentRequestedEvent(ShipmentRequestedEvent shipmentRequestedEvent)
 {
     if (shipmentRequestedEvent.FactoryId == _configuration.Factorino.FactoryId)
     {
         _logger.Debug($"Shipment requested for factory, waiting for fulfillment...");
         _state.PendingShipments[shipmentRequestedEvent.EntityId] = new Shipment
         {
             ShipmentId         = shipmentRequestedEvent.EntityId,
             DestinationStation = shipmentRequestedEvent.DestinationStation,
             Carts          = shipmentRequestedEvent.Carts,
             WaitConditions = shipmentRequestedEvent.WaitConditions,
         };
     }
     return(Task.CompletedTask);
 }
示例#2
0
        public async Task <Shipment> CreateShipment(Shipment shipment)
        {
            var player = await _playerRepo.GetPlayer(Context.User);

            var factory = await _factoryRepository.GetFactory(shipment.FactoryId);

            if (factory == null)
            {
                throw new EntityNotFoundException(shipment.FactoryId);
            }

            var shipmentId = Guid.NewGuid();

            shipment.ShipmentId     = shipmentId;
            shipment.Factory        = factory;
            shipment.WaitConditions = new[]
            {
                new WaitCondition
                {
                    CompareType = WaitConditionCompareType.Or,
                    Type        = WaitConditionType.Empty,
                },
                new WaitCondition
                {
                    CompareType = WaitConditionCompareType.Or,
                    Type        = WaitConditionType.Inactivity,
                    Ticks       = 2400,
                },
            };

            // We need to receive all events for this shipment from now on
            await Subscribe(shipmentId);

            var evnt = new ShipmentRequestedEvent(shipmentId, shipment.FactoryId, player)
            {
                DestinationStation = shipment.DestinationStation,
                Carts          = shipment.Carts.ToArray(),
                WaitConditions = shipment.WaitConditions.ToArray(),
            };
            await _eventStore.ProduceAsync(evnt);

            return(shipment);
        }