Example #1
0
        public async Task <TrackingDTO> FindByIdAsync(string bookingId)
        {
            //check in the redis cahce
            var bookingHistroy = await GetFromCache(bookingId);

            //if not found in the cahce
            if (string.IsNullOrEmpty(bookingHistroy))
            {
                //get from database
                var result = await _context.GetTrackingAsync(bookingId);

                if (result != null)
                {
                    //format result and serlize the history
                    bookingHistroy = JsonConvert.SerializeObject(result.orderHistory);
                    SetCache(bookingId, bookingHistroy);
                }
            }

            return(new TrackingDTO
            {
                BookingId = bookingId,
                TrackingHistory = bookingHistroy
            });
        }
Example #2
0
        public async Task Handle(OrderTransitIntegrationEvent eventMsg)
        {
            List <EventBase> events = new List <EventBase>();

            if (eventMsg.Id != Guid.Empty)
            {
                try
                {
                    Track trackings = await _trackingContext.GetTrackingAsync(eventMsg.BookingId);

                    if (trackings == null)
                    {
                        trackings = new Track();
                    }

                    var messageType = _assemblyTypes
                                      .Where(t => t.Name.Contains("OrderInTransit")).FirstOrDefault().
                                      Name.ToString();

                    OrderInTransit orderInTransit = new
                                                    OrderInTransit(eventMsg.BookingId, eventMsg.Description, eventMsg.Id
                                                                   , messageType, eventMsg.CreationDate);


                    events.AddRange(trackings.OrderInTransit(orderInTransit));
                    trackings.Version = trackings.OriginalVersion + 1;

                    await _trackingContext.SaveTrackingAsync(eventMsg.BookingId, trackings.OriginalVersion,
                                                             trackings.Version, events);


                    //Publish the event here
                    //Create Integration Event
                    var orderStatusChanged = new OrderStatusChangedIntegrationEvent(eventMsg.BookingId, "OrderInTransit");
                    _eventBus.Publish(orderStatusChanged);
                }
                catch (Exception e)
                {
                    var ExceptionTelemetry = new ExceptionTelemetry(e);
                    ExceptionTelemetry.Properties.Add("OrderTransitIntegrationEvent", eventMsg.BookingId);
                    ExceptionTelemetry.SeverityLevel = SeverityLevel.Critical;

                    telemetry.TrackException(ExceptionTelemetry);

                    throw; //Throw exception for service bus to abandon the message
                }
            }
        }
Example #3
0
        public async Task <TrackingDTO> FindByIdAsync(string bookingId)
        {
            var result = await _context.GetTrackingAsync(bookingId);

            var bookingHistroy = string.Empty;

            if (result != null)
            {
                //format result and serilize it
                bookingHistroy = JsonConvert.SerializeObject(result.orderHistory);
            }

            return(new TrackingDTO
            {
                BookingId = bookingId,
                TrackingHistory = bookingHistroy
            });
        }