Example #1
0
        private static bool LoadRequiredFields(XmlNode inputNode, ValuePresentation unit)
        {
            var offsetValue = inputNode.GetXmlNodeValue("@B");
            var scaleValue = inputNode.GetXmlNodeValue("@C");
            var decimalDigitsValue = inputNode.GetXmlNodeValue("@D");

            if (string.IsNullOrEmpty(offsetValue) ||
                string.IsNullOrEmpty(scaleValue) ||
                string.IsNullOrEmpty(decimalDigitsValue))
                return false;

            long offset;
            if (!long.TryParse(offsetValue, NumberStyles.Integer, CultureInfo.InvariantCulture, out offset))
                return false;
            unit.Offset = offset;

            double scale;
            if (!double.TryParse(scaleValue, NumberStyles.Number, CultureInfo.InvariantCulture, out scale) ||
                scale < 0)
                return false;
            unit.Scale = scale;

            byte decimalDigits;
            if (!byte.TryParse(decimalDigitsValue, NumberStyles.Integer, CultureInfo.InvariantCulture, out decimalDigits) ||
                decimalDigits < 0 || decimalDigits > 7)
                return false;
            unit.DecimalDigits = decimalDigits;

            return true;
        }
Example #2
0
        private ValuePresentation LoadUnit(XmlNode inputNode, out string unitId)
        {
            var unit = new ValuePresentation();

            // Required fields. Do not proceed if they are missing
            unitId = inputNode.GetXmlNodeValue("@A");
            if (string.IsNullOrEmpty(unitId) ||
                !LoadRequiredFields(inputNode, unit))
                return null;

            // Optional fields
            unit.Symbol = inputNode.GetXmlNodeValue("@E");

            _taskDocument.LoadLinkedIds(unitId, unit.Id);

            return unit;
        }