Exemplo n.º 1
0
 public void Init <TObjectWithFormula>(TObjectWithFormula formulaOwner, IBuildingBlock buildingBlock, FormulaDecoder <TObjectWithFormula> formulaDecoder)
     where TObjectWithFormula : IEntity, IWithDimension
 {
     _formulaOwner    = formulaOwner;
     _formulaDecoder  = formulaDecoder;
     _formula         = formulaDecoder.GetFormula(formulaOwner);
     _buildingBlock   = buildingBlock;
     _constantFormula = null;
     updateFormula();
 }
Exemplo n.º 2
0
        public IMoBiCommand AddFormulaToCacheOrFixReferenceCommand <T>(IBuildingBlock targetBuildingBlock, T usingFormulaObject, FormulaDecoder <T> decoder)
        {
            if (decoder.GetFormula(usingFormulaObject) == null)
            {
                return(new MoBiEmptyCommand());
            }

            var existingFormula = targetBuildingBlock.FormulaCache.FindByName(decoder.GetFormula(usingFormulaObject).Name);

            // There is no existing formula in the cache with the same name
            if (existingFormula == null)
            {
                return(new AddFormulaToFormulaCacheCommand(targetBuildingBlock, decoder.GetFormula(usingFormulaObject)));
            }

            // There is a formula with the same name, but it is not equal to the formula in the object
            if (!_formulaTask.FormulasAreTheSame(existingFormula, decoder.GetFormula(usingFormulaObject)))
            {
                _nameCorrector.AutoCorrectName(targetBuildingBlock.FormulaCache.Select(formula => formula.Name), decoder.GetFormula(usingFormulaObject));
                return(new AddFormulaToFormulaCacheCommand(targetBuildingBlock, decoder.GetFormula(usingFormulaObject)));
            }

            // not null and formulas are the same
            decoder.SetFormula(existingFormula, usingFormulaObject);
            return(new MoBiEmptyCommand());
        }
Exemplo n.º 3
0
        public IMoBiCommand UpdateFormula(IEntity usingFormula, IFormula oldFormula, IFormula newFormula, FormulaDecoder formulaDecoder, IBuildingBlock buildingBlock)
        {
            var command  = new EditObjectBasePropertyInBuildingBlockCommand(formulaDecoder.PropertyName, newFormula, oldFormula, usingFormula, buildingBlock).Run(_context);
            var quantity = usingFormula as IQuantity;

            if (quantity == null)
            {
                return(command);
            }

            var updateCommand = _quantityTask.UpdateDefaultStateAndValueOriginFor(quantity, buildingBlock);

            if (updateCommand.IsEmpty() || updateCommand.IsEmptyMacro())
            {
                return(command);
            }

            var macroCommand = new MoBiMacroCommand().WithHistoryEntriesFrom(command);

            macroCommand.Add(command);
            macroCommand.Add(updateCommand);
            return(macroCommand);
        }