Exemplo n.º 1
0
        public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            // Parse the base PDV first
            PDVFormatter pdvFormatter = new PDVFormatter();
            URG <Object> retVal       = pdvFormatter.Parse <URG <Object> >(s, result);

            if (retVal.NullFlavor != null) // Null, no longer process
            {
                return(retVal);
            }

            if (s.GetAttribute("probability") != null) // Probability
            {
                decimal prob = (decimal)0.0f;
                if (!Decimal.TryParse(s.GetAttribute("probability"), out prob)) // Try to parse
                {
                    result.AddResultDetail(new ResultDetail(ResultDetailType.Warning, string.Format("Value '{0}' can't be processed into 'Probability' on data type UVP", s.GetAttribute("probability")), s.ToString(), null));
                }
                else // Success, so assign
                {
                    retVal.Probability = prob;
                }
            }

            // Serialization
            IXmlStructureFormatter serHost = this.Host;

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

                s.Read();
                // string Name
                while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName))
                {
                    string oldName = s.Name; // Name
                    try
                    {
                        if (s.LocalName == "low") // Low , parse using the proper type
                        {
                            var hostResult = serHost.Parse(s, GenericArguments[0]);
                            result.Code = hostResult.Code;
                            result.AddResultDetail(hostResult.Details);
                            retVal.Low = hostResult.Structure;
                        }
                        else if (s.LocalName == "width") // Width
                        {
                            var hostResult = serHost.Parse(s, typeof(PQ));
                            result.Code = hostResult.Code;
                            result.AddResultDetail(hostResult.Details);
                            retVal.Width = hostResult.Structure as PQ;
                        }
                        else if (s.LocalName == "high") // High
                        {
                            var hostResult = serHost.Parse(s, GenericArguments[0]);
                            result.Code = hostResult.Code;
                            result.AddResultDetail(hostResult.Details);
                            retVal.High = hostResult.Structure;
                        }
                    }
                    catch (MessageValidationException e)
                    {
                        result.AddResultDetail(new MARC.Everest.Connectors.ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, e));
                    }
                    finally
                    {
                        if (s.Name == oldName)
                        {
                            s.Read();
                        }
                    }
                }
            }
            #endregion

            // Validate the data type
            ANYFormatter validator = new ANYFormatter();
            string       pathName  = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name;
            validator.Validate(retVal, pathName, result);

            return(retVal);
        }