//DOC: Describe the formatter parameter. /// <summary> /// Create a new instance of the XmlSerializationSurrogate. /// </summary> /// <param name="formatter"></param> public XmlSerializerSurrogate(IXmlStructureFormatter formatter) { this.Formatter = formatter; }
/// <summary> /// Constructs a new instance of the Everest Serializer operation behavior /// </summary> public EverestSerializerOperationBehavior(OperationDescription operation, IXmlStructureFormatter formatter) : base(operation) { // TODO: Complete member initialization this.m_formatter = formatter; }
public void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result) { ANYFormatter baseFormatter = new ANYFormatter(); baseFormatter.Graph(s, o, result); // Since this is a generic type, we'll need to get the values we're interested in // for the formatting operation Type oType = o.GetType(); object numerator = oType.GetProperty("Numerator").GetValue(o, null), denominator = oType.GetProperty("Denominator").GetValue(o, null); // Check for the QTY members QTY <Nullable <Double> > qtyPortion = o as QTY <Nullable <Double> >; // Check for non-representable properties if (qtyPortion.Expression != null) { result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Expression", "RTO", s.ToString())); } if (qtyPortion.OriginalText != null) { result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "OriginalText", "RTO", s.ToString())); } if (qtyPortion.Uncertainty != null) { result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Uncertainty", "RTO", s.ToString())); } if (qtyPortion.UncertaintyType != null) { result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "UncertaintyType", "RTO", s.ToString())); } if (qtyPortion.UncertainRange != null) { result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "UncertainRange", "RTO", s.ToString())); } if (qtyPortion.Value != null) { result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Value", "RTO", s.ToString())); } IXmlStructureFormatter serFormatter = Host; // Serialize the data-type if (numerator != null) { s.WriteStartElement("numerator", "urn:hl7-org:v3"); // Write the XSI type string xsiTypeName = Util.CreateXSITypeName(numerator.GetType()); // Write the type if (this.Host.Host == null) { s.WriteAttributeString("type", DatatypeFormatter.NS_XSI, xsiTypeName.ToString()); } else { s.WriteAttributeString("xsi", "type", DatatypeFormatter.NS_XSI, xsiTypeName.ToString()); } var hostResult = serFormatter.Graph(s, (IGraphable)numerator); result.Code = hostResult.Code; result.AddResultDetail(hostResult.Details); s.WriteEndElement(); } if (denominator != null) { s.WriteStartElement("denominator", "urn:hl7-org:v3"); // Write the XSI type string xsiTypeName = Util.CreateXSITypeName(denominator.GetType()); // Write the type if (this.Host.Host == null) { s.WriteAttributeString("type", DatatypeFormatter.NS_XSI, xsiTypeName.ToString()); } else { s.WriteAttributeString("xsi", "type", DatatypeFormatter.NS_XSI, xsiTypeName.ToString()); } var hostResult = serFormatter.Graph(s, (IGraphable)denominator); result.Code = hostResult.Code; result.AddResultDetail(hostResult.Details); s.WriteEndElement(); } // Append details //details.AddRange(serFormatter.Details); }
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); }
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); }
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); }