Esempio n. 1
0
 private NumericValue SimplifyComposite(CompositeUnitOfMeasure compositeUnitOfMeasure, double value)
 {
     if (compositeUnitOfMeasure.Components.Count <= 1)
     {
         return(new NumericValue(compositeUnitOfMeasure.ToModelUom(), value));
     }
     foreach (var firstComponent in compositeUnitOfMeasure.Components)
     {
         foreach (var secondComponent in compositeUnitOfMeasure.Components)
         {
             if (firstComponent.DomainID == secondComponent.DomainID)
             {
                 continue;
             }
             try
             {
                 var firstDomainId  = firstComponent.Power > 1 ? firstComponent.DomainID + firstComponent.Power : firstComponent.DomainID;
                 var secondDomainId = secondComponent.Power > 1 ? secondComponent.DomainID + secondComponent.Power : secondComponent.DomainID;
                 value = _converter.Convert(InternalUnitSystemManager.Instance.UnitOfMeasures[firstDomainId],
                                            InternalUnitSystemManager.Instance.UnitOfMeasures[secondDomainId], value);
                 var uomComponents = CombineCompositeComponents(compositeUnitOfMeasure, firstComponent, secondComponent);
                 return(Simplify(uomComponents, value));
             }
             catch (InvalidOperationException)
             {
             }
         }
     }
     return(new NumericValue(compositeUnitOfMeasure.ToModelUom(), value));
 }
Esempio n. 2
0
        public static AgGateway.ADAPT.ApplicationDataModel.Common.UnitOfMeasure GetModelUom(string unit)
        {
            AgGateway.ADAPT.ApplicationDataModel.Common.UnitOfMeasure uom = UnitSystemManager.GetUnitOfMeasure(unit);

            if (uom == null)
            {
                UnitOfMeasure incompatibleUnit = new CompositeUnitOfMeasure(unit);
                uom = incompatibleUnit.ToModelUom();
            }

            return(uom);
        }
 private NumericValue SimplifyComposite(CompositeUnitOfMeasure compositeUnitOfMeasure, double value)
 {
     if (compositeUnitOfMeasure.Components.Count <= 1)
         return new NumericValue(compositeUnitOfMeasure.ToModelUom(), value);
     foreach (var firstComponent in compositeUnitOfMeasure.Components)
     {
         foreach (var secondComponent in compositeUnitOfMeasure.Components)
         {
             if(firstComponent.DomainID == secondComponent.DomainID)
                 continue;
             try
             {
                 var firstDomainId = firstComponent.Power > 1 ? firstComponent.DomainID + firstComponent.Power : firstComponent.DomainID;
                 var secondDomainId = secondComponent.Power > 1 ? secondComponent.DomainID + secondComponent.Power : secondComponent.DomainID;
                 value = _converter.Convert(InternalUnitSystemManager.Instance.UnitOfMeasures[firstDomainId],
                                                                 InternalUnitSystemManager.Instance.UnitOfMeasures[secondDomainId], value);
                 var uomComponents = CombineCompositeComponents(compositeUnitOfMeasure, firstComponent, secondComponent);
                 return Simplify(uomComponents, value);
             }
             catch (InvalidOperationException)
             {
             }
         }
     }
     return new NumericValue(compositeUnitOfMeasure.ToModelUom(), value);
 }