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);
        }
Example #2
0
        public IMoBiCommand SetFormulaString(ExplicitFormula formula, string newFormulaString, string oldFormulaString, IBuildingBlock buildingBlock)
        {
            var command = new EditFormulaStringCommand(newFormulaString, oldFormulaString, formula, buildingBlock).Run(_context);

            return(withUpdatedDefaultStateAndValueOrigin(command, formula, buildingBlock));
        }