示例#1
0
            /// <summary>
            /// Populates the tracking info for each shipment.
            /// </summary>
            /// <param name="shipments">The shipments.</param>
            /// <param name="requestContext">The request context.</param>
            private static void PopulateTrackingInfo(ICollection <Shipment> shipments, RequestContext requestContext)
            {
                if (shipments == null)
                {
                    throw new ArgumentNullException("shipments");
                }

                if (requestContext == null)
                {
                    throw new ArgumentNullException("requestContext");
                }

                // Dictionary to keep track of non-duplicate delivery mode ids alongwith associated adapterconfigs and tracking numbers.
                Dictionary <string, TrackingConfig> deliveryModeIdMapper = new Dictionary <string, TrackingConfig>(StringComparer.OrdinalIgnoreCase);

                // Map a list of non-duplicate delivery mode Ids to corresponding tracking numbers containers across all shipments.
                foreach (Shipment shipment in shipments)
                {
                    // If deliveryModeId not encountered so far, then add entry to dictionary.
                    if (!deliveryModeIdMapper.ContainsKey(shipment.DeliveryMode))
                    {
                        deliveryModeIdMapper.Add(shipment.DeliveryMode, new TrackingConfig());
                    }

                    var trackingConfig = deliveryModeIdMapper[shipment.DeliveryMode];

                    // Consolidate all tracking numbers that have the same delivery mode.
                    if (!string.IsNullOrWhiteSpace(shipment.TrackingNumber))
                    {
                        trackingConfig.TrackingNumbers.Add(shipment.TrackingNumber);
                    }
                }

                PopulateAdapterConfig(requestContext, deliveryModeIdMapper);

                // For each unique delivery mode identifier, fetch and contact the associated adapter.
                foreach (var trackingConfig in deliveryModeIdMapper.Values)
                {
                    var             carrierServiceRequest  = new GetTrackingInformationFromCarrierServiceRequest(trackingConfig.AdapterConfig, trackingConfig.TrackingNumbers);
                    IRequestHandler carrierAdapterHandler  = GetCarrierAdapterService(requestContext, carrierServiceRequest.GetType(), trackingConfig.AdapterConfig);
                    var             carrierServiceResponse = requestContext.Runtime.Execute <GetTrackingInformationFromCarrierServiceResponse>(carrierServiceRequest, requestContext, carrierAdapterHandler);

                    // Update shipments based on response.
                    foreach (TrackingInfo trackingDetail in carrierServiceResponse.TrackingDetails.Results)
                    {
                        var matchingShipments = shipments.Where(shipment => string.Equals(shipment.TrackingNumber, trackingDetail.TrackingNumber, StringComparison.OrdinalIgnoreCase));
                        foreach (var shipment in matchingShipments)
                        {
                            shipment.LatestCarrierTrackingInfo = trackingDetail;
                        }
                    }
                }
            }
示例#2
0
 private static GetTrackingInformationFromCarrierServiceResponse GetTrackingDetails(GetTrackingInformationFromCarrierServiceRequest request)
 {
     return(new GetTrackingInformationFromCarrierServiceResponse((new Collection <TrackingInfo>()).AsPagedResult()));
 }