Beispiel #1
0
        public void HandleOpenRides()
        {
            foreach (var ride in rideRepo.All().Where(ride => ride.Status.Equals(RideStatus.Open)))
            {
                if (ride.EndTime > DateTime.Now)
                {
                    continue;
                }

                var unboardedVisitors = ride.UnboardVisitors();

                if (ride.Status.Equals(RideStatus.Open))
                {
                    ride.Start();
                }

                if (unboardedVisitors.Count > 0)
                {
                    var payload = new Dictionary <string, string>
                    {
                        { "Visitors", JsonConvert.SerializeObject(unboardedVisitors.ConvertAll(visitor => visitor.Guid)) },
                        { "DateTime", JsonConvert.SerializeObject(DateTime.Now) }
                    };

                    var unboardedEvent = new Event(EventType.VisitorsUnboarded, EventSource.Ride, payload);
                    eventProducer.Produce(unboardedEvent);
                }

                Task.Delay(100).Wait();
            }
        }
Beispiel #2
0
        public void OpenPark()
        {
            status = EntranceStatus.Open;
            logger.LogInformation("Park has opened");
            var eventOut = new Event(EventType.StatusChanged, EventSource.Park, new Dictionary <string, string>()
            {
                { "Status", "Open" }
            });

            eventProducer.Produce(eventOut);
        }
        private void SendOrderTicket(string ticket)
        {
            var orderEvent = new Event(EventType.OrderReady, EventSource.Stand, new Dictionary <string, string>()
            {
                { "Order", ticket }
            });

            eventProducer.Produce(orderEvent);
        }
Beispiel #4
0
        public void StartLocationActivity(Visitor visitor)
        {
            var eventPayload = new Dictionary <string, string>
            {
                { "Visitor", visitor.Guid.ToString() }
            };

            eventPayload.Add("FairyTale", visitor.TargetLocation.Guid.ToString());
            var watchingFairyTale = new Event(EventType.ArrivedAtFairyTale, EventSource.Visitor, eventPayload);

            eventProducer.Produce(watchingFairyTale);
            visitor.DoActivity(visitor.TargetLocation);
        }
        public void HandleVisitorArrivingAtFairyTale(Guid visitor)
        {
            logger.LogDebug("Visitor with ID {VisitorId} arrived at fairy tale", visitor.ToString());
            var payload = new Dictionary <string, string>()
            {
                { "Visitor", visitor.ToString() },
                { "EndDateTime", GetEndDateTimeForVisitorWatchingFairyTale().ToString() }
            };

            var outgoingEvent = new Event(EventType.WatchingFairyTale, EventSource.FairyTale, payload);

            eventProducer.Produce(outgoingEvent);
        }
Beispiel #6
0
        public void StartLocationActivity(Visitor visitor)
        {
            var eventPayload = new Dictionary <string, string>
            {
                { "Visitor", visitor.Guid.ToString() }
            };

            eventPayload.Add("Ride", visitor.TargetLocation.Guid.ToString());
            var steppingIntoRide = new Event(EventType.StepInRideLine, EventSource.Visitor, eventPayload);

            eventProducer.Produce(steppingIntoRide);

            visitor.DoActivity(visitor.TargetLocation);
        }
Beispiel #7
0
    /// <summary>
    /// Produce a message of type <see cref="TMessage"/>. The type is used to look up the type name
    /// in the <seealso cref="TypeMap"/>.
    /// </summary>
    /// <param name="producer"></param>
    /// <param name="stream">Stream name where the message should be produced</param>
    /// <param name="message">Message to produce</param>
    /// <param name="metadata"></param>
    /// <param name="onAck">Function to confirm that the message was produced</param>
    /// <param name="cancellationToken"></param>
    /// <typeparam name="TMessage">Message typ</typeparam>
    /// <returns></returns>
    public static Task Produce <TMessage>(
        this IEventProducer producer,
        StreamName stream,
        TMessage message,
        Metadata?metadata,
        AcknowledgeProduce?onAck            = null,
        CancellationToken cancellationToken = default
        ) where TMessage : class
    {
        var producedMessages =
            message is IEnumerable <object> collection
                ? ConvertMany(collection, metadata, onAck)
                : ConvertOne(message, metadata, onAck);

        return(producer.Produce(stream, producedMessages, cancellationToken));
    }
Beispiel #8
0
        public void StartLocationActivity(Visitor visitor)
        {
            StandDto stand  = standClient.GetStand(visitor.TargetLocation.Guid);
            string   ticket = standClient.OrderDinner(stand.Guid, visitor.PickStandProducts(stand));

            visitor.DoActivity(visitor.TargetLocation);

            var eventPayload = new Dictionary <string, string>
            {
                { "Visitor", visitor.Guid.ToString() },
                { "Ticket", ticket }
            };

            var waitingForOrder = new Event(EventType.WaitingForOrder, EventSource.Visitor, eventPayload);

            eventProducer.Produce(waitingForOrder);
        }
Beispiel #9
0
    public override async ValueTask <EventHandlingStatus> HandleEvent(IMessageConsumeContext context)
    {
        var shovelMessages = await _transform(context).NoContext();

        if (shovelMessages.Length == 0)
        {
            return(EventHandlingStatus.Ignored);
        }

        AcknowledgeProduce?onAck = null;

        if (context is DelayedAckConsumeContext delayed)
        {
            onAck = _ => delayed.Acknowledge();
        }

        try {
            var grouped = shovelMessages.GroupBy(x => x.TargetStream);

            await grouped
            .Select(x => ProduceToStream(x.Key, x))
            .WhenAll()
            .NoContext();
        }
        catch (OperationCanceledException e) {
            context.Nack <GatewayHandler>(e);
        }

        return(_awaitProduce ? EventHandlingStatus.Success : EventHandlingStatus.Pending);

        Task ProduceToStream(StreamName streamName, IEnumerable <GatewayMessage <TProduceOptions> > toProduce)
        => toProduce.Select(
            x =>
            _eventProducer.Produce(
                streamName,
                x.Message,
                x.GetMeta(context),
                x.ProduceOptions,
                onAck,
                context.CancellationToken
                )
            )
        .WhenAll();
    }