/// <summary>
        /// Parses XML file
        /// </summary>
        /// <param name="in_element"></param>
        public void ParseXML(XPathNavigator in_element)
        {
            // get name
            m_name = XMLAttributeParser.ConvertAttributeToString(in_element, "Name", XMLAttributeParser.atObligatory);

            m_multiplier = XMLAttributeParser.ConvertAttributeToDouble(in_element, "Multiplier", XMLAttributeParser.atOptional, 1);
        }
        /// <summary>
        /// Parses value member of the realtimeobject
        /// </summary>
        /// <param name="in_element"></param>
        /// <param name="in_xml_stream"></param>
        /// <param name="in_parent"></param>
        internal void ParseValueMember(XPathNavigator in_element, TextReader in_xml_stream, object in_parent)
        {
            // get name
            m_name = XMLAttributeParser.ConvertAttributeToString(in_element, "Name", XMLAttributeParser.atObligatory);

            // get type
            m_member_type = TypeStringToMemberType(in_element.Name);

            // check type
            if (m_member_type == RealtimeObjectMember.MemberType.Unknown)
            {
                throw XMLParserBase.CreateXMLParseException(string.Format(ParserRealtimeObjectStringConstants.ErrorInvalidElementType, in_element.Name), in_element);
            }

            // get multiplier for fixed types
            if (RealtimeObjectMember.IsFixedMember(m_member_type))
            {
                m_fixed_multiplier = XMLAttributeParser.ConvertAttributeToInt(in_element, "Multiplier", XMLAttributeParser.atObligatory);
            }

            // store attributes for further processing
            XPathNavigator element = in_element.Clone();

            if (element.MoveToFirstAttribute())
            {
                m_attributes.Add(element.Name, element.Value);
            }

            while (element.MoveToNextAttribute())
            {
                m_attributes.Add(element.Name, element.Value);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Parses value description
        /// </summary>
        /// <param name="in_element">Element to parse</param>
        public void ParseXML(XPathNavigator in_element)
        {
            // get id
            m_id = XMLAttributeParser.ConvertAttributeToString(in_element, "ID", XMLAttributeParser.atObligatory);

            // get value
            m_value = in_element.Value;
        }
        /// <summary>
        /// Parses XML element containing enumeration definition
        /// </summary>
        /// <param name="in_element"></param>
        public void ParseXML(XPathNavigator in_element)
        {
            // get id
            m_id = XMLAttributeParser.ConvertAttributeToString(in_element, "ID", XMLAttributeParser.atObligatory);

            // get name
            m_name = XMLAttributeParser.ConvertAttributeToString(in_element, "Name", XMLAttributeParser.atObligatory);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets min, max values
        /// </summary>
        /// <param name="in_element"></param>
        /// <param name="in_value"></param>
        private void GetAndCheckMinMaxFloat(XPathNavigator in_element, float in_value)
        {
            m_float_min = (float)XMLAttributeParser.ConvertAttributeToDouble(in_element, "Min", XMLAttributeParser.atOptional, m_float_min);
            m_float_max = (float)XMLAttributeParser.ConvertAttributeToDouble(in_element, "Max", XMLAttributeParser.atOptional, m_float_max);

            if (in_value < m_float_min && in_value > m_float_max)
            {
                XMLParserException exception = new XMLParserException(in_element);
                exception.SetOutOfRangeError();
                throw exception;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Parses Realtime object from the XML file
        /// </summary>
        /// <param name="in_element"></param>
        public void ParseXML(XPathNavigator in_element)
        {
            // get name
            m_name = XMLAttributeParser.ConvertAttributeToString(in_element, "Name", XMLAttributeParser.atObligatory);

            // store attributes for further processing
            XPathNavigator element = in_element.Clone();

            if (element.MoveToFirstAttribute())
            {
                m_attributes.Add(element.Name, element.Value);
            }

            while (element.MoveToNextAttribute())
            {
                m_attributes.Add(element.Name, element.Value);
            }
        }
        /// <summary>
        /// Parses group element
        /// </summary>
        /// <param name="in_element"></param>
        public void ParseXML(XPathNavigator in_element)
        {
            // get name
            m_id = XMLAttributeParser.ConvertAttributeToString(in_element, "ID", XMLAttributeParser.atObligatory);

            // get name
            m_name = XMLAttributeParser.ConvertAttributeToString(in_element, "Name", XMLAttributeParser.atObligatory);

            // get display name
            string display_name = XMLAttributeParser.ConvertAttributeToString(in_element, "DisplayName", 0);

            if (!string.IsNullOrEmpty(display_name))
            {
                m_display_name = display_name;
            }
            else
            {
                m_display_name = m_name;
            }
        }
        /// <summary>
        /// Parses real time object description file elements
        /// </summary>
        /// <param name="in_element"></param>
        protected override void ParseElement(XPathNavigator in_element, TextReader in_xml_stream, object in_parent)
        {
            string name;
            string cdecl;

            RealtimeObjectMember.MemberType type;

            switch (in_element.Name)
            {
            case "Type":
            {
                name  = XMLAttributeParser.ConvertAttributeToString(in_element, "Name", XMLAttributeParser.atObligatory);
                cdecl = XMLAttributeParser.ConvertAttributeToString(in_element, "CDecl", XMLAttributeParser.atObligatory);

                if (name == "PacketHeader")
                {
                    m_packet_header_declaration = cdecl;
                }
                else
                {
                    type = ParserRealtimeObjectMember.TypeStringToMemberType(name);

                    if (type == RealtimeObjectMember.MemberType.Unknown)
                    {
                        throw XMLParserBase.CreateXMLParseException(string.Format(ParserRealtimeObjectStringConstants.ErrorInvalidElementType, in_element.Name), in_element);
                    }

                    m_type_lookup.Add(type, cdecl);
                }
            }
            break;

            default:
                throw XMLParserBase.CreateXMLParseException(string.Format(ParserRealtimeObjectStringConstants.ErrorInvalidElementType, in_element.Name), in_element);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Parses value description
        /// </summary>
        /// <param name="in_element">Element to parse</param>
        public void ParseXML(XPathNavigator in_element)
        {
            // get id
            m_id = XMLAttributeParser.ConvertAttributeToString(in_element, "ID", XMLAttributeParser.atObligatory);

            // get name
            m_name = XMLAttributeParser.ConvertAttributeToString(in_element, "Name", XMLAttributeParser.atObligatory);

            // get unit
            m_units = XMLAttributeParser.ConvertAttributeToString(in_element, "Units", XMLAttributeParser.atOptional);

            // get description
            m_description = XMLAttributeParser.ConvertAttributeToString(in_element, "Description", XMLAttributeParser.atOptional);

            // get value
            switch (m_value_type)
            {
            case ValueType.StringValue:
                // if string type is specified length must be existing
                m_binary_length = XMLAttributeParser.ConvertAttributeToInt(in_element, "Length", XMLAttributeParser.atObligatory) + 1;                         // +1 because of the terminator zero
                m_value         = in_element.Value;

                // check length
                if (!string.IsNullOrEmpty((string)m_value))
                {
                    if (((string)m_value).Length > m_binary_length)
                    {
                        // throw an exception if string is too long
                        XMLParserException exception = new XMLParserException(in_element);
                        exception.SetStringIsTooLongError(m_name, m_binary_length);
                        throw exception;
                    }
                }
                break;

            case ValueType.Int32Value:
                m_binary_length = sizeof(Int32);
                try
                {
                    m_value = (Int32)in_element.ValueAsInt;
                }
                catch
                {
                    // throw an exception if value is invalid
                    XMLParserException exception = new XMLParserException(in_element);
                    exception.SetInvalidTypeError(m_name);
                    throw exception;
                }
                break;

            case ValueType.Int8Value:
                m_binary_length = sizeof(SByte);
                try
                {
                    m_value = (SByte)in_element.ValueAsInt;
                }
                catch
                {
                    // throw an exception if value is invalid
                    XMLParserException exception = new XMLParserException(in_element);
                    exception.SetInvalidTypeError(m_name);
                    throw exception;
                }
                break;

            case ValueType.UInt8Value:
            {
                int value;
                m_binary_length = sizeof(SByte);
                try
                {
                    value = in_element.ValueAsInt;
                }
                catch
                {
                    // throw an exception if value is invalid
                    XMLParserException exception = new XMLParserException(in_element);
                    exception.SetInvalidTypeError(m_name);
                    throw exception;
                }

                GetAndCheckMinMaxInt(in_element, value);

                m_value = (byte)value;
            }
            break;

            case ValueType.UInt16Value:
            {
                int value;
                m_binary_length = sizeof(UInt16);
                try
                {
                    value = in_element.ValueAsInt;
                }
                catch
                {
                    // throw an exception if value is invalid
                    XMLParserException exception = new XMLParserException(in_element);
                    exception.SetInvalidTypeError(m_name);
                    throw exception;
                }

                GetAndCheckMinMaxInt(in_element, value);

                m_value = (UInt16)value;
            }
            break;

            // Fixed values
            case ValueType.UInt8FixedValue:
            case ValueType.Int8FixedValue:
            case ValueType.UInt16FixedValue:
            case ValueType.Int16FixedValue:
            {
                float  float_value;
                object value = 0;

                m_binary_length = sizeof(Int16);

                // get multiplier
                m_multiplier = XMLAttributeParser.ConvertAttributeToInt(in_element, "Multiplier", XMLAttributeParser.atObligatory);

                if (m_multiplier < 1)
                {
                    XMLParserException exception = new XMLParserException(in_element);
                    exception.SetInvalidAttributeValue("Multiplier");
                    throw exception;
                }
                m_float_min /= m_multiplier;
                m_float_max /= m_multiplier;

                // get fractional digits number
                m_fractional_digits = XMLAttributeParser.ConvertAttributeToInt(in_element, "FractionalDigits", XMLAttributeParser.atOptional);
                if (m_fractional_digits < 0)
                {
                    XMLParserException exception = new XMLParserException(in_element);
                    exception.SetInvalidAttributeValue("FractionalDigits");
                    throw exception;
                }

                // store value
                try
                {
                    float_value = (float)in_element.ValueAsDouble;

                    switch (m_value_type)
                    {
                    case ValueType.UInt8FixedValue:
                        value = (byte)Math.Round(float_value * m_multiplier);
                        break;

                    case ValueType.Int8FixedValue:
                        value = (SByte)Math.Round(float_value * m_multiplier);
                        break;

                    case ValueType.UInt16FixedValue:
                        value = (UInt16)Math.Round(float_value * m_multiplier);
                        break;

                    case ValueType.Int16FixedValue:
                        value = (Int16)Math.Round(float_value * m_multiplier);
                        break;
                    }
                }
                catch
                {
                    // throw an exception if value is invalid
                    XMLParserException exception = new XMLParserException(in_element);
                    exception.SetInvalidTypeError(m_name);
                    throw exception;
                }

                GetAndCheckMinMaxFloat(in_element, float_value);

                m_value = value;
            }
            break;


            case ValueType.FloatValue:
                m_binary_length = sizeof(float);
                try
                {
                    m_value = (float)in_element.ValueAsDouble;
                }
                catch
                {
                    // throw an exception if value is invalid
                    XMLParserException exception = new XMLParserException(in_element);
                    exception.SetInvalidTypeError(m_name);
                    throw exception;
                }
                break;

            case ValueType.EnumValue:
            {
                m_binary_length = sizeof(byte);

                m_enumdef_ref = XMLAttributeParser.ConvertAttributeToString(in_element, "Enum", XMLAttributeParser.atObligatory);

                try
                {
                    m_value = (byte)in_element.ValueAsInt;
                }
                catch
                {
                    // throw an exception if value is invalid
                    XMLParserException exception = new XMLParserException(in_element);
                    exception.SetInvalidTypeError(m_name);
                    throw exception;
                }
            }
            break;

            default:
                throw new InvalidDataException();
            }
        }
 /// <summary>
 /// Parses base class
 /// </summary>
 /// <param name="in_element"></param>
 public void ParseXML(XPathNavigator in_element)
 {
     // get name
     m_name = XMLAttributeParser.ConvertAttributeToString(in_element, "Name", XMLAttributeParser.atOptional);
 }