/// <summary> /// Converts a minimum or maximum value received from the provider. /// </summary> /// <param name="value">The value to convert</param> /// <param name="formula">The formula string as returned by the ProviderToConsumer /// property of class EmberLib.Glow.GlowFormulaSource. Pass null if not present.</param> /// <param name="factor">A factor used to convert integer value into fixed-point /// real values as defined by the "factor" field of EmberPlus-Glow.ParameterContents.</param> /// <param name="log">A callback function invoked to log formula compilation errors.</param> /// <returns>The converted value.</returns> /// <remarks>This method caches formula compilation results in a global cache. This method is thread-safe.</remarks> public GlowMinMax Convert(GlowMinMax value, string formula, int?factor, Action <string> log = null) { if (String.IsNullOrEmpty(formula) == false) { if (value.Type == GlowParameterType.Integer || value.Type == GlowParameterType.Real) { var result = ValueConversion.CompileFormula(formula, log); if (result.Success) { if (value.Type == GlowParameterType.Integer) { value = result.Formula.Eval(value.Integer); } else { value = result.Formula.Eval(value.Real); } } } } else { if (factor != null && value.Type == GlowParameterType.Integer) { value = new GlowMinMax(value.Integer / (double)factor.Value); } } return(value); }
GlowMinMax ConvertMinMax(XElement xml) { var type = ConvertParameterType(xml.Attribute("type").Value); if (type == GlowParameterType.Integer || type == GlowParameterType.Real) { GlowMinMax value; if (GlowMinMax.TryParse(xml.Value, type.Value, CultureInfo.InvariantCulture, out value)) { return(value); } } return(null); }
void ConvertMinMax(string elementName, GlowMinMax value, XmlWriter writer) { var typeStr = null as string; switch (value.Type) { case GlowParameterType.Integer: typeStr = "INTEGER"; break; case GlowParameterType.Real: typeStr = "REAL"; break; } if (typeStr != null) { writer.WriteStartElement(elementName); writer.WriteAttributeString("type", typeStr); writer.WriteString(value.ToString(CultureInfo.InvariantCulture)); writer.WriteEndElement(); } }
/// <summary> /// Converts a minimum or maximum value received from the provider. /// </summary> /// <param name="value">The value to convert</param> /// <param name="formula">The formula string as returned by the ProviderToConsumer /// property of class EmberLib.Glow.GlowFormulaSource. Pass null if not present.</param> /// <param name="factor">A factor used to convert integer value into fixed-point /// real values as defined by the "factor" field of EmberPlus-Glow.ParameterContents.</param> /// <param name="log">A callback function invoked to log formula compilation errors.</param> /// <returns>The converted value.</returns> /// <remarks>This method caches formula compilation results in a global cache. This method is thread-safe.</remarks> public GlowMinMax Convert(GlowMinMax value, string formula, int? factor, Action<string> log = null) { if(String.IsNullOrEmpty(formula) == false) { if(value.Type == GlowParameterType.Integer || value.Type == GlowParameterType.Real) { var result = ValueConversion.CompileFormula(formula, log); if(result.Success) { if(value.Type == GlowParameterType.Integer) value = result.Formula.Eval(value.Integer); else value = result.Formula.Eval(value.Real); } } } else { if(factor != null && value.Type == GlowParameterType.Integer) value = new GlowMinMax(value.Integer / (double)factor.Value); } return value; }