Ejemplo n.º 1
0
        /// <summary>
        /// Parse the string
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Temporary holding value for value
            string tValue = null;
            if (s.GetAttribute("value") != null)
                tValue = s.GetAttribute("value");

            // Parse the CD stuff
            CDFormatter baseFormatter = new CDFormatter();
            baseFormatter.Host = this.Host;
            var retVal = baseFormatter.Parse<PQR>(s, result);

            // Interpret the value
            // If the value was interpreted
            if (!String.IsNullOrEmpty(tValue))
            {
                try
                {
                    retVal.Value = Util.Convert<decimal>(tValue);
                    if (tValue.Contains("."))
                        retVal.Precision = tValue.Length - tValue.IndexOf(".") - 1;
                }
                catch (Exception e)
                {
                    result.Code = ResultCode.Error;
                    result.AddResultDetail(new ResultDetail(ResultDetailType.Error, e.Message, s.ToString(), e));
                }
            }

            // Validate
            new ANYFormatter().Validate(retVal, s.ToString(), result);

            return retVal;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Graph <paramref name="o"/> onto <paramref name="s"/>
        /// </summary>
        public void Graph(System.Xml.XmlWriter s, object o, DatatypeR2FormatterGraphResult result)
        {

            var any = o as IAny;
            // Output flavor id
            if(any.Flavor == null && (any.NullFlavor == null || ((NullFlavor)any.NullFlavor).IsChildConcept(NullFlavor.Other)))
                s.WriteAttributeString("flavorId", "CD.CV");

            // Do a base format
            CDFormatter realFormatter = new CDFormatter();
            realFormatter.Host = this.Host;
            realFormatter.Graph(s, o, result);

        }
Ejemplo n.º 3
0
        /// <summary>
        /// Parse a CE instance from <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            CDFormatter realFormatter = new CDFormatter();

            if (String.IsNullOrEmpty(s.GetAttribute("flavorId")) ||
                s.GetAttribute("flavorId") != "CD.CE")
                result.AddResultDetail(new FixedValueMisMatchedResultDetail(s.GetAttribute("flavorId"), "CD.CE", s.ToString()));

            realFormatter.Host = this.Host;
            var retVal = realFormatter.Parse<CE<String>>(s, result);

            retVal.Flavor = null;

            return retVal;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Graph <paramref name="o"/> onto <paramref name="s"/> saving
        /// results in <paramref name="result"/>
        /// </summary>
        public void Graph(System.Xml.XmlWriter s, object o, DatatypeR2FormatterGraphResult result)
        {
            // Base formatter is the CD type
            CDFormatter baseFormatter = new CDFormatter();
            baseFormatter.Host = this.Host;

            // Graph the value if the null flavor of the object is not null
            PQR opqr = o as PQR;
            if (opqr.NullFlavor == null && opqr.Value.HasValue)
            {
                // Precision
                if (opqr.Precision == null)
                    s.WriteAttributeString("value", Util.ToWireFormat(opqr.Value));
                else
                    s.WriteAttributeString("value", String.Format(String.Format("{{0:0.{0}}}", new String('0', opqr.Precision)), opqr.Value));
            }

            // Graph the base stuff
            baseFormatter.Graph(s, o, result);
        }
Ejemplo n.º 5
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;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Graph object <paramref name="o"/> onto stream <paramref name="s"/>
        /// </summary>
        /// <param name="s">The stream to graph to</param>
        /// <param name="o">The object to graph</param>
        public void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            ANYFormatter baseFormatter = new ANYFormatter();
            baseFormatter.Graph(s, o, result); // Graph the base data

            // If there is no null flavor then graph the rest of the object

            object invertedValue = o.GetType().GetProperty("Inverted").GetValue(o, null),
                nameValue = o.GetType().GetProperty("Name").GetValue(o, null),
                valueValue = o.GetType().GetProperty("Value").GetValue(o, null);

            // Graph the structural attributes
            s.WriteAttributeString("inverted", Util.ToWireFormat(invertedValue));

            // Graph the non-structural elements
            if (nameValue != null)
            {
                s.WriteStartElement("name");
                CVFormatter cdFormatter = new CVFormatter();
                cdFormatter.Host = this.Host;
                cdFormatter.GenericArguments = this.GenericArguments;
                cdFormatter.Graph(s, nameValue, result);
                s.WriteEndElement(); // end name
            }
            if (valueValue != null)
            {
                s.WriteStartElement("value");
                CDFormatter cdFormatter = new CDFormatter();
                cdFormatter.Host = this.Host;
                cdFormatter.GenericArguments = this.GenericArguments;
                cdFormatter.Graph(s, valueValue, result);
                s.WriteEndElement(); // end value
            }
        }