private void ReadBaseUnits(SystemOfUnits system) { foreach (XPathNavigator n in navigator.Select("u:root/base-unit", ns)) { string name = n.SelectSingleNode("name").ToString(); string dimension = n.SelectSingleNode("property").ToString(); string symbol = n.SelectSingleNode("@Code").ToString(); system.AddUnit(name, symbol, dimension); } }
public SystemOfUnits Read() { SystemOfUnits system = new SystemOfUnits(); //ReadConstants(system); ReadPrefixes(system); ReadBaseUnits(system); ReadUnits(system); ReadConversions(system); return(system); }
public void AddConversion(SystemOfUnits system, string from, string formula, Exponential number) { Metric metricfrom = system.Metrics.ParseMetric(from); Metric metricto = system.Metrics.ParseMetric(Parser.ToUnaryTokens(formula).NonNumerics()); if ((metricfrom != null) && (metricto != null)) { ConversionMethod method = BuildConversion(formula, number); system.Conversions.Add(metricfrom, metricto, method); } }
private void ReadPrefixes(SystemOfUnits system) { foreach (XPathNavigator n in navigator.Select("u:root/prefix", ns)) { string name = n.SelectSingleNode("name").ToString(); string s = n.SelectSingleNode("value/@value").ToString(); Exponential factor = Exponential.Exact(s); //string symbol = n.SelectSingleNode("printSymbol").ToString(); string symbol = n.SelectSingleNode("@Code").ToString(); system.AddPrefix(name, symbol, factor); } }
private void ReadPrefixes(SystemOfUnits system) { foreach(XPathNavigator n in navigator.Select("u:root/prefix", ns)) { string name = n.SelectSingleNode("name").ToString(); string s = n.SelectSingleNode("value/@value").ToString(); Exponential factor = Exponential.Exact(s); //string symbol = n.SelectSingleNode("printSymbol").ToString(); string symbol = n.SelectSingleNode("@Code").ToString(); system.AddPrefix(name, symbol, factor); } }
private void ReadUnits(SystemOfUnits system) { foreach (XPathNavigator n in navigator.Select("u:root/unit", ns)) { string name = n.SelectSingleNode("name").ToString(); string classification = n.SelectSingleNode("@class", ns).ToString(); string symbol = n.SelectSingleNode("@Code").ToString(); //if (classification != "dimless") { system.AddUnit(name, symbol); } } }
public void ReadConversions(SystemOfUnits system) { foreach (XPathNavigator n in navigator.Select("u:root/unit", ns)) { string from = n.SelectSingleNode("@Code").ToString(); string formula = n.SelectSingleNode("value/@Unit").ToString(); try { string value = n.SelectSingleNode("value/@value").ToString(); if (value.Length > 16) { value = value.Substring(0, 16); } Exponential number = Exponential.Exact(value); AddConversion(system, from, formula, number); } catch { } } }
public static void Init(TestContext context) { system = UCUM.Load(); }
public SystemOfUnits Read() { SystemOfUnits system = new SystemOfUnits(); //ReadConstants(system); ReadPrefixes(system); ReadBaseUnits(system); ReadUnits(system); ReadConversions(system); return system; }
public void ReadConversions(SystemOfUnits system) { foreach (XPathNavigator n in navigator.Select("u:root/unit", ns)) { string from = n.SelectSingleNode("@Code").ToString(); string formula = n.SelectSingleNode("value/@Unit").ToString(); try { string value = n.SelectSingleNode("value/@value").ToString(); if (value.Length > 16) value = value.Substring(0, 16); Exponential number = Exponential.Exact(value); AddConversion(system, from, formula, number); } catch { } } }
public void AddConversion(SystemOfUnits system, string from, string formula, Exponential number) { Metric metricfrom = system.Metrics.ParseMetric(from); Metric metricto = system.Metrics.ParseMetric(Parser.ToUnaryTokens(formula).NonNumerics()); if ( (metricfrom != null) && (metricto != null) ) { ConversionMethod method = BuildConversion(formula, number); system.Conversions.Add(metricfrom, metricto, method); } }