Beispiel #1
0
        /// <summary>
        /// Parse <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Parse base (ANY) from the stream
            ANYFormatter baseFormatter = new ANYFormatter();

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

            // Get the value
            if (s.GetAttribute("value") != null)
                retVal.Value = s.GetAttribute("value");
            if (s.GetAttribute("use") != null)
                retVal.Use = Util.Convert<SET<CS<TelecommunicationAddressUse>>>(s.GetAttribute("use"));
            if (s.GetAttribute("capabilities") != null)
                retVal.Capabilities = Util.Convert<SET<CS<TelecommunicationCabability>>>(s.GetAttribute("capabilities"));

            // 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
                    {
                        // Numerator
                        if (s.LocalName == "useablePeriod")
                        {
                            var parseResult = this.Host.Parse(s, typeof(GTS));
                            result.Code = parseResult.Code;
                            result.AddResultDetail(parseResult.Details);
                            retVal.UseablePeriod = Util.Convert<GTS>(parseResult.Structure);
                        }
                        else if (s.NodeType == System.Xml.XmlNodeType.Element)
                            result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, s.LocalName, s.NamespaceURI, s.ToString(), null));

                    }
                    catch (MessageValidationException e)
                    {
                        result.AddResultDetail(new ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, e));
                    }
                    finally
                    {
                        if (s.Name == oldName) s.Read();
                    }
                }
            }
            #endregion

            // Base formatter
            baseFormatter.Validate(retVal, s.ToString(), result);

            return retVal;
        }
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            PDVFormatter qtyf = new PDVFormatter();

            qtyf.Host = this.Host;
            return(qtyf.Parse <REAL>(s, result));
        }
Beispiel #3
0
        /// <summary>
        /// Parse the PQ back into a structure
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Create the base formatter
            PDVFormatter baseFormatter = new PDVFormatter();
            baseFormatter.Host = this.Host;

            // Read temporary values
            string tCurrency = String.Empty;
            if(s.GetAttribute("currency") != null)
                tCurrency = s.GetAttribute("currency");

            // Parse PDV content 
            var retVal = baseFormatter.Parse<MO>(s, result);

            // Set PDV content
            retVal.Currency = tCurrency;

            // Validate
            ANYFormatter anyFormatter = new ANYFormatter();
            string pathName = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name;
            anyFormatter.Validate(retVal as ANY, pathName, result);
            
            // Return instance
            return retVal;
        }
Beispiel #4
0
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Parse the base
            ANYFormatter baseFormatter = new ANYFormatter();
            baseFormatter.Host = this.Host;
            baseFormatter.GenericArguments = this.GenericArguments;
            var retVal = baseFormatter.Parse<II>(s);

            // Parse II specific data
            if (s.GetAttribute("root") != null)
                retVal.Root = s.GetAttribute("root");
            if (s.GetAttribute("extension") != null)
                retVal.Extension = s.GetAttribute("extension");
            if (s.GetAttribute("identifierName") != null)
                retVal.IdentifierName = s.GetAttribute("identifierName");
            if (s.GetAttribute("displayable") != null)
                retVal.Displayable = Util.Convert<bool>(s.GetAttribute("displayable"));
            if (s.GetAttribute("scope") != null)
                retVal.Scope = Util.Convert<IdentifierScope>(s.GetAttribute("scope"));
            if (s.GetAttribute("reliability") != null)
                retVal.Reliability = Util.Convert<IdentifierReliability>(s.GetAttribute("reliability"));

            // Validate
            baseFormatter.Validate(retVal, s.ToString(), result);

            return retVal;
        }
Beispiel #5
0
        /// <summary>
        /// Parse the PQ back into a structure
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Create the base formatter
            PDVFormatter baseFormatter = new PDVFormatter();

            baseFormatter.Host = this.Host;

            // Read temporary values
            string tCurrency = String.Empty;

            if (s.GetAttribute("currency") != null)
            {
                tCurrency = s.GetAttribute("currency");
            }

            // Parse PDV content
            var retVal = baseFormatter.Parse <MO>(s, result);

            // Set PDV content
            retVal.Currency = tCurrency;

            // Validate
            ANYFormatter anyFormatter = new ANYFormatter();
            string       pathName     = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name;

            anyFormatter.Validate(retVal as ANY, pathName, result);

            // Return instance
            return(retVal);
        }
Beispiel #6
0
 /// <summary>
 /// Parse an object from <paramref name="s"/>
 /// </summary>
 public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
 {
     PDVFormatter qtyf = new PDVFormatter();
     qtyf.Host = this.Host;
     var retVal = qtyf.Parse<INT>(s, result);
     return retVal;
 }
Beispiel #7
0
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            PDVFormatter qtyf = new PDVFormatter();
            qtyf.Host = this.Host;
            return qtyf.Parse<REAL>(s, result);

        }
Beispiel #8
0
        /// <summary>
        /// Parses an object from stream <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Parse base (ANY) from the stream
            ANYFormatter baseFormatter = new ANYFormatter();

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

            // Get the value
            if (s.GetAttribute("value") != null)
                try
                {
                    retVal.Value = Util.Convert<Boolean>(s.GetAttribute("value"));
                }
                catch (Exception e)
                {
                    result.Code = ResultCode.Error;
                    result.AddResultDetail(new ResultDetail(ResultDetailType.Error, e.Message, s.ToString(), e));
                }

            // Base formatter
            baseFormatter.Validate(retVal, s.ToString(), result);

            return retVal;
        }
Beispiel #9
0
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        /// <returns></returns>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            if (String.IsNullOrEmpty(s.GetAttribute("flavorId")))
            {
                return(Parse <CD <String> >(s, result));
            }
            else
            {
                IAny retVal = null;
                switch (s.GetAttribute("flavorId"))
                {
                case "CD.CE":
                    retVal        = Parse <CE <String> >(s, result);
                    retVal.Flavor = null;
                    break;

                case "CD.CV":
                    retVal        = Parse <CV <String> >(s, result);
                    retVal.Flavor = null;
                    break;

                default:
                    retVal = Parse <CD <String> >(s, result);
                    break;
                }
                return(retVal);
            }
        }
Beispiel #10
0
        /// <summary>
        /// Parse the string
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Temporary holding value for value
            string tValue = null;
            if (s.GetAttribute("value") != null)
                tValue = s.GetAttribute("value");

            // Parse the CD stuff
            CDFormatter baseFormatter = new CDFormatter();
            baseFormatter.Host = this.Host;
            var retVal = baseFormatter.Parse<PQR>(s, result);

            // Interpret the value
            // If the value was interpreted
            if (!String.IsNullOrEmpty(tValue))
            {
                try
                {
                    retVal.Value = Util.Convert<decimal>(tValue);
                    if (tValue.Contains("."))
                        retVal.Precision = tValue.Length - tValue.IndexOf(".") - 1;
                }
                catch (Exception e)
                {
                    result.Code = ResultCode.Error;
                    result.AddResultDetail(new ResultDetail(ResultDetailType.Error, e.Message, s.ToString(), e));
                }
            }

            // Validate
            new ANYFormatter().Validate(retVal, s.ToString(), result);

            return retVal;
        }
 /// <summary>
 /// Parse elements that are inline in the read loop
 /// </summary>
 public void ParseElementsInline(XmlReader s, IQuantity retVal, DatatypeR2FormatterParseResult result)
 {
     if (s.LocalName == "expression") // Format using ED
     {
         var hostResult = this.Host.Parse(s, typeof(ED));
         result.Code = hostResult.Code;
         result.AddResultDetail(hostResult.Details);
         retVal.Expression = hostResult.Structure as ED;
     }
     else if (s.LocalName == "originalText") // display name
     {
         var hostResult = this.Host.Parse(s, typeof(ED));
         result.Code = hostResult.Code;
         result.AddResultDetail(hostResult.Details);
         retVal.OriginalText = hostResult.Structure as ED;
     }
     else if (s.LocalName == "uncertainty") // Translation
     {
         var hostResult = Host.Parse(s, retVal.GetType());
         result.Code = hostResult.Code;
         result.AddResultDetail(hostResult.Details);
         retVal.Uncertainty = hostResult.Structure as IQuantity;
     }
     else if (s.LocalName == "uncertainRange") // Uncertainty range
     {
         var hostResult = Host.Parse(s, typeof(IVL <IQuantity>));
         result.Code = hostResult.Code;
         result.AddResultDetail(hostResult.Details);
         retVal.UncertainRange = hostResult.Structure as IVL <IQuantity>;
     }
     else if (s.NodeType == System.Xml.XmlNodeType.Element)
     {
         result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, s.LocalName, s.NamespaceURI, s.ToString(), null));
     }
 }
Beispiel #12
0
        /// <summary>
        /// Parses an object from stream <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Parse base (ANY) from the stream
            ANYFormatter baseFormatter = new ANYFormatter();

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

            // Get the value
            if (s.GetAttribute("value") != null)
            {
                try
                {
                    retVal.Value = Util.Convert <Boolean>(s.GetAttribute("value"));
                }
                catch (Exception e)
                {
                    result.Code = ResultCode.Error;
                    result.AddResultDetail(new ResultDetail(ResultDetailType.Error, e.Message, s.ToString(), e));
                }
            }

            // Base formatter
            baseFormatter.Validate(retVal, s.ToString(), result);

            return(retVal);
        }
Beispiel #13
0
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            PDVFormatter baseFormatter = new PDVFormatter();

            baseFormatter.Host = this.Host;
            var retVal = baseFormatter.ParseAttributes <CO>(s, result);

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

                QTYFormatter qtyf = new QTYFormatter();

                // string Name
                while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName))
                {
                    string oldName = s.Name; // Name
                    try
                    {
                        // Numerator
                        if (s.LocalName == "code" && retVal.Code == null)
                        {
                            var parseResult = Host.Parse(s, typeof(CD <String>));
                            result.Code = parseResult.Code;
                            result.AddResultDetail(parseResult.Details);
                            retVal.Code = parseResult.Structure as CD <String>;
                        }
                        else if (s.LocalName == "code")
                        {
                            result.AddResultDetail(new NotImplementedResultDetail(ResultDetailType.Warning, "Code can only be assigned once", s.ToString()));
                        }
                        else
                        {
                            qtyf.ParseElementsInline(s, retVal, result);
                        }
                    }
                    catch (MessageValidationException e)
                    {
                        result.AddResultDetail(new ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, e));
                    }
                    finally
                    {
                        if (s.Name == oldName)
                        {
                            s.Read();
                        }
                    }
                }
            }
            #endregion

            // Validate
            new ANYFormatter().Validate(retVal, s.ToString(), result);
            return(retVal);
        }
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            PDVFormatter qtyf = new PDVFormatter();

            qtyf.Host = this.Host;
            var retVal = qtyf.Parse <INT>(s, result);

            return(retVal);
        }
Beispiel #15
0
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Parse the base data
            ANYFormatter baseFormatter = new ANYFormatter();

            baseFormatter.Host = this.Host;
            LIST <IGraphable> retVal = baseFormatter.Parse <LIST <IGraphable> >(s);

            // parse items
            // 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
                    {
                        // Numerator
                        if (s.LocalName == "item")
                        {
                            var parseResult = Host.Parse(s, GenericArguments[0]);
                            result.Code = parseResult.Code;
                            result.AddResultDetail(parseResult.Details);
                            retVal.Add(parseResult.Structure);
                        }
                        else if (s.NodeType == System.Xml.XmlNodeType.Element)
                        {
                            result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, s.LocalName, s.NamespaceURI, s.ToString(), null));
                        }
                    }
                    catch (MessageValidationException e)
                    {
                        result.AddResultDetail(new ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, e));
                    }
                    finally
                    {
                        if (s.Name == oldName)
                        {
                            s.Read();
                        }
                    }
                }
            }
            #endregion

            // Validate
            baseFormatter.Validate(retVal, s.ToString(), result);

            return(retVal);
        }
Beispiel #16
0
 /// <summary>
 /// Parse from <paramref name="s"/>
 /// </summary>
 public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
 {
     // Shouldn't really be here, but call the 
     result.AddResultDetail(new NotImplementedResultDetail(ResultDetailType.Warning, "SXPR cannot be parsed by the R2 formatter directly, processing as QSET", s.ToString(), null));
     QSETFormatter formatter = new QSETFormatter();
     formatter.Host = this.Host;
     formatter.GenericArguments = this.GenericArguments;
     object retval = formatter.Parse(s, result);
     return retval;
 }
Beispiel #17
0
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        public override object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Validate flavor
            if (String.IsNullOrEmpty(s.GetAttribute("flavorId")) ||
                s.GetAttribute("flavorId") != "EN.ON")
                result.AddResultDetail(new FixedValueMisMatchedResultDetail(s.GetAttribute("flavorId"), "EN.ON", s.ToString()));

            var retVal = base.Parse(s, result);
            (retVal as IAny).Flavor = "EN.ON";
            return retVal;
        }
Beispiel #18
0
        /// <summary>
        /// Parse an object instance from <paramref name="s"/>
        /// </summary>
        public virtual object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Parse the base attributes
            ANYFormatter baseFormatter = new ANYFormatter();
            baseFormatter.Host = this.Host;
            baseFormatter.GenericArguments = this.GenericArguments;
            EN retVal = baseFormatter.Parse<EN>(s);

            // Use
            if (s.GetAttribute("use") != null)
                retVal.Use = Util.Convert<SET<CS<EntityNameUse>>>(s.GetAttribute("use"));

            // Process the parts
            #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
                    {
                        // Numerator
                        if (s.LocalName == "part")
                        {
                            var parseResult = Host.Parse(s, typeof(ENXP));
                            result.Code = parseResult.Code;
                            result.AddResultDetail(parseResult.Details);
                            retVal.Part.Add(parseResult.Structure as ENXP);
                        }
                        else if (s.NodeType == System.Xml.XmlNodeType.Element)
                            result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, s.LocalName, s.NamespaceURI, s.ToString(), null));
                    }
                    catch (MessageValidationException e)
                    {
                        result.AddResultDetail(new ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, e));
                    }
                    finally
                    {
                        if (s.Name == oldName) s.Read();
                    }
                }
            }
            #endregion

            // Validate
            baseFormatter.Validate(retVal, s.ToString(), result);
            return retVal;
        }
        /// <summary>
        /// Parse from <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Shouldn't really be here, but call the
            result.AddResultDetail(new NotImplementedResultDetail(ResultDetailType.Warning, "SXPR cannot be parsed by the R2 formatter directly, processing as QSET", s.ToString(), null));
            QSETFormatter formatter = new QSETFormatter();

            formatter.Host             = this.Host;
            formatter.GenericArguments = this.GenericArguments;
            object retval = formatter.Parse(s, result);

            return(retval);
        }
Beispiel #20
0
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Parse the base data
            ANYFormatter baseFormatter = new ANYFormatter();
            baseFormatter.Host = this.Host;
            LIST<IGraphable> retVal = baseFormatter.Parse<LIST<IGraphable>>(s); 

            // parse items
            // 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
                    {
                        // Numerator
                        if (s.LocalName == "item")
                        {
                            var parseResult = Host.Parse(s, GenericArguments[0]);
                            result.Code = parseResult.Code;
                            result.AddResultDetail(parseResult.Details);
                            retVal.Add(parseResult.Structure);
                        }
                        else if (s.NodeType == System.Xml.XmlNodeType.Element)
                            result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, s.LocalName, s.NamespaceURI, s.ToString(), null));

                    }
                    catch (MessageValidationException e)
                    {
                        result.AddResultDetail(new ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, e));
                    }
                    finally
                    {
                        if (s.Name == oldName) s.Read();
                    }
                }
            }
            #endregion

            // Validate
            baseFormatter.Validate(retVal, s.ToString(), result);

            return retVal;

        }
Beispiel #21
0
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            PDVFormatter baseFormatter = new PDVFormatter();
            baseFormatter.Host = this.Host;
            var retVal = baseFormatter.ParseAttributes<CO>(s, result);

            // Process the parts
            #region Elements
            if (!s.IsEmptyElement)
            {

                int sDepth = s.Depth;
                string sName = s.Name;
                s.Read();

                QTYFormatter qtyf = new QTYFormatter();

                // string Name
                while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName))
                {
                    string oldName = s.Name; // Name
                    try
                    {
                        // Numerator
                        if (s.LocalName == "code" && retVal.Code == null)
                        {
                            var parseResult = Host.Parse(s, typeof(CD<String>));
                            result.Code = parseResult.Code;
                            result.AddResultDetail(parseResult.Details);
                            retVal.Code = parseResult.Structure as CD<String>;
                        }
                        else if (s.LocalName == "code")
                            result.AddResultDetail(new NotImplementedResultDetail(ResultDetailType.Warning, "Code can only be assigned once", s.ToString()));
                        else
                            qtyf.ParseElementsInline(s, retVal, result);
                    }
                    catch (MessageValidationException e)
                    {
                        result.AddResultDetail(new ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, e));
                    }
                    finally
                    {
                        if (s.Name == oldName) s.Read();
                    }
                }
            }
            #endregion

            // Validate
            new ANYFormatter().Validate(retVal, s.ToString(), result);
            return retVal;
        }
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        public T ParseAttributes <T>(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result) where T : ANY, IQuantity, new()
        {
            ANYFormatter baseFormatter = new ANYFormatter();
            T            retVal        = baseFormatter.Parse <T>(s);

            // attributes
            if (s.GetAttribute("uncertaintyType") != null)
            {
                retVal.UncertaintyType = Util.Convert <QuantityUncertaintyType>(s.GetAttribute("uncertaintyType"));
            }

            return(retVal);
        }
Beispiel #23
0
        /// <summary>
        /// Parse an object instance from <paramref name="s"/>
        /// </summary>
        public override object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Parse the base (SC)
            var retVal = base.ParseAttributes <SC>(s, result);

            // Parse the code element
            if (!s.IsEmptyElement)
            {
                // Exit markers
                int    sDepth = s.Depth;
                string sName  = s.Name;

                Encoding textEncoding = System.Text.Encoding.UTF8;
                s.Read();
                // Read until exit condition is fulfilled
                while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName))
                {
                    string oldName = s.Name; // Name
                    try
                    {
                        if (s.LocalName == "code") // Translation
                        {
                            var hostResult = Host.Parse(s, typeof(CD <String>));
                            result.Code = hostResult.Code;
                            result.AddResultDetail(hostResult.Details);
                            retVal.Code = result.Structure as CD <String>;
                        }
                        else
                        {
                            base.ParseElementsInline(s, retVal, result);
                        }
                    }
                    catch (MessageValidationException e)
                    {
                        result.AddResultDetail(new MARC.Everest.Connectors.ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, s.ToString(), e));
                    }
                    finally
                    {
                        if (s.Name == oldName)
                        {
                            s.Read();
                        }
                    }
                }
            }

            // Validate
            new ANYFormatter().Validate(retVal, s.ToString(), result);

            return(retVal);
        }
Beispiel #24
0
        /// <summary>
        /// Parse <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            SETFormatter formatter = new SETFormatter();
            formatter.Host = this.Host;

            // Create new generic arguments
            var uvpType = typeof(UVP<>);
            var genType = uvpType.MakeGenericType(GenericArguments);

            formatter.GenericArguments = new Type[] { genType };
            object retval = formatter.Parse(s, result);

            return retval;
        }
Beispiel #25
0
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        public override object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Validate flavor
            if (String.IsNullOrEmpty(s.GetAttribute("flavorId")) ||
                s.GetAttribute("flavorId") != "EN.PN")
            {
                result.AddResultDetail(new FixedValueMisMatchedResultDetail(s.GetAttribute("flavorId"), "EN.PN", s.ToString()));
            }

            var retVal = base.Parse(s, result);

            (retVal as IAny).Flavor = "EN.PN";
            return(retVal);
        }
Beispiel #26
0
        /// <summary>
        /// Parse a CE instance from <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            CDFormatter realFormatter = new CDFormatter();

            if (String.IsNullOrEmpty(s.GetAttribute("flavorId")) ||
                s.GetAttribute("flavorId") != "CD.CE")
                result.AddResultDetail(new FixedValueMisMatchedResultDetail(s.GetAttribute("flavorId"), "CD.CE", s.ToString()));

            realFormatter.Host = this.Host;
            var retVal = realFormatter.Parse<CE<String>>(s, result);

            retVal.Flavor = null;

            return retVal;
        }
        /// <summary>
        /// Parse <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            SETFormatter formatter = new SETFormatter();

            formatter.Host = this.Host;

            // Create new generic arguments
            var uvpType = typeof(UVP <>);
            var genType = uvpType.MakeGenericType(GenericArguments);

            formatter.GenericArguments = new Type[] { genType };
            object retval = formatter.Parse(s, result);

            return(retval);
        }
Beispiel #28
0
        /// <summary>
        /// Parse an object instance from <paramref name="s"/>
        /// </summary>
        public override object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Parse the base (SC)
            var retVal = base.ParseAttributes<SC>(s, result);
            
            // Parse the code element
            if (!s.IsEmptyElement)
            {
                // Exit markers
                int sDepth = s.Depth;
                string sName = s.Name;

                Encoding textEncoding = System.Text.Encoding.UTF8;
                s.Read();
                // Read until exit condition is fulfilled
                while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName))
                {
                    string oldName = s.Name; // Name
                    try
                    {

                        if (s.LocalName == "code") // Translation
                        {
                            var hostResult = Host.Parse(s, typeof(CD<String>));
                            result.Code = hostResult.Code;
                            result.AddResultDetail(hostResult.Details);
                            retVal.Code = result.Structure as CD<String>;
                        }
                        else
                            base.ParseElementsInline(s, retVal, result);
                    }
                    catch (MessageValidationException e)
                    {
                        result.AddResultDetail(new MARC.Everest.Connectors.ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, s.ToString(), e));
                    }
                    finally
                    {
                        if (s.Name == oldName) s.Read();
                    }
                }
            }

            // Validate
            new ANYFormatter().Validate(retVal, s.ToString(), result);

            return retVal;

        }
Beispiel #29
0
        /// <summary>
        /// Parse only the attributes
        /// </summary>
        protected T ParseAttributes <T>(XmlReader s, DatatypeR2FormatterParseResult result) where T : ST, new()
        {
            // Base formatter
            ANYFormatter baseFormatter = new ANYFormatter();
            var          retVal        = baseFormatter.Parse <T>(s);

            // Attributes
            if (s.GetAttribute("value") != null)
            {
                retVal.Value = s.GetAttribute("value");
            }
            if (s.GetAttribute("language") != null)
            {
                retVal.Language = s.GetAttribute("language");
            }
            return(retVal);
        }
Beispiel #30
0
        /// <summary>
        /// Parse a CE instance from <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            CDFormatter realFormatter = new CDFormatter();

            if (String.IsNullOrEmpty(s.GetAttribute("flavorId")) ||
                s.GetAttribute("flavorId") != "CD.CE")
            {
                result.AddResultDetail(new FixedValueMisMatchedResultDetail(s.GetAttribute("flavorId"), "CD.CE", s.ToString()));
            }

            realFormatter.Host = this.Host;
            var retVal = realFormatter.Parse <CE <String> >(s, result);

            retVal.Flavor = null;

            return(retVal);
        }
Beispiel #31
0
        /// <summary>
        /// Parse a QS* class from a QSET formatter
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // First off, there is no way to determine which of the classes it is..
            
            // Try using the xsi type
            var fmtr = new DatatypeR2Formatter().GetFormatter(s.GetAttribute("type", DatatypeR2Formatter.NS_XSI));
            if (fmtr == null) // No formatter available, add a result
            {
                result.AddResultDetail(new MandatoryElementMissingResultDetail(ResultDetailType.Error, "Cannot determine type of QSET to parse, use xsi:type to specify a type", s.ToString()));
                return null;
            }

            // Parse using the formatter
            // Fix: EV-876
            fmtr.GenericArguments = this.GenericArguments;
            fmtr.Host = this.Host; 
            return fmtr.Parse(s, result);
        }
Beispiel #32
0
 /// <summary>
 /// Parse elements inline (meaning the element exit criteria has already been handled
 /// </summary>
 protected void ParseElementsInline(XmlReader s, ST retVal, DatatypeR2FormatterParseResult result)
 {
     if (s.LocalName == "translation") // Translation
     {
         var hostResult = Host.Parse(s, typeof(ED));
         result.Code = hostResult.Code;
         result.AddResultDetail(hostResult.Details);
         if (retVal.Translation == null)
         {
             retVal.Translation = new SET <ST>();
         }
         retVal.Translation.Add((ST)hostResult.Structure);
     }
     else if (s.NodeType == System.Xml.XmlNodeType.Element)
     {
         result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, s.LocalName, s.NamespaceURI, s.ToString(), null));
     }
 }
Beispiel #33
0
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        public T Parse <T>(XmlReader r, DatatypeR2FormatterParseResult result) where T : ANY, IPrimitiveDataValue, IQuantity, new()
        {
            // Prepare QTY formatting
            QTYFormatter baseFormatter = new QTYFormatter();

            baseFormatter.Host = this.Host;

            // Parse attributes part of QTY
            T retVal = this.ParseAttributes <T>(r, result);

            // Parse the elements
            baseFormatter.ParseElements <T>(r, retVal, result);

            // Validate
            new ANYFormatter().Validate(retVal, r.ToString(), result);

            return(retVal);
        }
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Parse result data
            var retVal = new ENXP();

            // Parse the supported data
            if (s.GetAttribute("nullFlavor") != null)
            {
                retVal.NullFlavor = Util.Convert <NullFlavor>(s.GetAttribute("nullFlavor"));
            }
            if (s.GetAttribute("value") != null)
            {
                retVal.Value = s.GetAttribute("value");
            }
            if (s.GetAttribute("code") != null)
            {
                retVal.Code = s.GetAttribute("code");
            }
            if (s.GetAttribute("codeSystem") != null)
            {
                retVal.CodeSystem = s.GetAttribute("codeSystem");
            }
            if (s.GetAttribute("codeSystemVersion") != null)
            {
                retVal.CodeSystemVersion = s.GetAttribute("codeSystemVersion");
            }
            if (s.GetAttribute("type") != null)
            {
                retVal.Type = Util.Convert <EntityNamePartType>(s.GetAttribute("type"));
            }
            if (s.GetAttribute("qualifier") != null)
            {
                retVal.Qualifier = Util.Convert <SET <CS <EntityNamePartQualifier> > >(s.GetAttribute("qualifier"));
            }
            if (s.GetAttribute("language") != null)
            {
                result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, "@language", null, s.ToString(), null));
            }

            // Return & validate
            new ANYFormatter().Validate(retVal, s.ToString(), result);
            return(retVal);
        }
Beispiel #35
0
        /// <summary>
        /// Parse object from the wire
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Parse base (ANY) from the stream
            ANYFormatter baseFormatter = new ANYFormatter();

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

            // Now parse our data out... Attributes
            if (retVal.NullFlavor == null && s.GetAttribute("code") != null)
                retVal.Code = s.GetAttribute("code");

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


            return retVal;
        }
Beispiel #36
0
        /// <summary>
        /// Parse a QS* class from a QSET formatter
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // First off, there is no way to determine which of the classes it is..

            // Try using the xsi type
            var fmtr = new DatatypeR2Formatter().GetFormatter(s.GetAttribute("type", DatatypeR2Formatter.NS_XSI));

            if (fmtr == null) // No formatter available, add a result
            {
                result.AddResultDetail(new MandatoryElementMissingResultDetail(ResultDetailType.Error, "Cannot determine type of QSET to parse, use xsi:type to specify a type", s.ToString()));
                return(null);
            }

            // Parse using the formatter
            // Fix: EV-876
            fmtr.GenericArguments = this.GenericArguments;
            fmtr.Host             = this.Host;
            return(fmtr.Parse(s, result));
        }
        /// <summary>
        /// Parse an instance of GTS from <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Now determine the type of GTS
            string             typeName = s.GetAttribute("type", DatatypeR2Formatter.NS_XSI);
            IDatatypeFormatter formatter;

            object value = null;

            // Parse the type
            switch (typeName)
            {
            case "IVL_TS":
                formatter = new IVLFormatter();
                break;

            case "PIVL_TS":
                formatter = new PIVLFormatter();
                break;

            case "EIVL_TS":
                formatter = new EIVLFormatter();
                break;

            case "QSP_TS":
            case "QSS_TS":
            case "QSD_TS":
            case "QSU_TS":
            case "QSI_TS":
                formatter = new QSETFormatter();
                break;

            default:
                result.AddResultDetail(new ResultDetail(ResultDetailType.Error, String.Format("Cannot parse a GTS Hull of type '{0}'", typeName), s.ToString()));
                return(null);
            }

            // Graph the Hull
            // Fix: EV-876
            formatter.Host             = this.Host;
            formatter.GenericArguments = new Type[] { typeof(TS) };
            return(Util.Convert <GTS>(formatter.Parse(s, result)));
        }
        /// <summary>
        /// Parse elements
        /// </summary>
        public void ParseElements <T>(XmlReader s, T retVal, DatatypeR2FormatterParseResult result) where T : ANY, IQuantity, new()
        {
            if (retVal == null)
            {
                throw new ArgumentNullException("retVal");
            }

            // 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
                    {
                        ParseElementsInline(s, retVal, result);
                    }
                    catch (VocabularyException e)
                    {
                        result.AddResultDetail(new VocabularyIssueResultDetail(ResultDetailType.Error, e.Message, e));
                    }
                    catch (MessageValidationException e)
                    {
                        result.AddResultDetail(new MARC.Everest.Connectors.ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, s.ToString(), e));
                    }
                    finally
                    {
                        if (s.Name == oldName)
                        {
                            s.Read();
                        }
                    }
                }
            }
            #endregion
        }
Beispiel #39
0
        internal void Validate(ANY instance, string path, DatatypeR2FormatterParseResult resultDetails)
        {
            IResultDetail[] flavor;
            // Validate
            if (resultDetails.ValidateConformance && !instance.Validate())
            {
                foreach (var r in instance.ValidateEx())
                {
                    r.Location = path;
                    resultDetails.AddResultDetail(r);
                }
            }
            //resultDetails.AddResultDetail(new DatatypeValidationResultDetail(ResultDetailType.Error, instance.GetType().Name, path));

            // Validate flavor...
            if (resultDetails.ValidateConformance && instance.Flavor != null && Util.ValidateFlavor(instance.Flavor.ToUpper(), instance, out flavor) == false)
            {
                resultDetails.AddResultDetail(new DatatypeFlavorValidationResultDetail(ResultDetailType.Warning, instance.GetType().Name, instance.Flavor, path));
            }
        }
Beispiel #40
0
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        public T ParseAttributes <T>(XmlReader r, DatatypeR2FormatterParseResult result) where T : ANY, IPrimitiveDataValue, IQuantity, new()
        {
            string val = null;

            // Get the value
            if (r.GetAttribute("value") != null)
            {
                val = r.GetAttribute("value");
            }

            // Parse the QTY part
            QTYFormatter baseFormatter = new QTYFormatter();

            baseFormatter.Host = this.Host;

            // Parse attributes part of QTY
            T retVal = baseFormatter.ParseAttributes <T>(r, result);

            IRealValue rvRetVal = retVal as IRealValue;

            // If the value was interpreted
            if (!String.IsNullOrEmpty(val))
            {
                try
                {
                    retVal.Value = Util.FromWireFormat(val, retVal.GetType().GetProperty("Value").PropertyType);
                    if (rvRetVal != null && val.Contains(DatatypeR2Formatter.FormatterCulture.NumberFormat.NumberDecimalSeparator))
                    {
                        rvRetVal.Precision = val.Length - val.IndexOf(DatatypeR2Formatter.FormatterCulture.NumberFormat.NumberDecimalSeparator) - 1;
                    }
                }
                catch (Exception e)
                {
                    result.Code = ResultCode.Error;
                    result.AddResultDetail(new ResultDetail(ResultDetailType.Error, e.Message, r.ToString(), e));
                }
            }

            // REturn the retVal
            return(retVal);
        }
        /// <summary>
        /// Parse the string
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Temporary holding value for value
            string tValue = null;

            if (s.GetAttribute("value") != null)
            {
                tValue = s.GetAttribute("value");
            }

            // Parse the CD stuff
            CDFormatter baseFormatter = new CDFormatter();

            baseFormatter.Host = this.Host;
            var retVal = baseFormatter.Parse <PQR>(s, result);

            // Interpret the value
            // If the value was interpreted
            if (!String.IsNullOrEmpty(tValue))
            {
                try
                {
                    retVal.Value = Util.Convert <decimal>(tValue);
                    if (tValue.Contains("."))
                    {
                        retVal.Precision = tValue.Length - tValue.IndexOf(".") - 1;
                    }
                }
                catch (Exception e)
                {
                    result.Code = ResultCode.Error;
                    result.AddResultDetail(new ResultDetail(ResultDetailType.Error, e.Message, s.ToString(), e));
                }
            }

            // Validate
            new ANYFormatter().Validate(retVal, s.ToString(), result);

            return(retVal);
        }
Beispiel #42
0
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Parse the base
            ANYFormatter baseFormatter = new ANYFormatter();

            baseFormatter.Host             = this.Host;
            baseFormatter.GenericArguments = this.GenericArguments;
            var retVal = baseFormatter.Parse <II>(s);

            // Parse II specific data
            if (s.GetAttribute("root") != null)
            {
                retVal.Root = s.GetAttribute("root");
            }
            if (s.GetAttribute("extension") != null)
            {
                retVal.Extension = s.GetAttribute("extension");
            }
            if (s.GetAttribute("identifierName") != null)
            {
                retVal.IdentifierName = s.GetAttribute("identifierName");
            }
            if (s.GetAttribute("displayable") != null)
            {
                retVal.Displayable = Util.Convert <bool>(s.GetAttribute("displayable"));
            }
            if (s.GetAttribute("scope") != null)
            {
                retVal.Scope = Util.Convert <IdentifierScope>(s.GetAttribute("scope"));
            }
            if (s.GetAttribute("reliability") != null)
            {
                retVal.Reliability = Util.Convert <IdentifierReliability>(s.GetAttribute("reliability"));
            }

            // Validate
            baseFormatter.Validate(retVal, s.ToString(), result);

            return(retVal);
        }
Beispiel #43
0
        /// <summary>
        /// Parse an instance of GTS from <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Now determine the type of GTS
            string typeName = s.GetAttribute("type", DatatypeR2Formatter.NS_XSI);
            IDatatypeFormatter formatter;

            object value = null;

            // Parse the type
            switch (typeName)
            {
                case "IVL_TS":
                    formatter = new IVLFormatter();
                    break;
                case "PIVL_TS":
                    formatter = new PIVLFormatter();
                    break;
                case "EIVL_TS":
                    formatter = new EIVLFormatter();
                    break;
                case "QSP_TS":
                case "QSS_TS":
                case "QSD_TS":
                case "QSU_TS":
                case "QSI_TS":
                    formatter = new QSETFormatter();
                    break;
                default:
                    result.AddResultDetail(new ResultDetail(ResultDetailType.Error, String.Format("Cannot parse a GTS Hull of type '{0}'", typeName), s.ToString()));
                    return null;
            }

            // Graph the Hull 
            // Fix: EV-876
            formatter.Host = this.Host;
            formatter.GenericArguments = new Type[] { typeof(TS) };
            return Util.Convert<GTS>(formatter.Parse(s, result));

        }
Beispiel #44
0
        /// <summary>
        /// Parse an object instance from <paramref name="s"/>
        /// </summary>
        public virtual object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            var retVal = ParseAttributes <ST>(s, result);

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

                Encoding textEncoding = System.Text.Encoding.UTF8;
                s.Read();
                // Read until exit condition is fulfilled
                while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName))
                {
                    string oldName = s.Name; // Name
                    try
                    {
                        ParseElementsInline(s, retVal, result);
                    }
                    catch (MessageValidationException e)
                    {
                        result.AddResultDetail(new MARC.Everest.Connectors.ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, s.ToString(), e));
                    }
                    finally
                    {
                        if (s.Name == oldName)
                        {
                            s.Read();
                        }
                    }
                }
            }

            // Validate
            new ANYFormatter().Validate(retVal, s.ToString(), result);
            return(retVal);
        }
Beispiel #45
0
        /// <summary>
        /// Parse object from the wire
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Parse base (ANY) from the stream
            ANYFormatter baseFormatter = new ANYFormatter();

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

            // Now parse our data out... Attributes
            if (retVal.NullFlavor == null && s.GetAttribute("code") != null)
            {
                retVal.Code = s.GetAttribute("code");
            }

            // Validate
            string pathName = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name;

            baseFormatter.Validate(retVal, pathName, result);


            return(retVal);
        }
Beispiel #46
0
        /// <summary>
        /// Parse <paramref name="s"/> to an instance of ADXP
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Create base
            ANYFormatter baseFormatter = new ANYFormatter();
            ADXP retVal = baseFormatter.Parse<ADXP>(s);

            // Read data
            if (s.GetAttribute("type") != null)
                retVal.Type = Util.Convert<AddressPartType>(s.GetAttribute("type"));
            if (s.GetAttribute("code") != null)
                retVal.Code = s.GetAttribute("code");
            if (s.GetAttribute("codeSystem") != null)
                retVal.CodeSystem = s.GetAttribute("codeSystem");
            if (s.GetAttribute("codeSystemVersion") != null)
                retVal.CodeSystemVersion = s.GetAttribute("codeSystemVersion");
            if (s.GetAttribute("language") != null)
                result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, "@language", s.NamespaceURI, s.ToString(), null));
            if (s.GetAttribute("value") != null)
                retVal.Value = s.GetAttribute("value");
            
            // Validate
            baseFormatter.Validate(retVal, s.ToString(), result);
            return retVal;
        }
Beispiel #47
0
        /// <summary>
        /// Parse <paramref name="s"/> to an instance of ADXP
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Create base
            ANYFormatter baseFormatter = new ANYFormatter();
            ADXP         retVal        = baseFormatter.Parse <ADXP>(s);

            // Read data
            if (s.GetAttribute("type") != null)
            {
                retVal.Type = Util.Convert <AddressPartType>(s.GetAttribute("type"));
            }
            if (s.GetAttribute("code") != null)
            {
                retVal.Code = s.GetAttribute("code");
            }
            if (s.GetAttribute("codeSystem") != null)
            {
                retVal.CodeSystem = s.GetAttribute("codeSystem");
            }
            if (s.GetAttribute("codeSystemVersion") != null)
            {
                retVal.CodeSystemVersion = s.GetAttribute("codeSystemVersion");
            }
            if (s.GetAttribute("language") != null)
            {
                result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, "@language", s.NamespaceURI, s.ToString(), null));
            }
            if (s.GetAttribute("value") != null)
            {
                retVal.Value = s.GetAttribute("value");
            }

            // Validate
            baseFormatter.Validate(retVal, s.ToString(), result);
            return(retVal);
        }
Beispiel #48
0
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Parse base (ANY) from the stream
            ANYFormatter baseFormatter = new ANYFormatter();
            string pathName = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name;

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

            // Now parse our data out... Attributes
            if (s.GetAttribute("mediaType") != null)
                retVal.MediaType = s.GetAttribute("mediaType");
            if (s.GetAttribute("language") != null)
                retVal.Language = s.GetAttribute("language");
            if (s.GetAttribute("compression") != null)
                retVal.Compression = (EncapsulatedDataCompression?)Util.FromWireFormat(s.GetAttribute("compression"), typeof(EncapsulatedDataCompression));
            if (s.GetAttribute("integrityCheckAlgorithm") != null)
                retVal.IntegrityCheckAlgorithm = Util.Convert<EncapsulatedDataIntegrityAlgorithm>(s.GetAttribute("integrityCheckAlgorithm"));
            if (s.GetAttribute("value") != null)
            {
                retVal.Representation = EncapsulatedDataRepresentation.TXT;
                if(retVal.MediaType == null)
                    retVal.MediaType = "text/plain";
                retVal.Value = s.GetAttribute("value");
            }

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

                Encoding textEncoding = System.Text.Encoding.UTF8;
                s.Read();
                // Read until exit condition is fulfilled
                while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName))
                {
                    string oldName = s.Name; // Name
                    try
                    {
                        if (s.LocalName == "thumbnail") // Format using ED
                        {
                            var hostResult = Host.Parse(s, typeof(ED));
                            result.Code = hostResult.Code;
                            result.AddResultDetail(hostResult.Details);
                            retVal.Thumbnail = (ED)hostResult.Structure;
                        }
                        else if (s.LocalName == "reference") // Format using TEL
                        {
                            var hostResult = Host.Parse(s, typeof(TEL));
                            result.Code = hostResult.Code;
                            result.AddResultDetail(hostResult.Details);
                            retVal.Reference = (TEL)hostResult.Structure;
                        }
                        else if (s.LocalName == "translation") // Translation
                        {
                            var hostResult = Host.Parse(s, typeof(ED));
                            result.Code = hostResult.Code;
                            result.AddResultDetail(hostResult.Details);
                            if (retVal.Translation == null)
                                retVal.Translation = new SET<ED>();
                            retVal.Translation.Add((ED)hostResult.Structure);
                        }
                        else if (s.LocalName == "data") // Data
                        {
                            retVal.Representation = EncapsulatedDataRepresentation.B64;
                            retVal.Data = Convert.FromBase64String(s.ReadString());
                        }
                        else if (s.LocalName == "xml") // data
                        {
                            retVal.Representation = EncapsulatedDataRepresentation.XML;
                            retVal.Data = textEncoding.GetBytes(s.ReadInnerXml());
                        }
                        else if (s.LocalName == "integrityCheck")
                        {
                            retVal.IntegrityCheck = Convert.FromBase64String(s.ReadString());
                        }
                    }
                    catch (MessageValidationException e)
                    {
                        result.AddResultDetail(new MARC.Everest.Connectors.ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, s.ToString(), e));
                    }
                    finally
                    {
                        if (s.Name == oldName) s.Read();
                    }
                }
            }
            #endregion

         
            // Finally, the hash, this will validate the data
            if (!retVal.ValidateIntegrityCheck())
                result.AddResultDetail(new ResultDetail(ResultDetailType.Warning,
                    string.Format("Encapsulated data with content starting with '{0}' failed integrity check!", retVal.ToString().PadRight(10, ' ').Substring(0, 10)),
                    s.ToString(),
                    null));

            // Validate
            baseFormatter.Validate(retVal, pathName, result);

            return retVal;
        }
Beispiel #49
0
        /// <summary>
        /// Parse an instance of PIVL from <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Create the types
            Type pivlType = typeof(PIVL<>);
            Type ivlGenericType = pivlType.MakeGenericType(GenericArguments);

            // Create an instance of rto from the rtoType
            object instance = ivlGenericType.GetConstructor(Type.EmptyTypes).Invoke(null);

            // Parse an any
            ANYFormatter baseFormatter = new ANYFormatter();
            DatatypeR2Formatter.CopyBaseAttributes(baseFormatter.Parse(s, result) as ANY, instance as ANY);

            if ((instance as IAny).NullFlavor == null)
            {
                // Try get operator and value
                if (s.GetAttribute("operator") != null)
                    result.AddResultDetail(new NotPermittedDatatypeR2EntityResultDetail(ResultDetailType.Warning, "operator", "PIVL", s.ToString()));
                if (s.GetAttribute("value") != null)
                    result.AddResultDetail(new NotPermittedDatatypeR2EntityResultDetail(ResultDetailType.Warning, "value", "PIVL", s.ToString()));
                
                // Get property information
                PropertyInfo alignmentProperty = ivlGenericType.GetProperty("Alignment"),
                    phaseProperty = ivlGenericType.GetProperty("Phase"),
                    periodProperty = ivlGenericType.GetProperty("Period"),
                    institutionSpecifiedProperty = ivlGenericType.GetProperty("InstitutionSpecified"),
                    countProperty = ivlGenericType.GetProperty("Count"),
                    frequencyProperty = ivlGenericType.GetProperty("Frequency"),
                    originalTextProperty = ivlGenericType.GetProperty("OriginalText");

                // Attributes
                if(s.GetAttribute("isFlexible") != null)
                    institutionSpecifiedProperty.SetValue(instance, XmlConvert.ToBoolean(s.GetAttribute("isFlexible")), null);
                if(s.GetAttribute("alignment") != null)
                    alignmentProperty.SetValue(instance, Util.FromWireFormat(s.GetAttribute("alignment"), alignmentProperty.PropertyType), null);
                if(s.GetAttribute("count") != null)
                    countProperty.SetValue(instance, Util.Convert<INT>(s.GetAttribute("count")), null);

                // Now process the 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.NodeType == System.Xml.XmlNodeType.Element)
                            {
                                PropertyInfo setProperty = null;
                                switch(s.LocalName)
                                {
                                    case "originalText":
                                        setProperty = originalTextProperty;
                                        break;
                                    case "phase":
                                        setProperty = phaseProperty;
                                        break;
                                    case "frequency":
                                        setProperty = frequencyProperty;
                                        break;
                                    case "period":
                                        setProperty = periodProperty;
                                        break;
                                    default:
                                        result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, s.LocalName, s.NamespaceURI, s.ToString(), null));
                                        break;
                                }

                                // Set the property if we found something valid
                                if(setProperty != null)
                                {
                                    var hostResult = this.Host.Parse(s, setProperty.PropertyType);
                                    result.Code = hostResult.Code;
                                    result.AddResultDetail(hostResult.Details);
                                    setProperty.SetValue(instance, Util.FromWireFormat(hostResult.Structure, setProperty.PropertyType), null);
                                }
                            }
                        }
                        catch (MessageValidationException e) // Message validation error
                        {
                            result.AddResultDetail(new MARC.Everest.Connectors.ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, e));
                        }
                        finally
                        {
                            if (s.Name == oldName) s.Read();
                        }
                    }
                }
                #endregion

            }

            // Validate
            ANYFormatter validation = new ANYFormatter();
            validation.Validate(instance as ANY, s.LocalName, result);

            return instance;
        }
Beispiel #50
0
        /// <summary>
        /// Graph <paramref name="o"/> onto <paramref name="s"/>
        /// </summary>
        public void Graph(System.Xml.XmlWriter s, object o, DatatypeR2FormatterGraphResult result)
        {
            
            // XP is special, it does not extend anything so we have to graph from scratch
            var instance = o as ENXP;

            // Null flavor?
            if (instance.NullFlavor != null)
                s.WriteAttributeString("nullFlavor", Util.ToWireFormat(instance.NullFlavor));
            else
            {
                // Validate 
                DatatypeR2FormatterParseResult tResult = new DatatypeR2FormatterParseResult(result.ValidateConformance);
                new ANYFormatter().Validate(instance, s.ToString(), tResult);
                result.AddResultDetail(tResult.Details);
                
                // Qualifiers (copy for modification)
                SET<CS<EntityNamePartQualifier>> qualifiers = new SET<CS<EntityNamePartQualifier>>();
                if(instance.Qualifier != null)
                    foreach (var qlf in instance.Qualifier)
                        qualifiers.Add(qlf.Clone() as CS<EntityNamePartQualifier>);

                // Unsupported properties
                if (instance.ControlActExt != null)
                    result.AddResultDetail(new UnsupportedDatatypeR2PropertyResultDetail(ResultDetailType.Warning, "ControlActExt", "ENXP", s.ToString()));
                if (instance.ControlActRoot != null)
                    result.AddResultDetail(new UnsupportedDatatypeR2PropertyResultDetail(ResultDetailType.Warning, "ControlActRoot", "ENXP", s.ToString()));
                if (instance.ValidTimeHigh != null)
                    result.AddResultDetail(new UnsupportedDatatypeR2PropertyResultDetail(ResultDetailType.Warning, "ValidTimeHigh", "ENXP", s.ToString()));
                if (instance.ValidTimeLow != null)
                    result.AddResultDetail(new UnsupportedDatatypeR2PropertyResultDetail(ResultDetailType.Warning, "ValidTimeLow", "ENXP", s.ToString()));
                if (instance.Flavor != null)
                    result.AddResultDetail(new UnsupportedDatatypeR2PropertyResultDetail(ResultDetailType.Warning, "Flavor", "ENXP", s.ToString()));
                if (instance.UpdateMode != null)
                    result.AddResultDetail(new UnsupportedDatatypeR2PropertyResultDetail(ResultDetailType.Warning, "UpdateMode", "ENXP", s.ToString()));

                // Output the supported properties
                if (instance.Value != null)
                    s.WriteAttributeString("value", instance.Value);
                if (instance.Code != null)
                    s.WriteAttributeString("code", instance.Code);
                if (instance.CodeSystem != null)
                    s.WriteAttributeString("codeSystem", instance.CodeSystem);
                if (instance.CodeSystemVersion != null)
                    s.WriteAttributeString("codeSystemVersion", instance.CodeSystemVersion);
                if (instance.Type != null)
                {
                    // Qualifiers that count as TITLE
                    EntityNamePartQualifier[] titleQualifiers = new EntityNamePartQualifier[] {
                        EntityNamePartQualifier.Professional,
                        EntityNamePartQualifier.Nobility,
                        EntityNamePartQualifier.Academic ,
                        EntityNamePartQualifier.LegalStatus
                    };

                    // If type is not SFX or PFX then output the type,
                    // if it is either SFX or PFX then don't output the type
                    // but do modify the qualifier
                    switch(instance.Type.Value)
                    {
                        case EntityNamePartType.Prefix:
                            if (instance.Qualifier == null)
                                instance.Qualifier = new SET<CS<EntityNamePartQualifier>>();
                            if(!qualifiers.Contains(EntityNamePartQualifier.Prefix))
                                qualifiers.Add(EntityNamePartQualifier.Prefix);

                            // Change the instance type
                            if(Array.Exists(titleQualifiers, q => qualifiers.Contains(q)))
                                s.WriteAttributeString("type", "TITLE");

                            break;
                        case EntityNamePartType.Suffix:
                            if (instance.Qualifier == null)
                                instance.Qualifier = new SET<CS<EntityNamePartQualifier>>();
                            if (!qualifiers.Contains(EntityNamePartQualifier.Suffix))
                                qualifiers.Add(EntityNamePartQualifier.Suffix);
                            
                            // Change the instance type
                            if (Array.Exists(titleQualifiers, q => qualifiers.Contains(q)))
                                s.WriteAttributeString("type", "TITLE");

                            break;
                        default:
                            s.WriteAttributeString("type", Util.ToWireFormat(instance.Type));
                            break;
                    }
                }
                if (!qualifiers.IsEmpty)
                    s.WriteAttributeString("qualifier", Util.ToWireFormat(qualifiers));

            }
        }
Beispiel #51
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;
        }
Beispiel #52
0
        /// <summary>
        /// Parse an object from <paramref name="s"/> into an instance of QSP
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Create the types
            Type qspType = typeof(QSD<>);
            Type qspGenericType = qspType.MakeGenericType(GenericArguments);

            // Create an instance of rto from the rtoType
            object instance = qspGenericType.GetConstructor(Type.EmptyTypes).Invoke(null);

            // Parse an any
            ANYFormatter baseFormatter = new ANYFormatter();
            DatatypeR2Formatter.CopyBaseAttributes(baseFormatter.Parse(s, result) as ANY, instance as ANY);

            if ((instance as IAny).NullFlavor == null)
            {

                // Get property information
                PropertyInfo minuendProperty = qspGenericType.GetProperty("Minuend"),
                    subtrahendProperty = qspGenericType.GetProperty("Subtrahend"),
                    originalTextProperty = qspGenericType.GetProperty("OriginalText");

                // Now process the 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.NodeType == System.Xml.XmlNodeType.Element)
                            {
                                PropertyInfo setProperty = null;
                                switch (s.LocalName)
                                {
                                    case "originalText":
                                        setProperty = originalTextProperty;
                                        break;
                                    case "minuend":
                                        setProperty = minuendProperty;
                                        break;
                                    case "subtrahend":
                                        setProperty = subtrahendProperty;
                                        break;
                                    default:
                                        result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, s.LocalName, s.NamespaceURI, s.ToString(), null));
                                        break;
                                }

                                // Set the property if we found something valid
                                if (setProperty != null)
                                {
                                    var hostResult = this.Host.Parse(s, setProperty.PropertyType);
                                    result.Code = hostResult.Code;
                                    result.AddResultDetail(hostResult.Details);
                                    setProperty.SetValue(instance, Util.FromWireFormat(hostResult.Structure, setProperty.PropertyType), null);
                                }
                            }
                        }
                        catch (MessageValidationException e) // Message validation error
                        {
                            result.AddResultDetail(new MARC.Everest.Connectors.ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, e));
                        }
                        finally
                        {
                            if (s.Name == oldName) s.Read();
                        }
                    }
                }
                #endregion

            }

            // Validate
            ANYFormatter validation = new ANYFormatter();
            validation.Validate(instance as ANY, s.LocalName, result);

            return instance;
        }
Beispiel #53
0
        /// <summary>
        /// Parse the RTO
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Create the types
            Type rtoType = typeof(RTO<,>);

            QTYFormatter baseFormatter = (new QTYFormatter() { Host = this.Host});
            // Quantity value, just read into a REAL
            var qty = baseFormatter.ParseAttributes<REAL>(s, result);

            // Temporary values
            IGraphable denominator = null,
                numerator = null;
          
            // Elements
            // This type is a little different in R2, basically we can't determine the generic
            // parameters by the XSI Type so we have to parse the num/denom manually, and 
            // ensure that we have both, then we construct the object and set the properties
            #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
                    {
                        // Numerator
                        if (s.LocalName == "numerator")
                        {
                            var parseResult = Host.Parse(s, GenericArguments[0]);
                            result.Code = parseResult.Code;
                            result.AddResultDetail(parseResult.Details);
                            numerator = parseResult.Structure;
                        }
                        // Denominator
                        else if (s.LocalName == "denominator")
                        {
                            var parseResult = Host.Parse(s, GenericArguments[1]);
                            result.Code = parseResult.Code;
                            result.AddResultDetail(parseResult.Details);
                            denominator = parseResult.Structure;
                        }
                        else
                            baseFormatter.ParseElementsInline(s, qty, result);

                    }
                    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

            try
            {
                // Construct the generic type (if possible)
                Type rtoGenericType = rtoType.MakeGenericType(new Type[]
                {
                    numerator == null ? typeof(IQuantity) : numerator.GetType(),
                    denominator == null ? typeof(IQuantity) : denominator.GetType()
                });

                // Create an instance of rto from the rtoType
                object instance = rtoGenericType.GetConstructor(Type.EmptyTypes).Invoke(null);

                // Get the values from the QTY and copy
                IQuantity rtoQty = instance as IQuantity;
                DatatypeR2Formatter.CopyBaseAttributes(qty, rtoQty as ANY);
                rtoQty.Expression = qty.Expression;
                rtoQty.OriginalText = qty.OriginalText;
                rtoQty.UncertainRange = qty.UncertainRange;
                rtoQty.Uncertainty = qty.Uncertainty;
                rtoQty.UncertaintyType = qty.UncertaintyType;

                // rto properties
                PropertyInfo numeratorProperty = rtoGenericType.GetProperty("Numerator"),
                    denominatorProperty = rtoGenericType.GetProperty("Denominator");

                // Set the previously found properties
                numeratorProperty.SetValue(instance, Util.FromWireFormat(numerator, numeratorProperty.PropertyType), null);
                denominatorProperty.SetValue(instance, Util.FromWireFormat(denominator, denominatorProperty.PropertyType), null);

                // Validate
                ANYFormatter anyFormatter = new ANYFormatter();
                string pathName = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name;
                anyFormatter.Validate(instance as ANY, pathName, result);

                return instance;
            }
            catch (Exception e)
            {
                result.AddResultDetail(new ResultDetail(ResultDetailType.Error, e.Message, e));
                return null;
            }
        }
Beispiel #54
0
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Create the types
            Type ivlType = typeof(IVL<>);
            Type ivlGenericType = ivlType.MakeGenericType(GenericArguments);

            // Create an instance of rto from the rtoType
            object instance = ivlGenericType.GetConstructor(Type.EmptyTypes).Invoke(null);

            // Parse an any
            ANYFormatter baseFormatter = new ANYFormatter();
            DatatypeR2Formatter.CopyBaseAttributes(baseFormatter.Parse(s, result) as ANY, instance as ANY);

            if ((instance as IAny).NullFlavor == null)
            {

                // Try get operator and value
                if (s.GetAttribute("operator") != null)
                    result.AddResultDetail(new NotPermittedDatatypeR2EntityResultDetail(ResultDetailType.Warning, "operator", "IVL", s.ToString()));
                if (s.GetAttribute("value") != null)
                    result.AddResultDetail(new NotPermittedDatatypeR2EntityResultDetail(ResultDetailType.Warning, "value", "IVL", s.ToString()));
                
                // Get property information
                PropertyInfo lowProperty = ivlGenericType.GetProperty("Low"),
                    highProperty = ivlGenericType.GetProperty("High"),
                    widthProperty = ivlGenericType.GetProperty("Width"),
                    valueProperty = ivlGenericType.GetProperty("Value"),
                    originalTextProperty = ivlGenericType.GetProperty("OriginalText"),
                    lowClosedProperty = ivlGenericType.GetProperty("LowClosed"),
                    highClosedProperty = ivlGenericType.GetProperty("HighClosed");

                // Attributes
                if(s.GetAttribute("lowClosed") != null)
                    lowClosedProperty.SetValue(instance, XmlConvert.ToBoolean(s.GetAttribute("lowClosed")), null);
                if(s.GetAttribute("highClosed") != null)
                    highClosedProperty.SetValue(instance, XmlConvert.ToBoolean(s.GetAttribute("highClosed")), null);

                // Now process the 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.NodeType == System.Xml.XmlNodeType.Element)
                            {
                                PropertyInfo setProperty = null;
                                switch(s.LocalName)
                                {
                                    case "originalText":
                                        setProperty = originalTextProperty;
                                        break;
                                    case "low":
                                        setProperty = lowProperty;
                                        break;
                                    case "high":
                                        setProperty = highProperty;
                                        break;
                                    case "any":
                                        setProperty = valueProperty;
                                        break;
                                    case "width":
                                        setProperty = widthProperty;
                                        break;
                                    default:
                                        result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, String.Format("Element '{0}' is not supported in IVL", s.LocalName), s.ToString(), null));
                                        break;
                                }

                                // Set the property if we found something valid
                                if(setProperty != null)
                                {
                                    var hostResult = this.Host.Parse(s, setProperty.PropertyType);
                                    result.Code = hostResult.Code;
                                    result.AddResultDetail(hostResult.Details);
                                    setProperty.SetValue(instance, Util.FromWireFormat(hostResult.Structure, setProperty.PropertyType), null);
                                }
                            }
                        }
                        catch (MessageValidationException e) // Message validation error
                        {
                            result.AddResultDetail(new MARC.Everest.Connectors.ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, e));
                        }
                        finally
                        {
                            if (s.Name == oldName) s.Read();
                        }
                    }
                }
                #endregion

                // Validate combination
                if(!((lowProperty.GetValue(instance, null) != null || highProperty.GetValue(instance, null) != null) ^ (valueProperty.GetValue(instance, null) != null || widthProperty.GetValue(instance, null) != null)))
                    result.AddResultDetail(new NotSupportedChoiceResultDetail(ResultDetailType.Warning, "IVL instance is not comformant to ISO21090 data types specification. 'Value' and/or 'Width', or 'Low' and/or 'High' are compliant representations.", s.ToString(), null));

            }

            // Validate
            ANYFormatter validation = new ANYFormatter();
            validation.Validate(instance as ANY, s.LocalName, result);

            return instance;

        }
Beispiel #55
0
        /// <summary>
        /// Parse from wire level format
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {

            // Any formatter for the base attributes
            ANYFormatter baseFormatter = new ANYFormatter();
            // Create the types
            Type qsiType = typeof(QSS<>);
            Type qsiGenericType = qsiType.MakeGenericType(GenericArguments);

            // Create an instance of rto from the rtoType
            object instance = qsiGenericType.GetConstructor(Type.EmptyTypes).Invoke(null);
            DatatypeR2Formatter.CopyBaseAttributes(baseFormatter.Parse(s, result) as ANY, instance as ANY);

            // Read internal elements
            if ((instance as ANY).NullFlavor != null)
                return instance;

            // Now process the elements
            #region Elements
            if (!s.IsEmptyElement)
            {

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

                List<IGraphable> termList = new List<IGraphable>(4);

                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.NodeType == System.Xml.XmlNodeType.Element)
                        {
                            switch (s.LocalName)
                            {
                                case "originalText":
                                    {
                                        var hostResult = this.Host.Parse(s, typeof(ED));
                                        result.Code = hostResult.Code;
                                        result.AddResultDetail(hostResult.Details);
                                        (instance as IOriginalText).OriginalText = hostResult.Structure as ED;
                                        break;
                                    }
                                case "term":
                                    {
                                        var hostResult = this.Host.Parse(s, GenericArguments[0]);
                                        result.Code = hostResult.Code;
                                        result.AddResultDetail(hostResult.Details);
                                        termList.Add(hostResult.Structure as IGraphable);
                                        break;
                                    }
                                default:
                                    result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, s.LocalName, s.NamespaceURI, s.ToString(), null));
                                    break;
                            }
                        }
                    }
                    catch (MessageValidationException e) // Message validation error
                    {
                        result.AddResultDetail(new MARC.Everest.Connectors.ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, e));
                    }
                    finally
                    {
                        if (s.Name == oldName) s.Read();
                    }
                }

                // Set term list

                ((IListContainer)instance).ContainedList = termList;
            }
            #endregion

            // Validate
            baseFormatter.Validate(instance as ANY, s.ToString(), result);

            return instance;
        }
Beispiel #56
0
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            ANYFormatter baseFormatter = new ANYFormatter();
            baseFormatter.Host = this.Host;
            baseFormatter.GenericArguments = this.GenericArguments;
            ANY tRetVal = baseFormatter.Parse<ANY>(s);

            // Construct an instance of the SLIST
            var slistType = typeof(SLIST<>).MakeGenericType(this.GenericArguments);
            var constructor = slistType.GetConstructor(Type.EmptyTypes);
            ISampledList retVal = constructor.Invoke(null) as ISampledList;

            DatatypeR2Formatter.CopyBaseAttributes(tRetVal, retVal as ANY);

            // Parse the return value
            #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
                    {
                        // Origin
                        if (s.LocalName == "origin" && retVal.Origin == null)
                        {
                            var parseResult = Host.Parse(s, GenericArguments[0]);
                            result.Code = parseResult.Code;
                            result.AddResultDetail(parseResult.Details);
                            retVal.Origin = parseResult.Structure as IQuantity;
                        }
                        else if (s.LocalName == "origin")
                            result.AddResultDetail(new NotImplementedResultDetail(ResultDetailType.Warning, "origin may only be supplied once", s.ToString()));
                        // Scale
                        else if (s.LocalName == "scale" && retVal.Scale == null)
                        {
                            var parseResult = Host.Parse(s, typeof(IQuantity));
                            result.Code = parseResult.Code;
                            result.AddResultDetail(parseResult.Details);
                            retVal.Scale = parseResult.Structure as IQuantity;
                        }
                        else if (s.LocalName == "scale")
                            result.AddResultDetail(new NotImplementedResultDetail(ResultDetailType.Warning, "scale may only be supplied once", s.ToString()));
                        // Digit
                        else if (s.LocalName == "digit")
                        {
                            var parseResult = Host.Parse(s, typeof(INT));
                            result.Code = parseResult.Code;
                            result.AddResultDetail(parseResult.Details);
                            retVal.Items.Add(parseResult.Structure as INT);
                        }
                        else if (s.NodeType == System.Xml.XmlNodeType.Element)
                            result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, s.LocalName, s.NamespaceURI, s.ToString(), null));

                    }
                    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
            baseFormatter.Validate(retVal as ANY, s.ToString(), result);
            return retVal;
        }
Beispiel #57
0
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            ANYFormatter baseFormatter = new ANYFormatter();
            baseFormatter.Host = this.Host;
            baseFormatter.GenericArguments = this.GenericArguments;

            // Graph
            var tRetVal = baseFormatter.Parse<ANY>(s);
            var uvpType = typeof(UVP<>);
            var genType = uvpType.MakeGenericType(this.GenericArguments);

            // Construct
            var constructor = genType.GetConstructor(Type.EmptyTypes);
            IProbability retVal = constructor.Invoke(null) as IProbability;

            // Copy base attributes
            DatatypeR2Formatter.CopyBaseAttributes(tRetVal, retVal as ANY);

            // Parse UVP properties
            if (s.GetAttribute("probability") != null)
            {
                string tProb = s.GetAttribute("probability");
                try
                {
                    retVal.Probability = Decimal.Parse(tProb);
                }
                catch (Exception e)
                {
                    result.Code = ResultCode.Error;
                    result.AddResultDetail(new ResultDetail(ResultDetailType.Error, e.Message, s.ToString(), e));
                }
            }

            // Now process the 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 == "value" && retVal.Value == null)
                        {
                            var hostResult = this.Host.Parse(s, GenericArguments[0]);
                            result.AddResultDetail(hostResult.Details);
                            retVal.Value = hostResult.Structure;
                        }
                        else if(s.LocalName == "value")
                            result.AddResultDetail(new NotImplementedResultDetail(ResultDetailType.Warning, "Value can only be set once on an instance of UVP", s.ToString()));
                        else if (s.NodeType == System.Xml.XmlNodeType.Element)
                            result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, s.LocalName, s.NamespaceURI, s.ToString(), null));
                    }
                    catch (MessageValidationException e) // Message validation error
                    {
                        result.AddResultDetail(new MARC.Everest.Connectors.ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, e));
                    }
                    finally
                    {
                        if (s.Name == oldName) s.Read();
                    }
                }
            }
            #endregion

            // validate
            baseFormatter.Validate(retVal as ANY, s.ToString(), result);
            return retVal;
        }
Beispiel #58
0
        /// <summary>
        /// Parse an instance of PIVL from <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Create the types
            Type pivlType       = typeof(PIVL <>);
            Type ivlGenericType = pivlType.MakeGenericType(GenericArguments);

            // Create an instance of rto from the rtoType
            object instance = ivlGenericType.GetConstructor(Type.EmptyTypes).Invoke(null);

            // Parse an any
            ANYFormatter baseFormatter = new ANYFormatter();

            DatatypeR2Formatter.CopyBaseAttributes(baseFormatter.Parse(s, result) as ANY, instance as ANY);

            if ((instance as IAny).NullFlavor == null)
            {
                // Try get operator and value
                if (s.GetAttribute("operator") != null)
                {
                    result.AddResultDetail(new NotPermittedDatatypeR2EntityResultDetail(ResultDetailType.Warning, "operator", "PIVL", s.ToString()));
                }
                if (s.GetAttribute("value") != null)
                {
                    result.AddResultDetail(new NotPermittedDatatypeR2EntityResultDetail(ResultDetailType.Warning, "value", "PIVL", s.ToString()));
                }

                // Get property information
                PropertyInfo alignmentProperty            = ivlGenericType.GetProperty("Alignment"),
                             phaseProperty                = ivlGenericType.GetProperty("Phase"),
                             periodProperty               = ivlGenericType.GetProperty("Period"),
                             institutionSpecifiedProperty = ivlGenericType.GetProperty("InstitutionSpecified"),
                             countProperty                = ivlGenericType.GetProperty("Count"),
                             frequencyProperty            = ivlGenericType.GetProperty("Frequency"),
                             originalTextProperty         = ivlGenericType.GetProperty("OriginalText");

                // Attributes
                if (s.GetAttribute("isFlexible") != null)
                {
                    institutionSpecifiedProperty.SetValue(instance, XmlConvert.ToBoolean(s.GetAttribute("isFlexible")), null);
                }
                if (s.GetAttribute("alignment") != null)
                {
                    alignmentProperty.SetValue(instance, Util.FromWireFormat(s.GetAttribute("alignment"), alignmentProperty.PropertyType), null);
                }
                if (s.GetAttribute("count") != null)
                {
                    countProperty.SetValue(instance, Util.Convert <INT>(s.GetAttribute("count")), null);
                }

                // Now process the 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.NodeType == System.Xml.XmlNodeType.Element)
                            {
                                PropertyInfo setProperty = null;
                                switch (s.LocalName)
                                {
                                case "originalText":
                                    setProperty = originalTextProperty;
                                    break;

                                case "phase":
                                    setProperty = phaseProperty;
                                    break;

                                case "frequency":
                                    setProperty = frequencyProperty;
                                    break;

                                case "period":
                                    setProperty = periodProperty;
                                    break;

                                default:
                                    result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, s.LocalName, s.NamespaceURI, s.ToString(), null));
                                    break;
                                }

                                // Set the property if we found something valid
                                if (setProperty != null)
                                {
                                    var hostResult = this.Host.Parse(s, setProperty.PropertyType);
                                    result.Code = hostResult.Code;
                                    result.AddResultDetail(hostResult.Details);
                                    setProperty.SetValue(instance, Util.FromWireFormat(hostResult.Structure, setProperty.PropertyType), null);
                                }
                            }
                        }
                        catch (MessageValidationException e) // Message validation error
                        {
                            result.AddResultDetail(new MARC.Everest.Connectors.ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, e));
                        }
                        finally
                        {
                            if (s.Name == oldName)
                            {
                                s.Read();
                            }
                        }
                    }
                }
                #endregion
            }

            // Validate
            ANYFormatter validation = new ANYFormatter();
            validation.Validate(instance as ANY, s.LocalName, result);

            return(instance);
        }
Beispiel #59
0
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Create the types
            Type ivlType        = typeof(IVL <>);
            Type ivlGenericType = ivlType.MakeGenericType(GenericArguments);

            // Create an instance of rto from the rtoType
            object instance = ivlGenericType.GetConstructor(Type.EmptyTypes).Invoke(null);

            // Parse an any
            ANYFormatter baseFormatter = new ANYFormatter();

            DatatypeR2Formatter.CopyBaseAttributes(baseFormatter.Parse(s, result) as ANY, instance as ANY);

            if ((instance as IAny).NullFlavor == null)
            {
                // Try get operator and value
                if (s.GetAttribute("operator") != null)
                {
                    result.AddResultDetail(new NotPermittedDatatypeR2EntityResultDetail(ResultDetailType.Warning, "operator", "IVL", s.ToString()));
                }
                if (s.GetAttribute("value") != null)
                {
                    result.AddResultDetail(new NotPermittedDatatypeR2EntityResultDetail(ResultDetailType.Warning, "value", "IVL", s.ToString()));
                }

                // Get property information
                PropertyInfo lowProperty          = ivlGenericType.GetProperty("Low"),
                             highProperty         = ivlGenericType.GetProperty("High"),
                             widthProperty        = ivlGenericType.GetProperty("Width"),
                             valueProperty        = ivlGenericType.GetProperty("Value"),
                             originalTextProperty = ivlGenericType.GetProperty("OriginalText"),
                             lowClosedProperty    = ivlGenericType.GetProperty("LowClosed"),
                             highClosedProperty   = ivlGenericType.GetProperty("HighClosed");

                // Attributes
                if (s.GetAttribute("lowClosed") != null)
                {
                    lowClosedProperty.SetValue(instance, XmlConvert.ToBoolean(s.GetAttribute("lowClosed")), null);
                }
                if (s.GetAttribute("highClosed") != null)
                {
                    highClosedProperty.SetValue(instance, XmlConvert.ToBoolean(s.GetAttribute("highClosed")), null);
                }

                // Now process the 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.NodeType == System.Xml.XmlNodeType.Element)
                            {
                                PropertyInfo setProperty = null;
                                switch (s.LocalName)
                                {
                                case "originalText":
                                    setProperty = originalTextProperty;
                                    break;

                                case "low":
                                    setProperty = lowProperty;
                                    break;

                                case "high":
                                    setProperty = highProperty;
                                    break;

                                case "any":
                                    setProperty = valueProperty;
                                    break;

                                case "width":
                                    setProperty = widthProperty;
                                    break;

                                default:
                                    result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, String.Format("Element '{0}' is not supported in IVL", s.LocalName), s.ToString(), null));
                                    break;
                                }

                                // Set the property if we found something valid
                                if (setProperty != null)
                                {
                                    var hostResult = this.Host.Parse(s, setProperty.PropertyType);
                                    result.Code = hostResult.Code;
                                    result.AddResultDetail(hostResult.Details);
                                    setProperty.SetValue(instance, Util.FromWireFormat(hostResult.Structure, setProperty.PropertyType), null);
                                }
                            }
                        }
                        catch (MessageValidationException e) // Message validation error
                        {
                            result.AddResultDetail(new MARC.Everest.Connectors.ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, e));
                        }
                        finally
                        {
                            if (s.Name == oldName)
                            {
                                s.Read();
                            }
                        }
                    }
                }
                #endregion

                // Validate combination
                if (!((lowProperty.GetValue(instance, null) != null || highProperty.GetValue(instance, null) != null) ^ (valueProperty.GetValue(instance, null) != null || widthProperty.GetValue(instance, null) != null)))
                {
                    result.AddResultDetail(new NotSupportedChoiceResultDetail(ResultDetailType.Warning, "IVL instance is not comformant to ISO21090 data types specification. 'Value' and/or 'Width', or 'Low' and/or 'High' are compliant representations.", s.ToString(), null));
                }
            }

            // Validate
            ANYFormatter validation = new ANYFormatter();
            validation.Validate(instance as ANY, s.LocalName, result);

            return(instance);
        }
Beispiel #60
0
        /// <summary>
        /// Parse the PQ back into a structure
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Create the base formatter
            PDVFormatter baseFormatter = new PDVFormatter();
            baseFormatter.Host = this.Host;

            // Read temporary values
            string tUnit = null;
            if(s.GetAttribute("unit") != null)
                tUnit = s.GetAttribute("unit");
            SET<CodingRationale> tRationale = null;
            if (s.GetAttribute("codingRationale") != null)
                tRationale = Util.Convert<SET<CodingRationale>>(s.GetAttribute("codingRationale"));

            // Parse PDV content (only attributes)
            var retVal = baseFormatter.ParseAttributes<PQ>(s, result);

            // Set PDV content
            retVal.Unit = tUnit;
            retVal.CodingRationale = tRationale;

            // Process elements 
            // This requires a QTY formatter as QTY elements may be 
            // in the stream as well
            #region Elements
            if (!s.IsEmptyElement)
            {
                // Prepare a formatter to process QTY elements
                QTYFormatter qtyFormatter = new QTYFormatter();
                qtyFormatter.Host = this.Host;

                // Exit markers
                int sDepth = s.Depth;
                string sName = s.Name;

                // Translations
                SET<PQR> translations = new SET<PQR>();

                // Read the next element
                s.Read();

                // Read until exit condition is fulfilled
                while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName))
                {
                    string oldName = s.Name; // Name
                    try
                    {
                        if (s.LocalName == "translation") // Format using ED
                        {
                            var hostResult = Host.Parse(s, typeof(PQR));
                            result.Code = hostResult.Code;
                            result.AddResultDetail(hostResult.Details);
                            translations.Add(hostResult.Structure as PQR);
                        }
                        else
                            qtyFormatter.ParseElementsInline(s, retVal, result);

                    }
                    catch (MessageValidationException e)
                    {
                        result.AddResultDetail(new MARC.Everest.Connectors.ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, s.ToString(), e));
                    }
                    finally
                    {
                        if (s.Name == oldName) s.Read();
                    }
                }

                // Set translations
                if (!translations.IsEmpty)
                    retVal.Translation = translations;
            }
            #endregion

            // Validate
            ANYFormatter anyFormatter = new ANYFormatter();
            string pathName = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name;
            anyFormatter.Validate(retVal as ANY, pathName, result);
            
            // REturn instance
            return retVal;
        }