Пример #1
0
        public ShippingResult GetTrackingResult()
        {
            string         shippingResultInString = string.Empty;
            ShippingResult shippingResult         = new ShippingResult();

            shippingResultInString = GetTrackingInfoUSPSInString();


            MemoryStream memStream = new MemoryStream(Encoding.UTF8.GetBytes(shippingResultInString));


            USPSTrackingResult.TrackResponse resultingMessage = new USPSTrackingResult.TrackResponse();
            USPSTrackingResultError.Error    error            = new USPSTrackingResultError.Error();

            if (memStream != null)
            {
                if (shippingResultInString.Contains("<Error>") && !shippingResultInString.Contains("<TrackResponse>"))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(USPSTrackingResultError.Error));
                    error          = (USPSTrackingResultError.Error)serializer.Deserialize(memStream);
                    shippingResult = USPSTrackingResultErrorWrap(error);
                }
                else
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(USPSTrackingResult.TrackResponse));
                    resultingMessage = (USPSTrackingResult.TrackResponse)serializer.Deserialize(memStream);
                    shippingResult   = USPSTrackingResultWrap(resultingMessage);
                }
            }

            return(shippingResult);
        }
Пример #2
0
        private ShippingResult USPSTrackingResultErrorWrap(USPSTrackingResultError.Error resultingMessage)
        {
            ShippingResult shippingResult = new ShippingResult();

            shippingResult.StatusCode = "ERROR";
            shippingResult.Status     = resultingMessage.Description;
            shippingResult.Message    = resultingMessage.Description;

            return(shippingResult);
        }
Пример #3
0
        public List <ShippingResult> GetTrackingResult(List <string> trackingNumbers)
        {
            string shippingResultInString        = string.Empty;
            List <ShippingResult> shippingResult = new List <ShippingResult>();

            int           splitCount         = 0;
            List <string> throttledTrackings = null;

            while ((throttledTrackings = trackingNumbers.Skip(splitCount).Take(10).ToList()).Count() != 0)
            {
                if (splitCount != 0)
                {
                    System.Threading.Thread.Sleep(5000);
                }

                splitCount += 10;

                shippingResultInString = GetTrackingInfoUSPSInString(throttledTrackings);

                _memStream = new MemoryStream(Encoding.UTF8.GetBytes(shippingResultInString));


                USPSTrackingResult.TrackResponse resultingMessage = new USPSTrackingResult.TrackResponse();
                USPSTrackingResultError.Error    error            = new USPSTrackingResultError.Error();

                if (_memStream != null)
                {
                    if (shippingResultInString.Contains("<Error>") && !shippingResultInString.Contains("<TrackResponse>"))
                    {
                        XmlSerializer serializer = new XmlSerializer(typeof(USPSTrackingResultError.Error));
                        error = (USPSTrackingResultError.Error)serializer.Deserialize(_memStream);
                        shippingResult.Add(USPSTrackingResultErrorWrap(error));
                        serializer = null;
                    }
                    else
                    {
                        XmlSerializer serializer = new XmlSerializer(typeof(USPSTrackingResult.TrackResponse));
                        resultingMessage = (USPSTrackingResult.TrackResponse)serializer.Deserialize(_memStream);
                        shippingResult.AddRange(USPSTrackingResultWrap(resultingMessage));
                        serializer = null;
                    }
                }
            }

            return(shippingResult);
        }