Ejemplo n.º 1
0
        /// <summary>
        /// Converts from 1 distance to another. By default, converts to Meter and then back to the other measurements
        /// </summary>
        /// <param name="value">The value of the from unit</param>
        /// <param name="from">From unit can be anything listed in DistanceUnits</param>
        /// <param name="to">To unit can be anything listed in DistanceUnits</param>
        /// <returns></returns>
        public override decimal Convert(decimal value, Enum from, Enum to)
        {
            WeightUnits fromDu = (WeightUnits)from;
            WeightUnits toDu = (WeightUnits)to;

            decimal conversion;

            if (!conversionMap.TryGetValue(fromDu, out conversion))
            {
                throw new InvalidUnitTypeException(fromDu.ToString());
            }
            // Convert from to Meter
            value /= conversion;

            // Convert meter to to.
            if (!conversionMap.TryGetValue(toDu, out conversion))
            {
                throw new InvalidUnitTypeException(toDu.ToString());
            }

            return value * conversion;
        }
Ejemplo n.º 2
0
        public string BuildXml()
        {
            string result = string.Empty;

            StringWriter  sw = new StringWriter(System.Globalization.CultureInfo.InvariantCulture);
            XmlTextWriter xw = new XmlTextWriter(sw);

            xw.Formatting  = Formatting.Indented;
            xw.Indentation = 2;

            xw.WriteStartDocument();

            //Preamble
            xw.WriteStartElement("FDXRateRequest");
            xw.WriteAttributeString("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
            xw.WriteAttributeString("xsi:noNamespaceSchemaLocation", "FDXRateRequest.xsd");

            RequestHeader.WriteToXml(xw, "RequestHeader");
            xw.WriteElementString("ReturnShipmentIndicator", ReturnType.ToString());
            xw.WriteElementString("ShipDate", ShipDate.ToString("yyyy-MM-dd"));
            xw.WriteElementString("DropoffType", this.globals.DefaultDropOffType.ToString());
            xw.WriteElementString("Service", Service.ToString());
            xw.WriteElementString("Packaging", Packaging.ToString());
            xw.WriteElementString("WeightUnits", WeightUnits.ToString());
            xw.WriteElementString("Weight", _Weight.ToString("0.0"));
            xw.WriteElementString("ListRate", globals.UseListRates ? "1" : "0");

            OriginAddress.WriteToXml(xw, "OriginAddress");
            DestinationAddress.WriteToXml(xw, "DestinationAddress");

            xw.WriteStartElement("Payment");
            xw.WriteElementString("PayorType", "SENDER");
            xw.WriteEndElement();

            if (Packaging == PackageType.YOURPACKAGING)
            {
                Dimensions.WriteToXml(xw, "Dimensions");
            }

            xw.WriteStartElement("DeclaredValue");
            xw.WriteElementString("Value", _DeclaredValue.ToString("0.00"));
            xw.WriteElementString("CurrencyCode", "USD");
            xw.WriteEndElement();

            if (ContainsAlcohol)
            {
                xw.WriteElementString("Alcohol", "1");
            }
            SpecialServices.WriteToXml(xw, "SpecialServices");
            xw.WriteElementString("PackageCount", PackageCount.ToString());

            //_RequestContact.WriteToXml(xw, "Contact")
            //_RequestAddress.WriteToXml(xw, "Address")

            xw.WriteEndDocument();

            xw.Flush();
            xw.Close();

            result = sw.GetStringBuilder().ToString();

            return(result);
        }