예제 #1
0
        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);
            }
        }
예제 #2
0
        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);
            }
        }
예제 #3
0
        public SystemOfUnits Read()
        {
            SystemOfUnits system = new SystemOfUnits();

            //ReadConstants(system);
            ReadPrefixes(system);
            ReadBaseUnits(system);
            ReadUnits(system);
            ReadConversions(system);
            return(system);
        }
예제 #4
0
        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);
            }
        }
예제 #5
0
        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);
            }
        }
예제 #6
0
        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);
            }
        }
예제 #7
0
        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);
                }
            }
        }
예제 #8
0
 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);
         }
     }
 }
예제 #9
0
 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();
 }
예제 #11
0
 public SystemOfUnits Read()
 {
     SystemOfUnits system = new SystemOfUnits();
     //ReadConstants(system);
     ReadPrefixes(system);
     ReadBaseUnits(system);
     ReadUnits(system);
     ReadConversions(system);
     return system;
 }
예제 #12
0
        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
                {

                }
                
            }
        }
예제 #13
0
        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);
            }

        }