Esempio n. 1
0
        public static TrackingInfo FromXml(string xml)
        {
            int          idx1 = 0;
            int          idx2 = 0;
            TrackingInfo t    = new TrackingInfo();

            if (xml.Contains("<TrackSummary>"))
            {
                idx1       = xml.IndexOf("<TrackSummary>") + 14;
                idx2       = xml.IndexOf("</TrackSummary>");
                t._Summary = xml.Substring(idx1, idx2 - idx1);
            }
            int lastidx = 0;

            while (xml.IndexOf("<TrackDetail>", lastidx) > -1)
            {
                idx1 = xml.IndexOf("<TrackDetail>", lastidx) + 13;
                idx2 = xml.IndexOf("</TrackDetail>", lastidx + 13);
                t.Details.Add(xml.Substring(idx1, idx2 - idx1));
                lastidx = idx2;
            }
            return(t);
        }
Esempio n. 2
0
        public TrackingInfo GetTrackingInfo(string TrackingNumber)
        {
            try
            {
                string trackurl = "?API=TrackV2&XML=<TrackRequest USERID=\"{0}\"><TrackID ID=\"{1}\"></TrackID></TrackRequest>";
                string url      = GetURL() + trackurl;
                url = String.Format(url, _userid, TrackingNumber);
                string xml = web.DownloadString(url);
                if (xml.Contains("<Error>"))
                {
                    int    idx1    = xml.IndexOf("<Description>") + 13;
                    int    idx2    = xml.IndexOf("</Description>");
                    int    l       = xml.Length;
                    string errDesc = xml.Substring(idx1, idx2 - idx1);
                    throw new USPSManagerException(errDesc);
                }

                return(TrackingInfo.FromXml(xml));
            }
            catch (WebException ex)
            {
                throw new USPSManagerException(ex);
            }
        }