コード例 #1
0
        public T Parse <T>(XmlReader xr, DatatypeFormatterParseResult result) where T : ANY, new()
        {
            ANYFormatter baseFormatter = new ANYFormatter(); // Base formatter
            T            retVal        = baseFormatter.Parse <T>(xr, result);

            // If it is null return the null flavor
            if (retVal.NullFlavor != null)
            {
                return(retVal);
            }

            PropertyInfo pi = typeof(T).GetProperty("Value");

            try
            {
                // Value
                if (xr.GetAttribute("value") != null)
                {
                    pi.SetValue(retVal, Util.FromWireFormat(xr.GetAttribute("value"), pi.PropertyType), null);
                }
            }
            catch (Exception e)
            {
                result.AddResultDetail(new ResultDetail(ResultDetailType.Error, e.Message, xr.ToString(), e));
            }
            return(retVal);
        }
コード例 #2
0
        /// <summary>
        /// Parse the TN from the XmlReader <paramref name="s"/>.
        /// </summary>
        /// <param name="s">XmlReader stream to parse from.</param>
        /// <returns>Parsed TN.</returns>
        public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            ANYFormatter baseFormatter = new ANYFormatter();
            TN           tn            = baseFormatter.Parse <TN>(s, result);

            // Parse the mixed content and add it to the list.
            if (!s.IsEmptyElement)
            {
                string oldName = s.LocalName;
                ENXP   tnPart  = new ENXP("");
                while (s.Read() && s.NodeType != System.Xml.XmlNodeType.EndElement && s.LocalName != oldName)
                {
                    if (s.NodeType == System.Xml.XmlNodeType.Text || s.NodeType == System.Xml.XmlNodeType.CDATA)
                    {
                        tnPart.Value += s.Value;
                    }
                    else if (s.NodeType == System.Xml.XmlNodeType.Element)
                    {
                        result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning,
                                                                                     s.LocalName,
                                                                                     s.NamespaceURI,
                                                                                     s.ToString(), null));
                    }
                }
                tn.Part.Add(tnPart);
            }

            return(tn);
        }
コード例 #3
0
        /// <summary>
        /// Parse the object from <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            // Parse
            ANYFormatter anyFormatter = new ANYFormatter();
            GTS          retVal       = anyFormatter.Parse <GTS>(s, result);

            // Is there any need to continue?
            if (retVal.NullFlavor != null)
            {
                return(retVal);
            }

            // Now determine the type of GTS
            string             typeName = s.GetAttribute("type", "http://www.w3.org/2001/XMLSchema-instance");
            IDatatypeFormatter formatter;

            // 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 "SXPR_TS":
                formatter = new SXPRFormatter();
                break;

            case "SXCM_TS":
                formatter = new SXCMFormatter();
                break;

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

            // Graph the Hull
            formatter.Host             = this.Host;
            formatter.GenericArguments = new Type[] { typeof(TS) };
            retVal.Hull = formatter.Parse(s, result) as SXCM <TS>;

            // Correct the flavor, the flavor of the hull becomes the flavor of the object
            retVal.Flavor          = retVal.Flavor ?? retVal.Hull.Flavor;
            retVal.Hull.Flavor     = null;
            retVal.NullFlavor      = retVal.NullFlavor ?? (retVal.Hull.NullFlavor != null ? retVal.Hull.NullFlavor.Clone() as CS <NullFlavor> : null);
            retVal.Hull.NullFlavor = null;

            // Set the details
            return(retVal);
        }
コード例 #4
0
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        /// <param name="s">The stream to parse from</param>
        /// <returns>The parsed object</returns>
        public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            // The SC to return.
            ANYFormatter baseFormatter = new ANYFormatter();
            SC           sc            = baseFormatter.Parse <SC>(s, result);

            if (sc.NullFlavor != null)
            {
                return(sc);
            }

            if (s.GetAttribute("code") != null || s.GetAttribute("codeSystem") != null ||
                s.GetAttribute("codeSystemVersion") != null || s.GetAttribute("codeSystemName") != null ||
                s.GetAttribute("displayName") != null)
            {
                sc.Code = new CD <string>();
            }

            if (s.GetAttribute("code") != null)
            {
                sc.Code.Code = Util.Convert <CodeValue <String> >(s.GetAttribute("code"));
            }
            if (s.GetAttribute("codeSystem") != null)
            {
                sc.Code.CodeSystem = s.GetAttribute("codeSystem");
            }
            if (s.GetAttribute("codeSystemVersion") != null)
            {
                sc.Code.CodeSystemVersion = s.GetAttribute("codeSystemVersion");
            }
            if (s.GetAttribute("codeSystemName") != null)
            {
                sc.Code.CodeSystemName = s.GetAttribute("codeSystemName");
            }
            if (s.GetAttribute("displayName") != null)
            {
                sc.Code.DisplayName = s.GetAttribute("displayName");
            }

            // Read the ST parts
            STFormatter stFormatter = new STFormatter();
            ST          st          = (ST)stFormatter.Parse(s, result);

            sc.Language = st.Language;
            sc.Value    = st.Value;

            return(sc);
        }
コード例 #5
0
        public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            // Parse base (ANY) from the stream
            ANYFormatter baseFormatter = new ANYFormatter();

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

            // Now parse our data out... Attributes
            if (s.GetAttribute("value") != null)
            {
                retVal.Value = Convert.ToBoolean(s.GetAttribute("value"));
            }

            return(retVal);
        }
コード例 #6
0
        /// <summary>
        /// Parse this object
        /// </summary>
        public object Parse(XmlReader s, DatatypeFormatterParseResult result)
        {
            // Parse base (ANY) from the stream
            ANYFormatter baseFormatter = new ANYFormatter();

            // Parse CS
            II retVal = baseFormatter.Parse <II>(s, result);

            // Now parse our data out... Attributes
            if (s.GetAttribute("root") != null)
            {
                retVal.Root = s.GetAttribute("root");
            }
            if (s.GetAttribute("extension") != null)
            {
                retVal.Extension = s.GetAttribute("extension");
            }
            if (s.GetAttribute("displayable") != null)
            {
                retVal.Displayable = (bool)Util.FromWireFormat(s.GetAttribute("displayable"), typeof(bool));
            }
            if (s.GetAttribute("use") != null)
            {
                switch (s.GetAttribute("use"))
                {
                case "VER":
                    retVal.Scope = IdentifierScope.VersionIdentifier;
                    break;

                case "BUS":
                    retVal.Scope = IdentifierScope.BusinessIdentifier;
                    break;
                }
            }

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

            baseFormatter.Validate(retVal, pathName, result);


            return(retVal);
        }
コード例 #7
0
        /// <summary>
        /// Parse an ADXP from stream <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            // Parse base (ANY) from the stream
            ANYFormatter baseFormatter = new ANYFormatter();

            // Parse CS
            ADXP retVal = baseFormatter.Parse <ADXP>(s, result);

            // Now parse our data out...
            if (!s.IsEmptyElement)
            {
                if (s.GetAttribute("code") != null && result.CompatibilityMode == DatatypeFormatterCompatibilityMode.Canadian)
                {
                    retVal.Code = s.GetAttribute("code");
                }
                else
                {
                    result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "code", "ADXP", s.ToString()));
                }

                // Read next for text elemnt
                string sName = s.Name;
                s.Read();
                while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && sName == s.Name))
                {
                    if (s.NodeType == System.Xml.XmlNodeType.Text)
                    {
                        retVal.Value = s.Value;
                    }
                    s.Read();
                }
            }

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

            baseFormatter.Validate(retVal, pathName, result);


            return(retVal);
        }
コード例 #8
0
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        /// <param name="s">The XmlReader to parse from</param>
        public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            // Parse base (ANY) from the stream
            ANYFormatter baseFormatter = new ANYFormatter();

            // Parse TS
            TS retVal = baseFormatter.Parse <TS>(s, result);

            // Now parse our data out... Attributes
            if (s.GetAttribute("value") != null)
            {
                retVal.Value = s.GetAttribute("value");
            }

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

            baseFormatter.Validate(retVal, pathName, result);


            return(retVal);
        }
コード例 #9
0
        /// <summary>
        /// Parse an ENXP from stream <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            // Parse base (ANY) from the stream
            ANYFormatter baseFormatter = new ANYFormatter();

            // Parse CS
            ENXP retVal = baseFormatter.Parse <ENXP>(s, result);

            // Part Type is ignored by this formatter but qualifier is not
            if (s.GetAttribute("qualifier") != null)
            {
                retVal.Qualifier = Util.Convert <SET <CS <EntityNamePartQualifier> > >(s.GetAttribute("qualifier"));
            }

            // Now parse our data out...
            if (!s.IsEmptyElement)
            {
                // Read next for text elemnt
                string sName = s.Name;
                s.Read();
                while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && sName == s.Name))
                {
                    if (s.NodeType == System.Xml.XmlNodeType.Text)
                    {
                        retVal.Value = s.Value;
                    }
                    s.Read();
                }
            }

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

            baseFormatter.Validate(retVal, pathName, result);


            return(retVal);
        }
コード例 #10
0
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        /// <param name="s">The stream to parse</param>
        /// <returns>The parsed object</returns>
        public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            // Parse the address parts
            // Parse base (ANY) from the stream
            ANYFormatter baseFormatter = new ANYFormatter();

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

            // 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();
                // string Name
                while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName))
                {
                    string oldName = s.Name; // Name
                    try
                    {
                        AddressPartType?adxpType;  // Address part type

                        // JF - This is a Canadian extension
                        if (s.LocalName == "useablePeriod") // Usable Period, since this is an SXCM we'll need to read manually
                        {
                            // Useable period doesn't exist
                            GTSFormatter sxcmFormatter = new GTSFormatter();
                            sxcmFormatter.Host   = this.Host;
                            retVal.UseablePeriod = sxcmFormatter.Parse(s, result) as GTS;
                        }

                        if (reverseMapping.TryGetValue(s.LocalName, out adxpType)) // 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
                            part.Type = adxpType;
                            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);
        }
コード例 #11
0
        /// <summary>
        /// Parse the object
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            // Parse base (ANY) from the stream
            ANYFormatter baseFormatter = new ANYFormatter();
            string       pathName      = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name;


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

            // Now parse our data out... Attributes
            if (s.GetAttribute("mediaType") != null && s.GetAttribute("mediaType") != "text/plain")
            {
                result.AddResultDetail(new FixedValueMisMatchedResultDetail(s.GetAttribute("mediaType"), "text/plain", String.Format("{0}/@mediaType", pathName)));
            }
            if (s.GetAttribute("language") != null)
            {
                retVal.Language = s.GetAttribute("language");
            }

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

                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.NodeType == System.Xml.XmlNodeType.Text ||
                            s.NodeType == System.Xml.XmlNodeType.CDATA)
                        {
                            innerData += s.Value;
                        }
                    }
                    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();
                        }
                    }
                }
            }
            else
            {
                innerData = s.Value;
            }
            #endregion

            retVal.Value = innerData;

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

            return(retVal);
        }
コード例 #12
0
ファイル: CDFormatter.cs プロジェクト: zzllkk2003/everest
        internal static T Parse <T>(System.Xml.XmlReader s, IXmlStructureFormatter host, DatatypeFormatterParseResult result) where T : ANY, ICodedValue, new()
        {
            // Parse base (ANY) from the stream
            ANYFormatter anyFormatter = new ANYFormatter();
            string       pathName     = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name;

            // Parse CV
            anyFormatter.Host = host;
            T retVal = anyFormatter.Parse <T>(s, result);

            // Now parse our data out... Attributes
            // Was there a null flavor processed?
            if (s.GetAttribute("code") != null)
            {
                retVal.CodeValue = s.GetAttribute("code");
            }
            if (s.GetAttribute("codeSystem") != null)
            {
                retVal.CodeSystem = s.GetAttribute("codeSystem");
            }
            if (s.GetAttribute("codeSystemName") != null)
            {
                retVal.CodeSystemName = s.GetAttribute("codeSystemName");
            }
            if (s.GetAttribute("codeSystemVersion") != null)
            {
                retVal.CodeSystemVersion = s.GetAttribute("codeSystemVersion");
            }
            if (s.GetAttribute("displayName") != null)
            {
                retVal.DisplayName = Util.Convert <ST>(s.GetAttribute("displayName"));
            }

            // 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 == "originalText") // Format using ED
                        {
                            EDFormatter edFormatter = new EDFormatter();
                            edFormatter.Host    = host;
                            retVal.OriginalText = (ED)edFormatter.Parse(s, result);           // Parse ED
                        }
                        else if (s.LocalName == "translation" && retVal is ICodedEquivalents) // Translation
                        {
                            LISTFormatter setFormatter = new LISTFormatter();
                            setFormatter.GenericArguments = new Type[] { typeof(CD <String>) };
                            setFormatter.Host             = host;
                            if (retVal is ICodedEquivalents)
                            {
                                ((ICodedEquivalents)retVal).Translation = (LIST <IGraphable>)setFormatter.Parse(s, result); // Parse LIST
                            }
                            else
                            {
                                result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, s.LocalName, s.NamespaceURI, s.ToString(), null));
                            }
                        }
                        else if (s.LocalName == "qualifier" && retVal is IConceptDescriptor) // Qualifier
                        {
                            SETFormatter setFormatter = new SETFormatter();
                            setFormatter.GenericArguments = new Type[] { typeof(CR <String>) };
                            setFormatter.Host             = host;
                            if (retVal is IConceptDescriptor)
                            {
                                ((IConceptDescriptor)retVal).Qualifier = (LIST <IGraphable>)setFormatter.Parse(s, result); // Parse SET
                            }
                            else
                            {
                                result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, s.LocalName, s.NamespaceURI, s.ToString(), null));
                            }
                        }
                    }
                    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


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


            // Add validation to details
            return(retVal);
        }
コード例 #13
0
        /// <summary>
        /// Parse the object from stream <paramref name="s"/>
        /// </summary>
        /// <param name="s">The XmlReader to parse from</param>
        public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            // Parse base (ANY) from the stream
            ANYFormatter baseFormatter = new ANYFormatter();

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

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

            // 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 == "useablePeriod") // Usable Period, since this is an SXCM
                        {
                            // Useable period doesn't exist
                            //if (retVal.UseablePeriod == null) retVal.UseablePeriod = new SET<SXCM<TS>>();
                            //retVal.UseablePeriod.Add(this.Host.ParseObject(s, typeof(SXCM<TS>)) as SXCM<TS>);
                            GTSFormatter formatter = new GTSFormatter();
                            formatter.Host       = this.Host;
                            retVal.UseablePeriod = formatter.Parse(s, result) as GTS;
                        }
                    }
                    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

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


            return(retVal);
        }
コード例 #14
0
        public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult 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, result);

            // Now parse our data out... Attributes
            if (s.GetAttribute("representation") != null)
            {
                retVal.Representation = (EncapsulatedDataRepresentation)Util.FromWireFormat(s.GetAttribute("representation"), typeof(EncapsulatedDataRepresentation));
            }
            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)
            {
                switch (s.GetAttribute("integrityCheckAlgorithm"))
                {
                case "SHA-1":
                    retVal.IntegrityCheckAlgorithm = EncapsulatedDataIntegrityAlgorithm.SHA1;
                    break;

                case "SHA-256":
                    retVal.IntegrityCheckAlgorithm = EncapsulatedDataIntegrityAlgorithm.SHA256;
                    break;
                }
            }
            if (s.GetAttribute("integrityCheck") != null)
            {
                retVal.IntegrityCheck = Convert.FromBase64String(s.GetAttribute("integrityCheck"));
            }

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

                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
                        {
                            EDFormatter edFormatter = new EDFormatter();
                            edFormatter.Host = this.Host;
                            retVal.Thumbnail = (ED)edFormatter.Parse(s, result); // Parse ED
                        }
                        else if (s.LocalName == "reference")                     // Format using TEL
                        {
                            TELFormatter telFormatter = new TELFormatter();
                            telFormatter.Host = this.Host;
                            retVal.Reference  = (TEL)telFormatter.Parse(s, result);
                        }
                        else if (s.NodeType == System.Xml.XmlNodeType.Text ||
                                 s.NodeType == System.Xml.XmlNodeType.CDATA)
                        {
                            innerData += s.Value;
                        }
                        else if (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName) &&
                                 (s.NodeType == System.Xml.XmlNodeType.Element || s.NodeType == System.Xml.XmlNodeType.EndElement))
                        {
                            retVal.Representation = EncapsulatedDataRepresentation.XML;
                            innerData            += s.ReadOuterXml();
                        }
                    }
                    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

            Encoding textEncoding = System.Text.Encoding.UTF8;
            // Parse the innerData string into something meaningful
            if (innerData.Length > 0)
            {
                if (retVal.Representation == EncapsulatedDataRepresentation.B64)
                {
                    retVal.Data = Convert.FromBase64String(innerData);
                }
                else
                {
                    retVal.Data = textEncoding.GetBytes(innerData);
                }
            }

            // 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);
        }
コード例 #15
0
        public T Parse <T>(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
            where T : EN, new()
        {
            // Parse the address parts
            // Parse base (ANY) from the stream
            ANYFormatter baseFormatter = new ANYFormatter();

            // Parse EN
            T retVal = baseFormatter.Parse <T>(s, result);

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

            // Loop through content
            // 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
                    {
                        EntityNamePartType?enxpType;                               // entity part type

                        if (reverseMapping.TryGetValue(s.LocalName, out enxpType)) // Reverse map exists, so this is a part
                        {
                            ENXPFormatter adxpFormatter = new ENXPFormatter();     // ENXP Formatter
                            adxpFormatter.Host = this.Host;
                            ENXP part = (ENXP)adxpFormatter.Parse(s, result);      // Parse
                            part.Type = enxpType;
                            retVal.Part.Add(part);                                 // Add to EN
                        }
                        else if (s.NodeType == System.Xml.XmlNodeType.Text ||
                                 s.NodeType == System.Xml.XmlNodeType.CDATA)
                        {
                            retVal.Part.Add(new ENXP(s.Value));
                        }
                        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(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);
        }