Exemplo n.º 1
0
        /// <summary>
        /// Graph <paramref name="o"/> onto <paramref name="s"/>
        /// </summary>
        /// <remarks>For some reason this type is not defined in the ISO Data types XSD</remarks>
        public void Graph(System.Xml.XmlWriter s, object o, DatatypeR2FormatterGraphResult result)
        {
            // Format the base
            ANYFormatter anyFormatter = new ANYFormatter();

            anyFormatter.Graph(s, o, result);

            // If null flavor is not
            if ((o as IAny).NullFlavor != null)
            {
                return;
            }

            // Get the property information
            Type   pivlType                  = o.GetType();
            object valueValue                = pivlType.GetProperty("Value").GetValue(o, null),
                   operatorValue             = pivlType.GetProperty("Operator").GetValue(o, null),
                   alignmentValue            = pivlType.GetProperty("Alignment").GetValue(o, null),
                   phaseValue                = pivlType.GetProperty("Phase").GetValue(o, null),
                   periodValue               = pivlType.GetProperty("Period").GetValue(o, null),
                   institutionSpecifiedValue = pivlType.GetProperty("InstitutionSpecified").GetValue(o, null),
                   countValue                = pivlType.GetProperty("Count").GetValue(o, null),
                   frequencyValue            = pivlType.GetProperty("Frequency").GetValue(o, null),
                   originalTextValue         = pivlType.GetProperty("OriginalText").GetValue(o, null);

            // Attributes
            if (institutionSpecifiedValue != null)
            {
                s.WriteAttributeString("isFlexible", institutionSpecifiedValue.ToString().ToLower());
            }
            if (alignmentValue != null)
            {
                s.WriteAttributeString("alignment", Util.ToWireFormat(alignmentValue));
            }
            if (countValue != null)
            {
                s.WriteAttributeString("count", Util.ToWireFormat(countValue));
            }
            if (operatorValue != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR2PropertyResultDetail(ResultDetailType.Warning, "Operator", "PIVL", s.ToString()));
            }
            if (valueValue != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR2PropertyResultDetail(ResultDetailType.Warning, "Value", "PIVL", s.ToString()));
            }

            // Original text
            if (originalTextValue != null)
            {
                s.WriteStartElement("originalText", "urn:hl7-org:v3");
                var hostResult = this.Host.Graph(s, originalTextValue as IGraphable);
                result.Code = hostResult.Code;
                result.AddResultDetail(result.Details);
                s.WriteEndElement();
            }

            // Phase
            if (phaseValue != null)
            {
                s.WriteStartElement("phase", "urn:hl7-org:v3");
                var hostResult = this.Host.Graph(s, phaseValue as IGraphable);
                result.Code = hostResult.Code;
                result.AddResultDetail(result.Details);
                s.WriteEndElement();
            }

            // Frequency or period
            if (frequencyValue != null)
            {
                s.WriteStartElement("frequency", "urn:hl7-org:v3");
                var hostResult = this.Host.Graph(s, frequencyValue as IGraphable);
                result.Code = hostResult.Code;
                result.AddResultDetail(result.Details);
                s.WriteEndElement();
            }
            else if (periodValue != null)
            {
                s.WriteStartElement("period", "urn:hl7-org:v3");
                var hostResult = this.Host.Graph(s, periodValue as IGraphable);
                result.Code = hostResult.Code;
                result.AddResultDetail(result.Details);
                s.WriteEndElement();
                if (frequencyValue != null)
                {
                    result.AddResultDetail(new NotSupportedChoiceResultDetail(ResultDetailType.Warning, "'Period' and 'Frequency' specified, this is not permitted, either 'Period' xor 'Frequency' may be represented. Will only represent 'Period' property", s.ToString(), null));
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Graph <paramref name="o"/> onto <paramref name="s"/>
        /// </summary>
        public void Graph(System.Xml.XmlWriter s, object o, DatatypeR2FormatterGraphResult result)
        {
            // Format base attributes
            ANYFormatter baseFormatter = new ANYFormatter();

            baseFormatter.Graph(s, o, result);

            if ((o as ANY).NullFlavor != null)
            {
                return;                                // no need to continue formatting
            }
            // Get the values the formatter needs to represent in XML
            Type   ivlType           = o.GetType();
            object operatorValue     = ivlType.GetProperty("Operator").GetValue(o, null),
                   lowValue          = ivlType.GetProperty("Low").GetValue(o, null),
                   highValue         = ivlType.GetProperty("High").GetValue(o, null),
                   widthValue        = ivlType.GetProperty("Width").GetValue(o, null),
                   originalTextValue = ivlType.GetProperty("OriginalText").GetValue(o, null),
                   lowClosedValue    = ivlType.GetProperty("LowClosed").GetValue(o, null),
                   highClosedValue   = ivlType.GetProperty("HighClosed").GetValue(o, null),
                   valueValue        = ivlType.GetProperty("Value").GetValue(o, null);

            // Low / high closed
            if (lowClosedValue != null)
            {
                s.WriteAttributeString("lowClosed", Util.ToWireFormat(lowClosedValue));
            }
            if (highClosedValue != null)
            {
                s.WriteAttributeString("highClosed", Util.ToWireFormat(highClosedValue));
            }
            if (operatorValue != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR2PropertyResultDetail(ResultDetailType.Warning, "Operator", "IVL", s.ToString()));
            }

            // Original text
            if (originalTextValue != null)
            {
                s.WriteStartElement("originalText", "urn:hl7-org:v3");
                var hostResult = this.Host.Graph(s, originalTextValue as IGraphable);
                result.Code = hostResult.Code;
                result.AddResultDetail(hostResult.Details);
                s.WriteEndElement();
            }

            bool invalidCombo = false;

            // Valid combinations
            if (lowValue != null)
            {
                s.WriteStartElement("low", "urn:hl7-org:v3");

                // Low value XSI?
                if (lowValue.GetType() != GenericArguments[0])
                {
                    s.WriteAttributeString("xsi", "type", DatatypeR2Formatter.NS_XSI, DatatypeR2Formatter.CreateXSITypeName(lowValue.GetType()));
                }

                var hostResult = this.Host.Graph(s, lowValue as IGraphable);
                result.Code = hostResult.Code;
                result.AddResultDetail(hostResult.Details);
                s.WriteEndElement();
                if (highValue != null)
                {
                    s.WriteStartElement("high", "urn:hl7-org:v3");

                    if (highValue.GetType() != GenericArguments[0])
                    {
                        s.WriteAttributeString("xsi", "type", DatatypeR2Formatter.NS_XSI, DatatypeR2Formatter.CreateXSITypeName(highValue.GetType()));
                    }

                    hostResult  = this.Host.Graph(s, highValue as IGraphable);
                    result.Code = hostResult.Code;
                    result.AddResultDetail(hostResult.Details);
                    s.WriteEndElement();
                }
                invalidCombo |= valueValue != null || widthValue != null;
            }
            else if (highValue != null)
            {
                s.WriteStartElement("high", "urn:hl7-org:v3");

                // High value XSI
                if (highValue.GetType() != GenericArguments[0])
                {
                    s.WriteAttributeString("xsi", "type", DatatypeR2Formatter.NS_XSI, DatatypeR2Formatter.CreateXSITypeName(highValue.GetType()));
                }

                var hostResult = this.Host.Graph(s, highValue as IGraphable);
                result.Code = hostResult.Code;
                result.AddResultDetail(hostResult.Details);
                s.WriteEndElement();
                invalidCombo |= valueValue != null || widthValue != null;
            }
            if (widthValue != null && ((lowValue == null) ^ (highValue == null) || lowValue == null && highValue == null))
            {
                s.WriteStartElement("width", "urn:hl7-org:v3");
                var hostResult = this.Host.Graph(s, widthValue as IGraphable);
                result.Code = hostResult.Code;
                result.AddResultDetail(hostResult.Details);
                s.WriteEndElement();
                if (valueValue != null)
                {
                    s.WriteStartElement("any", "urn:hl7-org:v3");

                    // Value value xsi type
                    if (valueValue.GetType() != GenericArguments[0])
                    {
                        s.WriteAttributeString("xsi", "type", DatatypeR2Formatter.NS_XSI, DatatypeR2Formatter.CreateXSITypeName(valueValue.GetType()));
                    }

                    hostResult  = this.Host.Graph(s, valueValue as IGraphable);
                    result.Code = hostResult.Code;
                    result.AddResultDetail(hostResult.Details);
                    s.WriteEndElement();
                }
                invalidCombo |= lowValue != null || highValue != null;
            }
            else if (valueValue != null)
            {
                s.WriteStartElement("any", "urn:hl7-org:v3");

                // Value value xsi type
                if (valueValue.GetType() != GenericArguments[0])
                {
                    s.WriteAttributeString("xsi", "type", DatatypeR2Formatter.NS_XSI, DatatypeR2Formatter.CreateXSITypeName(valueValue.GetType()));
                }

                var hostResult = this.Host.Graph(s, valueValue as IGraphable);
                result.Code = hostResult.Code;
                result.AddResultDetail(hostResult.Details);
                s.WriteEndElement();
                invalidCombo |= lowValue != null || highValue != null;
            }
            else
            {
                invalidCombo = true;
            }

            // Invalid combination, warn
            if (invalidCombo)
            {
                result.AddResultDetail(new NotSupportedChoiceResultDetail(ResultDetailType.Warning, "This IVL is not conformant to the ISO21090 data types specification. Only 'Value' and/or 'Width', or 'Low' and/or 'High' are permitted. All data has been serialized but may not be interpreted by a remote system", s.ToString(), null));
            }
        }
Exemplo n.º 3
0
        public override void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            // Get the values the formatter needs to represent in XML
            Type   ivlType           = o.GetType();
            object operatorValue     = ivlType.GetProperty("Operator").GetValue(o, null),
                   lowValue          = ivlType.GetProperty("Low").GetValue(o, null),
                   highValue         = ivlType.GetProperty("High").GetValue(o, null),
                   widthValue        = ivlType.GetProperty("Width").GetValue(o, null),
                   originalTextValue = ivlType.GetProperty("OriginalText").GetValue(o, null),
                   lowClosedValue    = ivlType.GetProperty("LowClosed").GetValue(o, null),
                   highClosedValue   = ivlType.GetProperty("HighClosed").GetValue(o, null),
                   valueValue        = ivlType.GetProperty("Value").GetValue(o, null),
                   centerValue       = ivlType.GetProperty("Center").GetValue(o, null);

            // Warn the developer if there are any properties that can't be represented in R1
            if (originalTextValue != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "OriginalText", "IVL", s.ToString()));
            }
            if (lowClosedValue != null || highClosedValue != null)
            {
                result.AddResultDetail(new ResultDetail(ResultDetailType.Warning,
                                                        "The properties 'LowClosed' and 'HighClosed' will be used as low/@inclusive and high/@inclusive attributes for R1 formatting", s.ToString(), null));
            }


            // Representations of the IVL type
            if ((o as ANY).NullFlavor != null)
            {
                base.Graph(s, o, result); // Nullflavor so the formatter doesn't format anything more than base
                return;
            }

            // Output operator
            //if (operatorValue != null)
            //    s.WriteAttributeString("operator", Util.ToWireFormat(operatorValue));

            // Graph base attribute(s)
            base.Graph(s, o, result);

            if (valueValue != null)
            {
                result.AddResultDetail(new NotSupportedChoiceResultDetail(
                                           ResultDetailType.Warning, "Though XML ITS supports it, use of the IVL 'value' attribute should be avoided. The data has been serialized but may be uninterpretable by anoher system.", s.ToString(), null));
                //DOC: Further documentation required.
            }
            if (lowValue != null && highValue != null) // low & high
            {
                // low
                if (lowClosedValue != null)
                {
                    result.AddResultDetail(this.WriteValueAsElement(s, "low", (IGraphable)lowValue, this.GenericArguments[0], new KeyValuePair <String, String>("inclusive", Util.ToWireFormat(lowClosedValue))).Details);
                }
                else
                {
                    result.AddResultDetail(this.WriteValueAsElement(s, "low", (IGraphable)lowValue, this.GenericArguments[0]).Details);
                }

                // high
                if (highClosedValue != null)
                {
                    result.AddResultDetail(this.WriteValueAsElement(s, "high", (IGraphable)highValue, this.GenericArguments[0], new KeyValuePair <String, String>("inclusive", Util.ToWireFormat(highClosedValue))).Details);
                }
                else
                {
                    result.AddResultDetail(this.WriteValueAsElement(s, "high", (IGraphable)highValue, this.GenericArguments[0]).Details);
                }


                #region Warnings
                if (valueValue != null)
                {
                    result.AddResultDetail(new ResultDetail(ResultDetailType.Warning,
                                                            "low, high, value can't be represented together in an IVL data type in R1. The data has been formatted but may be invalid", s.ToString(), null));
                }
                if (widthValue != null)
                {
                    result.AddResultDetail(new ResultDetail(ResultDetailType.Warning,
                                                            "low, high, width can't be represented together in an IVL data type in R1. The data has been formatted but may be invalid", s.ToString(), null));
                }
                if (centerValue != null)
                {
                    result.AddResultDetail(new ResultDetail(ResultDetailType.Warning,
                                                            "low, high, center can't be represented together in an IVL data type in R1. The data has been formatted but may be invalid", s.ToString(), null));
                }

                #endregion
            }
            else if (lowValue != null && widthValue != null) // Low & width
            {
                // low
                if (lowClosedValue != null)
                {
                    result.AddResultDetail(this.WriteValueAsElement(s, "low", (IGraphable)lowValue, this.GenericArguments[0], new KeyValuePair <String, String>("inclusive", Util.ToWireFormat(lowClosedValue))).Details);
                }
                else
                {
                    result.AddResultDetail(this.WriteValueAsElement(s, "low", (IGraphable)lowValue, this.GenericArguments[0]).Details);
                }

                result.AddResultDetail(this.WriteValueAsElement(s, "width", (IGraphable)widthValue, typeof(PQ)).Details);

                #region Warnings
                if (valueValue != null)
                {
                    result.AddResultDetail(new ResultDetail(ResultDetailType.Warning,
                                                            "low, width, value can't be represented together in an IVL data type in R1. The data has been formatted but may be invalid", s.ToString(), null));
                }
                if (highValue != null)
                {
                    result.AddResultDetail(new ResultDetail(ResultDetailType.Warning,
                                                            "low, width, high can't be represented together in an IVL data type in R1. The data has been formatted but may be invalid", s.ToString(), null));
                }
                if (centerValue != null)
                {
                    result.AddResultDetail(new ResultDetail(ResultDetailType.Warning,
                                                            "low, width, center can't be represented together in an IVL data type in R1. The data has been formatted but may be invalid", s.ToString(), null));
                }

                #endregion
            }
            else if (highValue != null && widthValue != null) // high & width
            {
                result.AddResultDetail(this.WriteValueAsElement(s, "width", (IGraphable)widthValue, typeof(PQ)).Details);

                // high
                if (highClosedValue != null)
                {
                    result.AddResultDetail(this.WriteValueAsElement(s, "high", (IGraphable)highValue, this.GenericArguments[0], new KeyValuePair <String, String>("inclusive", Util.ToWireFormat(highClosedValue))).Details);
                }
                else
                {
                    result.AddResultDetail(this.WriteValueAsElement(s, "high", (IGraphable)highValue, this.GenericArguments[0]).Details);
                }


                #region Warnings
                if (valueValue != null)
                {
                    result.AddResultDetail(new ResultDetail(ResultDetailType.Warning,
                                                            "high, width, value can't be represented together in an IVL data type in R1. The data has been formatted but may be invalid", s.ToString(), null));
                }
                if (lowValue != null)
                {
                    result.AddResultDetail(new ResultDetail(ResultDetailType.Warning,
                                                            "high, width, low can't be represented together in an IVL data type in R1. The data has been formatted but may be invalid", s.ToString(), null));
                }
                if (centerValue != null)
                {
                    result.AddResultDetail(new ResultDetail(ResultDetailType.Warning,
                                                            "high, width, center can't be represented together in an IVL data type in R1. The data has been formatted but may be invalid", s.ToString(), null));
                }
                #endregion
            }
            else if (centerValue != null && widthValue != null)
            {
                // center
                result.AddResultDetail(this.WriteValueAsElement(s, "center", (IGraphable)centerValue, this.GenericArguments[0]).Details);
                result.AddResultDetail(this.WriteValueAsElement(s, "width", (IGraphable)widthValue, typeof(PQ)).Details);

                #region Warnings
                if (valueValue != null)
                {
                    result.AddResultDetail(new ResultDetail(ResultDetailType.Warning,
                                                            "center, width, value can't be represented together in an IVL data type in R1. The data has been formatted but may be invalid", s.ToString(), null));
                }
                if (lowValue != null)
                {
                    result.AddResultDetail(new ResultDetail(ResultDetailType.Warning,
                                                            "center, width, low can't be represented together in an IVL data type in R1. The data has been formatted but may be invalid", s.ToString(), null));
                }
                if (highValue != null)
                {
                    result.AddResultDetail(new ResultDetail(ResultDetailType.Warning,
                                                            "center, width, high can't be represented together in an IVL data type in R1. The data has been formatted but may be invalid", s.ToString(), null));
                }
                #endregion
            }
            else if (lowValue != null) // low only
            {
                // low
                if (lowClosedValue != null)
                {
                    result.AddResultDetail(this.WriteValueAsElement(s, "low", (IGraphable)lowValue, this.GenericArguments[0], new KeyValuePair <String, String>("inclusive", Util.ToWireFormat(lowClosedValue))).Details);
                }
                else
                {
                    result.AddResultDetail(this.WriteValueAsElement(s, "low", (IGraphable)lowValue, this.GenericArguments[0]).Details);
                }

                if (valueValue != null)
                {
                    result.AddResultDetail(new ResultDetail(ResultDetailType.Warning, "low and value can't be represented in an IVL data type in R1. The data has been formatted but may be invalid", s.ToString(), null));
                }
            }
            else if (highValue != null) // High only
            {
                // high
                if (highClosedValue != null)
                {
                    result.AddResultDetail(this.WriteValueAsElement(s, "high", (IGraphable)highValue, this.GenericArguments[0], new KeyValuePair <String, String>("inclusive", Util.ToWireFormat(highClosedValue))).Details);
                }
                else
                {
                    result.AddResultDetail(this.WriteValueAsElement(s, "high", (IGraphable)highValue, this.GenericArguments[0]).Details);
                }

                if (valueValue != null)
                {
                    result.AddResultDetail(new ResultDetail(ResultDetailType.Warning, "high and value can't be represented in an IVL data type in R1. The data has been formatted but may be invalid", s.ToString(), null));
                }
            }
            else if (centerValue != null) // High only
            {
                // center
                result.AddResultDetail(this.WriteValueAsElement(s, "center", (IGraphable)centerValue, this.GenericArguments[0]).Details);

                if (valueValue != null)
                {
                    result.AddResultDetail(new ResultDetail(ResultDetailType.Warning, "center and value can't be represented in an IVL data type in R1. The data has been formatted but may be invalid", s.ToString(), null));
                }
            }
            else if (widthValue != null) // width only
            {
                result.AddResultDetail(this.WriteValueAsElement(s, "width", (IGraphable)widthValue, typeof(PQ)).Details);

                if (valueValue != null)
                {
                    result.AddResultDetail(new ResultDetail(ResultDetailType.Warning, "width and value can't be represented together in an IVL data type in R1. The data has been formatted but may be invalid", s.ToString(), null));
                }
            }
            else if (valueValue != null)
            {
                ;
            }
            // No need for this ;
            else
            {
                result.AddResultDetail(new ResultDetail(ResultDetailType.Error,
                                                        "Can't create a valid representation of IVL using the supplied data for data types R1. Valid IVL must have [low & [high | width]] | [high & width] | [center & width] | high | value to satisfy data type R1 constraints",
                                                        s.ToString(), null));
            }
        }
Exemplo n.º 4
0
        public void Graph(XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            II instance = o as II;

            // Base graph
            base.Graph(s, o as ANY, result);

            // Handle II graphing
            if (instance.IsNull)
                return;
            if(instance.Root != null) // root
                s.WriteAttributeString("root", instance.Root);
            if (instance.Extension != null) // extension
                s.WriteAttributeString("extension", instance.Extension);
            if (instance.AssigningAuthorityName != null) // assigning authority
                s.WriteAttributeString("assigningAuthorityName", instance.AssigningAuthorityName);
            
            if(instance.Displayable != null)
                s.WriteAttributeString("displayable", instance.Displayable.ToString().ToLower());

            // JF - Use is not permitted
            if (instance.Scope != null && instance.Scope.HasValue)
            {
                if (result.CompatibilityMode == DatatypeFormatterCompatibilityMode.Canadian)
                    switch (instance.Scope.Value)
                    {
                        case IdentifierScope.VersionIdentifier:
                            s.WriteAttributeString("use", "VER");
                            break;
                        case IdentifierScope.BusinessIdentifier:
                            s.WriteAttributeString("use", "BUS");
                            break;
                        default:
                            result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Scope", "II", s.ToString()));
                            break;
                    }
                else
                    result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Scope", "II", s.ToString()));
            }

            // Non supported features
            if (instance.IdentifierName != null)
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "IdentifierName", "II", s.ToString()));
            if(instance.Reliability != null)
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Reliability", "II", s.ToString()));

        }
Exemplo n.º 5
0
        /// <summary>
        /// Graphs object <paramref name="o"/> onto <paramref name="s"/>
        /// </summary>
        /// <param name="s">The stream to graph to</param>
        /// <param name="o">The object to graph</param>
        /// <returns>A formatter graphing result</returns>
        public IFormatterGraphResult Graph(XmlWriter s, IGraphable o)
        {
            if (o == null)
                return new DatatypeFormatterGraphResult(this.CompatibilityMode, ResultCode.Accepted, null, this.ValidateConformance);

            try
            {
                IDatatypeFormatter formatter = GetFormatter(o.GetType());

                if (formatter == null)
                    return new DatatypeFormatterGraphResult(this.CompatibilityMode, ResultCode.NotAvailable, new IResultDetail[] {
                        new NotImplementedResultDetail(ResultDetailType.Error, String.Format("Could not find formatter for '{0}'", o.GetType().FullName), null)
                    }, this.ValidateConformance);

                // Set the host
                formatter.Host = (IXmlStructureFormatter)(this.Host ?? this);

                var result = new DatatypeFormatterGraphResult(this.CompatibilityMode, ResultCode.Accepted, null, this.ValidateConformance);

                formatter.Graph(s, o, result);

                return result;
            }
            catch (Exception e)
            {
                return new DatatypeFormatterGraphResult(this.CompatibilityMode, ResultCode.Error, new IResultDetail[] {
                    new ResultDetail(ResultDetailType.Error, e.Message, s.ToString(), e)
                }, this.ValidateConformance);
            }
        }
Exemplo n.º 6
0
        public string build_xml(XmlWriter xmlWriter)
        {

            return xmlWriter.ToString();
        }
Exemplo n.º 7
0
        /// <summary>
        /// Graphs <paramref name="o"/> onto the <see cref="T:System.Xml.XmlWriter"/> <paramref name="s"/>
        /// </summary>
        /// <param name="s">The <see cref="T:System.Xml.XmlWriter"/> that should be used to graph the object</param>
        /// <param name="o">The <see cref="T:MARC.Everest.Interfaces.IGraphable"/> that should be graphed</param>
        /// <returns>A <see cref="T:MARC.Everest.Formatters.XML.ITS1.Its1FormatterGraphResult"/> containing the results of the graph</returns>
        /// <remarks>
        /// <para>
        /// This particular overload of the Graph method can be used to graph objects into a <see cref="T:System.Xml.XmlWriter"/> and can provide
        /// an opportunity to use Everest as an assistant (or XmlSerializerSurrogate) for more complex systems like WCF.
        /// </para>
        /// <example>
        /// <code lang="cs" title="Using Everest as a Serializer Assistant">
        /// <![CDATA[
        /// StringWriter sw = new StringWriter();
        /// XmlWriter writer = XmlWriter.Create(sw);
        /// writer.WriteStartElement("hello", "urn:my-org");
        /// 
        /// Formatter f = new Formatter();
        /// f.GraphAides.Add(typeof(MARC.Everest.Formatters.XML.DataTypes.R1.Formatter));
        /// f.ValidateConformance = false;
        /// f.Graph(writer, new MCCI_IN000002CA());
        /// 
        /// writer.WriteEndElement();
        /// writer.Close();
        /// Console.WriteLine(sw.ToString());
        /// 
        /// ]]>
        /// </code>
        /// outputs
        /// <code lang="xml" title="Output of example">
        /// <![CDATA[
        /// <hello xmlns="urn:my-org">
        ///     <MCCI_IN000002CA xmlns="urn:hl7-org:v3"/>
        /// </hello>
        /// ]]>
        /// </code>
        /// </example>
        /// <para>
        /// When using this method, it is recommended that you pass a <see cref="T:MARC.Everest.Xml.XmlStateWriter"/> as it 
        /// will allow the formatter to give additional location information when reporting issues.
        /// </para>
        /// </remarks>
        public IFormatterGraphResult Graph(XmlWriter s, IGraphable o)
        {
            ThrowIfDisposed();

            var resultContext = new XmlIts1FormatterGraphResult(ResultCode.Accepted, null);

            IGraphable context = null;
            // Clear out result cache
            if (s.WriteState == WriteState.Start || String.IsNullOrEmpty(s.ToString()) || o is IInteraction)
                context = o;

            if (!(s is XmlStateWriter))
                s = new XmlStateWriter(s);

            if (o == null)
                resultContext.Code = ResultCode.AcceptedNonConformant;
            else
            {
                GraphObject(s, o, o.GetType(), context, resultContext);
                resultContext.Code = CalculateResultCode(resultContext.Details);
            }

            return resultContext;
        }
Exemplo n.º 8
0
        public void ValidateHelper(XmlWriter s, IGraphable o, ITypeFormatter formatter, XmlIts1FormatterGraphResult resultContext)
        {
            IResultDetail[] details = null;

            if (ValidateConformance && (!formatter.Validate(o, s.ToString(), out details)))
                resultContext.AddResultDetail(details.Length > 0 ? details : new IResultDetail[] { new DatatypeValidationResultDetail(ValidateConformance ? ResultDetailType.Error : ResultDetailType.Warning, o.GetType().ToString(), s.ToString()) });
        }
Exemplo n.º 9
0
        protected virtual void GraphObject(XmlWriter s, IGraphable o, Type useType, IGraphable context, XmlIts1FormatterGraphResult resultContext)
        {

            // Find the HL7 alias for the type and build the cache for the type
            string typeName = GetStructureName(useType);

            // Find a helper
            IXmlStructureFormatter ixsf = (IXmlStructureFormatter)this.GraphAides.Find(t => t.HandleStructure.Contains(typeName));

            // Does the helper graph aide have a handler?
            if (ixsf != null)
            {
                ixsf.Host = this;
                var rv = ixsf.Graph(s, o);

                resultContext.AddResultDetail(rv.Details);

                return;
            }

#if WINDOWS_PHONE
            ITypeFormatter formatter = m_codeGeneratorFormatter.GetFormatter(useType);
            if (formatter == null)
                formatter = new ReflectFormatter();
#else
            ITypeFormatter formatter = m_codeGeneratorFormatter.GetFormatter(useType);
            // Is there a formatter and if there is not a formatter 
            // can we create one?
            if (formatter == null && (Settings & SettingsType.UseGeneratorFormat) == SettingsType.UseGeneratorFormat)
                s_threadPool.QueueUserWorkItem((WaitCallback)delegate(object state)
                {
                    BuildCache(new Type[] { (Type)state });
                }, useType);
            // If there is no connector can we use reflection?
            if (formatter == null && (Settings & SettingsType.UseReflectionFormat) == SettingsType.UseReflectionFormat)
                formatter = new ReflectFormatter();
            else if (formatter == null && (Settings & SettingsType.UseGeneratorFormat) == SettingsType.UseGeneratorFormat)
            {
                s_threadPool.WaitOne();
                formatter = m_codeGeneratorFormatter.GetFormatter(useType);
            }
#endif
            if(formatter == null)
                throw new InvalidOperationException(string.Format("Couldn't format '{0}' at {1}, verify formatter settings!", useType.FullName, s.ToString()));

            // Validate the instance
            formatter.Host = this;
            
            // Graph using helper
            formatter.Graph(s, o, context, resultContext);

        }