protected void ExportContextItems(List <ContextItem> contextItems, string isoIDRef, string groupName, string prefix = "") { if (contextItems.Any()) { List <string> errors = UniqueIDMapper.ExportContextItems(contextItems, isoIDRef, groupName, prefix); foreach (string error in errors) { TaskDataMapper.AddError(error); } } }
protected BaseMapper(TaskDataMapper taskDataMapper, string xmlPrefix, int startId = 1) { TaskDataMapper = taskDataMapper; XmlPrefix = xmlPrefix; _itemId = startId; DataModel = TaskDataMapper.AdaptDataModel; ISOTaskData = TaskDataMapper.ISOTaskData; UniqueIDMapper = TaskDataMapper.UniqueIDMapper; RepresentationMapper = TaskDataMapper.RepresentationMapper; DDIs = taskDataMapper.DDIs; DeviceOperationTypes = taskDataMapper.DeviceOperationTypes; }
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); if (isoComponent != null) //Skip PRN if PRN@A doesn't resolve to a product { //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); } else { TaskDataMapper.AddError($"Product relation with quantity {prn.QuantityValue} ommitted for product {isoProduct.ProductId} due to no ProductIdRef"); } } //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); }