public void should_return_a_macro_command_containing_all_sub_commands_executed_by_the_user()
 {
     _resultOfScaleIndividual.ShouldNotBeNull();
     _resultOfScaleIndividual.All().ShouldOnlyContainInOrder(_command1, _command2);
 }
예제 #2
0
        private ICommand synchronizeBuildingBlocks(IPKSimBuildingBlock templateBuildingBlock, IPKSimMacroCommand updateTemplateParametersCommand)
        {
            var simulationSubject = templateBuildingBlock as ISimulationSubject;

            //For now, deal with update from Individual or Population into Expression Profile
            if (simulationSubject == null)
            {
                return(new PKSimEmptyCommand());
            }

            var allExpressionProfileParameterValueCommand = updateTemplateParametersCommand.All()
                                                            .OfType <SetExpressionProfileValueCommand>()
                                                            .ToList();

            if (!allExpressionProfileParameterValueCommand.Any())
            {
                return(new PKSimEmptyCommand());
            }


            var expressionProfilesToUpdate = new HashSet <ExpressionProfile>();
            var macroCommand = new PKSimMacroCommand();

            //We have some commands related to expression profile. We need to update the expression profile
            foreach (var parameterCommand in allExpressionProfileParameterValueCommand)
            {
                var simulationSubjectParameter = _executionContext.Get <IParameter>(parameterCommand.ParameterId);
                if (simulationSubjectParameter == null)
                {
                    continue;
                }

                //This should be the id of the parameter in the expression profile
                var expressionProfileParameterId = simulationSubjectParameter.Origin.ParameterId;
                var expressionProfileParameter   = _executionContext.Get <IParameter>(expressionProfileParameterId);
                if (expressionProfileParameter == null)
                {
                    continue;
                }

                var expressionProfile = _executionContext.BuildingBlockContaining(expressionProfileParameter) as ExpressionProfile;
                if (expressionProfile == null)
                {
                    continue;
                }

                expressionProfilesToUpdate.Add(expressionProfile);

                //We do not update the simulation subject. It will be done at the end of the loop
                var command = new SetExpressionProfileValueCommand(expressionProfileParameter, simulationSubjectParameter.Value, updateSimulationSubjects: false);
                macroCommand.Add(command);
            }

            macroCommand.Run(_executionContext);
            _executionContext.UpdateBuildingBlockPropertiesInCommand(macroCommand, templateBuildingBlock);

            //Now that our expression profile are updated, we need to trigger the synchronization in all building blocks
            expressionProfilesToUpdate.Each(x => _expressionProfileUpdater.SynchronizeAllSimulationSubjectsWithExpressionProfile(x));

            return(macroCommand);
        }