예제 #1
0
        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));
            }
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #7
0
        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);
        }
예제 #9
0
 protected abstract bool ValidateDTOForInsert(ImportedQuantityDTO dto);
예제 #10
0
 protected override bool IsUpdate(ImportedQuantityDTO dto, IMoBiSimulation simulation)
 {
     return(!IsNewInsert(dto, simulation));
 }
예제 #11
0
        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));
        }
예제 #12
0
 protected override IMoBiCommand GetUpdateStartValueInBuildingBlockCommand(IParameterStartValuesBuildingBlock startValuesBuildingBlock, ImportedQuantityDTO dto)
 {
     return(new UpdateParameterStartValueInBuildingBlockCommand(startValuesBuildingBlock, dto.Path, dto.QuantityInBaseUnit));
 }
예제 #13
0
 protected abstract IMoBiCommand GetUpdateStartValueInBuildingBlockCommand(TBuildingBlock startValuesBuildingBlock, ImportedQuantityDTO dto);
예제 #14
0
 protected override bool ValidateDTOForInsert(ImportedQuantityDTO dto)
 {
     // Cannot insert new values into simulations
     return(false);
 }
예제 #15
0
 protected abstract bool IsNewInsert(ImportedQuantityDTO dto, TImportTarget importTarget);
예제 #16
0
 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);
 }
예제 #21
0
 protected abstract bool ValidateDTOForUpdate(ImportedQuantityDTO dto);
예제 #22
0
        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);
        }
예제 #23
0
 protected abstract bool IsUpdate(ImportedQuantityDTO dto, TImportTarget importTarget);
 protected override bool IsNewInsert(ImportedQuantityDTO dto, IStartValuesBuildingBlock <IParameterStartValue> importTarget)
 {
     return(importTarget[dto.Path] == null);
 }
예제 #25
0
 protected abstract void AddDTOToImportList(QuantityImporterDTO quantityImporterDTO, TImportTarget importTarget, ImportedQuantityDTO dto);
 protected override bool ValidateDTOForInsert(ImportedQuantityDTO dto)
 {
     return(!double.IsNaN(dto.QuantityInBaseUnit));
 }
예제 #27
0
 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));
 }
예제 #30
0
 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));
 }