Esempio n. 1
0
        public ISODataLogTrigger ExportDataLogTrigger(DataLogTrigger adaptDataLogTrigger)
        {
            ISODataLogTrigger isoDataLogTrigger = new ISODataLogTrigger();

            int?ddi = RepresentationMapper.Map(adaptDataLogTrigger.Representation);

            if (ddi.HasValue) //Need DDI for a valid DLT
            {
                isoDataLogTrigger.DataLogDDI              = ddi.Value.AsHexDDI();
                isoDataLogTrigger.DataLogMethod           = ExportDataLogMethod(adaptDataLogTrigger.DataLogMethod);
                isoDataLogTrigger.DataLogDistanceInterval = adaptDataLogTrigger.DataLogDistanceInterval.AsIntViaMappedDDI(RepresentationMapper);
                isoDataLogTrigger.DataLogTimeInterval     = adaptDataLogTrigger.DataLogTimeInterval.AsIntViaMappedDDI(RepresentationMapper);
                isoDataLogTrigger.DataLogThresholdMinimum = adaptDataLogTrigger.DataLogThresholdMinimum.AsIntViaMappedDDI(RepresentationMapper);
                isoDataLogTrigger.DataLogThresholdMaximum = adaptDataLogTrigger.DataLogThresholdMaximum.AsIntViaMappedDDI(RepresentationMapper);
                isoDataLogTrigger.DataLogThresholdChange  = adaptDataLogTrigger.DataLogThresholdChange.AsIntViaMappedDDI(RepresentationMapper);
                if (adaptDataLogTrigger.DeviceElementId.HasValue)
                {
                    isoDataLogTrigger.DeviceElementIdRef = TaskDataMapper.InstanceIDMap.GetISOID(adaptDataLogTrigger.DeviceElementId.Value);
                }

                //Not yet implemented
                //isoDataLogTrigger.ValuePresentationIdRef = "";
                //isoDataLogTrigger.DataLogPGN = null;
                //isoDataLogTrigger.DataLogPGNStartBit = null;
                //isoDataLogTrigger.DataLogPGNStopBit = null;
            }

            return(isoDataLogTrigger);
        }
Esempio n. 2
0
        public static UnitOfMeasure ToDisplayUnit(this ISOProcessDataVariable pdv, RepresentationMapper mapper, ISO11783_TaskData taskData)
        {
            ISOUnit userUnit = null;

            if (!string.IsNullOrEmpty(pdv.ValuePresentationIdRef))
            {
                ISOValuePresentation vpn = taskData.ChildElements.OfType <ISOValuePresentation>().FirstOrDefault(v => v.ValuePresentationID == pdv.ValuePresentationIdRef);
                if (vpn != null)
                {
                    userUnit = new ISOUnit(vpn);
                }
            }
            if (userUnit != null)
            {
                UnitOfMeasure adaptUnit = null;
                try
                {
                    adaptUnit = userUnit.ToAdaptUnit();
                }
                catch
                {
                    //Suppressing this as a non-critical exception
                }
                return(adaptUnit);
            }
            return(null);
        }
        public DeviceElementHierarchies(IEnumerable <ISODevice> devices,
                                        RepresentationMapper representationMapper,
                                        bool mergeBins,
                                        IEnumerable <ISOTimeLog> timeLogs,
                                        string dataPath)
        {
            Items = new Dictionary <string, DeviceHierarchyElement>();

            //Track any device element geometries not logged as a DPT
            Dictionary <string, List <string> > missingGeometryDefinitions = new Dictionary <string, List <string> >();

            foreach (ISODevice device in devices)
            {
                ISODeviceElement rootDeviceElement = device.DeviceElements.SingleOrDefault(det => det.DeviceElementType == ISODeviceElementType.Device);
                if (rootDeviceElement != null)
                {
                    DeviceHierarchyElement hierarchyElement = new DeviceHierarchyElement(rootDeviceElement, 0, representationMapper, mergeBins, missingGeometryDefinitions);
                    hierarchyElement.HandleBinDeviceElements();
                    Items.Add(device.DeviceId, hierarchyElement);
                }
            }

            //Address the missing geometry data with targeted reads of the TLG binaries for any DPDs
            if (missingGeometryDefinitions.Any())
            {
                FillDPDGeometryDefinitions(missingGeometryDefinitions, timeLogs, dataPath);
            }
        }
Esempio n. 4
0
        private MeteredValue GetSummaryMeteredValue(ISODataLogValue dlv)
        {
            if (dlv.ProcessDataDDI == null)
            {
                return(null);
            }
            int ddi = dlv.ProcessDataDDI.AsInt32DDI();

            int dataValue = 0;

            if (dlv.ProcessDataValue.HasValue)
            {
                dataValue = dlv.ProcessDataValue.Value;
            }

            var unitOfMeasure = RepresentationMapper.GetUnitForDdi(ddi);

            if (!DDIs.ContainsKey(ddi) || unitOfMeasure == null)
            {
                return(null);
            }

            DdiDefinition ddiDefintion = DDIs[ddi];

            return(new MeteredValue
            {
                Value = new NumericRepresentationValue(RepresentationMapper.Map(ddi) as NumericRepresentation,
                                                       unitOfMeasure, new NumericValue(unitOfMeasure, dataValue * ddiDefintion.Resolution))
            });
        }
Esempio n. 5
0
 private PrescriptionLoader(TaskDataDocument taskDocument)
 {
     _taskDocument = taskDocument;
     _rootNode = _taskDocument.RootNode;
     _baseFolder = _taskDocument.BaseFolder;
     _prescriptions = new List<RasterGridPrescription>();
     _representationMapper = new RepresentationMapper();
 }
Esempio n. 6
0
 private PrescriptionLoader(TaskDataDocument taskDocument)
 {
     _taskDocument         = taskDocument;
     _rootNode             = _taskDocument.RootNode;
     _baseFolder           = _taskDocument.BaseFolder;
     _prescriptions        = new List <RasterGridPrescription>();
     _representationMapper = new RepresentationMapper();
 }
Esempio n. 7
0
 public TaskDataMapper(string dataPath, Properties properties)
 {
     BaseFolder           = dataPath;
     RepresentationMapper = new RepresentationMapper();
     DDIs                 = DdiLoader.Ddis;
     Properties           = properties;
     DeviceOperationTypes = new DeviceOperationTypes();
     InstanceIDMap        = new InstanceIDMap();
     Errors               = new List <IError>();
 }
        public DataLogTrigger ImportDataLogTrigger(ISODataLogTrigger isoDataLogTrigger)
        {
            int ddi = isoDataLogTrigger.DataLogDDI.AsInt32DDI();

            ApplicationDataModel.Representations.Representation representation = null;
            if (ddi != DefaultSet)
            {
                representation = RepresentationMapper.Map(ddi);
            }
            if (ddi == DefaultSet || representation != null) //Check that we can map to something meaningful before creating the DLT
            {
                DataLogTrigger adaptTrigger = new DataLogTrigger();

                if (ddi == DefaultSet)
                {
                    adaptTrigger.RequestDefaultProcessData = true;
                }
                else
                {
                    adaptTrigger.Representation = representation;
                }
                adaptTrigger.DataLogMethods = ImportDataLogMethods(isoDataLogTrigger.DataLogMethod);

                //Obsolete behavior
                adaptTrigger.DataLogMethod = adaptTrigger.DataLogMethods.Any() ? adaptTrigger.DataLogMethods.First() : LoggingMethodEnum.Total;

                if (isoDataLogTrigger.DataLogDistanceInterval.HasValue)
                {
                    adaptTrigger.DataLogDistanceInterval = isoDataLogTrigger.DataLogDistanceInterval.Value.AsNumericRepresentationValue(ddi, RepresentationMapper);
                }
                if (isoDataLogTrigger.DataLogTimeInterval.HasValue)
                {
                    adaptTrigger.DataLogTimeInterval = isoDataLogTrigger.DataLogTimeInterval.Value.AsNumericRepresentationValue(ddi, RepresentationMapper);
                }
                if (isoDataLogTrigger.DataLogThresholdMinimum.HasValue)
                {
                    adaptTrigger.DataLogThresholdMinimum = isoDataLogTrigger.DataLogThresholdMinimum.Value.AsNumericRepresentationValue(ddi, RepresentationMapper);
                }
                if (isoDataLogTrigger.DataLogThresholdMaximum.HasValue)
                {
                    adaptTrigger.DataLogThresholdMaximum = isoDataLogTrigger.DataLogThresholdMaximum.Value.AsNumericRepresentationValue(ddi, RepresentationMapper);
                }
                if (isoDataLogTrigger.DataLogThresholdChange.HasValue)
                {
                    adaptTrigger.DataLogThresholdChange = isoDataLogTrigger.DataLogThresholdChange.Value.AsNumericRepresentationValue(ddi, RepresentationMapper);
                }
                adaptTrigger.DeviceElementId = TaskDataMapper.InstanceIDMap.GetADAPTID(isoDataLogTrigger.DeviceElementIdRef);

                //Not yet implemented
                //adaptTrigger.LoggingLevel = null;

                return(adaptTrigger);
            }
            return(null);
        }
        private NumericWorkingData CreateProductIndexWorkingData(int deviceElementUseId)
        {
            var meter = new NumericWorkingData
            {
                UnitOfMeasure      = UnitSystemManager.GetUnitOfMeasure("count"),
                DeviceElementUseId = deviceElementUseId,
                Representation     = RepresentationMapper.GetRepresentation("vrProductIndex")
            };

            return(meter);
        }
Esempio n. 10
0
        private NumericWorkingData MapNumericMeter(ISODataLogValue dlv, int deviceElementUseId)
        {
            var meter = new NumericWorkingData
            {
                UnitOfMeasure      = RepresentationMapper.GetUnitForDdi(dlv.ProcessDataDDI.AsInt32DDI()),
                DeviceElementUseId = deviceElementUseId,
                Representation     = RepresentationMapper.Map(dlv.ProcessDataDDI.AsInt32DDI())
            };

            return(meter);
        }
Esempio n. 11
0
 public DeviceElementHierarchies(IEnumerable <ISODevice> devices, RepresentationMapper representationMapper)
 {
     Items = new Dictionary <string, DeviceElementHierarchy>();
     foreach (ISODevice device in devices)
     {
         ISODeviceElement rootDeviceElement = device.DeviceElements.SingleOrDefault(det => det.DeviceElementType == ISODeviceElementType.Device);
         if (rootDeviceElement != null)
         {
             Items.Add(device.DeviceId, new DeviceElementHierarchy(rootDeviceElement, 0, representationMapper));
         }
     }
 }
Esempio n. 12
0
        private List <ISOTime> ExportSummary(Summary summary)
        {
            List <ISOTime> times = new List <ISOTime>();

            foreach (StampedMeteredValues values in summary.SummaryData)
            {
                ISOTime time = new ISOTime();
                time.Start = values.Stamp.TimeStamp1;
                time.Stop  = values.Stamp.TimeStamp2;
                if (values.Stamp.Duration.HasValue)
                {
                    time.Duration = (uint)values.Stamp.Duration.Value.TotalSeconds;
                }
                time.Type = values.Stamp.DateContext == DateContextEnum.ProposedStart ? ISOEnumerations.ISOTimeType.Planned : ISOEnumerations.ISOTimeType.Effective;

                foreach (MeteredValue value in values.Values)
                {
                    if (value.Value != null && value.Value is NumericRepresentationValue)
                    {
                        NumericRepresentationValue numericValue = value.Value as NumericRepresentationValue;
                        ISODataLogValue            dlv          = new ISODataLogValue();
                        int?ddi = RepresentationMapper.Map(numericValue.Representation);
                        if (ddi.HasValue)
                        {
                            dlv.ProcessDataDDI = ddi.Value.AsHexDDI();
                            DdiDefinition DdiDefinition = DDIs[ddi.Value];
                            dlv.ProcessDataValue = (int)(numericValue.Value.Value / (DdiDefinition.Resolution != 0 ? DdiDefinition.Resolution : 1d));
                        }
                        else
                        {
                            if (numericValue.Representation.CodeSource == RepresentationCodeSourceEnum.ISO11783_DDI)
                            {
                                dlv.ProcessDataDDI   = numericValue.Representation.Code;
                                dlv.ProcessDataValue = (int)numericValue.Value.Value;
                            }
                        }
                        if (value.DeviceConfigurationId.HasValue)
                        {
                            DeviceElementConfiguration config = DataModel.Catalog.DeviceElementConfigurations.FirstOrDefault(c => c.Id.ReferenceId == value.DeviceConfigurationId.Value);
                            if (config != null)
                            {
                                dlv.DeviceElementIdRef = TaskDataMapper.InstanceIDMap.GetISOID(config.DeviceElementId);
                            }
                        }
                        time.DataLogValues.Add(dlv);
                    }
                }
                times.Add(time);
            }
            return(times);
        }
Esempio n. 13
0
        public IEnumerable <ISOProduct> ExportProducts(IEnumerable <Product> adaptProducts)
        {
            List <ISOProduct> isoProducts = new List <ISOProduct>();

            //Add all the products
            foreach (Product adaptProduct in adaptProducts)
            {
                ISOProduct product = ExportProduct(adaptProduct);
                isoProducts.Add(product);
            }

            //Fill in detail on the product mixes
            if (adaptProducts.OfType <MixProduct>().Any())
            {
                foreach (MixProduct adaptMixProduct in adaptProducts.OfType <MixProduct>())
                {
                    //Find the ISO Product
                    ISOProduct isoMixProduct = isoProducts.Single(p => p.ProductId == TaskDataMapper.InstanceIDMap.GetISOID(adaptMixProduct.Id.ReferenceId));

                    foreach (ProductComponent component in adaptMixProduct.ProductComponents)
                    {
                        //Components may map to either an ingredient or a product
                        //See comments at ProductComponent in ADAPT repo.
                        Product adaptProduct = DataModel.Catalog.Products.FirstOrDefault(i => i.Id.ReferenceId == component.IngredientId);
                        if (adaptProduct != null)
                        {
                            ExportProductRelation(isoProducts, adaptProduct.Description, component.Quantity, isoMixProduct);
                        }
                        else
                        {
                            Ingredient adaptIngredient = DataModel.Catalog.Ingredients.FirstOrDefault(i => i.Id.ReferenceId == component.IngredientId);
                            if (adaptIngredient != null)
                            {
                                ExportProductRelation(isoProducts, adaptIngredient.Description, component.Quantity, isoMixProduct);
                            }
                        }
                    }

                    //Total Quantity
                    isoMixProduct.MixtureRecipeQuantity = adaptMixProduct.TotalQuantity.AsIntViaMappedDDI(RepresentationMapper);

                    //Quantity DDI
                    int?ddi = RepresentationMapper.Map(adaptMixProduct.TotalQuantity.Representation);
                    if (ddi.HasValue)
                    {
                        isoMixProduct.QuantityDDI = ddi.Value.AsHexDDI();
                    }
                }
            }
            return(isoProducts);
        }
Esempio n. 14
0
        public IEnumerable <ISODataLogValue> ExportDataLogValues(List <WorkingData> workingDatas, List <DeviceElementUse> deviceElementUses)
        {
            if (workingDatas == null)
            {
                return(null);
            }

            List <ISODataLogValue> dlvs = new List <ISODataLogValue>();
            int i = 0;

            foreach (WorkingData workingData in workingDatas)
            {
                //DDI
                int?mappedDDI = RepresentationMapper.Map(workingData.Representation);
                var dlv       = new ISODataLogValue();
                if (mappedDDI != null)
                {
                    if (workingData.Representation != null && workingData.Representation.Code == "dtRecordingStatus" && workingData.DeviceElementUseId != 0)
                    {
                        dlv.ProcessDataDDI = 141.AsHexDDI(); //No support for exporting CondensedWorkState at this time
                    }
                    else
                    {
                        dlv.ProcessDataDDI = mappedDDI.Value.AsHexDDI();
                    }
                }
                else if (workingData.Representation.CodeSource == ApplicationDataModel.Representations.RepresentationCodeSourceEnum.ISO11783_DDI)
                {
                    dlv.ProcessDataDDI = workingData.Representation.Code;
                }

                //DeviceElementIdRef
                DeviceElementUse use = deviceElementUses.FirstOrDefault(d => d.Id.ReferenceId == workingData.DeviceElementUseId);
                if (use != null)
                {
                    DeviceElementConfiguration deviceElementConfiguration = DataModel.Catalog.DeviceElementConfigurations.FirstOrDefault(d => d.Id.ReferenceId == use.DeviceConfigurationId);
                    if (deviceElementConfiguration != null)
                    {
                        //This requires the Devices will have been mapped prior to the LoggedData
                        dlv.DeviceElementIdRef = TaskDataMapper.InstanceIDMap.GetISOID(deviceElementConfiguration.DeviceElementId);
                    }
                }

                if (dlv.ProcessDataDDI != null && dlv.DeviceElementIdRef != null)
                {
                    dlvs.Add(dlv);
                    _dataLogValueOrdersByWorkingDataID.Add(workingData.Id.ReferenceId, i++);
                }
            }
            return(dlvs);
        }
Esempio n. 15
0
        private MeteredValue GetSummaryMeteredValue(ISODataLogValue dlv)
        {
            if (dlv.ProcessDataDDI == null)
            {
                return(null);
            }
            int ddi = dlv.ProcessDataDDI.AsInt32DDI();

            int dataValue = 0;

            if (dlv.ProcessDataValue.HasValue)
            {
                dataValue = dlv.ProcessDataValue.Value;
            }

            var unitOfMeasure = RepresentationMapper.GetUnitForDdi(ddi);

            if (!DDIs.ContainsKey(ddi) || unitOfMeasure == null)
            {
                return(null);
            }

            DdiDefinition ddiDefintion = DDIs[ddi];

            int?deviceConfigurationID = null;
            int?deviceElementID       = TaskDataMapper.InstanceIDMap.GetADAPTID(dlv.DeviceElementIdRef);

            if (deviceElementID.HasValue)
            {
                //Since Device creation is on-demand, we need to call GetDeviceElementConfiguration here to ensure the relevant device is created if it hasn't been yet.
                var hierarchy          = TaskDataMapper?.DeviceElementHierarchies?.GetRelevantHierarchy(dlv.DeviceElementIdRef);
                var adaptDeviceElement = DataModel?.Catalog?.DeviceElements?.FirstOrDefault(d => d?.Id?.ReferenceId == deviceElementID.Value);
                if (hierarchy != null && adaptDeviceElement != null)
                {
                    DeviceElementConfiguration config = DeviceElementMapper.GetDeviceElementConfiguration(adaptDeviceElement, hierarchy, DataModel.Catalog);
                    if (config != null)
                    {
                        deviceConfigurationID = config.Id.ReferenceId;
                    }
                }
            }

            return(new MeteredValue
            {
                Value = new NumericRepresentationValue(RepresentationMapper.Map(ddi) as NumericRepresentation,
                                                       unitOfMeasure,
                                                       new NumericValue(unitOfMeasure, dataValue * ddiDefintion.Resolution)),
                DeviceConfigurationId = deviceConfigurationID
            });
        }
Esempio n. 16
0
        private static void AreEqual(XmlNode prnNode, ProductComponent productComponent, XmlNodeList productNodes, Catalog catalog, Dictionary<string, List<UniqueId>> linkList)
        {
            var productNode = FindMatchingProductNode(prnNode.GetXmlAttribute("A"), productNodes);
            if (productNode == null)
                return;

            var quantityDdi = Int32.Parse(productNode.GetXmlAttribute("E"));
            var uom = new RepresentationMapper().GetUnitForDdi(quantityDdi);
            Assert.AreEqual(uom, productComponent.Quantity.Value.UnitOfMeasure);
            Assert.AreEqual(prnNode.GetXmlAttribute("B"), productComponent.Quantity.Value.Value);

            var ingredient = catalog.Ingredients.Single(x => x.Id.ReferenceId == productComponent.IngredientId);
            Assert.AreEqual(productNode.GetXmlAttribute("B"), ingredient.Description);
        }
Esempio n. 17
0
        public IEnumerable <ISOProduct> ExportProducts(IEnumerable <Product> adaptProducts)
        {
            List <ISOProduct> isoProducts = new List <ISOProduct>();

            //Add all the products
            foreach (Product adaptProduct in adaptProducts)
            {
                ISOProduct product = ExportProduct(adaptProduct);
                isoProducts.Add(product);
            }

            //Fill in detail on the product mixes
            if (adaptProducts.OfType <MixProduct>().Any())
            {
                foreach (MixProduct adaptMixProduct in adaptProducts.OfType <MixProduct>())
                {
                    //Find the ISO Product
                    ISOProduct isoMixProduct = isoProducts.Single(p => p.ProductId == TaskDataMapper.InstanceIDMap.GetISOID(adaptMixProduct.Id.ReferenceId));

                    foreach (ProductComponent component in adaptMixProduct.ProductComponents)
                    {
                        Ingredient ingredient = DataModel.Catalog.Ingredients.FirstOrDefault(i => i.Id.ReferenceId == component.IngredientId);
                        if (ingredient != null)
                        {
                            ISOProduct componentProduct = isoProducts.FirstOrDefault(p => p.ProductDesignator == ingredient.Description); //Matches on name; assumes all ingredients are also products
                            if (componentProduct != null)
                            {
                                //Create PRNs if we can match to pre-existing products
                                ISOProductRelation relation = new ISOProductRelation();
                                relation.ProductIdRef  = componentProduct.ProductId;
                                relation.QuantityValue = component.Quantity.AsIntViaMappedDDI(RepresentationMapper);
                                isoMixProduct.ProductRelations.Add(relation);
                            }
                        }
                    }

                    //Total Quantity
                    isoMixProduct.MixtureRecipeQuantity = adaptMixProduct.TotalQuantity.AsIntViaMappedDDI(RepresentationMapper);

                    //Quantity DDI
                    int?ddi = RepresentationMapper.Map(adaptMixProduct.TotalQuantity.Representation);
                    if (ddi.HasValue)
                    {
                        isoMixProduct.QuantityDDI = ddi.Value.AsHexDDI();
                    }
                }
            }
            return(isoProducts);
        }
Esempio n. 18
0
        /// <summary>
        /// Converts an ADAPT NumericRepresentation value with an included Representation mapped to a DDI to the appropriate int value for ISO
        /// </summary>
        /// <param name="value"></param>
        /// <param name="mapper"></param>
        /// <returns></returns>
        public static int AsIntViaMappedDDI(this NumericRepresentationValue value, RepresentationMapper mapper)
        {
            int?ddi = mapper.Map(value.Representation);

            if (ddi.HasValue)
            {
                ISOUnit unit = UnitFactory.Instance.GetUnitByDDI(ddi.Value);
                return((int)unit.ConvertToIsoUnit(value.Value.Value));
            }
            else if (value.Representation != null && value.Representation.CodeSource == RepresentationCodeSourceEnum.ISO11783_DDI)
            {
                //No need to convert if the value is natively a DDI
                return((int)value.Value.Value);
            }
            return(0);
        }
Esempio n. 19
0
        private MeteredValue GetSummaryMeteredValue(ISODataLogValue dlv)
        {
            if (dlv.ProcessDataDDI == null)
            {
                return(null);
            }
            int ddi = dlv.ProcessDataDDI.AsInt32DDI();

            int dataValue = 0;

            if (dlv.ProcessDataValue.HasValue)
            {
                dataValue = dlv.ProcessDataValue.Value;
            }

            var unitOfMeasure = RepresentationMapper.GetUnitForDdi(ddi);

            if (!DDIs.ContainsKey(ddi) || unitOfMeasure == null)
            {
                return(null);
            }

            DdiDefinition ddiDefintion = DDIs[ddi];

            int?deviceConfigurationID = null;
            int?deviceElementID       = TaskDataMapper.InstanceIDMap.GetADAPTID(dlv.DeviceElementIdRef);

            if (deviceElementID.HasValue)
            {
                DeviceElementConfiguration config = DataModel.Catalog.DeviceElementConfigurations.FirstOrDefault(c => c.DeviceElementId == deviceElementID.Value);
                if (config != null)
                {
                    deviceConfigurationID = config.Id.ReferenceId;
                }
            }

            return(new MeteredValue
            {
                Value = new NumericRepresentationValue(RepresentationMapper.Map(ddi) as NumericRepresentation,
                                                       unitOfMeasure,
                                                       new NumericValue(unitOfMeasure, dataValue * ddiDefintion.Resolution)),
                DeviceConfigurationId = deviceConfigurationID
            });
        }
        private static void AreEqual(XmlNode prnNode, ProductComponent productComponent, XmlNodeList productNodes, Catalog catalog, Dictionary <string, List <UniqueId> > linkList)
        {
            var productNode = FindMatchingProductNode(prnNode.GetXmlAttribute("A"), productNodes);

            if (productNode == null)
            {
                return;
            }

            var quantityDdi = Int32.Parse(productNode.GetXmlAttribute("E"));
            var uom         = new RepresentationMapper().GetUnitForDdi(quantityDdi);

            Assert.AreEqual(uom, productComponent.Quantity.Value.UnitOfMeasure);
            Assert.AreEqual(prnNode.GetXmlAttribute("B"), productComponent.Quantity.Value.Value);

            var ingredient = catalog.Ingredients.Single(x => x.Id.ReferenceId == productComponent.IngredientId);

            Assert.AreEqual(productNode.GetXmlAttribute("B"), ingredient.Description);
        }
Esempio n. 21
0
        public ISODataLogTrigger ExportDataLogTrigger(DataLogTrigger adaptDataLogTrigger)
        {
            ISODataLogTrigger isoDataLogTrigger = new ISODataLogTrigger();

            int?ddi = null;

            if (adaptDataLogTrigger.RequestDefaultProcessData)
            {
                ddi = DefaultSet; //DFFF
            }
            else if (adaptDataLogTrigger.Representation != null)
            {
                ddi = RepresentationMapper.Map(adaptDataLogTrigger.Representation);
            }

            if (ddi.HasValue) //Need DDI for a valid DLT
            {
                isoDataLogTrigger.DataLogDDI = ddi.Value.AsHexDDI();
                var loggingMethods = adaptDataLogTrigger.DataLogMethods.Any() ? adaptDataLogTrigger.DataLogMethods : new List <LoggingMethodEnum> {
                    adaptDataLogTrigger.DataLogMethod
                };
                isoDataLogTrigger.DataLogMethod           = ExportDataLogMethods(loggingMethods);
                isoDataLogTrigger.DataLogDistanceInterval = adaptDataLogTrigger.DataLogDistanceInterval?.AsIntViaMappedDDI(RepresentationMapper);
                isoDataLogTrigger.DataLogTimeInterval     = adaptDataLogTrigger.DataLogTimeInterval?.AsIntViaMappedDDI(RepresentationMapper);
                isoDataLogTrigger.DataLogThresholdMinimum = adaptDataLogTrigger.DataLogThresholdMinimum?.AsIntViaMappedDDI(RepresentationMapper);
                isoDataLogTrigger.DataLogThresholdMaximum = adaptDataLogTrigger.DataLogThresholdMaximum?.AsIntViaMappedDDI(RepresentationMapper);
                isoDataLogTrigger.DataLogThresholdChange  = adaptDataLogTrigger.DataLogThresholdChange?.AsIntViaMappedDDI(RepresentationMapper);
                if (adaptDataLogTrigger.DeviceElementId.HasValue)
                {
                    isoDataLogTrigger.DeviceElementIdRef = TaskDataMapper.InstanceIDMap.GetISOID(adaptDataLogTrigger.DeviceElementId.Value);
                }

                //Not yet implemented
                //isoDataLogTrigger.ValuePresentationIdRef = "";
                //isoDataLogTrigger.DataLogPGN = null;
                //isoDataLogTrigger.DataLogPGNStartBit = null;
                //isoDataLogTrigger.DataLogPGNStopBit = null;
            }

            return(isoDataLogTrigger);
        }
Esempio n. 22
0
        public const string ExportVersion = "ExportVersion"; //Version "3" or "4"

        public TaskDataMapper(string dataPath, Properties properties)
        {
            BaseFolder           = dataPath;
            RepresentationMapper = new RepresentationMapper();
            DDIs                 = DdiLoader.Ddis;
            Properties           = properties ?? new Properties();
            DeviceOperationTypes = new DeviceOperationTypes();
            InstanceIDMap        = new InstanceIDMap();
            Errors               = new List <IError>();

            //Export version
            string exportVersion = Properties.GetProperty(ExportVersion);

            if (Int32.TryParse(exportVersion, out int version))
            {
                Version = version;  //3 or 4
            }
            if (version != 3 && version != 4)
            {
                Version = 4; //Default ISO Version for the export
            }
        }
Esempio n. 23
0
        public DataLogTrigger ImportDataLogTrigger(ISODataLogTrigger isoDataLogTrigger)
        {
            int ddi = isoDataLogTrigger.DataLogDDI.AsInt32DDI();

            ApplicationDataModel.Representations.Representation representation = RepresentationMapper.Map(ddi);
            if (representation != null)
            {
                DataLogTrigger adaptTrigger = new DataLogTrigger();
                adaptTrigger.Representation = representation;
                adaptTrigger.DataLogMethod  = ImportDataLogMethod(isoDataLogTrigger.DataLogMethod);
                if (isoDataLogTrigger.DataLogDistanceInterval.HasValue)
                {
                    adaptTrigger.DataLogDistanceInterval = isoDataLogTrigger.DataLogDistanceInterval.Value.AsNumericRepresentationValue(ddi, RepresentationMapper);
                }
                if (isoDataLogTrigger.DataLogTimeInterval.HasValue)
                {
                    adaptTrigger.DataLogTimeInterval = isoDataLogTrigger.DataLogTimeInterval.Value.AsNumericRepresentationValue(ddi, RepresentationMapper);
                }
                if (isoDataLogTrigger.DataLogThresholdMinimum.HasValue)
                {
                    adaptTrigger.DataLogThresholdMinimum = isoDataLogTrigger.DataLogThresholdMinimum.Value.AsNumericRepresentationValue(ddi, RepresentationMapper);
                }
                if (isoDataLogTrigger.DataLogThresholdMaximum.HasValue)
                {
                    adaptTrigger.DataLogThresholdMaximum = isoDataLogTrigger.DataLogThresholdMaximum.Value.AsNumericRepresentationValue(ddi, RepresentationMapper);
                }
                if (isoDataLogTrigger.DataLogThresholdChange.HasValue)
                {
                    adaptTrigger.DataLogThresholdChange = isoDataLogTrigger.DataLogThresholdChange.Value.AsNumericRepresentationValue(ddi, RepresentationMapper);
                }
                adaptTrigger.DeviceElementId = TaskDataMapper.InstanceIDMap.GetADAPTID(isoDataLogTrigger.DeviceElementIdRef);

                //Not yet implemented
                //adaptTrigger.LoggingLevel = null;

                return(adaptTrigger);
            }
            return(null);
        }
Esempio n. 24
0
        /// <summary>
        /// If an implementer wants to export to a custom DDI or otherwise one that doesn't map,
        /// the appropriate DDI may be set in the Prescription prior to exporting.
        /// A ISO11783_DDI representation is as such the first mapping attempted.
        /// </summary>
        /// <param name="representation"></param>
        /// <param name="adaptUnit"></param>
        /// <returns></returns>
        private int DetermineVariableDDI(NumericRepresentation representation, UnitOfMeasure adaptUnit)
        {
            if (representation != null)
            {
                if (representation.CodeSource == RepresentationCodeSourceEnum.ISO11783_DDI)
                {
                    return(Int32.Parse(representation.Code));
                }

                int?mappedDDI = RepresentationMapper.Map(representation);
                if (mappedDDI.HasValue)
                {
                    return(mappedDDI.Value);
                }
            }

            if (adaptUnit != null && UnitFactory.DimensionToDdi.ContainsKey(adaptUnit.Dimension))
            {
                return(UnitFactory.DimensionToDdi[adaptUnit.Dimension]);
            }

            TaskDataMapper.AddError($"Unable to determine DDI for Prescription export {representation.Code}.", $"Representation ID : {representation.Id.ReferenceId}", "PrescriptionMapper.DetermineVariableDDI()");
            return(0); //Return an invalid DDI
        }
 public void Setup()
 {
     _representationMapper = new RepresentationMapper();
 }
        public DeviceElementHierarchy(ISODeviceElement deviceElement, int depth, RepresentationMapper representationMapper, HashSet <int> crawledElements = null, DeviceElementHierarchy parent = null)
        {
            RepresentationMapper = representationMapper;
            //This Hashset will track that we don't build infinite hierarchies.
            //The plugin does not support peer control at this time.
            _crawledElements = crawledElements;
            if (_crawledElements == null)
            {
                _crawledElements = new HashSet <int>();
            }

            if (_crawledElements.Add((int)deviceElement.DeviceElementObjectId))
            {
                Type          = deviceElement.DeviceElementType;
                DeviceElement = deviceElement;
                Depth         = depth;
                Order         = (int)deviceElement.DeviceElementNumber; //Using this number as analagous to this purpose.  The ISO spec requires these numbers increment from left to right as in ADAPT.  (See ISO11783-10:2015(E) B.3.2 Element number)

                //DeviceProperty assigned Widths & Offsets
                //DeviceProcessData assigned values will be assigned as the SectionMapper reads timelog data.

                //Width
                ISODeviceProperty widthProperty = deviceElement.DeviceProperties.FirstOrDefault(dpt => dpt.DDI == "0046");
                if (widthProperty != null)
                {
                    Width    = widthProperty.Value;
                    WidthDDI = "0046";
                }
                else
                {
                    widthProperty = deviceElement.DeviceProperties.FirstOrDefault(dpt => dpt.DDI == "0043");
                    if (widthProperty != null)
                    {
                        Width    = widthProperty.Value;
                        WidthDDI = "0043";
                    }
                }

                //Offsets
                ISODeviceProperty xOffsetProperty = deviceElement.DeviceProperties.FirstOrDefault(dpt => dpt.DDI == "0086");
                if (xOffsetProperty != null)
                {
                    XOffset = xOffsetProperty.Value;
                }

                ISODeviceProperty yOffsetProperty = deviceElement.DeviceProperties.FirstOrDefault(dpt => dpt.DDI == "0087");
                if (yOffsetProperty != null)
                {
                    YOffset = yOffsetProperty.Value;
                }

                ISODeviceProperty zOffsetProperty = deviceElement.DeviceProperties.FirstOrDefault(dpt => dpt.DDI == "0088");
                if (zOffsetProperty != null)
                {
                    ZOffset = zOffsetProperty.Value;
                }

                //Children
                IEnumerable <ISODeviceElement> childDeviceElements = deviceElement.Device.DeviceElements.Where(det => det.ParentObjectId == deviceElement.DeviceElementObjectId);// && det.DeviceElementType == ISOEnumerations.ISODeviceElementType.Section);
                if (childDeviceElements.Any())
                {
                    int childDepth = depth + 1;
                    Children = new List <DeviceElementHierarchy>();
                    foreach (ISODeviceElement det in childDeviceElements)
                    {
                        DeviceElementHierarchy child = new DeviceElementHierarchy(det, childDepth, representationMapper, _crawledElements, this);
                        Children.Add(child);
                    }
                }

                //Parent
                Parent = parent;
            }
        }
        private int?GetZOffsetFromSpatialData(IEnumerable <ISOSpatialRow> isoRecords, string isoDeviceElementID, RepresentationMapper representationMapper)
        {
            double        offset       = 0d;
            ISOSpatialRow firstZOffset = isoRecords.FirstOrDefault(r => r.SpatialValues.Any(s => s.DataLogValue.DeviceElementIdRef == isoDeviceElementID &&
                                                                                            s.DataLogValue.ProcessDataDDI == "0088"));

            if (firstZOffset != null)
            {
                offset = firstZOffset.SpatialValues.Single(s => s.DataLogValue.DeviceElementIdRef == isoDeviceElementID && s.DataLogValue.ProcessDataDDI == "0088").Value;
                return((int)offset);
            }
            else
            {
                return(null);
            }
        }
        private int?GetWidthFromSpatialData(IEnumerable <ISOSpatialRow> isoRecords, string isoDeviceElementID, RepresentationMapper representationMapper)
        {
            double        maxWidth        = 0d;
            string        updatedWidthDDI = null;
            ISOSpatialRow rowWithMaxWidth = isoRecords.FirstOrDefault(r => r.SpatialValues.Any(s => s.DataLogValue.DeviceElementIdRef == isoDeviceElementID &&
                                                                                               s.DataLogValue.ProcessDataDDI == "0046"));

            if (rowWithMaxWidth != null)
            {
                maxWidth        = rowWithMaxWidth.SpatialValues.Single(s => s.DataLogValue.DeviceElementIdRef == isoDeviceElementID && s.DataLogValue.ProcessDataDDI == "0046").Value;
                updatedWidthDDI = "0046";
            }
            else
            {
                //Find the largest working width
                IEnumerable <ISOSpatialRow> rows = isoRecords.Where(r => r.SpatialValues.Any(s => s.DataLogValue.DeviceElementIdRef == isoDeviceElementID &&
                                                                                             s.DataLogValue.ProcessDataDDI == "0043"));
                if (rows.Any())
                {
                    foreach (ISOSpatialRow row in rows)
                    {
                        double value = row.SpatialValues.Single(s => s.DataLogValue.DeviceElementIdRef == isoDeviceElementID && s.DataLogValue.ProcessDataDDI == "0043").Value;
                        if (value > maxWidth)
                        {
                            maxWidth = value;
                        }
                    }
                    updatedWidthDDI = "0043";
                }
            }

            if (updatedWidthDDI != null)
            {
                WidthDDI = updatedWidthDDI;
                return((int)maxWidth);
            }
            else
            {
                return(null);
            }
        }
        public void SetWidthsAndOffsetsFromSpatialData(IEnumerable <ISOSpatialRow> isoRecords, DeviceElementConfiguration config, RepresentationMapper representationMapper)
        {
            //Set values on this object and associated DeviceElementConfiguration
            if (Width == null)
            {
                Width = GetWidthFromSpatialData(isoRecords, DeviceElement.DeviceElementId, representationMapper);
            }

            if (config.Offsets == null)
            {
                config.Offsets = new List <NumericRepresentationValue>();
            }

            if (XOffset == null)
            {
                XOffset = GetXOffsetFromSpatialData(isoRecords, DeviceElement.DeviceElementId, representationMapper);
                if (XOffsetRepresentation != null)
                {
                    config.Offsets.Add(XOffsetRepresentation);
                }
            }

            if (YOffset == null)
            {
                YOffset = GetYOffsetFromSpatialData(isoRecords, DeviceElement.DeviceElementId, representationMapper);
                if (YOffsetRepresentation != null)
                {
                    config.Offsets.Add(YOffsetRepresentation);
                }
            }

            if (ZOffset == null)
            {
                ZOffset = GetZOffsetFromSpatialData(isoRecords, DeviceElement.DeviceElementId, representationMapper);
                if (ZOffsetRepresentation != null)
                {
                    config.Offsets.Add(ZOffsetRepresentation);
                }
            }

            //Update config values as appropriate
            if (this.DeviceElement.DeviceElementType == ISODeviceElementType.Navigation)
            {
                MachineConfiguration machineConfig = config as MachineConfiguration;
                if (machineConfig.GpsReceiverXOffset == null)
                {
                    machineConfig.GpsReceiverXOffset = XOffsetRepresentation;
                }
                if (machineConfig.GpsReceiverYOffset == null)
                {
                    machineConfig.GpsReceiverYOffset = YOffsetRepresentation;
                }
                if (machineConfig.GpsReceiverZOffset == null)
                {
                    machineConfig.GpsReceiverZOffset = ZOffsetRepresentation;
                }
            }
            else
            {
                if (config is SectionConfiguration)
                {
                    SectionConfiguration sectionConfig = config as SectionConfiguration;
                    if (sectionConfig.SectionWidth == null)
                    {
                        sectionConfig.SectionWidth = WidthRepresentation;
                    }
                    if (sectionConfig.InlineOffset == null)
                    {
                        sectionConfig.InlineOffset = XOffsetRepresentation;
                    }
                    if (sectionConfig.LateralOffset == null)
                    {
                        sectionConfig.LateralOffset = YOffsetRepresentation;
                    }
                }
                else if (config is ImplementConfiguration)
                {
                    ImplementConfiguration implementConfig = config as ImplementConfiguration;
                    if (implementConfig.Width == null)
                    {
                        implementConfig.Width = WidthRepresentation;
                    }
                }
            }
        }
 public void TearDown()
 {
     _representationMapper = null;
 }
        public DeviceHierarchyElement(ISODeviceElement deviceElement,
                                      int depth,
                                      RepresentationMapper representationMapper,
                                      bool mergeSingleBinsIntoBoom,
                                      Dictionary <string, List <string> > missingGeometryDefinitions,
                                      HashSet <int> crawledElements = null,
                                      DeviceHierarchyElement parent = null)
        {
            RepresentationMapper = representationMapper;
            MergedElements       = new List <ISODeviceElement>();
            //This Hashset will track that we don't build infinite hierarchies.
            //The plugin does not support peer control at this time.
            _crawledElements = crawledElements;
            if (_crawledElements == null)
            {
                _crawledElements = new HashSet <int>();
            }

            if (_crawledElements.Add((int)deviceElement.DeviceElementObjectId))
            {
                Type          = deviceElement.DeviceElementType;
                DeviceElement = deviceElement;
                Depth         = depth;
                Order         = (int)deviceElement.DeviceElementNumber; //Using this number as analagous to this purpose.  The ISO spec requires these numbers increment from left to right as in ADAPT.  (See ISO11783-10:2015(E) B.3.2 Element number)

                //DeviceProperty assigned Widths & Offsets
                //DeviceProcessData assigned values will be assigned as the SectionMapper reads timelog data.

                //Width
                ISODeviceProperty widthProperty = deviceElement.DeviceProperties.FirstOrDefault(dpt => dpt.DDI == "0046"); //Max width
                if (widthProperty != null)
                {
                    Width    = widthProperty.Value;
                    WidthDDI = "0046";
                }
                else
                {
                    widthProperty = deviceElement.DeviceProperties.FirstOrDefault(dpt => dpt.DDI == "0044"); //Default working width
                    if (widthProperty != null)
                    {
                        Width    = widthProperty.Value;
                        WidthDDI = "0044";
                    }

                    if (widthProperty == null)
                    {
                        widthProperty = deviceElement.DeviceProperties.FirstOrDefault(dpt => dpt.DDI == "0043"); //Actual working width
                        if (widthProperty != null)
                        {
                            Width    = widthProperty.Value;
                            WidthDDI = "0043";
                        }
                    }
                }

                if (Width == null)
                {
                    //We are missing a width DPT.   Log it (0046 as a substitute here for any valid width) for possible retrieval from the TLG binaries.
                    AddMissingGeometryDefinition(missingGeometryDefinitions, deviceElement.DeviceElementId, "0046");
                }

                //Offsets
                ISODeviceProperty xOffsetProperty = deviceElement.DeviceProperties.FirstOrDefault(dpt => dpt.DDI == "0086");
                if (xOffsetProperty != null)
                {
                    XOffset = xOffsetProperty.Value;
                }
                else
                {
                    AddMissingGeometryDefinition(missingGeometryDefinitions, deviceElement.DeviceElementId, "0086");
                }

                ISODeviceProperty yOffsetProperty = deviceElement.DeviceProperties.FirstOrDefault(dpt => dpt.DDI == "0087");
                if (yOffsetProperty != null)
                {
                    YOffset = yOffsetProperty.Value;
                }
                else
                {
                    AddMissingGeometryDefinition(missingGeometryDefinitions, deviceElement.DeviceElementId, "0087");
                }

                ISODeviceProperty zOffsetProperty = deviceElement.DeviceProperties.FirstOrDefault(dpt => dpt.DDI == "0088");
                if (zOffsetProperty != null)
                {
                    ZOffset = zOffsetProperty.Value;
                }
                else
                {
                    AddMissingGeometryDefinition(missingGeometryDefinitions, deviceElement.DeviceElementId, "0088");
                }

                //Children
                IEnumerable <ISODeviceElement> childDeviceElements = deviceElement.Device.DeviceElements.Where(det => det.ParentObjectId == deviceElement.DeviceElementObjectId && det.ParentObjectId != det.DeviceElementObjectId); //Do not create children for an element classified as its own parent
                if (childDeviceElements.Any())
                {
                    int childDepth = depth + 1;
                    Children = new List <DeviceHierarchyElement>();
                    foreach (ISODeviceElement childDeviceElement in childDeviceElements)
                    {
                        //If there is a single bin child of the boom (usually alongside sections),
                        //we can logically combine the bin and boom to have a clean hierarchy
                        //where sections are the direct children of the element containing the rates.
                        //We currently use an import property (MergeSingleBinsIntoBoom) to enable this functionality.
                        //Note that if there are any duplicate DDIs on both the Bin and Boom (non-standard per Annex F.3),
                        //the FirstOrDefault() logic in the setter methods in the SpatialRecordMapper will prefer the Boom and suppress the Bin data.
                        if (mergeSingleBinsIntoBoom &&
                            (DeviceElement.DeviceElementType == ISODeviceElementType.Device || DeviceElement.DeviceElementType == ISODeviceElementType.Function) &&
                            childDeviceElement.DeviceElementType == ISODeviceElementType.Bin &&
                            childDeviceElements.Count(c => c.DeviceElementType == ISODeviceElementType.Bin) == 1)
                        {
                            //Set the element into the MergedElements list
                            MergedElements.Add(childDeviceElement);

                            //Set its children as children of the boom
                            foreach (ISODeviceElement binChild in childDeviceElement.ChildDeviceElements.Where(det => det.ParentObjectId == childDeviceElement.DeviceElementObjectId && det.ParentObjectId != det.DeviceElementObjectId))
                            {
                                Children.Add(new DeviceHierarchyElement(binChild, childDepth, representationMapper, mergeSingleBinsIntoBoom, missingGeometryDefinitions, _crawledElements, this));
                            }

                            //This functionality will not work in the ADAPT framework today for multiple bins on one boom (i.e., ISO 11783-10:2015(E) F.23 & F.33).
                            //For these, we will fall back to the more basic default functionality in HandleBinDeviceElements()
                            //where we separate bins and sections into different depths within the ADAPT device hierarchy.
                            //Plugin implementers will need to rationalize the separate bins to the single boom,
                            //with the rate for each bin associated to the corresponding DeviceElement in the ADAPT model.
                            //Were this multi-bin/single boom DDOP common, we could perhaps extend the WorkingData(?) class with some new piece of information
                            //To differentiate like data elements from different bins and thereby extend the merge functionality to this case.
                        }
                        else
                        {
                            //Add the child device element
                            DeviceHierarchyElement child = new DeviceHierarchyElement(childDeviceElement, childDepth, representationMapper, mergeSingleBinsIntoBoom, missingGeometryDefinitions, _crawledElements, this);
                            Children.Add(child);
                        }
                    }
                }

                //Parent
                Parent = parent;
            }
        }
Esempio n. 32
0
        internal void ImportSharedPrescriptionProperties(ISOTask task, WorkItem workItem, Prescription prescription)
        {
            //Description
            prescription.Description = task.TaskDesignator;

            //CropZone/Field
            if (workItem.CropZoneId.HasValue)
            {
                prescription.CropZoneId = workItem.CropZoneId.Value;
            }
            else if (workItem.FieldId.HasValue)
            {
                prescription.FieldId = workItem.FieldId.Value;
            }

            //Products
            prescription.ProductIds = new List <int>();
            foreach (ISOTreatmentZone treatmentZone in task.TreatmentZones)
            {
                foreach (var dataVariable in treatmentZone.ProcessDataVariables)
                {
                    if (!string.IsNullOrEmpty(dataVariable.ProductIdRef))
                    {
                        int?productID = TaskDataMapper.InstanceIDMap.GetADAPTID(dataVariable.ProductIdRef);
                        if (productID.HasValue)
                        {
                            //ProductIDs
                            if (!prescription.ProductIds.Contains(productID.Value))
                            {
                                prescription.ProductIds.Add(productID.Value);
                            }

                            //Product Lookups
                            int ddi             = dataVariable.ProcessDataDDI.AsInt32DDI();
                            var rxProductLookup = new RxProductLookup
                            {
                                ProductId      = productID,
                                UnitOfMeasure  = UnitFactory.Instance.GetUnitByDDI(ddi).ToAdaptUnit(),
                                Representation = (NumericRepresentation)RepresentationMapper.Map(ddi)
                            };

                            if (!prescription.RxProductLookups.Any(r => r.ProductId == rxProductLookup.ProductId))
                            {
                                prescription.RxProductLookups.Add(rxProductLookup);
                            }
                        }
                    }
                }
            }

            //Connections
            if (task.Connections.Any())
            {
                IEnumerable <EquipmentConfiguration> equipConfigs = _connectionMapper.ImportConnections(task);

                workItem.EquipmentConfigurationGroup = new EquipmentConfigurationGroup();
                workItem.EquipmentConfigurationGroup.EquipmentConfigurations = equipConfigs.ToList();

                DataModel.Catalog.EquipmentConfigurations.AddRange(equipConfigs);
            }
        }
Esempio n. 33
0
 public static NumericRepresentationValue AsNumericRepresentationValue(this ISOProcessDataVariable pdv, RepresentationMapper mapper, ISO11783_TaskData taskData)
 {
     return(pdv.ProcessDataValue.AsNumericRepresentationValue(pdv.ProcessDataDDI, mapper, pdv.ToDisplayUnit(mapper, taskData)));
 }
Esempio n. 34
0
        /// <summary>
        /// Looks up unit, converts and loads representation
        /// </summary>
        /// <param name="n"></param>
        /// <param name="ddi"></param>
        /// <param name="mapper"></param>
        /// <returns></returns>
        ///
        public static NumericRepresentationValue AsNumericRepresentationValue(this int n, int ddi, RepresentationMapper mapper, UnitOfMeasure userUnitOfMeasure = null)
        {
            //RepresentationValue
            NumericRepresentationValue returnValue = new ApplicationDataModel.Representations.NumericRepresentationValue();

            //Representation
            returnValue.Representation = mapper.Map(ddi) as NumericRepresentation;

            //Value
            double        convertedValue = (double)n;
            UnitOfMeasure uom            = null;
            ISOUnit       isoUnit        = UnitFactory.Instance.GetUnitByDDI(ddi);

            if (isoUnit != null)
            {
                convertedValue = isoUnit.ConvertFromIsoUnit(convertedValue);
                uom            = isoUnit.ToAdaptUnit();
            }
            returnValue.Value = new ApplicationDataModel.Representations.NumericValue(uom, convertedValue);

            //User UOM
            if (userUnitOfMeasure != null)
            {
                returnValue.UserProvidedUnitOfMeasure = userUnitOfMeasure;
            }

            return(returnValue);
        }