/// <summary> /// Parse the PQ back into a structure /// </summary> public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result) { // Create the base formatter PDVFormatter baseFormatter = new PDVFormatter(); baseFormatter.Host = this.Host; // Read temporary values string tCurrency = String.Empty; if (s.GetAttribute("currency") != null) { tCurrency = s.GetAttribute("currency"); } // Parse PDV content var retVal = baseFormatter.Parse <MO>(s, result); // Set PDV content retVal.Currency = tCurrency; // Validate ANYFormatter anyFormatter = new ANYFormatter(); string pathName = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name; anyFormatter.Validate(retVal as ANY, pathName, result); // Return instance return(retVal); }
/// <summary> /// Parses an object from stream <paramref name="s"/> /// </summary> public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result) { // Parse base (ANY) from the stream ANYFormatter baseFormatter = new ANYFormatter(); // Parse BL BL retVal = baseFormatter.Parse <BL>(s); // Get the value if (s.GetAttribute("value") != null) { try { retVal.Value = Util.Convert <Boolean>(s.GetAttribute("value")); } catch (Exception e) { result.Code = ResultCode.Error; result.AddResultDetail(new ResultDetail(ResultDetailType.Error, e.Message, s.ToString(), e)); } } // Base formatter baseFormatter.Validate(retVal, s.ToString(), result); return(retVal); }
/// <summary> /// Parse an object from <paramref name="s"/> /// </summary> public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result) { // Parse the base data ANYFormatter baseFormatter = new ANYFormatter(); baseFormatter.Host = this.Host; LIST <IGraphable> retVal = baseFormatter.Parse <LIST <IGraphable> >(s); // parse items // Elements #region Elements if (!s.IsEmptyElement) { int sDepth = s.Depth; string sName = s.Name; s.Read(); // string Name while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName)) { string oldName = s.Name; // Name try { // Numerator if (s.LocalName == "item") { var parseResult = Host.Parse(s, GenericArguments[0]); result.Code = parseResult.Code; result.AddResultDetail(parseResult.Details); retVal.Add(parseResult.Structure); } else if (s.NodeType == System.Xml.XmlNodeType.Element) { result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, s.LocalName, s.NamespaceURI, s.ToString(), null)); } } catch (MessageValidationException e) { result.AddResultDetail(new ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, e)); } finally { if (s.Name == oldName) { s.Read(); } } } } #endregion // Validate baseFormatter.Validate(retVal, s.ToString(), result); return(retVal); }
/// <summary> /// Parse an object from <paramref name="s"/> /// </summary> public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result) { // Parse the base ANYFormatter baseFormatter = new ANYFormatter(); baseFormatter.Host = this.Host; baseFormatter.GenericArguments = this.GenericArguments; var retVal = baseFormatter.Parse <II>(s); // Parse II specific data if (s.GetAttribute("root") != null) { retVal.Root = s.GetAttribute("root"); } if (s.GetAttribute("extension") != null) { retVal.Extension = s.GetAttribute("extension"); } if (s.GetAttribute("identifierName") != null) { retVal.IdentifierName = s.GetAttribute("identifierName"); } if (s.GetAttribute("displayable") != null) { retVal.Displayable = Util.Convert <bool>(s.GetAttribute("displayable")); } if (s.GetAttribute("scope") != null) { retVal.Scope = Util.Convert <IdentifierScope>(s.GetAttribute("scope")); } if (s.GetAttribute("reliability") != null) { retVal.Reliability = Util.Convert <IdentifierReliability>(s.GetAttribute("reliability")); } // Validate baseFormatter.Validate(retVal, s.ToString(), result); return(retVal); }
/// <summary> /// Parse object from the wire /// </summary> public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result) { // Parse base (ANY) from the stream ANYFormatter baseFormatter = new ANYFormatter(); // Parse CS CS <String> retVal = baseFormatter.Parse <CS <String> >(s); // Now parse our data out... Attributes if (retVal.NullFlavor == null && s.GetAttribute("code") != null) { retVal.Code = s.GetAttribute("code"); } // Validate string pathName = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name; baseFormatter.Validate(retVal, pathName, result); return(retVal); }
/// <summary> /// Parse <paramref name="s"/> to an instance of ADXP /// </summary> public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result) { // Create base ANYFormatter baseFormatter = new ANYFormatter(); ADXP retVal = baseFormatter.Parse <ADXP>(s); // Read data if (s.GetAttribute("type") != null) { retVal.Type = Util.Convert <AddressPartType>(s.GetAttribute("type")); } if (s.GetAttribute("code") != null) { retVal.Code = s.GetAttribute("code"); } if (s.GetAttribute("codeSystem") != null) { retVal.CodeSystem = s.GetAttribute("codeSystem"); } if (s.GetAttribute("codeSystemVersion") != null) { retVal.CodeSystemVersion = s.GetAttribute("codeSystemVersion"); } if (s.GetAttribute("language") != null) { result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, "@language", s.NamespaceURI, s.ToString(), null)); } if (s.GetAttribute("value") != null) { retVal.Value = s.GetAttribute("value"); } // Validate baseFormatter.Validate(retVal, s.ToString(), result); return(retVal); }
/// <summary> /// Parse <paramref name="s"/> /// </summary> public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result) { // Parse base (ANY) from the stream ANYFormatter baseFormatter = new ANYFormatter(); // Parse TEL TEL retVal = baseFormatter.Parse <TEL>(s); // Get the value if (s.GetAttribute("value") != null) { retVal.Value = s.GetAttribute("value"); } if (s.GetAttribute("use") != null) { retVal.Use = Util.Convert <SET <CS <TelecommunicationAddressUse> > >(s.GetAttribute("use")); } if (s.GetAttribute("capabilities") != null) { retVal.Capabilities = Util.Convert <SET <CS <TelecommunicationCabability> > >(s.GetAttribute("capabilities")); } // Elements #region Elements if (!s.IsEmptyElement) { int sDepth = s.Depth; string sName = s.Name; s.Read(); // string Name while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName)) { string oldName = s.Name; // Name try { // Numerator if (s.LocalName == "useablePeriod") { var parseResult = this.Host.Parse(s, typeof(GTS)); result.Code = parseResult.Code; result.AddResultDetail(parseResult.Details); retVal.UseablePeriod = Util.Convert <GTS>(parseResult.Structure); } else if (s.NodeType == System.Xml.XmlNodeType.Element) { result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, s.LocalName, s.NamespaceURI, s.ToString(), null)); } } catch (MessageValidationException e) { result.AddResultDetail(new ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, e)); } finally { if (s.Name == oldName) { s.Read(); } } } } #endregion // Base formatter baseFormatter.Validate(retVal, s.ToString(), result); return(retVal); }
/// <summary> /// Parse an AD instance from <paramref name="s"/> /// </summary> public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result) { // Create a base formatter so it can construct the object ANYFormatter baseFormatter = new ANYFormatter(); // Parse AD AD retVal = baseFormatter.Parse <AD>(s); // Now parse our data out... Attributes if (s.GetAttribute("use") != null) { retVal.Use = (SET <CS <PostalAddressUse> >)Util.FromWireFormat(s.GetAttribute("use"), typeof(SET <CS <PostalAddressUse> >)); } if (s.GetAttribute("isNotOrdered") != null) { retVal.IsNotOrdered = (bool)Util.FromWireFormat(s.GetAttribute("isNotOrdered"), typeof(bool)); } // Loop through content // Elements #region Elements if (!s.IsEmptyElement) { int sDepth = s.Depth; string sName = s.Name; s.Read(); // Read all internal elements while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName)) { string oldName = s.Name; // Name try { AddressPartType?adxpType; // Address part type if (s.LocalName == "useablePeriod") // Usable Period, since this is a GTS { // Useable period doesn't exist GTSFormatter sxcmFormatter = new GTSFormatter(); sxcmFormatter.Host = this.Host; retVal.UseablePeriod = sxcmFormatter.Parse(s, result) as GTS; } else if (s.LocalName == "part") // Reverse map exists, so this is a part { ADXPFormatter adxpFormatter = new ADXPFormatter(); // ADXP Formatter adxpFormatter.Host = this.Host; ADXP part = (ADXP)adxpFormatter.Parse(s, result); // Parse retVal.Part.Add(part); // Add to AD } } catch (MessageValidationException e) { result.AddResultDetail(new ResultDetail(ResultDetailType.Error, e.Message, s.ToString(), e)); // Append details } finally { if (oldName == s.Name) { s.Read(); // Read if we need to } } } } #endregion // Validate string pathName = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name; baseFormatter.Validate(retVal, pathName, result); return(retVal); }
/// <summary> /// Parse the PQ back into a structure /// </summary> public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result) { // Create the base formatter PDVFormatter baseFormatter = new PDVFormatter(); baseFormatter.Host = this.Host; // Read temporary values string tUnit = null; if (s.GetAttribute("unit") != null) { tUnit = s.GetAttribute("unit"); } SET <CodingRationale> tRationale = null; if (s.GetAttribute("codingRationale") != null) { tRationale = Util.Convert <SET <CodingRationale> >(s.GetAttribute("codingRationale")); } // Parse PDV content (only attributes) var retVal = baseFormatter.ParseAttributes <PQ>(s, result); // Set PDV content retVal.Unit = tUnit; retVal.CodingRationale = tRationale; // Process elements // This requires a QTY formatter as QTY elements may be // in the stream as well #region Elements if (!s.IsEmptyElement) { // Prepare a formatter to process QTY elements QTYFormatter qtyFormatter = new QTYFormatter(); qtyFormatter.Host = this.Host; // Exit markers int sDepth = s.Depth; string sName = s.Name; // Translations SET <PQR> translations = new SET <PQR>(); // Read the next element s.Read(); // Read until exit condition is fulfilled while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName)) { string oldName = s.Name; // Name try { if (s.LocalName == "translation") // Format using ED { var hostResult = Host.Parse(s, typeof(PQR)); result.Code = hostResult.Code; result.AddResultDetail(hostResult.Details); translations.Add(hostResult.Structure as PQR); } else { qtyFormatter.ParseElementsInline(s, retVal, result); } } catch (MessageValidationException e) { result.AddResultDetail(new MARC.Everest.Connectors.ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, s.ToString(), e)); } finally { if (s.Name == oldName) { s.Read(); } } } // Set translations if (!translations.IsEmpty) { retVal.Translation = translations; } } #endregion // Validate ANYFormatter anyFormatter = new ANYFormatter(); string pathName = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name; anyFormatter.Validate(retVal as ANY, pathName, result); // REturn instance return(retVal); }
/// <summary> /// Parse an object from <paramref name="s"/> /// </summary> public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result) { ANYFormatter baseFormatter = new ANYFormatter(); baseFormatter.Host = this.Host; baseFormatter.GenericArguments = this.GenericArguments; ANY tRetVal = baseFormatter.Parse <ANY>(s); // Construct an instance of the SLIST var slistType = typeof(SLIST <>).MakeGenericType(this.GenericArguments); var constructor = slistType.GetConstructor(Type.EmptyTypes); ISampledList retVal = constructor.Invoke(null) as ISampledList; DatatypeR2Formatter.CopyBaseAttributes(tRetVal, retVal as ANY); // Parse the return value #region Elements if (!s.IsEmptyElement) { int sDepth = s.Depth; string sName = s.Name; s.Read(); // string Name while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName)) { string oldName = s.Name; // Name try { // Origin if (s.LocalName == "origin" && retVal.Origin == null) { var parseResult = Host.Parse(s, GenericArguments[0]); result.Code = parseResult.Code; result.AddResultDetail(parseResult.Details); retVal.Origin = parseResult.Structure as IQuantity; } else if (s.LocalName == "origin") { result.AddResultDetail(new NotImplementedResultDetail(ResultDetailType.Warning, "origin may only be supplied once", s.ToString())); } // Scale else if (s.LocalName == "scale" && retVal.Scale == null) { var parseResult = Host.Parse(s, typeof(IQuantity)); result.Code = parseResult.Code; result.AddResultDetail(parseResult.Details); retVal.Scale = parseResult.Structure as IQuantity; } else if (s.LocalName == "scale") { result.AddResultDetail(new NotImplementedResultDetail(ResultDetailType.Warning, "scale may only be supplied once", s.ToString())); } // Digit else if (s.LocalName == "digit") { var parseResult = Host.Parse(s, typeof(INT)); result.Code = parseResult.Code; result.AddResultDetail(parseResult.Details); retVal.Items.Add(parseResult.Structure as INT); } else if (s.NodeType == System.Xml.XmlNodeType.Element) { result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, s.LocalName, s.NamespaceURI, s.ToString(), null)); } } catch (MessageValidationException e) { result.AddResultDetail(new MARC.Everest.Connectors.ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, e)); } finally { if (s.Name == oldName) { s.Read(); } } } } #endregion // Validate baseFormatter.Validate(retVal as ANY, s.ToString(), result); return(retVal); }
/// <summary> /// Parse an object instance from <paramref name="s"/> /// </summary> public virtual object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result) { // Parse the base attributes ANYFormatter baseFormatter = new ANYFormatter(); baseFormatter.Host = this.Host; baseFormatter.GenericArguments = this.GenericArguments; EN retVal = baseFormatter.Parse <EN>(s); // Use if (s.GetAttribute("use") != null) { retVal.Use = Util.Convert <SET <CS <EntityNameUse> > >(s.GetAttribute("use")); } // Process the parts #region Elements if (!s.IsEmptyElement) { int sDepth = s.Depth; string sName = s.Name; s.Read(); // string Name while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName)) { string oldName = s.Name; // Name try { // Numerator if (s.LocalName == "part") { var parseResult = Host.Parse(s, typeof(ENXP)); result.Code = parseResult.Code; result.AddResultDetail(parseResult.Details); retVal.Part.Add(parseResult.Structure as ENXP); } else if (s.NodeType == System.Xml.XmlNodeType.Element) { result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, s.LocalName, s.NamespaceURI, s.ToString(), null)); } } catch (MessageValidationException e) { result.AddResultDetail(new ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, e)); } finally { if (s.Name == oldName) { s.Read(); } } } } #endregion // Validate baseFormatter.Validate(retVal, s.ToString(), result); return(retVal); }
/// <summary> /// Parse an instance of PIVL from <paramref name="s"/> /// </summary> public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result) { // Create the types Type pivlType = typeof(PIVL <>); Type ivlGenericType = pivlType.MakeGenericType(GenericArguments); // Create an instance of rto from the rtoType object instance = ivlGenericType.GetConstructor(Type.EmptyTypes).Invoke(null); // Parse an any ANYFormatter baseFormatter = new ANYFormatter(); DatatypeR2Formatter.CopyBaseAttributes(baseFormatter.Parse(s, result) as ANY, instance as ANY); if ((instance as IAny).NullFlavor == null) { // Try get operator and value if (s.GetAttribute("operator") != null) { result.AddResultDetail(new NotPermittedDatatypeR2EntityResultDetail(ResultDetailType.Warning, "operator", "PIVL", s.ToString())); } if (s.GetAttribute("value") != null) { result.AddResultDetail(new NotPermittedDatatypeR2EntityResultDetail(ResultDetailType.Warning, "value", "PIVL", s.ToString())); } // Get property information PropertyInfo alignmentProperty = ivlGenericType.GetProperty("Alignment"), phaseProperty = ivlGenericType.GetProperty("Phase"), periodProperty = ivlGenericType.GetProperty("Period"), institutionSpecifiedProperty = ivlGenericType.GetProperty("InstitutionSpecified"), countProperty = ivlGenericType.GetProperty("Count"), frequencyProperty = ivlGenericType.GetProperty("Frequency"), originalTextProperty = ivlGenericType.GetProperty("OriginalText"); // Attributes if (s.GetAttribute("isFlexible") != null) { institutionSpecifiedProperty.SetValue(instance, XmlConvert.ToBoolean(s.GetAttribute("isFlexible")), null); } if (s.GetAttribute("alignment") != null) { alignmentProperty.SetValue(instance, Util.FromWireFormat(s.GetAttribute("alignment"), alignmentProperty.PropertyType), null); } if (s.GetAttribute("count") != null) { countProperty.SetValue(instance, Util.Convert <INT>(s.GetAttribute("count")), null); } // Now process the elements #region Elements if (!s.IsEmptyElement) { int sDepth = s.Depth; string sName = s.Name; s.Read(); // string Name while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName)) { string oldName = s.Name; // Name try { if (s.NodeType == System.Xml.XmlNodeType.Element) { PropertyInfo setProperty = null; switch (s.LocalName) { case "originalText": setProperty = originalTextProperty; break; case "phase": setProperty = phaseProperty; break; case "frequency": setProperty = frequencyProperty; break; case "period": setProperty = periodProperty; break; default: result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, s.LocalName, s.NamespaceURI, s.ToString(), null)); break; } // Set the property if we found something valid if (setProperty != null) { var hostResult = this.Host.Parse(s, setProperty.PropertyType); result.Code = hostResult.Code; result.AddResultDetail(hostResult.Details); setProperty.SetValue(instance, Util.FromWireFormat(hostResult.Structure, setProperty.PropertyType), null); } } } catch (MessageValidationException e) // Message validation error { result.AddResultDetail(new MARC.Everest.Connectors.ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, e)); } finally { if (s.Name == oldName) { s.Read(); } } } } #endregion } // Validate ANYFormatter validation = new ANYFormatter(); validation.Validate(instance as ANY, s.LocalName, result); return(instance); }
/// <summary> /// Parse an object from <paramref name="s"/> /// </summary> public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result) { // Parse base (ANY) from the stream ANYFormatter baseFormatter = new ANYFormatter(); string pathName = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name; // Parse ED ED retVal = baseFormatter.Parse <ED>(s); // Now parse our data out... Attributes if (s.GetAttribute("mediaType") != null) { retVal.MediaType = s.GetAttribute("mediaType"); } if (s.GetAttribute("language") != null) { retVal.Language = s.GetAttribute("language"); } if (s.GetAttribute("compression") != null) { retVal.Compression = (EncapsulatedDataCompression?)Util.FromWireFormat(s.GetAttribute("compression"), typeof(EncapsulatedDataCompression)); } if (s.GetAttribute("integrityCheckAlgorithm") != null) { retVal.IntegrityCheckAlgorithm = Util.Convert <EncapsulatedDataIntegrityAlgorithm>(s.GetAttribute("integrityCheckAlgorithm")); } if (s.GetAttribute("value") != null) { retVal.Representation = EncapsulatedDataRepresentation.TXT; if (retVal.MediaType == null) { retVal.MediaType = "text/plain"; } retVal.Value = s.GetAttribute("value"); } // Elements and inner data #region Elements if (!s.IsEmptyElement) { // Exit markers int sDepth = s.Depth; string sName = s.Name; Encoding textEncoding = System.Text.Encoding.UTF8; s.Read(); // Read until exit condition is fulfilled while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName)) { string oldName = s.Name; // Name try { if (s.LocalName == "thumbnail") // Format using ED { var hostResult = Host.Parse(s, typeof(ED)); result.Code = hostResult.Code; result.AddResultDetail(hostResult.Details); retVal.Thumbnail = (ED)hostResult.Structure; } else if (s.LocalName == "reference") // Format using TEL { var hostResult = Host.Parse(s, typeof(TEL)); result.Code = hostResult.Code; result.AddResultDetail(hostResult.Details); retVal.Reference = (TEL)hostResult.Structure; } else if (s.LocalName == "translation") // Translation { var hostResult = Host.Parse(s, typeof(ED)); result.Code = hostResult.Code; result.AddResultDetail(hostResult.Details); if (retVal.Translation == null) { retVal.Translation = new SET <ED>(); } retVal.Translation.Add((ED)hostResult.Structure); } else if (s.LocalName == "data") // Data { retVal.Representation = EncapsulatedDataRepresentation.B64; retVal.Data = Convert.FromBase64String(s.ReadString()); } else if (s.LocalName == "xml") // data { retVal.Representation = EncapsulatedDataRepresentation.XML; retVal.Data = textEncoding.GetBytes(s.ReadInnerXml()); } else if (s.LocalName == "integrityCheck") { retVal.IntegrityCheck = Convert.FromBase64String(s.ReadString()); } } catch (MessageValidationException e) { result.AddResultDetail(new MARC.Everest.Connectors.ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, s.ToString(), e)); } finally { if (s.Name == oldName) { s.Read(); } } } } #endregion // Finally, the hash, this will validate the data if (!retVal.ValidateIntegrityCheck()) { result.AddResultDetail(new ResultDetail(ResultDetailType.Warning, string.Format("Encapsulated data with content starting with '{0}' failed integrity check!", retVal.ToString().PadRight(10, ' ').Substring(0, 10)), s.ToString(), null)); } // Validate baseFormatter.Validate(retVal, pathName, result); return(retVal); }
/// <summary> /// Parse the RTO /// </summary> public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result) { // Create the types Type rtoType = typeof(RTO <,>); QTYFormatter baseFormatter = (new QTYFormatter() { Host = this.Host }); // Quantity value, just read into a REAL var qty = baseFormatter.ParseAttributes <REAL>(s, result); // Temporary values IGraphable denominator = null, numerator = null; // Elements // This type is a little different in R2, basically we can't determine the generic // parameters by the XSI Type so we have to parse the num/denom manually, and // ensure that we have both, then we construct the object and set the properties #region Elements if (!s.IsEmptyElement) { int sDepth = s.Depth; string sName = s.Name; s.Read(); // string Name while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName)) { string oldName = s.Name; // Name try { // Numerator if (s.LocalName == "numerator") { var parseResult = Host.Parse(s, GenericArguments[0]); result.Code = parseResult.Code; result.AddResultDetail(parseResult.Details); numerator = parseResult.Structure; } // Denominator else if (s.LocalName == "denominator") { var parseResult = Host.Parse(s, GenericArguments[1]); result.Code = parseResult.Code; result.AddResultDetail(parseResult.Details); denominator = parseResult.Structure; } else { baseFormatter.ParseElementsInline(s, qty, result); } } catch (MessageValidationException e) { result.AddResultDetail(new MARC.Everest.Connectors.ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, e)); } finally { if (s.Name == oldName) { s.Read(); } } } } #endregion try { // Construct the generic type (if possible) Type rtoGenericType = rtoType.MakeGenericType(new Type[] { numerator == null ? typeof(IQuantity) : numerator.GetType(), denominator == null ? typeof(IQuantity) : denominator.GetType() }); // Create an instance of rto from the rtoType object instance = rtoGenericType.GetConstructor(Type.EmptyTypes).Invoke(null); // Get the values from the QTY and copy IQuantity rtoQty = instance as IQuantity; DatatypeR2Formatter.CopyBaseAttributes(qty, rtoQty as ANY); rtoQty.Expression = qty.Expression; rtoQty.OriginalText = qty.OriginalText; rtoQty.UncertainRange = qty.UncertainRange; rtoQty.Uncertainty = qty.Uncertainty; rtoQty.UncertaintyType = qty.UncertaintyType; // rto properties PropertyInfo numeratorProperty = rtoGenericType.GetProperty("Numerator"), denominatorProperty = rtoGenericType.GetProperty("Denominator"); // Set the previously found properties numeratorProperty.SetValue(instance, Util.FromWireFormat(numerator, numeratorProperty.PropertyType), null); denominatorProperty.SetValue(instance, Util.FromWireFormat(denominator, denominatorProperty.PropertyType), null); // Validate ANYFormatter anyFormatter = new ANYFormatter(); string pathName = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name; anyFormatter.Validate(instance as ANY, pathName, result); return(instance); } catch (Exception e) { result.AddResultDetail(new ResultDetail(ResultDetailType.Error, e.Message, e)); return(null); } }
/// <summary> /// Parse from wire level format /// </summary> public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result) { // Any formatter for the base attributes ANYFormatter baseFormatter = new ANYFormatter(); // Create the types Type qsiType = typeof(QSU <>); Type qsiGenericType = qsiType.MakeGenericType(GenericArguments); // Create an instance of rto from the rtoType object instance = qsiGenericType.GetConstructor(Type.EmptyTypes).Invoke(null); DatatypeR2Formatter.CopyBaseAttributes(baseFormatter.Parse(s, result) as ANY, instance as ANY); // Read internal elements if ((instance as ANY).NullFlavor != null) { return(instance); } // Now process the elements #region Elements if (!s.IsEmptyElement) { int sDepth = s.Depth; string sName = s.Name; LIST <IGraphable> termList = new LIST <IGraphable>(4); s.Read(); // string Name while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName)) { string oldName = s.Name; // Name try { if (s.NodeType == System.Xml.XmlNodeType.Element) { switch (s.LocalName) { case "originalText": { var hostResult = this.Host.Parse(s, typeof(ED)); result.Code = hostResult.Code; result.AddResultDetail(hostResult.Details); (instance as IOriginalText).OriginalText = hostResult.Structure as ED; break; } case "term": { var hostResult = this.Host.Parse(s, typeof(IGraphable)); result.Code = hostResult.Code; result.AddResultDetail(hostResult.Details); termList.Add(hostResult.Structure as IGraphable); break; } default: result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, s.LocalName, s.NamespaceURI, s.ToString(), null)); break; } } } catch (MessageValidationException e) // Message validation error { result.AddResultDetail(new MARC.Everest.Connectors.ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, e)); } finally { if (s.Name == oldName) { s.Read(); } } } // Set term list ((IListContainer)instance).ContainedList = termList; } #endregion // Validate baseFormatter.Validate(instance as ANY, s.ToString(), result); return(instance); }
/// <summary> /// Parse an object from <paramref name="s"/> /// </summary> public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result) { ANYFormatter baseFormatter = new ANYFormatter(); baseFormatter.Host = this.Host; baseFormatter.GenericArguments = this.GenericArguments; // Graph var tRetVal = baseFormatter.Parse <ANY>(s); var uvpType = typeof(UVP <>); var genType = uvpType.MakeGenericType(this.GenericArguments); // Construct var constructor = genType.GetConstructor(Type.EmptyTypes); IProbability retVal = constructor.Invoke(null) as IProbability; // Copy base attributes DatatypeR2Formatter.CopyBaseAttributes(tRetVal, retVal as ANY); // Parse UVP properties if (s.GetAttribute("probability") != null) { string tProb = s.GetAttribute("probability"); try { retVal.Probability = Decimal.Parse(tProb); } catch (Exception e) { result.Code = ResultCode.Error; result.AddResultDetail(new ResultDetail(ResultDetailType.Error, e.Message, s.ToString(), e)); } } // Now process the elements #region Elements if (!s.IsEmptyElement) { int sDepth = s.Depth; string sName = s.Name; s.Read(); // string Name while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName)) { string oldName = s.Name; // Name try { if (s.LocalName == "value" && retVal.Value == null) { var hostResult = this.Host.Parse(s, GenericArguments[0]); result.AddResultDetail(hostResult.Details); retVal.Value = hostResult.Structure; } else if (s.LocalName == "value") { result.AddResultDetail(new NotImplementedResultDetail(ResultDetailType.Warning, "Value can only be set once on an instance of UVP", s.ToString())); } else if (s.NodeType == System.Xml.XmlNodeType.Element) { result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, s.LocalName, s.NamespaceURI, s.ToString(), null)); } } catch (MessageValidationException e) // Message validation error { result.AddResultDetail(new MARC.Everest.Connectors.ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, e)); } finally { if (s.Name == oldName) { s.Read(); } } } } #endregion // validate baseFormatter.Validate(retVal as ANY, s.ToString(), result); return(retVal); }
/// <summary> /// Parse an object from <paramref name="s"/> into an instance of QSP /// </summary> public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result) { // Create the types Type qspType = typeof(QSP <>); Type qspGenericType = qspType.MakeGenericType(GenericArguments); // Create an instance of rto from the rtoType object instance = qspGenericType.GetConstructor(Type.EmptyTypes).Invoke(null); // Parse an any ANYFormatter baseFormatter = new ANYFormatter(); DatatypeR2Formatter.CopyBaseAttributes(baseFormatter.Parse(s, result) as ANY, instance as ANY); if ((instance as IAny).NullFlavor == null) { // Get property information PropertyInfo lowProperty = qspGenericType.GetProperty("Low"), highProperty = qspGenericType.GetProperty("High"), originalTextProperty = qspGenericType.GetProperty("OriginalText"); // Now process the elements #region Elements if (!s.IsEmptyElement) { int sDepth = s.Depth; string sName = s.Name; s.Read(); // string Name while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName)) { string oldName = s.Name; // Name try { if (s.NodeType == System.Xml.XmlNodeType.Element) { PropertyInfo setProperty = null; switch (s.LocalName) { case "originalText": setProperty = originalTextProperty; break; case "low": setProperty = lowProperty; break; case "high": setProperty = highProperty; break; default: result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, s.LocalName, s.NamespaceURI, s.ToString(), null)); break; } // Set the property if we found something valid if (setProperty != null) { var hostResult = this.Host.Parse(s, setProperty.PropertyType); result.Code = hostResult.Code; result.AddResultDetail(hostResult.Details); setProperty.SetValue(instance, Util.FromWireFormat(hostResult.Structure, setProperty.PropertyType), null); } } } catch (MessageValidationException e) // Message validation error { result.AddResultDetail(new MARC.Everest.Connectors.ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, e)); } finally { if (s.Name == oldName) { s.Read(); } } } } #endregion } // Validate ANYFormatter validation = new ANYFormatter(); validation.Validate(instance as ANY, s.LocalName, result); return(instance); }
/// <summary> /// Parse an object from <paramref name="s"/> /// </summary> public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result) { // Create the types Type ivlType = typeof(IVL <>); Type ivlGenericType = ivlType.MakeGenericType(GenericArguments); // Create an instance of rto from the rtoType object instance = ivlGenericType.GetConstructor(Type.EmptyTypes).Invoke(null); // Parse an any ANYFormatter baseFormatter = new ANYFormatter(); DatatypeR2Formatter.CopyBaseAttributes(baseFormatter.Parse(s, result) as ANY, instance as ANY); if ((instance as IAny).NullFlavor == null) { // Try get operator and value if (s.GetAttribute("operator") != null) { result.AddResultDetail(new NotPermittedDatatypeR2EntityResultDetail(ResultDetailType.Warning, "operator", "IVL", s.ToString())); } if (s.GetAttribute("value") != null) { result.AddResultDetail(new NotPermittedDatatypeR2EntityResultDetail(ResultDetailType.Warning, "value", "IVL", s.ToString())); } // Get property information PropertyInfo lowProperty = ivlGenericType.GetProperty("Low"), highProperty = ivlGenericType.GetProperty("High"), widthProperty = ivlGenericType.GetProperty("Width"), valueProperty = ivlGenericType.GetProperty("Value"), originalTextProperty = ivlGenericType.GetProperty("OriginalText"), lowClosedProperty = ivlGenericType.GetProperty("LowClosed"), highClosedProperty = ivlGenericType.GetProperty("HighClosed"); // Attributes if (s.GetAttribute("lowClosed") != null) { lowClosedProperty.SetValue(instance, XmlConvert.ToBoolean(s.GetAttribute("lowClosed")), null); } if (s.GetAttribute("highClosed") != null) { highClosedProperty.SetValue(instance, XmlConvert.ToBoolean(s.GetAttribute("highClosed")), null); } // Now process the elements #region Elements if (!s.IsEmptyElement) { int sDepth = s.Depth; string sName = s.Name; s.Read(); // string Name while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName)) { string oldName = s.Name; // Name try { if (s.NodeType == System.Xml.XmlNodeType.Element) { PropertyInfo setProperty = null; switch (s.LocalName) { case "originalText": setProperty = originalTextProperty; break; case "low": setProperty = lowProperty; break; case "high": setProperty = highProperty; break; case "any": setProperty = valueProperty; break; case "width": setProperty = widthProperty; break; default: result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, String.Format("Element '{0}' is not supported in IVL", s.LocalName), s.ToString(), null)); break; } // Set the property if we found something valid if (setProperty != null) { var hostResult = this.Host.Parse(s, setProperty.PropertyType); result.Code = hostResult.Code; result.AddResultDetail(hostResult.Details); setProperty.SetValue(instance, Util.FromWireFormat(hostResult.Structure, setProperty.PropertyType), null); } } } catch (MessageValidationException e) // Message validation error { result.AddResultDetail(new MARC.Everest.Connectors.ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, e)); } finally { if (s.Name == oldName) { s.Read(); } } } } #endregion // Validate combination if (!((lowProperty.GetValue(instance, null) != null || highProperty.GetValue(instance, null) != null) ^ (valueProperty.GetValue(instance, null) != null || widthProperty.GetValue(instance, null) != null))) { result.AddResultDetail(new NotSupportedChoiceResultDetail(ResultDetailType.Warning, "IVL instance is not comformant to ISO21090 data types specification. 'Value' and/or 'Width', or 'Low' and/or 'High' are compliant representations.", s.ToString(), null)); } } // Validate ANYFormatter validation = new ANYFormatter(); validation.Validate(instance as ANY, s.LocalName, result); return(instance); }
/// <summary> /// Parse a CD as a particular type /// </summary> internal T Parse <T>(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result) where T : ANY, ICodedValue, new() { // Instantiate the genericized T ANYFormatter baseFormatter = new ANYFormatter(); T retVal = baseFormatter.Parse <T>(s); 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("valueSet") != null) { retVal.ValueSet = s.GetAttribute("valueSet"); } if (s.GetAttribute("valueSetVersion") != null) { retVal.ValueSetVersion = s.GetAttribute("valueSetVersion"); } // Now parse our data out... Attributes if (s.GetAttribute("code") != null) { string codeString = s.GetAttribute("code"); if (retVal is IConceptDescriptor) { var cdExpr = ParseCodeExpression(codeString, retVal); retVal.CodeValue = cdExpr.Code; retVal.DisplayName = cdExpr.DisplayName; if (cdExpr.Qualifier != null && !cdExpr.Qualifier.IsEmpty) { (retVal as IConceptDescriptor).Qualifier = new LIST <IGraphable>(cdExpr.Qualifier); } } else { retVal.CodeValue = codeString; } } // Elements #region Elements if (!s.IsEmptyElement) { int sDepth = s.Depth; string sName = s.Name; LIST <IGraphable> translations = new LIST <IGraphable>(10); 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 { var hostResult = this.Host.Parse(s, typeof(ED)); result.Code = hostResult.Code; result.AddResultDetail(hostResult.Details); retVal.OriginalText = hostResult.Structure as ED; } else if (s.LocalName == "displayName") // display name { var hostResult = this.Host.Parse(s, typeof(ST)); result.Code = hostResult.Code; result.AddResultDetail(hostResult.Details); retVal.DisplayName = hostResult.Structure as ST; } else if (s.LocalName == "translation") // Translation { var hostResult = Host.Parse(s, typeof(CD <String>)); result.Code = hostResult.Code; result.AddResultDetail(hostResult.Details); translations.Add(hostResult.Structure); } else if (s.NodeType == System.Xml.XmlNodeType.Element) { 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(); } } } // Translations if (!translations.IsEmpty) { if (retVal is ICodedEquivalents) { (retVal as ICodedEquivalents).Translation = translations; } else { result.AddResultDetail(new NotImplementedResultDetail(ResultDetailType.Warning, String.Format("Type does not support translations, '{0}' translations will not be included", translations.Count), s.ToString(), null)); } } } #endregion // Validate baseFormatter.Validate(retVal, s.ToString(), result); // Add validation to details return(retVal); }