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; }
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); }
public TrackingInfo GetTrackingInfo(string TrackingNumber) { try { string trackurl = "?API=TrackV2&XML=<TrackRequest USERID=\"{0}\"><TrackID ID=\"{1}\"></TrackID></TrackRequest>"; string url = ProductionUrl + 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); } }
private void ParseUSPSRawDataIntoList(TrackerData Entry, TrackingInfo Reply) { //Only need the information in Reply.Summary if (Reply.Summary.Contains("delivered")) { Entry.Status = PackageStatus.Delivered; Entry.Location = ExtractAddressFromString(Reply.Summary); Entry.Service = ParcelService.USPS; } else if (Reply.Summary.Contains("departed")) { Entry.Status = PackageStatus.Shipped; Entry.Location = ExtractAddressFromString(Reply.Summary); Entry.Service = ParcelService.USPS; } else if (Reply.Summary.Contains("picked up")) { Entry.Status = PackageStatus.Shipped; Entry.Location = ExtractAddressFromString(Reply.Summary); Entry.Service = ParcelService.USPS; } else if (Reply.Summary.Contains("arrived")) { Entry.Status = PackageStatus.Shipped; Entry.Location = ExtractAddressFromString(Reply.Summary); Entry.Service = ParcelService.USPS; } else if (Reply.Summary.Contains("error")) { Entry.Status = PackageStatus.NotFound; Entry.Location = "Not Found"; } else { Entry.Status = PackageStatus.Other; Entry.Location = "Error"; } }