Beispiel #1
0
        /// <summary>
        ///		Puts the tracking response data into the common
        ///		<see cref="TrackingData"/> format.
        /// </summary>
        /// <returns>
        ///		Gets the <see cref="TrackingData"/> that contains the tracking
        ///		information for this response.
        /// </returns>
        public static TrackingData GetCommonTrackingData(string xml)
        {
            _log.Debug("Processing UPS tracking response data: " + xml);

            try
            {
                var td = new TrackingData();

                var xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(xml);

                //Verify that the shipment information is available
                //in the XML, if it isn't, they must not have any
                //tracking data yet.
                var node = xmlDoc.SelectSingleNode("/TrackResponse/Shipment");
                if (node == null)
                {
                    return(null);
                }

                node = xmlDoc.SelectSingleNode("/TrackResponse/Shipment/ScheduledDeliveryDate/text()");
                if (node != null)
                {
                    td.EstimatedDelivery = UpsFormatConversions.parseUpsDate(node.Value);
                }

                var nodes = xmlDoc.SelectNodes("/TrackResponse/Shipment/ReferenceNumber/Value/text()");
                for (var i = 0; i < nodes.Count; i++)
                {
                    td.ReferenceNumbers.Add(nodes[i].Value);
                }

                node = xmlDoc.SelectSingleNode("/TrackResponse/Shipment/Service/Description/text()");
                if (node != null)
                {
                    td.ServiceType = node.Value;
                }

                node = xmlDoc.SelectSingleNode("/TrackResponse/Shipment/Package/PackageWeight/Weight/text()");
                if (node != null)
                {
                    td.Weight = decimal.Parse(node.Value);
                }

                td.Activity = getActivities(xmlDoc);

                td.TrackerName       = SHIPPER_NAME;
                td.UsageRequirements = USAGE_REQUIREMENTS;

                td.LastUpdated = DateTime.Now;

                return(td);
            }
            catch (Exception ex)
            {
                throw new ResponseParseException(xml, ex);
            }
        }
Beispiel #2
0
        /// <summary>
        ///		Converts a "Scan" node in the XML document into an <see cref="Activity"/>.
        /// </summary>
        /// <param name="scanNode">
        ///		The <see cref="XmlNode"/> that represents a "scan" node.
        /// </param>
        /// <returns>
        ///		An activity that contains the data from the scan.
        /// </returns>
        private static Activity getActivityFromScanNode(XmlNode scanNode)
        {
            var activity = new Activity();

            var dateString = scanNode.SelectSingleNode("Date/text()").Value;
            var timeString = scanNode.SelectSingleNode("Time/text()").Value;

            var date = UpsFormatConversions.parseUpsDate(dateString);
            var time = UpsFormatConversions.parseUpsTime(timeString);

            activity.Timestamp = date.Add(time.TimeOfDay);

            var scanDescriptionNode = scanNode.SelectSingleNode("Status/StatusType/Description/text()");

            if (scanDescriptionNode != null)
            {
                activity.ShortDescription = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(scanDescriptionNode.Value.ToLower());
            }

            string city = null, state = null, countryCode = null;

            var node = scanNode.SelectSingleNode("ActivityLocation/Address/City/text()");

            if (node != null)
            {
                city = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(node.Value.ToLower());
            }
            node = scanNode.SelectSingleNode("ActivityLocation/Address/StateProvinceCode/text()");
            if (node != null)
            {
                state = node.Value;
            }
            node = scanNode.SelectSingleNode("ActivityLocation/Address/CountryCode/text()");
            if (node != null)
            {
                countryCode = node.Value;
            }

            activity.LocationDescription = Location.GetLocationString(city, state, countryCode);

            return(activity);
        }