Пример #1
0
        public async Task <IEnumerable <Event> > ProcessAsync(Event evnt)
        {
            var fraudCheckFailed = evnt.GetBody <FraudCheckFailed>();
            var order            = await _orderStore.GetAsync(fraudCheckFailed.OrderId);

            Trace.TraceInformation("FraudCancelOrderActor - This order must be cancelled: " + order.Id);

            if (order.IsCancelled)
            {
                return(new Event[0]);
            }

            order.IsCancelled = true;
            await _orderStore.UpsertAsync(order);

            Trace.TraceInformation("FraudCancelOrderActor - order cancelled: " + order.Id);

            return(new[]
            {
                new Event(new OrderCancelled()
                {
                    OrderId = order.Id,
                    Reason = "Fraudulent payment"
                })
                {
                    EventType = "OrderCancelled",
                    QueueName = "OrderCancelled"
                }
            });
        }
Пример #2
0
        public async Task <IEnumerable <Event> > ProcessAsync(Event evnt)
        {
            var newsFeedPulsed = evnt.GetBody <NewsFeedPulsed>();
            var client         = new HttpClient();
            var stream         = await client.GetStreamAsync(newsFeedPulsed.Url);

            var feedChannel = new FeedChannel(newsFeedPulsed.Url);
            var feed        = SyndicationFeed.Load(XmlReader.Create(stream));
            var offset      = DateTimeOffset.MinValue;

            if (await _channelStore.ExistsAsync(feedChannel.Id))
            {
                feedChannel = await _channelStore.GetAsync(feedChannel.Id);

                offset = feedChannel.LastOffset;
            }
            feedChannel.LastOffset = feed.Items.Max(x => x.PublishDate);
            await _channelStore.UpsertAsync(feedChannel);

            return(feed.Items.OrderByDescending(x => x.PublishDate)
                   .TakeWhile(y => offset < y.PublishDate)
                   .Select(z => new Event(new NewsItemCaptured()
            {
                Item = z.ToFeedItem()
            })));
        }
Пример #3
0
        public async Task <IEnumerable <Event> > ProcessAsync(Event evnt)
        {
            var paymentFailed = evnt.GetBody <PaymentFailed>();
            var order         = await _orderStore.GetAsync(paymentFailed.OrderId);

            order.IsCancelled = true;
            await _orderStore.UpsertAsync(order);

            Trace.TraceInformation("Order cancelled");

            return(new[]
            {
                new Event(new OrderCancelled()
                {
                    OrderId = order.Id,
                    Reason = "Payment failure"
                })
            });
        }