示例#1
0
        public static void AreEqual(XmlNode productNode, XmlNodeList productNodes, MixProduct productMix, Catalog catalog, Dictionary <string, List <UniqueId> > linkList)
        {
            if (productNode.GetXmlAttribute("A") == null || productNode.GetXmlAttribute("B") == null)
            {
                return;
            }

            UniqueIdAssert.AreEqual(linkList, productNode.GetXmlAttribute("A"), productMix.Id.UniqueIds);
            Assert.AreEqual(productNode.GetXmlAttribute("A"), productMix.Id.FindIsoId());
            Assert.AreEqual(productNode.GetXmlAttribute("B"), productMix.Description);

            var prnNodes = productNode.SelectNodes("PRN");

            ProductComponentAssert.AreEqual(prnNodes, productMix.ProductComponents, productNodes, catalog, linkList);
        }
示例#2
0
        private Product CreateNewProductInstance(ISOProduct isoProduct)
        {
            // If there is a manufacturer defined attribute representing a crop name, use it
            string cropName = _manufacturer?.GetCropName(isoProduct);

            if (!string.IsNullOrWhiteSpace(cropName))
            {
                // New crop variety product
                var cropProduct = new CropVarietyProduct();
                cropProduct.ProductType = ProductTypeEnum.Variety;

                // Check if there is already Crop in ADAPT model
                Crop adaptCrop = TaskDataMapper.AdaptDataModel.Catalog.Crops.FirstOrDefault(x => x.Name.EqualsIgnoreCase(cropName));
                if (adaptCrop == null)
                {
                    // Create a new one
                    adaptCrop      = new Crop();
                    adaptCrop.Name = cropName;
                    TaskDataMapper.AdaptDataModel.Catalog.Crops.Add(adaptCrop);
                }
                cropProduct.CropId = adaptCrop.Id.ReferenceId;
                return(cropProduct);
            }

            Product product;

            //Type
            switch (isoProduct.ProductType)
            {
            case ISOProductType.Mixture:
            case ISOProductType.TemporaryMixture:
                product             = new MixProduct();
                product.ProductType = ProductTypeEnum.Mix;
                break;

            default:
                product             = new GenericProduct();
                product.ProductType = _manufacturer?.GetProductType(isoProduct) ?? ProductTypeEnum.Generic;
                break;
            }
            return(product);
        }
示例#3
0
        public Product ImportProduct(ISOProduct isoProduct)
        {
            //First check if we've already created a matching seed product from the crop type
            Product product = DataModel.Catalog.Products.FirstOrDefault(p => p.ProductType == ProductTypeEnum.Variety && p.Description == isoProduct.ProductDesignator);

            //If not, create a new product
            if (product == null)
            {
                //Type
                switch (isoProduct.ProductType)
                {
                case ISOProductType.Mixture:
                case ISOProductType.TemporaryMixture:
                    product             = new MixProduct();
                    product.ProductType = ProductTypeEnum.Mix;
                    break;

                default:
                    product             = new GenericProduct();
                    product.ProductType = ProductTypeEnum.Generic;
                    break;
                }
            }

            //ID
            if (!ImportIDs(product.Id, isoProduct.ProductId))
            {
                //Replace the CVT id with the PDT id in the mapping
                TaskDataMapper.InstanceIDMap.ReplaceISOID(product.Id.ReferenceId, isoProduct.ProductId);
            }

            //Description
            product.Description = isoProduct.ProductDesignator;

            //Mixes
            if (isoProduct.ProductRelations.Any())
            {
                if (product.ProductComponents == null)
                {
                    product.ProductComponents = new List <ProductComponent>();
                }

                foreach (ISOProductRelation prn in isoProduct.ProductRelations)
                {
                    //Find the product referenced by the relation
                    ISOProduct isoComponent = ISOTaskData.ChildElements.OfType <ISOProduct>().FirstOrDefault(p => p.ProductId == prn.ProductIdRef);

                    //Find or create the active ingredient to match the component
                    Ingredient ingredient = DataModel.Catalog.Ingredients.FirstOrDefault(i => i.Id.FindIsoId() == isoComponent.ProductId);
                    if (ingredient == null)
                    {
                        ingredient             = new ActiveIngredient();
                        ingredient.Description = isoComponent.ProductDesignator;
                        DataModel.Catalog.Ingredients.Add(ingredient);
                    }

                    //Create a component for this ingredient
                    ProductComponent component = new ProductComponent()
                    {
                        IngredientId = ingredient.Id.ReferenceId
                    };
                    if (!string.IsNullOrEmpty(isoComponent.QuantityDDI))
                    {
                        component.Quantity = prn.QuantityValue.AsNumericRepresentationValue(isoComponent.QuantityDDI, RepresentationMapper);
                    }
                    product.ProductComponents.Add(component);
                }

                //Total Mix quantity
                if (isoProduct.MixtureRecipeQuantity.HasValue)
                {
                    MixProduct mixProduct = product as MixProduct;
                    mixProduct.TotalQuantity = isoProduct.MixtureRecipeQuantity.Value.AsNumericRepresentationValue(isoProduct.QuantityDDI, RepresentationMapper);
                }
            }

            //Density
            if (isoProduct.DensityMassPerCount.HasValue)
            {
                product.Density = isoProduct.DensityMassPerCount.Value.AsNumericRepresentationValue("007A", RepresentationMapper);
            }
            else if (isoProduct.DensityMassPerVolume.HasValue)
            {
                product.Density = isoProduct.DensityMassPerVolume.Value.AsNumericRepresentationValue("0079", RepresentationMapper);
            }
            else if (isoProduct.DensityVolumePerCount.HasValue)
            {
                product.Density = isoProduct.DensityVolumePerCount.Value.AsNumericRepresentationValue("007B", RepresentationMapper);
            }

            return(product);
        }