public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            ANY instance = new ANY();

            // Read the NullFlavor, and Specialization data from the wire
            if (s.GetAttribute("nullFlavor") != null) // Stop processing if null flavor is present
            {
                instance.NullFlavor = (NullFlavor)Util.FromWireFormat(s.GetAttribute("nullFlavor"), typeof(NullFlavor));
            }
            else if (s.GetAttribute("specializationType") != null && result.CompatibilityMode == DatatypeFormatterCompatibilityMode.Canadian)
            {
                instance.Flavor = s.GetAttribute("specializationType");
            }

            if (result.ValidateConformance && !instance.Validate())
            {
                result.AddResultDetail(new DatatypeValidationResultDetail(ResultDetailType.Error, instance.GetType().Name, s.ToString()));
            }

            // Disabled for test
            // Validate flavor...
            IResultDetail[] flavor;
            if (instance.Flavor != null && result.ValidateConformance && Util.ValidateFlavor(instance.Flavor.ToUpper(), instance, out flavor) == false)
            {
                result.AddResultDetail(new DatatypeFlavorValidationResultDetail(ResultDetailType.Warning, instance.GetType().Name, instance.Flavor, s.ToString()));
                result.AddResultDetail(flavor);
            }

            return(instance);
        }
Esempio n. 2
0
        internal void Validate(ANY instance, string path, DatatypeFormatterParseResult resultDetails)
        {
            // Don't validate null
            if (instance == null)
            {
                return;
            }

            IResultDetail[] flavor;

            // Validate
            if (resultDetails.ValidateConformance && !instance.Validate())
            {
                foreach (var dtl in instance.ValidateEx())
                {
                    dtl.Location = path;
                    resultDetails.AddResultDetail(dtl);
                }
            }

            // Validate flavor...
            if (instance.Flavor != null && resultDetails.ValidateConformance && Util.ValidateFlavor(instance.Flavor.ToUpper(), instance, out flavor) == false)
            {
                resultDetails.AddResultDetail(new DatatypeFlavorValidationResultDetail(ResultDetailType.Warning, instance.GetType().Name, instance.Flavor, path));
            }

            // Append details
        }
Esempio n. 3
0
        public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            ANYFormatter pdvFormatter = new ANYFormatter();

            // parse PDV portion
            Type            uvpType = typeof(UVP <>).MakeGenericType(GenericArguments);
            ConstructorInfo ci      = uvpType.GetConstructor(Type.EmptyTypes);
            ANY             retVal  = ci.Invoke(null) as ANY;

            // Property information
            PropertyInfo probabilityProperty = uvpType.GetProperty("Probability"),
                         valueProperty       = uvpType.GetProperty("Value");

            // Clean the
            if (s.GetAttribute("type", DatatypeFormatter.NS_XSI) != null && s is XmlStateReader)
            {
                (s as XmlStateReader).AddFakeAttribute("type", Util.CreateXSITypeName(GenericArguments[0]));
            }

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

            // Set value
            var hostResult = Host.Parse(s, GenericArguments[0]);

            result.Code = hostResult.Code;
            result.AddResultDetail(hostResult.Details);
            valueProperty.SetValue(retVal, hostResult.Structure, null);

            // Move null flavors and flavors up
            ANY resultAny = hostResult.Structure as ANY;

            retVal.NullFlavor    = resultAny.NullFlavor;
            resultAny.NullFlavor = null;
            retVal.Flavor        = resultAny.Flavor;
            resultAny.Flavor     = null;

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

            validator.Validate(retVal, pathName, result);
            return(retVal);
        }
Esempio n. 4
0
        /// <summary>
        /// Parse from the stream
        /// </summary>
        public override object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            result.AddResultDetail(new NotImplementedResultDetail(ResultDetailType.Warning, "QSET and derivatives cannot be parsed by the R1 formatter directly, processing as SXPR", s.ToString(), null));
            object retval = base.Parse(s, result);

            return(retval);
        }
        /// <summary>
        /// Parse the object from the specified stream
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            ENFormatter formatter = new ENFormatter()
            {
                Host = this.Host
            };
            var instance = formatter.Parse(s, result) as EN;

            ON retVal = new ON(EntityNameUse.Alphabetic, instance.Part)
            {
                Use = instance.Use
            };

            // Remove non-allowed parts
            for (int i = retVal.Part.Count - 1; i >= 0; i--)
            {
                if (retVal.Part[i].Type == EntityNamePartType.Family ||
                    retVal.Part[i].Type == EntityNamePartType.Given)
                {
                    result.AddResultDetail(new VocabularyIssueResultDetail(ResultDetailType.Warning,
                                                                           String.Format("Part name '{0}' in ON instance will be removed. ON Parts cannot have FAM or GIV parts", retVal.Part[i]),
                                                                           s.ToString(),
                                                                           null));
                    retVal.Part.RemoveAt(i);
                }
            }

            retVal.NullFlavor = instance.NullFlavor;
            retVal.Flavor     = instance.Flavor;


            return(retVal);
        }
Esempio n. 6
0
        /// <summary>
        /// Parse from the stream
        /// </summary>
        public override object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            result.AddResultDetail(new NotImplementedResultDetail(ResultDetailType.Warning, "QSET and derivatives cannot be parsed by the R1 formatter directly, processing as SXPR", s.ToString(), null));
            object retval = base.Parse(s, result);
            return retval;

        }
        /// <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);
        }
        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);
        }
        /// <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);
        }
Esempio n. 10
0
        internal void Validate(ANY instance, string path, DatatypeFormatterParseResult resultDetails)
        {
            IResultDetail[] flavor;

            // Validate
            if (resultDetails.ValidateConformance && !instance.Validate())
            {
                resultDetails.AddResultDetail(new DatatypeValidationResultDetail(ResultDetailType.Error, instance.GetType().Name, path));
            }

            // Validate flavor...
            if (instance.Flavor != null && resultDetails.ValidateConformance && Util.ValidateFlavor(instance.Flavor.ToUpper(), instance, out flavor) == false)
            {
                resultDetails.AddResultDetail(new DatatypeFlavorValidationResultDetail(ResultDetailType.Warning, instance.GetType().Name, instance.Flavor, path));
            }

            // Append details
        }
Esempio n. 11
0
        /// <summary>
        /// Parse the object
        /// </summary>
        public override object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            // Parse base (ANY) from the stream

            // Parse ED
            ST retVal = base.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", s.ToString())));
            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
            base.Validate(retVal, s.ToString(), result);

            return retVal;
        }
Esempio n. 12
0
        /// <summary>
        /// Parse from the stream
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            result.AddResultDetail(new NotImplementedResultDetail(ResultDetailType.Warning, "QSS cannot be parsed by the R1 formatter directly, processing as SXPR", s.ToString(), null));
            SXPRFormatter formatter = new SXPRFormatter();

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

            return(retval);
        }
        public SXCM <T> Parse <T>(System.Xml.XmlReader s, DatatypeFormatterParseResult result) where T :  IAny, new()
        {
            // Return value
            //SXCM<T> retVal = (T)Host.ParseObject(s, typeof(T));

            //// Operator
            //if (s.GetAttribute("operator") != null)
            //    retVal.Operator = (SetOperator?)Util.FromWireFormat(s.GetAttribute("operator"), typeof(SetOperator));

            //return retVal;
            result.AddResultDetail(new NotImplementedResultDetail(ResultDetailType.Error, "SXCM is an abstract class and cannot be instantiated by itself", s.ToString(), null));
            return(null);
        }
Esempio n. 14
0
        public virtual object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            ANY instance = this.Parse <ANY>(s, result);

            if (result.ValidateConformance && !instance.Validate())
            {
                foreach (var r in instance.ValidateEx())
                {
                    r.Location = s.ToString();
                    result.AddResultDetail(r);
                }
            }
            //result.AddResultDetail(new DatatypeValidationResultDetail(ResultDetailType.Error, instance.GetType().Name, s.ToString()));
            // Disabled for test
            // Validate flavor...
            IResultDetail[] flavor;
            if (instance.Flavor != null && result.ValidateConformance && Util.ValidateFlavor(instance.Flavor.ToUpper(), instance, out flavor) == false)
            {
                result.AddResultDetail(new DatatypeFlavorValidationResultDetail(ResultDetailType.Warning, instance.GetType().Name, instance.Flavor, s.ToString()));
                result.AddResultDetail(flavor);
            }

            return(instance);
        }
Esempio n. 15
0
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        public override object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {

            result.AddResultDetail(new MARC.Everest.Connectors.NotImplementedResultDetail(Connectors.ResultDetailType.Warning, "The NPPD type is not an official R1 data type, the data has been parsed", s.ToString()));
            
            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);
            base.Validate((ANY)retval, s.ToString(), result);
            return retval;
        }
Esempio n. 16
0
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        public override object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            result.AddResultDetail(new MARC.Everest.Connectors.NotImplementedResultDetail(Connectors.ResultDetailType.Warning, "The NPPD type is not an official R1 data type, the data has been parsed", s.ToString()));

            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);

            base.Validate((ANY)retval, s.ToString(), result);
            return(retval);
        }
Esempio n. 17
0
        /// <summary>
        /// Parse the object from the specified stream
        /// </summary>
        public override object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {

            ON retVal = Util.Convert<ON>(base.Parse(s, result) as EN);
            
            // Remove non-allowed parts
                for (int i = retVal.Part.Count - 1; i >= 0; i--)
                    if (retVal.Part[i].Type == EntityNamePartType.Family ||
                        retVal.Part[i].Type == EntityNamePartType.Given)
                    {
                        result.AddResultDetail(new VocabularyIssueResultDetail(ResultDetailType.Warning,
                            String.Format("Part name '{0}' in ON instance will be removed. ON Parts cannot have FAM or GIV parts", retVal.Part[i]),
                            s.ToString(),
                            null));
                        retVal.Part.RemoveAt(i);
                    }

            return retVal;
        }
Esempio n. 18
0
        /// <summary>
        /// Parse the object from the specified stream
        /// </summary>
        public override object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            ON retVal = Util.Convert <ON>(base.Parse(s, result) as EN);

            // Remove non-allowed parts
            for (int i = retVal.Part.Count - 1; i >= 0; i--)
            {
                if (retVal.Part[i].Type == EntityNamePartType.Family ||
                    retVal.Part[i].Type == EntityNamePartType.Given)
                {
                    result.AddResultDetail(new VocabularyIssueResultDetail(ResultDetailType.Warning,
                                                                           String.Format("Part name '{0}' in ON instance will be removed. ON Parts cannot have FAM or GIV parts", retVal.Part[i]),
                                                                           s.ToString(),
                                                                           null));
                    retVal.Part.RemoveAt(i);
                }
            }

            return(retVal);
        }
        /// <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);
        }
Esempio n. 20
0
        protected T Parse <T>(XmlReader xr, DatatypeFormatterParseResult result) where T : ANY, new()
        {
            T retVal = base.Parse <T>(xr, result);


            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);
        }
Esempio n. 21
0
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        /// <param name="s">The stream to read from</param>
        public virtual object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            // Get the current element name
            string currentElementName = s.LocalName;

            LIST <IGraphable> retVal = new LIST <IGraphable>();

            // Read until the current name is exhausted
            while (s.LocalName == currentElementName && !s.EOF)
            {
                if (s.NodeType == System.Xml.XmlNodeType.Element)
                {
                    // Correct the XSI attribute
                    //if (Util.CreateXSITypeName(GenericArguments[0]) != s.GetAttribute("type", DatatypeFormatter.NS_XSI) &&
                    //    s is XmlStateReader && !String.IsNullOrEmpty(s.GetAttribute("type", DatatypeFormatter.NS_XSI)))
                    //    (s as XmlStateReader).AddFakeAttribute("type", Util.CreateXSITypeName(GenericArguments[0]));

                    var hostResult = Host.Parse(s, GenericArguments[0]);
                    result.Code = hostResult.Code;
                    result.AddResultDetail(hostResult.Details);
                    retVal.Add(hostResult.Structure);
                }

                // Read until the next element
                s.Read();
                while (s.NodeType != System.Xml.XmlNodeType.Element && !s.EOF)
                {
                    if (s.NodeType == System.Xml.XmlNodeType.EndElement &&
                        s.LocalName != currentElementName)
                    {
                        return(retVal);
                    }
                    s.Read();
                }
            }

            // Return the array
            return(retVal);
        }
Esempio n. 22
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 override object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            TN tn = base.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;
        }
Esempio n. 23
0
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        /// <param name="s">The stream to read from</param>
        public virtual object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            // Get the current element name
            string currentElementName = s.LocalName;

            LIST<IGraphable> retVal = new LIST<IGraphable>();

            // Read until the current name is exhausted
            while (s.LocalName == currentElementName && !s.EOF)
            {
                if (s.NodeType == System.Xml.XmlNodeType.Element)
                {
                    // Correct the XSI attribute
                    //if (Util.CreateXSITypeName(GenericArguments[0]) != s.GetAttribute("type", DatatypeFormatter.NS_XSI) &&
                    //    s is XmlStateReader && !String.IsNullOrEmpty(s.GetAttribute("type", DatatypeFormatter.NS_XSI)))
                    //    (s as XmlStateReader).AddFakeAttribute("type", Util.CreateXSITypeName(GenericArguments[0]));
                    
                    var hostResult = Host.Parse(s, GenericArguments[0]);
                    result.Code = hostResult.Code;
                    result.AddResultDetail(hostResult.Details);
                    retVal.Add(hostResult.Structure);
                }

                // Read until the next element
                s.Read();
                while (s.NodeType != System.Xml.XmlNodeType.Element && !s.EOF)
                {
                    if (s.NodeType == System.Xml.XmlNodeType.EndElement &&
                        s.LocalName != currentElementName)
                        return retVal;
                    s.Read();
                }
            }

            // Return the array
            return retVal;
        }
Esempio n. 24
0
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        /// <param name="s">The stream to parse</param>
        public override object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            PQ retVal = base.Parse <PQ>(s, result);

            retVal.Unit = s.GetAttribute("unit");

            // Precision is not supported in R1, but is still useful to have so
            // we will report the precision of the data that was on the wire
            string valStr = s.GetAttribute("value");

            if (valStr != null && valStr.Contains(DatatypeFormatter.FormatterCulture.NumberFormat.NumberDecimalSeparator))
            {
                retVal.Precision = valStr.Length - valStr.IndexOf(DatatypeFormatter.FormatterCulture.NumberFormat.NumberDecimalSeparator) - 1;
            }
            else
            {
                retVal.Precision = 0;
            }

            #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 == "translation") // Format using ED
                        {
                            SETFormatter pqrFormatter = new SETFormatter();
                            pqrFormatter.GenericArguments = new Type[] { typeof(PQR) };
                            pqrFormatter.Host             = Host.Clone() as IXmlStructureFormatter;
                            retVal.Translation            = new SET <PQR>((LIST <IGraphable>)pqrFormatter.Parse(s, result)); // Parse ED
                            //details.AddRange(pqrFormatter.Details);
                        }
                        else
                        {
                            result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, s.LocalName, s.NamespaceURI, 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
            base.Validate(retVal, s.ToString(), result);

            return(retVal);
        }
Esempio n. 25
0
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        /// <param name="s">The stream to parse</param>
        public override object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            PQ retVal = base.Parse<PQ>(s, result);
            retVal.Unit = s.GetAttribute("unit");

            // Precision is not supported in R1, but is still useful to have so 
            // we will report the precision of the data that was on the wire
            string valStr = s.GetAttribute("value");
            if (valStr != null && valStr.Contains(DatatypeFormatter.FormatterCulture.NumberFormat.NumberDecimalSeparator))
                retVal.Precision = valStr.Length - valStr.IndexOf(DatatypeFormatter.FormatterCulture.NumberFormat.NumberDecimalSeparator) - 1;
            else
                retVal.Precision = 0;

            #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 == "translation") // Format using ED
                        {
                            SETFormatter pqrFormatter = new SETFormatter();
                            pqrFormatter.GenericArguments = new Type[] { typeof(PQR) };
                            pqrFormatter.Host = Host.Clone() as IXmlStructureFormatter;
                            retVal.Translation = new SET<PQR>((LIST<IGraphable>)pqrFormatter.Parse(s, result)); // Parse ED
                            //details.AddRange(pqrFormatter.Details);
                        }
                        else
                            result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, s.LocalName, s.NamespaceURI, 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
            base.Validate(retVal, s.ToString(), result);

            return retVal;
        }
Esempio n. 26
0
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        public override object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            // Create the types
            Type eivlType        = typeof(EIVL <>);
            Type eivlGenericType = eivlType.MakeGenericType(GenericArguments);

            // For the phase
            Type ivlType = typeof(IVL <PQ>);

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

            if (s.GetAttribute("nullFlavor") != null)
            {
                ((ANY)instance).NullFlavor = (NullFlavor)Util.FromWireFormat(s.GetAttribute("nullFlavor"), typeof(NullFlavor));
            }
            // Try get operator and value
            if (s.GetAttribute("operator") != null)
            {
                eivlGenericType.GetProperty("Operator").SetValue(instance, Util.FromWireFormat(s.GetAttribute("operator"), typeof(SetOperator?)), null);
            }
            if (s.GetAttribute("value") != null)
            {
                result.AddResultDetail(new NotSupportedChoiceResultDetail(
                                           ResultDetailType.Warning, "The 'value' attribute of a SXCM does not interpretable in this context, and has been ignored", s.ToString(), null));
            }

            // JF - Spec type is a CA extension
            if (s.GetAttribute("specializationType") != null && result.CompatibilityMode == DatatypeFormatterCompatibilityMode.Canadian)
            {
                ((ANY)instance).Flavor = s.GetAttribute("specializationType");
            }

            // Get property information
            PropertyInfo eventProperty  = eivlGenericType.GetProperty("Event"),
                         offsetProperty = eivlGenericType.GetProperty("Offset");

            // 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 == "offset")     // low value
                        {
                            var hostResult = Host.Parse(s, typeof(IVL <PQ>));
                            result.AddResultDetail(hostResult.Details);
                            offsetProperty.SetValue(instance, hostResult.Structure, null);
                        }
                        else if (s.LocalName == "event")     // high value
                        {
                            var hostResult = Host.Parse(s, typeof(CS <DomainTimingEventType>));
                            result.AddResultDetail(hostResult.Details);
                            eventProperty.SetValue(instance, Util.Convert <CS <DomainTimingEventType> >(hostResult.Structure), null);
                        }
                    }
                    catch (MessageValidationException e)     // Message validation error
                    {
                        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 validation = new ANYFormatter();
            string       pathName   = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name;
            validation.Validate(instance as ANY, pathName, result);

            return(instance);
        }
Esempio n. 27
0
        public override object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            // Create the types
            Type pivlType = typeof(PIVL<>);
            Type pivlGenericType = pivlType.MakeGenericType(GenericArguments);

            // For the phase
            Type ivlType = typeof(IVL<>);
            Type phaseIvlType = ivlType.MakeGenericType(GenericArguments);

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

            if (s.GetAttribute("specializationType") != null && result.CompatibilityMode == DatatypeFormatterCompatibilityMode.Canadian)
                ((ANY)instance).Flavor = s.GetAttribute("specializationType");

            if (s.GetAttribute("nullFlavor") != null)
                ((ANY)instance).NullFlavor = (NullFlavor)Util.FromWireFormat(s.GetAttribute("nullFlavor"), typeof(NullFlavor));

            // Try get operator and value
            if (s.GetAttribute("operator") != null)
                pivlGenericType.GetProperty("Operator").SetValue(instance, Util.FromWireFormat(s.GetAttribute("operator"), typeof(SetOperator?)), null);
            if (s.GetAttribute("value") != null)
                result.AddResultDetail(new NotSupportedChoiceResultDetail(
                    ResultDetailType.Warning, "The 'value' attribute of a SXCM does not interpretable in this context, and has been ignored", s.ToString(), null));

            //    pivlGenericType.GetProperty("Value").SetValue(instance, Util.FromWireFormat(s.GetAttribute("value"), GenericArguments[0]), null);
            if (s.GetAttribute("institutionSpecified") != null)
                pivlGenericType.GetProperty("InstitutionSpecified").SetValue(instance, Util.FromWireFormat(s.GetAttribute("institutionSpecified"), typeof(bool?)), null);
            if (s.GetAttribute("alignment") != null)
                pivlGenericType.GetProperty("Alignment").SetValue(instance, Util.FromWireFormat(s.GetAttribute("alignment"), typeof(CalendarCycle?)), null);

            // Get property information
            PropertyInfo phaseProperty = pivlGenericType.GetProperty("Phase"),
               periodProperty = pivlGenericType.GetProperty("Period"),
               frequencyProperty = pivlGenericType.GetProperty("Frequency");

            // 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 == "phase") // low value
                        {
                            var hostResult = Host.Parse(s, phaseIvlType);
                            result.AddResultDetail(hostResult.Details);
                            phaseProperty.SetValue(instance, hostResult.Structure, null);
                        }
                        else if (s.LocalName == "period") // high value
                        {
                            var hostResult = Host.Parse(s, typeof(PQ));
                            result.AddResultDetail(hostResult.Details);
                            periodProperty.SetValue(instance, hostResult.Structure, null);
                        }
                        else if (s.LocalName == "frequency" && result.CompatibilityMode == DatatypeFormatterCompatibilityMode.Canadian) // frequency
                        {
                            var hostResult = Host.Parse(s, typeof(RTO<INT, PQ>));
                            result.AddResultDetail(hostResult.Details);
                            frequencyProperty.SetValue(instance, hostResult.Structure, null);
                        }
                        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, s.ToString(), e));
                    }
                    finally
                    {
                        if (s.Name == oldName) s.Read();
                    }
                }
            }
            #endregion


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

            return instance;
        }
Esempio n. 28
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;
        }
Esempio n. 29
0
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            // Create the types
            Type eivlType = typeof(EIVL<>);
            Type eivlGenericType = eivlType.MakeGenericType(GenericArguments);

            // For the phase
            Type ivlType = typeof(IVL<PQ>);

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

            if (s.GetAttribute("nullFlavor") != null)
                ((ANY)instance).NullFlavor = (NullFlavor)Util.FromWireFormat(s.GetAttribute("nullFlavor"), typeof(NullFlavor));
            else
            {
                // Try get operator and value
                if (s.GetAttribute("operator") != null)
                    eivlGenericType.GetProperty("Operator").SetValue(instance, Util.FromWireFormat(s.GetAttribute("operator"), typeof(SetOperator?)), null);
                if (s.GetAttribute("value") != null)
                    result.AddResultDetail(new NotSupportedChoiceResultDetail(
                        ResultDetailType.Warning, "The 'value' attribute of a SXCM does not interpretable in this context, and has been ignored", s.ToString(), null));

                // JF - Spec type is a CA extension
                if (s.GetAttribute("specializationType") != null && result.CompatibilityMode == DatatypeFormatterCompatibilityMode.Canadian)
                    ((ANY)instance).Flavor = s.GetAttribute("specializationType");

                // Get property information
                PropertyInfo eventProperty = eivlGenericType.GetProperty("Event"),
                   offsetProperty = eivlGenericType.GetProperty("Offset");

                // 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 == "offset") // low value
                                offsetProperty.SetValue(instance, Host.ParseObject(s, typeof(IVL<PQ>)), null);
                            else if (s.LocalName == "event") // high value
                                eventProperty.SetValue(instance, Util.FromWireFormat(Host.ParseObject(s, typeof(CS<DomainTimingEventType>)), typeof(CS<DomainTimingEventType>)), null);
                        }
                        catch (MessageValidationException e) // Message validation error
                        {
                            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 validation = new ANYFormatter();
            string pathName = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name;
            validation.Validate(instance as ANY, pathName, result);

            return instance;
        }
Esempio n. 30
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;
        }
Esempio n. 31
0
        /// <summary>
        /// Parse the object from the specified stream
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            ENFormatter formatter = new ENFormatter()  { Host = this.Host };
            var instance = formatter.Parse(s, result) as EN;

            ON retVal = new ON(EntityNameUse.Alphabetic, instance.Part) { Use = instance.Use };

            // Remove non-allowed parts
                for (int i = retVal.Part.Count - 1; i >= 0; i--)
                    if (retVal.Part[i].Type == EntityNamePartType.Family ||
                        retVal.Part[i].Type == EntityNamePartType.Given)
                    {
                        result.AddResultDetail(new VocabularyIssueResultDetail(ResultDetailType.Warning,
                            String.Format("Part name '{0}' in ON instance will be removed. ON Parts cannot have FAM or GIV parts", retVal.Part[i]),
                            s.ToString(),
                            null));
                        retVal.Part.RemoveAt(i);
                    }

            retVal.NullFlavor = instance.NullFlavor;
            retVal.Flavor = instance.Flavor;

            return retVal;
        }
Esempio n. 32
0
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        public override object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            // Create the types
            Type sxprType        = typeof(SXPR <>);
            Type sxprGenericType = sxprType.MakeGenericType(GenericArguments);

            // Details

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

            if (s.GetAttribute("nullFlavor") != null)
            {
                ((ANY)instance).NullFlavor = (NullFlavor)Util.FromWireFormat(s.GetAttribute("nullFlavor"), typeof(NullFlavor));
            }
            // Try get operator
            if (s.GetAttribute("operator") != null)
            {
                sxprGenericType.GetProperty("Operator").SetValue(instance, Util.FromWireFormat(s.GetAttribute("operator"), typeof(SetOperator?)), null);
            }
            if (s.GetAttribute("specializationType") != null)
            {
                if (result.CompatibilityMode == DatatypeFormatterCompatibilityMode.Canadian)
                {
                    sxprGenericType.GetProperty("Flavor").SetValue(instance, s.GetAttribute("specializationType"), null);
                }
                else
                {
                    result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Flavor", "SXPR", s.ToString()));
                }
            }
            #region Element Processing

            // List of components
            LIST <IGraphable> componentList = new LIST <IGraphable>();

            // Parse 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 == "comp")     // component
                        {
                            // Now determine the type of GTS
                            //string typeName = s.GetAttribute("type", DatatypeFormatter.NS_XSI);
                            //IDatatypeFormatter formatter = DatatypeFormatter.GetFormatter(typeName);

                            //if (formatter == null)
                            //{
                            //    result.AddResultDetail(new ResultDetail(String.Format("Cannot parse a SXPR member of type '{0}'", typeName)));
                            //    return null;
                            //}
                            //else
                            //{
                            //    // Graph the Hull
                            //    formatter.Host = this.Host;
                            //    formatter.GenericArguments = GenericArguments;
                            //    componentList.Add(formatter.Parse(s, result) as IGraphable);
                            //}
                            var hostResult = this.Host.Parse(s, GenericArguments[0]);
                            result.Code = hostResult.Code;
                            result.AddResultDetail(hostResult.Details);
                            componentList.Add(hostResult.Structure as IGraphable);
                        }
                    }
                    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();
                        }
                    }
                }
            }

            ((IListContainer)instance).ContainedList = componentList;
            #endregion

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

            return(instance);
        }
Esempio n. 33
0
        public override object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            
            // Create the types
            Type rtoType = typeof(RTO<,>);
            Type rtoGenericType = rtoType.MakeGenericType(GenericArguments);

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

            if (s.GetAttribute("nullFlavor") != null)
                ((ANY)instance).NullFlavor = (NullFlavor)Util.FromWireFormat(s.GetAttribute("nullFlavor"), typeof(NullFlavor));
             
            PropertyInfo numeratorProperty= rtoGenericType.GetProperty("Numerator"),
                    denominatorProperty = rtoGenericType.GetProperty("Denominator");

            if (s.GetAttribute("specializationType") != null)
                ((ANY)instance).Flavor = s.GetAttribute("specializationType");

            // Get the values
            // 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 == "numerator")
                        {
                            var parseResult = Host.Parse(s, GenericArguments[0]);
                            result.Code = parseResult.Code;
                            result.AddResultDetail(parseResult.Details);
                            numeratorProperty.SetValue(instance, parseResult.Structure, null);
                        }
                        else if (s.LocalName == "denominator")
                        {
                            var parseResult = Host.Parse(s, GenericArguments[1]);
                            result.Code = parseResult.Code;
                            result.AddResultDetail(parseResult.Details);
                            denominatorProperty.SetValue(instance, parseResult.Structure, 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
            base.Validate(instance as ANY, s.ToString(), result);

            return instance;
        }
Esempio n. 34
0
        /// <summary>
        /// Parse the object from stream <paramref name="s"/>
        /// </summary>
        /// <param name="s">The XmlReader to parse from</param>
        public override object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            // Parse TS
            TEL retVal = base.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;
            base.Validate(retVal, pathName, result);


            return retVal;
        }
Esempio n. 35
0
        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);
        }
Esempio n. 36
0
        public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            // Parse the base PDV first
            PDVFormatter pdvFormatter = new PDVFormatter();
            URG <Object> retVal       = pdvFormatter.Parse <URG <Object> >(s, result);

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

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

            // Serialization
            IXmlStructureFormatter serHost = this.Host;

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

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

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

            return(retVal);
        }
Esempio n. 37
0
        public override object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            // Create the types
            Type ivlType        = typeof(IVL <>);
            Type ivlGenericType = ivlType.MakeGenericType(GenericArguments);

            // Sometimes there can be just a messy, unstructured value inline with this IVL (like in CCDA) so we still need to support that
            MemoryStream leftOvers      = new MemoryStream();
            XmlWriter    leftoverWriter = XmlWriter.Create(leftOvers);

            leftoverWriter.WriteStartElement(s.LocalName, s.NamespaceURI);

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

            if (s.MoveToFirstAttribute())
            {
                do
                {
                    switch (s.LocalName)
                    {
                    case "nullFlavor":

                        ((ANY)instance).NullFlavor = (NullFlavor)Util.FromWireFormat(s.GetAttribute("nullFlavor"), typeof(NullFlavor));
                        break;

                    case "operator":
                        ivlGenericType.GetProperty("Operator").SetValue(instance, Util.FromWireFormat(s.GetAttribute("operator"), typeof(SetOperator?)), null);
                        break;

                    case "specializationType":
                        if (result.CompatibilityMode == DatatypeFormatterCompatibilityMode.Canadian)
                        {
                            ((ANY)instance).Flavor = s.GetAttribute("specializationType");
                        }
                        break;

                    default:
                        leftoverWriter.WriteAttributeString(s.Prefix, s.LocalName, s.NamespaceURI, s.Value);
                        break;
                    }
                } while (s.MoveToNextAttribute());
                s.MoveToElement();
            }

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

            // 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 && s.LocalName == "low") // low value
                        {
                            if (!String.IsNullOrEmpty(s.GetAttribute("inclusive")))
                            {
                                lowClosedProperty.SetValue(instance, Util.FromWireFormat(s.GetAttribute("inclusive"), typeof(bool?)), null);
                            }
                            var parseResult = Host.Parse(s, GenericArguments[0]);
                            result.Code = parseResult.Code;
                            result.AddResultDetail(parseResult.Details);
                            lowProperty.SetValue(instance, parseResult.Structure, null);
                        }
                        else if (s.NodeType == System.Xml.XmlNodeType.Element && s.LocalName == "high") // high value
                        {
                            if (!String.IsNullOrEmpty(s.GetAttribute("inclusive")))
                            {
                                highClosedProperty.SetValue(instance, Util.FromWireFormat(s.GetAttribute("inclusive"), typeof(bool?)), null);
                            }
                            var parseResult = Host.Parse(s, GenericArguments[0]);
                            result.Code = parseResult.Code;
                            result.AddResultDetail(parseResult.Details);
                            highProperty.SetValue(instance, parseResult.Structure, null);
                        }
                        else if (s.NodeType == System.Xml.XmlNodeType.Element && s.LocalName == "center") // center
                        {
                            var parseResult = Host.Parse(s, GenericArguments[0]);
                            result.Code = parseResult.Code;
                            result.AddResultDetail(parseResult.Details);
                            centerProperty.SetValue(instance, parseResult.Structure, null);
                        }
                        else if (s.NodeType == System.Xml.XmlNodeType.Element && s.LocalName == "width") // width
                        {
                            var parseResult = Host.Parse(s, typeof(PQ));
                            result.Code = parseResult.Code;
                            result.AddResultDetail(parseResult.Details);
                            widthProperty.SetValue(instance, parseResult.Structure, null);
                        }
                        else if (s.NodeType == System.Xml.XmlNodeType.Element)
                        {
                            leftoverWriter.WriteNode(s, true);
                            //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

            // Process any leftovers as Value !!!
            try
            {
                leftoverWriter.WriteEndElement();
                leftoverWriter.Flush();
                leftOvers.Seek(0, SeekOrigin.Begin);
                using (XmlReader xr = XmlReader.Create(leftOvers))
                {
                    xr.MoveToContent();
                    if (xr.AttributeCount > 1 || !xr.IsEmptyElement)
                    {
                        bool isNotEmpty = !xr.IsEmptyElement;
                        if (xr.MoveToFirstAttribute())
                        {
                            do
                            {
                                isNotEmpty |= xr.Prefix != "xmlns" && xr.LocalName != "xmlns" && xr.NamespaceURI != DatatypeFormatter.NS_XSI;
                            } while (!isNotEmpty && xr.MoveToNextAttribute());
                        }
                        xr.MoveToElement();
                        if (isNotEmpty)
                        {
                            var baseResult = base.Parse(xr, result);
                            valueProperty.SetValue(instance, Util.FromWireFormat(baseResult, valueProperty.PropertyType), null);
                        }
                    }
                }
            }
            catch { }
            // Validate
            base.Validate(instance as ANY, s.LocalName, result);

            return(instance);
        }
Esempio n. 38
0
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        /// <param name="s">The stream to parse</param>
        public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            PDVFormatter pdvFormatter = new PDVFormatter();
            PQ           retVal       = pdvFormatter.Parse <PQ>(s, result);

            if (s.GetAttribute("unit") != null)
            {
                retVal.Unit = s.GetAttribute("unit");
            }

            // Precision is not supported in R1, but is still useful to have so
            // we will report the precision of the data that was on the wire
            string valStr = s.GetAttribute("value");

            if (valStr != null && valStr.Contains("."))
            {
                retVal.Precision = valStr.Length - valStr.IndexOf(".") - 1;
            }
            else
            {
                retVal.Precision = 0;
            }

            #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 == "translation") // Format using ED
                        {
                            SETFormatter pqrFormatter = new SETFormatter();
                            pqrFormatter.GenericArguments = new Type[] { typeof(PQR) };
                            pqrFormatter.Host             = Host.Clone() as IXmlStructureFormatter;
                            retVal.Translation            = new SET <PQR>((LIST <IGraphable>)pqrFormatter.Parse(s, result)); // Parse ED
                            //details.AddRange(pqrFormatter.Details);
                        }
                    }
                    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
            ANYFormatter fmtr     = new ANYFormatter();
            string       pathName = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name;
            fmtr.Validate(retVal, pathName, result);

            return(retVal);
        }
Esempio n. 39
0
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        /// <param name="s">The stream to parse the object from</param>
        /// <returns>The constructed object</returns>
        public override object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {

            Type crGenericType = typeof(CR<>).MakeGenericType(GenericArguments);
            ConstructorInfo ci = crGenericType.GetConstructor(Type.EmptyTypes);

            if (ci == null)
                throw new InvalidOperationException("Type being parsed must have parameterless constructor");
            object instance = ci.Invoke(null);
            
            // NullFlavor ? 
            if (s.GetAttribute("nullFlavor") != null)
                ((ANY)instance).NullFlavor = (NullFlavor)Util.FromWireFormat(s.GetAttribute("nullFlavor"), typeof(NullFlavor));
                
                // JF - Supported only in CA extensions to R1 data types
                if (s.GetAttribute("specializationType") != null && result.CompatibilityMode == DatatypeFormatterCompatibilityMode.Canadian)
                    ((ANY)instance).Flavor = s.GetAttribute("specializationType");
                // Inverted
                if (s.GetAttribute("inverted") != null)
                    crGenericType.GetProperty("Inverted").SetValue(instance, Util.FromWireFormat(s.GetAttribute("inverted"), typeof(bool)), null);

                #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 == "name") // Format using ED
                            {
                                CVFormatter cvFormatter = new CVFormatter();
                                cvFormatter.Host = this.Host;
                                cvFormatter.GenericArguments = this.GenericArguments;
                                crGenericType.GetProperty("Name").SetValue(instance, Util.FromWireFormat(cvFormatter.Parse(s, result), crGenericType.GetProperty("Name").PropertyType), null);
                            }
                            else if (s.LocalName == "value")
                            {
                                CDFormatter cdFormatter = new CDFormatter();
                                cdFormatter.Host = this.Host;
                                cdFormatter.GenericArguments = this.GenericArguments;
                                crGenericType.GetProperty("Value").SetValue(instance, Util.FromWireFormat(cdFormatter.Parse(s, result), crGenericType.GetProperty("Value").PropertyType), null);
                            }
                            else
                                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, s.ToString(), e));
                        }
                        finally
                        {
                            if (s.Name == oldName) s.Read();
                        }
                    }
                }
                #endregion

            base.Validate((ANY)instance, s.ToString(), result);

            return instance;
        }
Esempio n. 40
0
        public override object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            // TODO: Determine how to parse a URG when the complex type is used. For example, URG<PQ> that is not a range, rather just a PQ
            //PDVFormatter pdvFormatter = new PDVFormatter();
            Type urgType        = typeof(URG <>);
            Type urgGenericType = urgType.MakeGenericType(GenericArguments);

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

            if (s.GetAttribute("nullFlavor") != null)
            {
                ((ANY)instance).NullFlavor = (NullFlavor)Util.FromWireFormat(s.GetAttribute("nullFlavor"), typeof(NullFlavor));
            }
            if (s.GetAttribute("probability") != null) // Probability
            {
                decimal prob = (decimal)0.0f;
                if (!Decimal.TryParse(s.GetAttribute("probability"), out prob)) // Try to parse
                {
                    result.AddResultDetail(new ResultDetail(ResultDetailType.Warning, string.Format("Value '{0}' can't be processed into 'Probability' on data type UVP", s.GetAttribute("probability")), s.ToString(), null));
                }
                else // Success, so assign
                {
                    ((IProbability)instance).Probability = prob;
                }
            }
            // This doesn't make sense as "value" is inline with the type
            if (s.GetAttribute("value") != null)
            {
                urgGenericType.GetProperty("Value").SetValue(instance, Util.FromWireFormat(s.GetAttribute("value"), GenericArguments[0]), null);
                result.AddResultDetail(new NotSupportedChoiceResultDetail(
                                           ResultDetailType.Warning, "Though XML ITS supports it, use of the URG 'value' attribute should be avoided. The data has been parsed anyways.", s.ToString(), null));
            }
            if (s.GetAttribute("specializationType") != null && result.CompatibilityMode == DatatypeFormatterCompatibilityMode.Canadian)
            {
                ((ANY)instance).Flavor = s.GetAttribute("specializationType");
            }

            // Serialization
            IXmlStructureFormatter serHost = this.Host;

            // Get property information
            PropertyInfo lowProperty        = urgGenericType.GetProperty("Low"),
                         highProperty       = urgGenericType.GetProperty("High"),
                         widthProperty      = urgGenericType.GetProperty("Width"),
                         lowClosedProperty  = urgGenericType.GetProperty("LowClosed"),
                         highClosedProperty = urgGenericType.GetProperty("HighClosed");

            // 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 && s.LocalName == "low") // low value
                        {
                            if (!String.IsNullOrEmpty(s.GetAttribute("inclusive")))
                            {
                                lowClosedProperty.SetValue(instance, Util.FromWireFormat(s.GetAttribute("inclusive"), typeof(bool?)), null);
                            }
                            var parseResult = Host.Parse(s, GenericArguments[0]);
                            result.Code = parseResult.Code;
                            result.AddResultDetail(parseResult.Details);
                            lowProperty.SetValue(instance, parseResult.Structure, null);
                        }
                        else if (s.NodeType == System.Xml.XmlNodeType.Element && s.LocalName == "high") // high value
                        {
                            if (!String.IsNullOrEmpty(s.GetAttribute("inclusive")))
                            {
                                highClosedProperty.SetValue(instance, Util.FromWireFormat(s.GetAttribute("inclusive"), typeof(bool?)), null);
                            }
                            var parseResult = Host.Parse(s, GenericArguments[0]);
                            result.Code = parseResult.Code;
                            result.AddResultDetail(parseResult.Details);
                            highProperty.SetValue(instance, parseResult.Structure, null);
                        }
                        else if (s.LocalName == "width") // width
                        {
                            var parseResult = Host.Parse(s, typeof(PQ));
                            result.Code = parseResult.Code;
                            result.AddResultDetail(parseResult.Details);
                            widthProperty.SetValue(instance, parseResult.Structure, null);
                        }
                        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 the data type
            string pathName = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name;
            base.Validate((ANY)instance, pathName, result);

            return(instance);
        }
Esempio n. 41
0
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        public override object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            // Create the types
            Type sxprType = typeof(SXPR<>);
            Type sxprGenericType = sxprType.MakeGenericType(GenericArguments);

            // Details

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

            if (s.GetAttribute("nullFlavor") != null)
                ((ANY)instance).NullFlavor = (NullFlavor)Util.FromWireFormat(s.GetAttribute("nullFlavor"), typeof(NullFlavor));
                // Try get operator 
                if (s.GetAttribute("operator") != null)
                    sxprGenericType.GetProperty("Operator").SetValue(instance, Util.FromWireFormat(s.GetAttribute("operator"), typeof(SetOperator?)), null);
                if (s.GetAttribute("specializationType") != null)
                {
                    if (result.CompatibilityMode == DatatypeFormatterCompatibilityMode.Canadian)
                        sxprGenericType.GetProperty("Flavor").SetValue(instance, s.GetAttribute("specializationType"), null);
                    else
                        result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Flavor", "SXPR", s.ToString()));
                }
                #region Element Processing 

                // List of components
                LIST<IGraphable> componentList = new LIST<IGraphable>();

                // Parse 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 == "comp") // component
                            {
                                // Now determine the type of GTS
                                //string typeName = s.GetAttribute("type", DatatypeFormatter.NS_XSI);
                                //IDatatypeFormatter formatter = DatatypeFormatter.GetFormatter(typeName);

                                //if (formatter == null)
                                //{
                                //    result.AddResultDetail(new ResultDetail(String.Format("Cannot parse a SXPR member of type '{0}'", typeName)));
                                //    return null;
                                //}
                                //else
                                //{
                                //    // Graph the Hull
                                //    formatter.Host = this.Host;
                                //    formatter.GenericArguments = GenericArguments;
                                //    componentList.Add(formatter.Parse(s, result) as IGraphable);
                                //}
                                var hostResult = this.Host.Parse(s, GenericArguments[0]);
                                result.Code = hostResult.Code;
                                result.AddResultDetail(hostResult.Details);
                                componentList.Add(hostResult.Structure as IGraphable);
                            }
                        }
                        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();
                        }
                    }
                }

                ((IListContainer)instance).ContainedList = componentList;
                #endregion

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

            return instance;
        }
Esempio n. 42
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;
        }
Esempio n. 43
0
        /// <summary>
        /// Parse the object
        /// </summary>
        public override object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            // Parse base (ANY) from the stream

            // Parse ED
            ST retVal = base.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", s.ToString())));
            }
            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
            base.Validate(retVal, s.ToString(), result);

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

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

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

            // Serialization
            IXmlStructureFormatter serHost = this.Host;

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

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

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

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

            return retVal;
        }
Esempio n. 45
0
 /// <summary>
 /// Parse from the stream
 /// </summary>
 public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
 {
     result.AddResultDetail(new NotImplementedResultDetail(ResultDetailType.Warning, "QSET cannot be parsed by the R1 formatter directly, processing as SXPR", s.ToString(), null));
     SXPRFormatter formatter = new SXPRFormatter();
     formatter.Host = this.Host;
     formatter.GenericArguments = this.GenericArguments;
     object retval = formatter.Parse(s, result);
     return retval;
 }
Esempio n. 46
0
        public override object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            // Create the types
            Type ivlType = typeof(IVL<>);
            Type ivlGenericType = ivlType.MakeGenericType(GenericArguments);

            // Sometimes there can be just a messy, unstructured value inline with this IVL (like in CCDA) so we still need to support that
            MemoryStream leftOvers = new MemoryStream();
            XmlWriter leftoverWriter = XmlWriter.Create(leftOvers);
            leftoverWriter.WriteStartElement(s.LocalName, s.NamespaceURI);

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

            if (s.MoveToFirstAttribute())
            {
                do
                {
                    switch (s.LocalName)
                    {
                        case "nullFlavor":

                            ((ANY)instance).NullFlavor = (NullFlavor)Util.FromWireFormat(s.GetAttribute("nullFlavor"), typeof(NullFlavor));
                            break;
                        case "operator":
                            ivlGenericType.GetProperty("Operator").SetValue(instance, Util.FromWireFormat(s.GetAttribute("operator"), typeof(SetOperator?)), null);
                            break;
                        case "specializationType":
                            if (result.CompatibilityMode == DatatypeFormatterCompatibilityMode.Canadian)
                                ((ANY)instance).Flavor = s.GetAttribute("specializationType");
                            break;
                        default:
                            leftoverWriter.WriteAttributeString(s.Prefix, s.LocalName, s.NamespaceURI, s.Value);
                            break;
                    }
                } while (s.MoveToNextAttribute());
                s.MoveToElement();
            }

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

            // 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 && s.LocalName == "low") // low value
                        {
                            if (!String.IsNullOrEmpty(s.GetAttribute("inclusive")))
                                lowClosedProperty.SetValue(instance, Util.FromWireFormat(s.GetAttribute("inclusive"), typeof(bool?)), null);
                            var parseResult = Host.Parse(s, GenericArguments[0]);
                            result.Code = parseResult.Code;
                            result.AddResultDetail(parseResult.Details);
                            lowProperty.SetValue(instance, parseResult.Structure, null);
                        }
                        else if (s.NodeType == System.Xml.XmlNodeType.Element && s.LocalName == "high") // high value
                        {
                            if (!String.IsNullOrEmpty(s.GetAttribute("inclusive")))
                                highClosedProperty.SetValue(instance, Util.FromWireFormat(s.GetAttribute("inclusive"), typeof(bool?)), null);
                            var parseResult = Host.Parse(s, GenericArguments[0]);
                            result.Code = parseResult.Code;
                            result.AddResultDetail(parseResult.Details);
                            highProperty.SetValue(instance, parseResult.Structure, null);
                        }
                        else if (s.NodeType == System.Xml.XmlNodeType.Element && s.LocalName == "center") // center
                        {
                            var parseResult = Host.Parse(s, GenericArguments[0]);
                            result.Code = parseResult.Code;
                            result.AddResultDetail(parseResult.Details);
                            centerProperty.SetValue(instance, parseResult.Structure, null);
                        }
                        else if (s.NodeType == System.Xml.XmlNodeType.Element && s.LocalName == "width") // width
                        {
                            var parseResult = Host.Parse(s, typeof(PQ));
                            result.Code = parseResult.Code;
                            result.AddResultDetail(parseResult.Details);
                            widthProperty.SetValue(instance, parseResult.Structure, null);
                        }
                        else if (s.NodeType == System.Xml.XmlNodeType.Element)
                        {
                            leftoverWriter.WriteNode(s, true);
                            //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

            // Process any leftovers as Value !!!
            try
            {
                leftoverWriter.WriteEndElement();
                leftoverWriter.Flush();
                leftOvers.Seek(0, SeekOrigin.Begin);
                using (XmlReader xr = XmlReader.Create(leftOvers))
                {
                    xr.MoveToContent();
                    if (xr.AttributeCount > 1 || !xr.IsEmptyElement)
                    {
                        bool isNotEmpty = !xr.IsEmptyElement;
                        if (xr.MoveToFirstAttribute())
                            do
                            {
                                isNotEmpty |= xr.Prefix != "xmlns" && xr.LocalName != "xmlns" && xr.NamespaceURI != DatatypeFormatter.NS_XSI;
                            } while (!isNotEmpty && xr.MoveToNextAttribute());
                        xr.MoveToElement();
                        if (isNotEmpty)
                        {
                            var baseResult = base.Parse(xr, result);
                            valueProperty.SetValue(instance, Util.FromWireFormat(baseResult, valueProperty.PropertyType), null);
                        }
                    }
                }
            }
            catch { }
            // Validate
            base.Validate(instance as ANY, s.LocalName, result);

            return instance;
        }
Esempio n. 47
0
        public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            ANYFormatter pdvFormatter = new ANYFormatter();

            // parse PDV portion
            Type uvpType = typeof(UVP<>).MakeGenericType(GenericArguments);
            ConstructorInfo ci = uvpType.GetConstructor(Type.EmptyTypes);
            ANY retVal = ci.Invoke(null) as ANY;

            // Property information
            PropertyInfo probabilityProperty = uvpType.GetProperty("Probability"),
                valueProperty = uvpType.GetProperty("Value");

            // Clean the
            if (s.GetAttribute("type", DatatypeFormatter.NS_XSI) != null && s is XmlStateReader)
            {
                (s as XmlStateReader).AddFakeAttribute("type", Util.CreateXSITypeName(GenericArguments[0]));
            }

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

            // Set value
            var hostResult = Host.Parse(s, GenericArguments[0]);
            result.Code = hostResult.Code;
            result.AddResultDetail(hostResult.Details);
            valueProperty.SetValue(retVal, hostResult.Structure, null);

            // Move null flavors and flavors up
            ANY resultAny = hostResult.Structure as ANY;
            retVal.NullFlavor = resultAny.NullFlavor;
            resultAny.NullFlavor = null;
            retVal.Flavor = resultAny.Flavor;
            resultAny.Flavor = null;

            // Validate the data type
            ANYFormatter validator = new ANYFormatter();
            string pathName = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name;
            validator.Validate(retVal, pathName, result);
            return retVal;
        }
Esempio n. 48
0
        /// <summary>
        /// Parse the object from stream <paramref name="s"/>
        /// </summary>
        /// <param name="s">The XmlReader to parse from</param>
        public override object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            // Parse TS
            TEL retVal = base.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;
            base.Validate(retVal, pathName, result);


            return(retVal);
        }
Esempio n. 49
0
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        /// <param name="s">The stream to parse</param>
        public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            PDVFormatter pdvFormatter = new PDVFormatter();
            PQ retVal = pdvFormatter.Parse<PQ>(s, result);

            if (s.GetAttribute("unit") != null)
                retVal.Unit = s.GetAttribute("unit");

            // Precision is not supported in R1, but is still useful to have so
            // we will report the precision of the data that was on the wire
            string valStr = s.GetAttribute("value");
            if (valStr != null && valStr.Contains("."))
                retVal.Precision = valStr.Length - valStr.IndexOf(".") - 1;
            else
                retVal.Precision = 0;

            #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 == "translation") // Format using ED
                        {
                            SETFormatter pqrFormatter = new SETFormatter();
                            pqrFormatter.GenericArguments = new Type[] { typeof(PQR) };
                            pqrFormatter.Host = Host.Clone() as IXmlStructureFormatter;
                            retVal.Translation = new SET<PQR>((LIST<IGraphable>)pqrFormatter.Parse(s, result)); // Parse ED
                            //details.AddRange(pqrFormatter.Details);
                        }
                    }
                    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
            ANYFormatter fmtr = new ANYFormatter();
            string pathName = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name;
            fmtr.Validate(retVal, pathName, result);

            return retVal;
        }
Esempio n. 50
0
        public override object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            // TODO: Determine how to parse a URG when the complex type is used. For example, URG<PQ> that is not a range, rather just a PQ
            //PDVFormatter pdvFormatter = new PDVFormatter();
            Type urgType = typeof(URG<>);
            Type urgGenericType = urgType.MakeGenericType(GenericArguments);

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

            if (s.GetAttribute("nullFlavor") != null)
                ((ANY)instance).NullFlavor = (NullFlavor)Util.FromWireFormat(s.GetAttribute("nullFlavor"), typeof(NullFlavor));
            if (s.GetAttribute("probability") != null) // Probability
            {
                decimal prob = (decimal)0.0f;
                if (!Decimal.TryParse(s.GetAttribute("probability"), out prob)) // Try to parse
                    result.AddResultDetail(new ResultDetail(ResultDetailType.Warning, string.Format("Value '{0}' can't be processed into 'Probability' on data type UVP", s.GetAttribute("probability")), s.ToString(), null));
                else // Success, so assign
                    ((IProbability)instance).Probability = prob;
            }
            // This doesn't make sense as "value" is inline with the type
            if (s.GetAttribute("value") != null)
            {
                urgGenericType.GetProperty("Value").SetValue(instance, Util.FromWireFormat(s.GetAttribute("value"), GenericArguments[0]), null);
                result.AddResultDetail(new NotSupportedChoiceResultDetail(
                        ResultDetailType.Warning, "Though XML ITS supports it, use of the URG 'value' attribute should be avoided. The data has been parsed anyways.", s.ToString(), null));
            }
            if (s.GetAttribute("specializationType") != null && result.CompatibilityMode == DatatypeFormatterCompatibilityMode.Canadian)
                ((ANY)instance).Flavor = s.GetAttribute("specializationType");

            // Serialization
            IXmlStructureFormatter serHost = this.Host;

            // Get property information
            PropertyInfo lowProperty = urgGenericType.GetProperty("Low"),
                highProperty = urgGenericType.GetProperty("High"),
                widthProperty = urgGenericType.GetProperty("Width"),
                lowClosedProperty = urgGenericType.GetProperty("LowClosed"),
                highClosedProperty = urgGenericType.GetProperty("HighClosed");

            // 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 && s.LocalName == "low") // low value
                        {
                            if (!String.IsNullOrEmpty(s.GetAttribute("inclusive")))
                                lowClosedProperty.SetValue(instance, Util.FromWireFormat(s.GetAttribute("inclusive"), typeof(bool?)), null);
                            var parseResult = Host.Parse(s, GenericArguments[0]);
                            result.Code = parseResult.Code;
                            result.AddResultDetail(parseResult.Details);
                            lowProperty.SetValue(instance, parseResult.Structure, null);
                        }
                        else if (s.NodeType == System.Xml.XmlNodeType.Element && s.LocalName == "high") // high value
                        {
                            if (!String.IsNullOrEmpty(s.GetAttribute("inclusive")))
                                highClosedProperty.SetValue(instance, Util.FromWireFormat(s.GetAttribute("inclusive"), typeof(bool?)), null);
                            var parseResult = Host.Parse(s, GenericArguments[0]);
                            result.Code = parseResult.Code;
                            result.AddResultDetail(parseResult.Details);
                            highProperty.SetValue(instance, parseResult.Structure, null);
                        }
                        else if (s.LocalName == "width") // width
                        {
                            var parseResult = Host.Parse(s, typeof(PQ));
                            result.Code = parseResult.Code;
                            result.AddResultDetail(parseResult.Details);
                            widthProperty.SetValue(instance, parseResult.Structure, null);
                        }
                        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 the data type
            string pathName = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name;
            base.Validate((ANY)instance, pathName, result);

            return instance;
        }
Esempio n. 51
0
        public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            // Create the types
            Type pivlType        = typeof(PIVL <>);
            Type pivlGenericType = pivlType.MakeGenericType(GenericArguments);

            // For the phase
            Type ivlType      = typeof(IVL <>);
            Type phaseIvlType = ivlType.MakeGenericType(GenericArguments);

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

            if (s.GetAttribute("specializationType") != null && result.CompatibilityMode == DatatypeFormatterCompatibilityMode.Canadian)
            {
                ((ANY)instance).Flavor = s.GetAttribute("specializationType");
            }

            if (s.GetAttribute("nullFlavor") != null)
            {
                ((ANY)instance).NullFlavor = (NullFlavor)Util.FromWireFormat(s.GetAttribute("nullFlavor"), typeof(NullFlavor));
            }
            else
            {
                // Try get operator and value
                if (s.GetAttribute("operator") != null)
                {
                    pivlGenericType.GetProperty("Operator").SetValue(instance, Util.FromWireFormat(s.GetAttribute("operator"), typeof(SetOperator?)), null);
                }
                if (s.GetAttribute("value") != null)
                {
                    result.AddResultDetail(new NotSupportedChoiceResultDetail(
                                               ResultDetailType.Warning, "The 'value' attribute of a SXCM does not interpretable in this context, and has been ignored", s.ToString(), null));
                }

                //    pivlGenericType.GetProperty("Value").SetValue(instance, Util.FromWireFormat(s.GetAttribute("value"), GenericArguments[0]), null);
                if (s.GetAttribute("institutionSpecified") != null)
                {
                    pivlGenericType.GetProperty("InstitutionSpecified").SetValue(instance, Util.FromWireFormat(s.GetAttribute("institutionSpecified"), typeof(bool?)), null);
                }
                if (s.GetAttribute("alignment") != null)
                {
                    pivlGenericType.GetProperty("Alignment").SetValue(instance, Util.FromWireFormat(s.GetAttribute("alignment"), typeof(CalendarCycle?)), null);
                }

                // Get property information
                PropertyInfo phaseProperty     = pivlGenericType.GetProperty("Phase"),
                             periodProperty    = pivlGenericType.GetProperty("Period"),
                             frequencyProperty = pivlGenericType.GetProperty("Frequency");

                // 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 == "phase") // low value
                            {
                                phaseProperty.SetValue(instance, Host.ParseObject(s, phaseIvlType), null);
                            }
                            else if (s.LocalName == "period") // high value
                            {
                                periodProperty.SetValue(instance, Host.ParseObject(s, typeof(PQ)), null);
                            }
                            else if (s.LocalName == "frequency" && result.CompatibilityMode == DatatypeFormatterCompatibilityMode.Canadian) // frequency
                            {
                                frequencyProperty.SetValue(instance, Host.ParseObject(s, typeof(RTO <INT, PQ>)), null);
                            }
                            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, s.ToString(), e));
                        }
                        finally
                        {
                            if (s.Name == oldName)
                            {
                                s.Read();
                            }
                        }
                    }
                }
                #endregion
            }

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

            return(instance);
        }
Esempio n. 52
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;
        }
Esempio n. 53
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);
        }
Esempio n. 54
0
        public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            // Create the types
            Type rtoType        = typeof(RTO <,>);
            Type rtoGenericType = rtoType.MakeGenericType(GenericArguments);

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

            if (s.GetAttribute("nullFlavor") != null)
            {
                ((ANY)instance).NullFlavor = (NullFlavor)Util.FromWireFormat(s.GetAttribute("nullFlavor"), typeof(NullFlavor));
            }
            else
            {
                PropertyInfo numeratorProperty   = rtoGenericType.GetProperty("Numerator"),
                             denominatorProperty = rtoGenericType.GetProperty("Denominator");

                if (s.GetAttribute("specializationType") != null)
                {
                    ((ANY)instance).Flavor = s.GetAttribute("specializationType");
                }

                // Get the values
                // 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 == "numerator")
                            {
                                var parseResult = Host.Parse(s, GenericArguments[0]);
                                result.Code = parseResult.Code;
                                result.AddResultDetail(parseResult.Details);
                                numeratorProperty.SetValue(instance, parseResult.Structure, null);
                            }
                            else if (s.LocalName == "denominator")
                            {
                                var parseResult = Host.Parse(s, GenericArguments[1]);
                                result.Code = parseResult.Code;
                                result.AddResultDetail(parseResult.Details);
                                denominatorProperty.SetValue(instance, parseResult.Structure, 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
            ANYFormatter anyFormatter = new ANYFormatter();
            string       pathName     = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name;
            anyFormatter.Validate(instance as ANY, pathName, result);

            return(instance);
        }