protected virtual void ValidateInContext(ImportedQuantityDTO dto, QuantityImporterDTO quantityImporterDTO, TImportTarget buildingBlock, DataRow row, int rowIndex) { if (IsUpdate(dto, buildingBlock) && !ValidateDTOForUpdate(dto)) { throw new ImportQuantityDTOsFromDataTablesMapperException(row, rowIndex, AppConstants.Validation.ValueNotValidForUpdate(dto.Path.ToString())); } if (IsNewInsert(dto, buildingBlock) && !ValidateDTOForInsert(dto)) { throw new ImportQuantityDTOsFromDataTablesMapperException(row, rowIndex, AppConstants.Validation.ValueNotValidForInsert(dto.Path.ToString())); } if (string.IsNullOrEmpty(dto.Name)) { throw new ImportQuantityDTOsFromDataTablesMapperException(row, rowIndex, AppConstants.Exceptions.ImportedStartValueMustHaveName); } if (string.IsNullOrEmpty(dto.ContainerPath.PathAsString)) { throw new ImportQuantityDTOsFromDataTablesMapperException(row, rowIndex, AppConstants.Exceptions.ImportedStartValueMustHaveContainerPath); } if (quantityImporterDTO.QuantitDTOs.Any(x => Equals(x.Path, dto.Path))) { throw new ImportQuantityDTOsFromDataTablesMapperException(row, rowIndex, AppConstants.Exceptions.DuplicatedImportedStartValue(dto.Path.PathAsString)); } }
protected override ImportedQuantityDTO MapQuantityFromRow(DataTable table, DataRow row, int rowIndex) { if (row.ItemArray.Count() < DataTableRowIndexes.COLUMNS) { throw new ImportQuantityDTOsFromDataTablesMapperException(row, rowIndex, AppConstants.Exceptions.TableShouldBeNColumns(DataTableRowIndexes.COLUMNS)); } var dimension = GetDimension(table, rowIndex, DataTableRowIndexes.UNIT, DataTableRowIndexes.DIMENSION); var containerPath = GetPath(row, DataTableRowIndexes.CONTAINER_PATH); var quantity = GetQuantity(table, rowIndex, DataTableRowIndexes.VALUE); var parameterName = GetQuantityName(row, DataTableRowIndexes.NAME); var dto = new ImportedQuantityDTO { Dimension = dimension, ContainerPath = new ObjectPath(containerPath), Name = parameterName, DisplayUnit = dimension.Unit(row[DataTableRowIndexes.UNIT].ToString()), IsQuantitySpecified = true, IsScaleDivisorSpecified = false }; dto.QuantityInBaseUnit = dto.ConvertToBaseUnit(quantity); return(dto); }
public IParameterStartValue MapFrom(ImportedQuantityDTO input) { var psv = _psvCreator.CreateParameterStartValue(input.Path, input.QuantityInBaseUnit, input.Dimension); psv.DisplayUnit = input.DisplayUnit; return(psv); }
protected override void ValidateInContext(ImportedQuantityDTO dto, QuantityImporterDTO quantityImporterDTO, IStartValuesBuildingBlock <IParameterStartValue> buildingBlock, DataRow row, int rowIndex) { base.ValidateInContext(dto, quantityImporterDTO, buildingBlock, row, rowIndex); var builder = buildingBlock[dto.Path]; if (builder != null) { ValidateDtoAgainstBuilderForUpdate(builder, dto, row, rowIndex); } }
protected override void ValidateInContext(ImportedQuantityDTO dto, QuantityImporterDTO quantityImporterDTO, IStartValuesBuildingBlock <IMoleculeStartValue> buildingBlock, DataRow row, int rowIndex) { base.ValidateInContext(dto, quantityImporterDTO, buildingBlock, row, rowIndex); if (isDimensionRequired(dto) && !isCorrectDimensionForDimensionMode(_reactionDimensionRetriever.SelectedDimensionMode, dto)) { throw new ImportQuantityDTOsFromDataTablesMapperException( row, rowIndex, AppConstants.Exceptions.ImportedDimensionNotRecognized(getDimensionConstantForProject(_reactionDimensionRetriever.SelectedDimensionMode), _dimensionFactory.Dimension(getDimensionConstantForProject(_reactionDimensionRetriever.SelectedDimensionMode)).GetUnitNames())); } }
public IMoleculeStartValue MapFrom(ImportedQuantityDTO input) { var msv = _msvCreator.CreateMoleculeStartValue(input.ContainerPath, input.Name, input.Dimension, input.DisplayUnit); msv.StartValue = input.QuantityInBaseUnit; msv.DisplayUnit = input.DisplayUnit; msv.IsPresent = input.IsPresent; msv.NegativeValuesAllowed = input.NegativeValuesAllowed; if (input.IsQuantitySpecified) { msv.StartValue = input.QuantityInBaseUnit; } if (input.IsScaleDivisorSpecified) { msv.ScaleDivisor = input.ScaleDivisor; } return(msv); }
protected override void ValidateInContext(ImportedQuantityDTO dto, QuantityImporterDTO quantityImporterDTO, IMoBiSimulation simulation, DataRow row, int rowIndex) { // Skipping base call because the default validation is to stop import when first error occurs if (IsUpdate(dto, simulation)) { if (!ValidateDTOForUpdate(dto)) { throw new ImportQuantityDTOsFromDataTablesMapperException(row, rowIndex, AppConstants.Validation.ValueNotValidForUpdate(dto.Path.ToString())); } ValidateDtoAgainstBuilderForUpdate(dto.Path.TryResolve <IParameter>(simulation.Model.Root), dto, row, rowIndex); } if (!IsNewInsert(dto, simulation)) { return; } // +2 because there is a mandatory header row (+1) and this index is 0-based, while excel rows start at 1 (+1) dto.SetWarning(row, rowIndex + 2, AppConstants.Warnings.CannotAddNewParameterFromImportToSimulation(simulation.Name, dto.Path.ToString())); dto.SkipImport = true; }
protected override ImportedQuantityDTO MapQuantityFromRow(DataTable table, DataRow row, int rowIndex) { if (row.ItemArray.Count() < DataTableRowIndexes.COLUMNS) { throw new ImportQuantityDTOsFromDataTablesMapperException(row, rowIndex, AppConstants.Exceptions.TableShouldBeNColumns(DataTableRowIndexes.COLUMNS)); } var path = GetPath(row, DataTableRowIndexes.PATH); var moleculeName = GetQuantityName(row, DataTableRowIndexes.MOLECULE); var msv = new ImportedQuantityDTO { ContainerPath = new ObjectPath(path), Name = moleculeName, IsPresent = getIsPresent(row), IsScaleDivisorSpecified = getIsValueSpecified(row, DataTableRowIndexes.SCALE_DIVISOR), IsQuantitySpecified = getIsValueSpecified(row, DataTableRowIndexes.VALUE), NegativeValuesAllowed = getNegativeValuesAllowed(row) }; msv.ScaleDivisor = msv.IsScaleDivisorSpecified ? getScaleFactor(table, rowIndex) : double.NaN; if (!msv.IsQuantitySpecified) { return(msv); } var dimension = GetDimension(table, rowIndex, DataTableRowIndexes.UNIT); msv.Dimension = dimension; msv.DisplayUnit = dimension.Unit(row[DataTableRowIndexes.UNIT].ToString()); msv.QuantityInBaseUnit = msv.IsQuantitySpecified ? msv.ConvertToBaseUnit(GetQuantity(table, rowIndex, DataTableRowIndexes.VALUE)) : double.NaN; return(msv); }
protected abstract bool ValidateDTOForInsert(ImportedQuantityDTO dto);
protected override bool IsUpdate(ImportedQuantityDTO dto, IMoBiSimulation simulation) { return(!IsNewInsert(dto, simulation)); }
protected override IMoBiCommand GetUpdateStartValueInBuildingBlockCommand(IMoleculeStartValuesBuildingBlock startValuesBuildingBlock, ImportedQuantityDTO dto) { var scaleDisivor = dto.IsScaleDivisorSpecified ? dto.ScaleDivisor : startValuesBuildingBlock[dto.Path].ScaleDivisor; var startValue = dto.IsQuantitySpecified ? dto.QuantityInBaseUnit : startValuesBuildingBlock[dto.Path].StartValue; return(new UpdateMoleculeStartValueInBuildingBlockCommand(startValuesBuildingBlock, dto.Path, startValue, dto.IsPresent, scaleDisivor, dto.NegativeValuesAllowed)); }
protected override IMoBiCommand GetUpdateStartValueInBuildingBlockCommand(IParameterStartValuesBuildingBlock startValuesBuildingBlock, ImportedQuantityDTO dto) { return(new UpdateParameterStartValueInBuildingBlockCommand(startValuesBuildingBlock, dto.Path, dto.QuantityInBaseUnit)); }
protected abstract IMoBiCommand GetUpdateStartValueInBuildingBlockCommand(TBuildingBlock startValuesBuildingBlock, ImportedQuantityDTO dto);
protected override bool ValidateDTOForInsert(ImportedQuantityDTO dto) { // Cannot insert new values into simulations return(false); }
protected abstract bool IsNewInsert(ImportedQuantityDTO dto, TImportTarget importTarget);
protected override bool IsNewInsert(ImportedQuantityDTO dto, IMoBiSimulation simulation) { return(dto.Path.TryResolve <IParameter>(simulation.Model.Root) == null); }
private bool isCorrectDimensionForDimensionMode(ReactionDimensionMode dimensionMode, ImportedQuantityDTO dto) { if (dto.Dimension == _dimensionFactory.Dimension(Constants.Dimension.MOLAR_CONCENTRATION) && dimensionMode == ReactionDimensionMode.ConcentrationBased) { return(true); } if (dto.Dimension == _dimensionFactory.Dimension(Constants.Dimension.AMOUNT) && dimensionMode == ReactionDimensionMode.AmountBased) { return(true); } return(false); }
private bool isDimensionRequired(ImportedQuantityDTO dto) { return(dto.IsQuantitySpecified); }
protected override void AddDTOToImportList(QuantityImporterDTO quantityImporterDTO, IStartValuesBuildingBlock <IMoleculeStartValue> importTarget, ImportedQuantityDTO dto) { quantityImporterDTO.QuantitDTOs.Add(dto); if (dto.HasWarning()) { quantityImporterDTO.AddToLog(dto.GetWarning()); } quantityImporterDTO.AddToLog(IsNewInsert(dto, importTarget) ? AppConstants.Captions.AddingMoleculeStartValue(dto.Path, dto.ConvertToDisplayUnit(dto.QuantityInBaseUnit), dto.DisplayUnit, dto.IsPresent, dto.Name, dto.NegativeValuesAllowed) : AppConstants.Captions.UpdatingMoleculeStartValue(dto.Path, dto.ConvertToDisplayUnit(dto.QuantityInBaseUnit), dto.DisplayUnit, dto.IsPresent, dto.Name, dto.NegativeValuesAllowed)); }
protected override bool ValidateDTOForUpdate(ImportedQuantityDTO dto) { return(dto.IsQuantitySpecified || dto.IsScaleDivisorSpecified); }
protected abstract bool ValidateDTOForUpdate(ImportedQuantityDTO dto);
private static void updateImportedQuantityWithQuantityDimension(IWithDimension originalWithDimension, ImportedQuantityDTO dto) { var valueInDisplayUnit = dto.ConvertToDisplayUnit(dto.QuantityInBaseUnit); dto.Dimension = originalWithDimension.Dimension; dto.DisplayUnit = originalWithDimension.Dimension.Unit(dto.DisplayUnit.Name); dto.QuantityInBaseUnit = dto.ConvertToBaseUnit(valueInDisplayUnit); }
protected abstract bool IsUpdate(ImportedQuantityDTO dto, TImportTarget importTarget);
protected override bool IsNewInsert(ImportedQuantityDTO dto, IStartValuesBuildingBlock <IParameterStartValue> importTarget) { return(importTarget[dto.Path] == null); }
protected abstract void AddDTOToImportList(QuantityImporterDTO quantityImporterDTO, TImportTarget importTarget, ImportedQuantityDTO dto);
protected override bool ValidateDTOForInsert(ImportedQuantityDTO dto) { return(!double.IsNaN(dto.QuantityInBaseUnit)); }
protected static bool ShouldFormulaBeOverridden(ImportedQuantityDTO quantityDTO, TStartValue startValue) { return(quantityDTO.IsQuantitySpecified && startValue.Formula != null); }
protected override string LogMessageFor(ImportedQuantityDTO dto, IStartValuesBuildingBlock <IParameterStartValue> importTarget) { return(IsNewInsert(dto, importTarget) ? AppConstants.Captions.AddingParameterStartValue(dto.Path, dto.ConvertToDisplayUnit(dto.QuantityInBaseUnit), dto.DisplayUnit) : AppConstants.Captions.UpdatingParameterStartValue(dto.Path, dto.ConvertToDisplayUnit(dto.QuantityInBaseUnit), dto.DisplayUnit)); }
protected override bool IsUpdate(ImportedQuantityDTO dto, IStartValuesBuildingBlock <IParameterStartValue> importTarget) { return(!IsNewInsert(dto, importTarget)); }
protected override string LogMessageFor(ImportedQuantityDTO dto, IMoBiSimulation simulation) { return(IsNewInsert(dto, simulation) ? AppConstants.Captions.AddingParameterValueToSimulation(dto.Path, dto.ConvertToDisplayUnit(dto.QuantityInBaseUnit), dto.DisplayUnit) : AppConstants.Captions.UpdatingParameterValueInSimulation(dto.Path, dto.ConvertToDisplayUnit(dto.QuantityInBaseUnit), dto.DisplayUnit)); }