Example #1
0
        private IOSPSuiteCommand withUpdatedDefaultStateAndValue(IOSPSuiteCommand executedCommand, IParameter parameter, bool shouldChangeVersion = true, bool shouldUpdateDefaultStateAndValueOriginForDefaultParameter = true)
        {
            if (!shouldUpdateDefaultStateAndValueOriginForDefaultParameter)
            {
                return(executedCommand);
            }

            if (!parameter.IsDefault)
            {
                return(executedCommand);
            }

            if (executedCommand.IsEmpty())
            {
                return(executedCommand);
            }

            var macroCommand = new PKSimMacroCommand().WithHistoryEntriesFrom(executedCommand);

            macroCommand.Add(executedCommand);
            macroCommand.Add(new SetParameterDefaultStateCommand(parameter, isDefault: false)
            {
                ShouldChangeVersion = shouldChangeVersion
            }.Run(_executionContext).AsHidden());

            var setValueOriginCommand = setParameterValueOrigin(parameter, ValueOrigin.Unknown, shouldChangeVersion).AsHidden();

            macroCommand.Add(setValueOriginCommand);
            return(macroCommand);
        }
Example #2
0
        private IOSPSuiteCommand withUpdatedDefaultStateAndValueOrigin <T>(
            IOSPSuiteCommand executedCommand,
            IQuantity quantity,
            T buildingBlockOrSimulation,
            Func <IParameter, bool, T, ICommand> setParameterDefaultStateFunc,
            Func <IParameter, ValueOrigin, T, ICommand> setParameterValueOriginFunc
            )
        {
            if (executedCommand.IsEmpty() || executedCommand.IsEmptyMacro())
            {
                return(executedCommand);
            }

            var updateCommand = new MoBiMacroCommand();

            addUpdateDefaultStateAndValueOriginCommand(updateCommand, quantity, buildingBlockOrSimulation, setParameterDefaultStateFunc, setParameterValueOriginFunc);

            if (updateCommand.IsEmtpy)
            {
                return(executedCommand);
            }

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

            macroCommand.Add(executedCommand);
            macroCommand.AddRange(updateCommand.All());
            return(macroCommand);
        }
Example #3
0
 public static T UpdatePropertiesFrom <T>(this T command, IOSPSuiteCommand originalCommand) where T : IOSPSuiteCommand
 {
     if (originalCommand == null)
     {
         return(command);
     }
     command.BuildingBlockName = originalCommand.BuildingBlockName;
     command.BuildingBlockType = originalCommand.BuildingBlockType;
     return(command);
 }
        protected override void Context()
        {
            _originalCommand  = A.Fake <IOSPSuiteCommand>();
            _resultingCommand = A.Fake <IOSPSuiteCommand>();

            _originalCommand.CommandType       = "commandType";
            _originalCommand.Description       = "description";
            _originalCommand.ObjectType        = "objectType";
            _originalCommand.BuildingBlockType = "buildingBlockType";
            _originalCommand.BuildingBlockName = "buildingBlockName";
        }
Example #5
0
        private static void replaceTemplateWithValue(this IOSPSuiteCommand command, string template, string value)
        {
            command.Description         = replaceIn(command.Description, template, value);
            command.ExtendedDescription = replaceIn(command.ExtendedDescription, template, value);
            command.BuildingBlockName   = replaceIn(command.BuildingBlockName, template, value);
            command.BuildingBlockType   = replaceIn(command.BuildingBlockType, template, value);

            var macroCommand = command as IPKSimMacroCommand;

            macroCommand?.All().Each(c => c.replaceTemplateWithValue(template, value));
        }
Example #6
0
        public void UpdateBuildinBlockPropertiesInCommand(IOSPSuiteCommand command, IPKSimBuildingBlock buildingBlock)
        {
            if (buildingBlock == null)
            {
                command.BuildingBlockType = CoreConstants.ContainerName.TypeTemplate;
                command.BuildingBlockName = CoreConstants.ContainerName.NameTemplate;
                return;
            }

            command.BuildingBlockType = TypeFor(buildingBlock);
            command.BuildingBlockName = string.IsNullOrEmpty(buildingBlock.Name) ? CoreConstants.ContainerName.NameTemplate : buildingBlock.Name;
        }
Example #7
0
        private ICommand synchronizedCommand(IQuantity quantity, IMoBiSimulation simulation, IMoBiCommand simulationCommandToBeRun, bool shouldUpdateValueOriginAndState = true)
        {
            var macroCommand = new MoBiMacroCommand();

            //add one before setting the value in the simulation to enable correct undo
            macroCommand.Add(_quantitySynchronizer.Synchronize(quantity, simulation));

            IOSPSuiteCommand executedCommand = simulationCommandToBeRun.AsHidden().Run(_context);

            if (shouldUpdateValueOriginAndState)
            {
                executedCommand = withUpdatedDefaultStateAndValueOrigin(executedCommand, quantity, simulation);
            }

            macroCommand.Add(executedCommand);

            macroCommand.Add(_quantitySynchronizer.Synchronize(quantity, simulation));

            //needs to be done at the end because description might be set only after run
            return(macroCommand.WithHistoryEntriesFrom(simulationCommandToBeRun));
        }
 protected override void Because()
 {
     _resultingCommand = _resultingCommand.WithHistoryEntriesFrom(_originalCommand);
 }
Example #9
0
 /// <summary>
 ///    Replace the occurence of the term Template with the given name
 /// </summary>
 public static void ReplaceNameTemplateWithName(this IOSPSuiteCommand command, string name)
 {
     command.replaceTemplateWithValue(CoreConstants.ContainerName.NameTemplate, name);
 }
Example #10
0
 private IOSPSuiteCommand withUpdatedDefaultStateAndValueOrigin(IOSPSuiteCommand executedCommand, IQuantity quantity, IMoBiSimulation simulation)
 {
     //Do not use UpdateQuantityValueOriginInSimulation as it will otherwise create an issue with updating value origin many times in synchronization
     return(withUpdatedDefaultStateAndValueOrigin(executedCommand, quantity, simulation, setParameterDefaultStateInSimulation, updateQuantityValueOriginInSimulation));
 }
Example #11
0
 private ICommand withUpdatedDefaultStateAndValueOrigin(IOSPSuiteCommand executedCommand, IQuantity quantity, IBuildingBlock buildingBlock)
 {
     return(withUpdatedDefaultStateAndValueOrigin(executedCommand, quantity, buildingBlock, setParameterDefaultStateInBuildingBlock, UpdateQuantityValueOriginInBuildingBlock));
 }
 public static TCommand WithHistoryEntriesFrom <TCommand>(this TCommand targetCommand, IOSPSuiteCommand sourceCommand) where TCommand : IOSPSuiteCommand
 {
     targetCommand.ObjectType        = sourceCommand.ObjectType;
     targetCommand.Description       = sourceCommand.Description;
     targetCommand.CommandType       = sourceCommand.CommandType;
     targetCommand.BuildingBlockType = sourceCommand.BuildingBlockType;
     targetCommand.BuildingBlockName = sourceCommand.BuildingBlockName;
     return(targetCommand);
 }