/// <summary> /// Obtain the rates for a single parcel. /// </summary> /// <param name="package"></param> /// <returns></returns> private IParcelRate ParseParcel(XElement package) { int intValue; double doubleValue; ParcelContent parcel = new ParcelContent(); parcel.ID = package.Attribute("ID").Value; // Check for an error if (package.Element("Error") != null) { XElement error = package.Element("Error"); string errNum = error.Element("Number").Value; string errSource = error.Element("Source").Value; string errDesc = error.Element("Description").Value; if (errNum.Equals("-2147219498")) { throw new ApplicationException(string.Format("Error: {0} - {1} ({2})", errNum, errDesc, errSource)); } else { throw new Exception(string.Format("Error: {0} - {1} ({2})", errNum, errDesc, errSource)); } } Int32.TryParse(package.Element("Pounds").Value, out intValue); parcel.Pounds = intValue; Int32.TryParse(package.Element("Ounces").Value, out intValue); parcel.Ounces = intValue; ParcelRates rates = new ParcelRates(parcel); Int32.TryParse(package.Element("ZipOrigination").Value, out intValue); rates.ZipOrigination = intValue; Int32.TryParse(package.Element("ZipDestination").Value, out intValue); rates.ZipDestination = intValue; if (package.Element("FirstClassMailType") != null) { parcel.ContainerType = package.Element("FirstClassMailType").Value; } if (package.Element("Container") != null) { parcel.ContainerType = package.Element("Container").Value; } if (package.Element("Width") != null && double.TryParse(package.Element("Width").Value, out doubleValue)) { parcel.Width = doubleValue; } if (package.Element("Length") != null && double.TryParse(package.Element("Length").Value, out doubleValue)) { parcel.Length = doubleValue; } if (package.Element("Height") != null && double.TryParse(package.Element("Height").Value, out doubleValue)) { parcel.Height = doubleValue; } if (package.Element("Girth") != null && double.TryParse(package.Element("Girth").Value, out doubleValue)) { parcel.Girth = doubleValue; } if (package.Element("Machinable") != null) { rates.IsMachinable = package.Element("Machinable").Value.Equals("TRUE"); } if (Int32.TryParse(package.Element("Zone").Value, out intValue)) { rates.Zone = intValue; } IEnumerable<XElement> postageCollection = package.Elements("Postage"); foreach (var postage in postageCollection) { rates.AddRate(ParsePostage(postage)); } return rates; }
public ParcelRates(ParcelContent parcel) { _parcel = parcel; _rates = new List<IPostage>(); }