// Entry Point. public void GetTrackingResult(string trackingNo) { shippingResult = new ShippingResult(); string shippingResultInString = string.Empty; if (!string.IsNullOrEmpty(trackingNo)) { CarrierName carrier = getCarrierName(trackingNo); CredentialValidation(carrier); switch (carrier) { case CarrierName.UPS: trackingFacility = new UPSTracking(); break; case CarrierName.USPS: trackingFacility = new USPSTracking(); break; case CarrierName.FedEx: trackingFacility = new FedExTracking(); break; default: trackingFacility = new USPSTracking(); break; } shippingResult = trackingFacility.GetTrackingResult(trackingNo); } }
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); }
private ShippingResult USPSTrackingResultWrap(USPSTrackingResult.TrackResponse resultingMessage) { ShippingResult shippingResult = new ShippingResult(); shippingResult.ServiceType = resultingMessage.Items[0].Class; shippingResult.StatusCode = resultingMessage.Items[0].StatusCategory; shippingResult.Status = resultingMessage.Items[0].Status; shippingResult.StatusSummary = resultingMessage.Items[0].StatusSummary; if (resultingMessage.Items[0].Error != null) { if (!string.IsNullOrEmpty(resultingMessage.Items[0].Error.Number.ToString())) { shippingResult.Delivered = false; shippingResult.StatusCode = "Error"; shippingResult.Status = resultingMessage.Items[0].Error.Description; shippingResult.StatusSummary = resultingMessage.Items[0].Error.Description; shippingResult.Message = resultingMessage.Items[0].Error.Description; } } if (!string.IsNullOrEmpty(shippingResult.StatusCode)) { if (shippingResult.StatusCode.ToUpper().Trim() == "DELIVERED") { shippingResult.Delivered = true; foreach (var item in resultingMessage.Items[0].TrackSummary) { if (item.Event.ToUpper().Contains("DELIVERED")) { shippingResult.DeliveredDateTime = item.EventDate + " " + item.EventTime; //by CJ on Oct-05-2016, to have the signatureName. shippingResult.SignatureName = string.IsNullOrEmpty(item.Name) ? "" : item.Name; break; } } } } if (resultingMessage.Items[0].TrackDetail != null) { if (resultingMessage.Items[0].TrackDetail.Length > 0) { foreach (var detail in resultingMessage.Items[0].TrackDetail) { ShippingResultEventDetail eventDetail = new ShippingResultEventDetail(); eventDetail.Event = detail.Event; eventDetail.EventDateTime = detail.EventDate + " " + detail.EventTime; eventDetail.EventAddress = detail.EventCity + " " + detail.EventState + " " + detail.EventZIPCode; shippingResult.TrackingDetails.Add(eventDetail); } } } return(shippingResult); }
private ShippingResult USPSTrackingResultErrorWrap(USPSTrackingResultError.Error resultingMessage) { ShippingResult shippingResult = new ShippingResult(); shippingResult.StatusCode = "ERROR"; shippingResult.Status = resultingMessage.Description; shippingResult.Message = resultingMessage.Description; return(shippingResult); }
private ShippingResult FedExTrackingResultWrap(FedExTrackingResult.TrackReply resultMessage) { ShippingResult shippingResult = new ShippingResult(); if (resultMessage.HighestSeverity == "ERROR") { shippingResult.StatusCode = "ERROR"; shippingResult.Status = resultMessage.Notifications[0].Message; shippingResult.Message = resultMessage.Notifications[0].Message; } else if (resultMessage.HighestSeverity == "SUCCESS") { if (resultMessage.TrackDetails[0].StatusCode.Trim().ToUpper() == "DL") { shippingResult.Delivered = true; } shippingResult.StatusCode = resultMessage.TrackDetails[0].StatusCode; shippingResult.Status = resultMessage.TrackDetails[0].StatusDescription; shippingResult.StatusSummary = resultMessage.TrackDetails[0].StatusDescription; shippingResult.ServiceType = resultMessage.TrackDetails[0].ServiceType; if (shippingResult.Delivered) { shippingResult.DeliveredDateTime = !string.IsNullOrEmpty(resultMessage.TrackDetails[0].ActualDeliveryTimestamp) ? resultMessage.TrackDetails[0].ActualDeliveryTimestamp : ""; // by CJ on Oct-05-2016 to include Signature. shippingResult.SignatureName = !string.IsNullOrEmpty(resultMessage.TrackDetails[0].DeliverySignatureName) ? resultMessage.TrackDetails[0].DeliverySignatureName : ""; } else { shippingResult.ScheduledDeliveryDate = !string.IsNullOrEmpty(resultMessage.TrackDetails[0].EstimatedDeliveryTimestamp) ? resultMessage.TrackDetails[0].EstimatedDeliveryTimestamp : ""; } if (resultMessage.TrackDetails[0].Events != null) { if (resultMessage.TrackDetails[0].Events.Length > 0) { foreach (var detail in resultMessage.TrackDetails[0].Events) { ShippingResultEventDetail eventDetail = new ShippingResultEventDetail(); eventDetail.Event = detail.EventType + " " + detail.EventDescription;; eventDetail.EventDateTime = detail.Timestamp; if (detail.Address != null) { eventDetail.EventAddress = detail.Address[0].City + " " + detail.Address[0].StateOrProvinceCode + " " + detail.Address[0].PostalCode; } shippingResult.TrackingDetails.Add(eventDetail); } } } } return(shippingResult); }
private ShippingResult UPSTrackingResultWrap(UPSTrackingResult.TrackResponse resultingMessage) { ShippingResult shippingResult = new ShippingResult(); UPSTrackingResult.TrackResponseResponse response = (UPSTrackingResult.TrackResponseResponse)resultingMessage.Items[0]; if (response.ResponseStatusCode == "1") { UPSTrackingResult.TrackResponseShipment shipment = (UPSTrackingResult.TrackResponseShipment)resultingMessage.Items[1]; shippingResult.ServiceType = shipment.Service[0].Description; shippingResult.StatusCode = shipment.Package[0].Activity[0].Status[0].StatusType[0].Code; shippingResult.Status = shipment.Package[0].Activity[0].Status[0].StatusType[0].Description; if (!string.IsNullOrEmpty(shippingResult.StatusCode)) { if (shippingResult.StatusCode == "D") { shippingResult.Delivered = true; shippingResult.StatusSummary = shipment.Package[0].Activity[0].ActivityLocation[0].Description; shippingResult.DeliveredDateTime = shipment.Package[0].Activity[0].Date + " " + shipment.Package[0].Activity[0].Time; shippingResult.SignatureName = string.IsNullOrEmpty(shipment.Package[0].Activity[0].ActivityLocation[0].SignedForByName) ? "" : shipment.Package[0].Activity[0].ActivityLocation[0].SignedForByName; } } if (!string.IsNullOrEmpty(shippingResult.StatusCode)) { if (shippingResult.StatusCode != "D") { shippingResult.PickupDate = shipment.PickupDate; shippingResult.ScheduledDeliveryDate = shipment.ScheduledDeliveryDate; if (shipment.Package[0].Message != null) { shippingResult.Message = shipment.Package[0].Message[0].Description; } } } } else { shippingResult.StatusCode = "Error"; shippingResult.Status = response.Error.ErrorDescription; shippingResult.Message = response.Error.ErrorDescription; } return(shippingResult); }
public ShippingResult GetTrackingResult() { ShippingResult shippingResult = new ShippingResult(); string shippingResultInString = GetTrackingInfoUPSInString(); XmlSerializer serializer = new XmlSerializer(typeof(UPSTrackingResult.TrackResponse)); MemoryStream memStream = new MemoryStream(Encoding.UTF8.GetBytes(shippingResultInString)); UPSTrackingResult.TrackResponse resultingMessage = new UPSTrackingResult.TrackResponse(); if (memStream != null) { resultingMessage = (UPSTrackingResult.TrackResponse)serializer.Deserialize(memStream); } shippingResult = UPSTrackingResultWrap(resultingMessage); return(shippingResult); }
public ShippingResult GetTrackingResult() { ShippingResult shippingResult = new ShippingResult(); string shippingResultInString = GetTrackingInfoFedExInString(); XmlSerializer serializer = new XmlSerializer(typeof(FedExTrackingResult.TrackReply)); MemoryStream memStream = new MemoryStream(Encoding.UTF8.GetBytes(shippingResultInString)); FedExTrackingResult.TrackReply resultingMessage = new FedExTrackingResult.TrackReply(); if (memStream != null) { resultingMessage = (FedExTrackingResult.TrackReply)serializer.Deserialize(memStream); } shippingResult = FedExTrackingResultWrap(resultingMessage); return(shippingResult); }
public ShippingResult GetTrackingResult() { var shippingResult = new ShippingResult(); var shippingResultInString = GetTrackingInfoUPSInString(); if (shippingResultInString.Contains("<ResponseStatusDescription>Failure</ResponseStatusDescription>") && shippingResultInString.Contains("<Error><ErrorSeverity>Hard</ErrorSeverity>") && !shippingResultInString.Contains("No tracking information available")) { throw new ShippingTrackingException("UPS API ERROR", shippingResultInString); } var serializer = new XmlSerializer(typeof(TrackResponse)); TrackResponse resultingMessage; using (var memStream = new MemoryStream(Encoding.UTF8.GetBytes(shippingResultInString))) { resultingMessage = (TrackResponse)serializer.Deserialize(memStream); } shippingResult = UPSTrackingResultWrap(resultingMessage); return(shippingResult); }
// Entry Point. public void GetTrackingResult(string trackingNo) { shippingResult = new ShippingResult(); string strShippingResult = string.Empty; try { if (!string.IsNullOrEmpty(trackingNo)) { CarrierName carrier = getCarrierName(trackingNo); CredentialValidation(carrier); trackingFacility = new UPSTracking(trackingNo); shippingResult = trackingFacility.GetTrackingResult(); } } catch (Exception e) { Console.WriteLine(e); } }