Esempio n. 1
0
        /// <summary>
        /// Parse an AD instance from <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Create a base formatter so it can construct the object
            ANYFormatter baseFormatter = new ANYFormatter();

            // Parse AD
            AD retVal = baseFormatter.Parse <AD>(s);

            // Now parse our data out... Attributes
            if (s.GetAttribute("use") != null)
            {
                retVal.Use = (SET <CS <PostalAddressUse> >)Util.FromWireFormat(s.GetAttribute("use"), typeof(SET <CS <PostalAddressUse> >));
            }
            if (s.GetAttribute("isNotOrdered") != null)
            {
                retVal.IsNotOrdered = (bool)Util.FromWireFormat(s.GetAttribute("isNotOrdered"), typeof(bool));
            }

            // Loop through content
            // Elements
            #region Elements
            if (!s.IsEmptyElement)
            {
                int    sDepth = s.Depth;
                string sName  = s.Name;

                s.Read();

                // Read all internal elements
                while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName))
                {
                    string oldName = s.Name; // Name
                    try
                    {
                        AddressPartType?adxpType;           // Address part type

                        if (s.LocalName == "useablePeriod") // Usable Period, since this is a GTS
                        {
                            // Useable period doesn't exist
                            GTSFormatter sxcmFormatter = new GTSFormatter();
                            sxcmFormatter.Host   = this.Host;
                            retVal.UseablePeriod = sxcmFormatter.Parse(s, result) as GTS;
                        }
                        else if (s.LocalName == "part")                        // Reverse map exists, so this is a part
                        {
                            ADXPFormatter adxpFormatter = new ADXPFormatter(); // ADXP Formatter
                            adxpFormatter.Host = this.Host;
                            ADXP part = (ADXP)adxpFormatter.Parse(s, result);  // Parse
                            retVal.Part.Add(part);                             // Add to AD
                        }
                    }
                    catch (MessageValidationException e)
                    {
                        result.AddResultDetail(new ResultDetail(ResultDetailType.Error, e.Message, s.ToString(), e)); // Append details
                    }
                    finally
                    {
                        if (oldName == s.Name)
                        {
                            s.Read();                    // Read if we need to
                        }
                    }
                }
            }
            #endregion

            // Validate
            string pathName = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name;
            baseFormatter.Validate(retVal, pathName, result);
            return(retVal);
        }
Esempio n. 2
0
        /// <summary>
        /// Parse an AD instance from <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Create a base formatter so it can construct the object
            ANYFormatter baseFormatter = new ANYFormatter(); 

            // Parse AD
            AD retVal = baseFormatter.Parse<AD>(s);

            // Now parse our data out... Attributes
            if (s.GetAttribute("use") != null)
                retVal.Use = (SET<CS<PostalAddressUse>>)Util.FromWireFormat(s.GetAttribute("use"), typeof(SET<CS<PostalAddressUse>>));
            if (s.GetAttribute("isNotOrdered") != null)
                retVal.IsNotOrdered = (bool)Util.FromWireFormat(s.GetAttribute("isNotOrdered"), typeof(bool));

            // Loop through content
            // Elements
            #region Elements
            if (!s.IsEmptyElement)
            {

                int sDepth = s.Depth;
                string sName = s.Name;

                s.Read();

                // Read all internal elements
                while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName))
                {
                    string oldName = s.Name; // Name
                    try
                    {
                        AddressPartType? adxpType; // Address part type

                        if (s.LocalName == "useablePeriod") // Usable Period, since this is a GTS
                        {
                            // Useable period doesn't exist
                            GTSFormatter sxcmFormatter = new GTSFormatter();
                            sxcmFormatter.Host = this.Host;
                            retVal.UseablePeriod = sxcmFormatter.Parse(s, result) as GTS;
                        }
                        else if (s.LocalName == "part") // Reverse map exists, so this is a part
                        {
                            ADXPFormatter adxpFormatter = new ADXPFormatter(); // ADXP Formatter
                            adxpFormatter.Host = this.Host;
                            ADXP part = (ADXP)adxpFormatter.Parse(s, result); // Parse
                            retVal.Part.Add(part); // Add to AD
                        }
                    }
                    catch (MessageValidationException e)
                    {
                        result.AddResultDetail(new ResultDetail(ResultDetailType.Error, e.Message, s.ToString(), e)); // Append details
                    }
                    finally
                    {
                        if (oldName == s.Name) s.Read(); // Read if we need to
                    }
                }
            }
            #endregion

            // Validate
            string pathName = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name;
            baseFormatter.Validate(retVal, pathName, result);
            return retVal;
        }