public void Visit(IFormula formula) { checkObjectBase(formula); // create aliases from name to change them acordingly var oldAlias = _aliasCreator.CreateAliasFrom(_oldName); var newAlias = _aliasCreator.CreateAliasFrom(_newName); foreach (var path in formula.ObjectPaths) { // possible path adjustments if (path.Contains(_oldName)) { //var newPath = generateNewPath(path); _changes.Add(formula, _buildingBlock, new ChangePathElementAtFormulaUseablePathCommand(_newName, formula, _oldName, path, _buildingBlock)); } // possible alias Adjustments if (path.Alias.Equals(oldAlias)) { var i = 0; // change new alias and remember this for this formula to change formula strign right if nessesary while (formula.ObjectPaths.Select(x => x.Alias).Contains(newAlias)) { newAlias = $"{newAlias}{i}"; i++; } _changes.Add(formula, _buildingBlock, new EditFormulaAliasCommand(formula, newAlias, oldAlias, _buildingBlock)); } } var explicitFormula = formula as ExplicitFormula; if (explicitFormula == null) { return; } // possible Formula string adjustments if (!containsWord(explicitFormula.FormulaString, oldAlias)) { return; } var newFormulaString = wordReplace(explicitFormula.FormulaString, oldAlias, newAlias); var editFormulaStringCommand = new EditFormulaStringCommand(newFormulaString, explicitFormula, _buildingBlock); _changes.Add(formula, _buildingBlock, editFormulaStringCommand, editFormulaStringCommand.Description); }
public string AddParentVolumeReferenceToFormula(IFormula formula) { string volumeAlias = _aliasCreator.CreateAliasFrom(Constants.VOLUME_ALIAS, formula.ObjectPaths.Select(p => p.Alias)); //possible reference var volumeReferencePath = _objectPathFactory.CreateFormulaUsablePathFrom(ObjectPath.PARENT_CONTAINER, Constants.Parameters.VOLUME) .WithAlias(volumeAlias) .WithDimension(_dimensionFactory.Dimension(Constants.Dimension.VOLUME)); //do we have one already? var volumeReference = formula.ObjectPaths.FirstOrDefault(x => Equals(x.PathAsString, volumeReferencePath.PathAsString)); //was not defined yet if (volumeReference == null) { formula.AddObjectPath(volumeReferencePath); } else { volumeAlias = volumeReference.Alias; } //return the used alias return(volumeAlias); }
private string createAliasFrom(string objectName) { if (_forbiddenNames.Contains(objectName.ToUpperInvariant())) { objectName = $"{objectName}_"; } return(_aliasCreator.CreateAliasFrom(objectName, _objectPaths.Select(x => x.Alias))); }
/// <summary> /// Creates the path from parameter dummy. /// </summary> /// <param name="objectBaseDTO">The dummy parameter dto.</param> /// <param name="shouldCreateAbsolutePaths">if set to <c>true</c> creates absolute paths otherwise creates reltive paths.</param> /// <param name="refObject"> /// The reference object the user chosen (may the concrete object that uses the reference or a /// existing parent of it). /// </param> /// <param name="editedObject"></param> /// <returns> The path that could be uses in the model to reference the object</returns> public virtual ReferenceDTO CreatePathFromParameterDummy(IObjectBaseDTO objectBaseDTO, bool shouldCreateAbsolutePaths, IEntity refObject, IUsingFormula editedObject) { if (IsMoleculeReference(objectBaseDTO)) { return(createMoleculeReference()); } var dtoDummyParameter = (DummyParameterDTO)objectBaseDTO; var parameterToUse = _context.Get <IParameter>(dtoDummyParameter.ParameterToUse.Id); ReferenceDTO dtoReference; if (parameterToUse.IsAtMolecule()) { dtoReference = new ReferenceDTO(); IObjectPath tmpPath; //global molecule parameters we always reference absolute if (shouldCreateAbsolutePaths || !parameterToUse.BuildMode.Equals(ParameterBuildMode.Local)) { tmpPath = _objectPathFactory.CreateAbsoluteObjectPath(dtoDummyParameter.Parent); } else { if (refObject != dtoDummyParameter.Parent) { tmpPath = _objectPathFactory.CreateRelativeObjectPath(refObject, dtoDummyParameter.Parent); } else { tmpPath = new ObjectPath(); } tmpPath = AdjustReferences(parameterToUse, tmpPath); } dtoReference.Path = _objectPathFactory.CreateFormulaUsablePathFrom(tmpPath) .WithAlias(_aliasCreator.CreateAliasFrom(parameterToUse.Name)) .WithDimension(parameterToUse.Dimension); dtoReference.Path.Add(parameterToUse.Name); } else { dtoReference = CreatePathsFromEntity(parameterToUse, shouldCreateAbsolutePaths, refObject, editedObject); } dtoReference.Path.Replace(Constants.MOLECULE_PROPERTIES, dtoDummyParameter.ModelParentName); dtoReference.BuildMode = parameterToUse.BuildMode; return(dtoReference); }
private string createAliasFrom(string name) { return(_aliasCreator.CreateAliasFrom(name)); }