Exemple #1
0
        /// <summary>
        /// Graph <paramref name="o"/> onto <paramref name="s"/>
        /// </summary>
        public void Graph(System.Xml.XmlWriter s, object o, DatatypeR2FormatterGraphResult result)
        {
            ANYFormatter baseFormatter = new ANYFormatter();

            baseFormatter.Host             = this.Host;
            baseFormatter.GenericArguments = this.GenericArguments;

            // Graph
            baseFormatter.Graph(s, o, result);

            // Instance
            IProbability instance = o as IProbability;

            if (instance.NullFlavor != null)
            {
                return;
            }

            // Graph UVP properties
            if (instance.Probability.HasValue)
            {
                s.WriteAttributeString("probability", Util.ToWireFormat(instance.Probability.Value));
            }

            // Value
            if (instance.Value != null)
            {
                s.WriteStartElement("value", "urn:hl7-org:v3");
                var hostResult = this.Host.Graph(s, instance.Value as IGraphable);
                result.AddResultDetail(hostResult.Details);
                s.WriteEndElement();
            }
        }
        /// <summary>
        /// Sets the specified probability value, discarding any previously assigned probability.
        /// </summary>
        /// <param name="probability">The probability to assign.</param>
        public virtual void Set(IProbability probability)
        {
            if (probability == null)
            {
                throw new ArgumentNullException(nameof(probability));
            }

            Value = probability.Value;
        }
        /// <summary>
        /// Determines whether the specified probability is larger than the current probability.
        /// </summary>
        /// <param name="probability">The probability to check.</param>
        /// <returns><c>true</c> if the specified probability is larger than the current probability; otherwise, <c>false</c>.</returns>
        /// <exception cref="ArgumentNullException">probability</exception>
        public virtual bool IsLarger(IProbability probability)
        {
            if (probability == null)
            {
                throw new ArgumentNullException(nameof(probability));
            }

            return(Value < probability.Value);
        }
Exemple #4
0
        /// <summary>
        /// Sets the specified probability value, discarding any previously assigned probability.
        /// </summary>
        /// <param name="probability">The probability to assign.</param>
        public override void Set(IProbability probability)
        {
            if (probability == null)
            {
                throw new ArgumentNullException(nameof(probability));
            }

            base.Set(probability.Log);
        }
        /// <summary>
        /// Sets the specified probability value, discarding any previously assigned probability, if the new probability is greater than the old one.
        /// </summary>
        /// <param name="probability">The probability to assign.</param>
        public virtual void SetIfLarger(IProbability probability)
        {
            if (probability == null)
            {
                throw new ArgumentNullException(nameof(probability));
            }

            if (Value < probability.Value)
            {
                Value = probability.Value;
            }
        }
Exemple #6
0
            public int CompareTo(object obj)
            {
                IProbability toCompare = (IProbability)obj;

                if (m_Probability < toCompare.Probability)
                {
                    return(-1);
                }
                if (m_Probability > toCompare.Probability)
                {
                    return(1);
                }
                else
                {
                    return(0);
                }
            }
Exemple #7
0
        /// <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);
        }
Exemple #8
0
 /// <summary>
 /// Determines whether the specified probability is larger than the current probability.
 /// </summary>
 /// <param name="probability">The probability to check.</param>
 /// <returns><c>true</c> if the specified probability is larger than the current probability; otherwise, <c>false</c>.</returns>
 /// <exception cref="ArgumentNullException">probability</exception>
 public override bool IsLarger(IProbability probability)
 {
     return(base.IsLarger(probability.Log));
 }