public virtual void Merge(ICache <string, T> merge, ICache <string, T> target, Func <T, T, bool> areElementsEquivalent = null)
        {
            var resolved            = 0;
            var conflictResolution  = areElementsEquivalent ?? ((x, y) => false);
            var conflictingElements = GetConflictingElements(merge, target, conflictResolution).ToList();

            var option = MergeConflictOptions.SkipOnce;

            foreach (var key in conflictingElements)
            {
                resolved++;
                if (!option.IsAppliedToAll())
                {
                    option = prompt(merge[key], target[key], conflictingElements.Count() - resolved);
                }

                if (option.IsClone())
                {
                    if (option.IsAutoRename())
                    {
                        _nameCorrector.AutoCorrectName(AppConstants.UnallowedNames.Union(target.Select(targetEntity => targetEntity.Name)), merge[key]);
                    }
                    else
                    {
                        if (!_nameCorrector.CorrectName(AppConstants.UnallowedNames.Union(target.Select(targetEntity => targetEntity.Name)), merge[key]))
                        {
                            return;
                        }
                    }
                    _cloneAction(merge[key], key);
                }
                else if (option.IsMerge())
                {
                    _mergeAction(target[key], merge[key]);
                }

                else if (option.IsSkip())
                {
                    continue;
                }

                else if (option == MergeConflictOptions.Cancel)
                {
                    _context.PublishEvent(new MergeCanceledEvent());
                    _cancelAction();
                    return;
                }
                else
                {
                    _removeAction(target[key]);
                    _addAction(merge[key]);
                }
            }

            GetElementsToAdd(merge, target).Each(_addAction);
        }
Exemplo n.º 2
0
        private void addSimulationToProject(IMoBiSimulation simulation, MoBiMacroCommand loadCommand, bool shouldCloneSimulation)
        {
            var moBiSimulation = simulation;

            simulation.MoBiBuildConfiguration.AllBuildingBlockInfos().Each(checkTemplateBuildingBlock);
            var project = _context.CurrentProject;

            if (shouldCloneSimulation)
            {
                moBiSimulation = cloneSimulation(moBiSimulation);
            }

            addBuildConfigurationToProject(project, moBiSimulation.MoBiBuildConfiguration, loadCommand);

            moBiSimulation.Results = simulation.Results;
            if (!_nameCorrector.CorrectName(project.Simulations, moBiSimulation))
            {
                return;
            }

            moBiSimulation.HasChanged = true;
            loadCommand.AddCommand(new AddSimulationCommand(moBiSimulation));
        }
Exemplo n.º 3
0
 public bool CorrectName <T>(T objectBase, IEnumerable <string> forbiddenNames) where T : IObjectBase
 {
     return(_nameCorrector.CorrectName(forbiddenNames, objectBase));
 }
 private void correctName(IFormulaCache formulaCache, IFormula formula)
 {
     _canceled = !_nameCorrector.CorrectName(formulaCache, formula);
 }