public void AddObserver()
        {
            var newFile = getNewFile();

            if (string.IsNullOrEmpty(newFile))
            {
                return;
            }

            var observer = _observerTask.LoadObserverFrom(newFile);

            if (observer == null)
            {
                return;
            }

            if (_observerDTOs.ExistsByName(observer.Name))
            {
                var newName = _entityTask.NewNameFor(observer, _observerDTOs.AllNames());
                if (string.IsNullOrEmpty(newName))
                {
                    return;
                }

                observer.Name = newName;
            }

            var observerDTO = addObserver(observer, newFile);

            AddCommand(() => _observerTask.AddObserver(observer, _observerSet));
            updateView(observerDTO);
        }
Example #2
0
        public ICommand LoadOntogenyForMolecule(IndividualMolecule molecule, TSimulationSubject simulationSubject)
        {
            var dataImporterSettings = new DataImporterSettings
            {
                Caption = $"{CoreConstants.ProductDisplayName} - {PKSimConstants.UI.ImportOntogeny}",
                Icon    = ApplicationIcons.Excel
            };

            var data = _dataImporter.ImportDataSet(new List <MetaDataCategory>(), getColumnInfos(), dataImporterSettings);

            if (data == null)
            {
                return(null);
            }

            var ontogeny = new UserDefinedOntogeny {
                Table = formulaFrom(data), Name = data.Name
            };

            //only first formulation will be imported
            if (_ontogenyRepository.AllNames().Contains(ontogeny.Name))
            {
                var name = _entityTask.NewNameFor(ontogeny, _ontogenyRepository.AllNames());
                if (string.IsNullOrEmpty(name))
                {
                    return(null);
                }

                ontogeny.Name = name;
            }

            return(SetOntogenyForMolecule(molecule, ontogeny, simulationSubject));
        }
Example #3
0
        protected override void Context()
        {
            _executionContext        = A.Fake <ISBSuiteExecutionContext>();
            _entityTask              = A.Fake <IEntityTask>();
            _eventPublisher          = A.Fake <IEventPublisher>();
            _project                 = A.Fake <IPKSimProject>();
            _parameterIdentification = new ParameterIdentification();

            A.CallTo(() => _executionContext.Project).Returns(_project);
            A.CallTo(() => _entityTask.NewNameFor(_parameterIdentification, A <IEnumerable <string> > ._, A <string> ._)).Returns("newName");

            A.CallTo(() => _project.AllParameterIdentifications).Returns(new[]
            {
                new ParameterIdentification()
                {
                    Name = "name1"
                },
                new ParameterIdentification()
                {
                    Name = "name2"
                }
            });

            sut = new RenameParameterIdentificationUICommand(_entityTask, _eventPublisher, _executionContext);
            sut.For(_parameterIdentification);
        }
        protected override void PerformExecute()
        {
            var newName = _entityTask.NewNameFor(Subject, ForbiddenNamesFor(Subject));

            if (string.IsNullOrEmpty(newName))
            {
                return;
            }

            Subject.Name = newName;
            _eventPublisher.PublishEvent(new RenamedEvent(Subject));
        }
        public ICommand LoadOntogenyForMolecule(IndividualMolecule molecule, ISimulationSubject simulationSubject)
        {
            var dataImporterSettings = new DataImporterSettings
            {
                Caption  = $"{CoreConstants.ProductDisplayName} - {PKSimConstants.UI.ImportOntogeny}",
                IconName = ApplicationIcons.Excel.IconName
            };

            dataImporterSettings.AddNamingPatternMetaData(Constants.FILE);

            var data = _dataImporter.ImportDataSets(
                new List <MetaDataCategory>(),
                getColumnInfos(),
                dataImporterSettings,
                _dialogCreator.AskForFileToOpen(Captions.Importer.OpenFile, Captions.Importer.ImportFileFilter, Constants.DirectoryKey.OBSERVED_DATA)
                ).DataRepositories.FirstOrDefault();

            if (data == null)
            {
                return(null);
            }

            var ontogeny = new UserDefinedOntogeny {
                Table = formulaFrom(data), Name = data.Name
            };

            //only first ontogeny will be imported
            if (_ontogenyRepository.AllNames().Contains(ontogeny.Name))
            {
                var name = _entityTask.NewNameFor(ontogeny, _ontogenyRepository.AllNames());
                if (string.IsNullOrEmpty(name))
                {
                    return(null);
                }

                ontogeny.Name = name;
            }

            return(SetOntogenyForMolecule(molecule, ontogeny, simulationSubject));
        }
Example #6
0
        private LocalTemplate templateItemFor(IPKSimBuildingBlock buildingBlockToSave, TemplateDatabaseType templateDatabaseType)
        {
            string buildingBlockName = buildingBlockToSave.Name;
            string buildingBlockType = TypeFor(buildingBlockToSave);
            var    templateType      = buildingBlockToSave.BuildingBlockType.AsTemplateType();

            if (_templateTaskQuery.Exists(templateDatabaseType, buildingBlockName, templateType))
            {
                var result = _dialogCreator.MessageBoxYesNoCancel(PKSimConstants.UI.TemplateWithNameAlreadyExistsInTheDatabase(buildingBlockToSave.Name, buildingBlockType),
                                                                  PKSimConstants.UI.Override, PKSimConstants.UI.SaveAs, PKSimConstants.UI.CancelButton);

                //user does not want to override
                if (result == ViewResult.Cancel)
                {
                    return(null);
                }

                //retrieve a new name
                if (result == ViewResult.No)
                {
                    var allTemplateNames = _templateTaskQuery.AllTemplatesFor(templateDatabaseType, templateType).Select(x => x.Name);
                    buildingBlockName = _entityTask.NewNameFor(buildingBlockToSave, allTemplateNames);
                    if (string.IsNullOrEmpty(buildingBlockName))
                    {
                        return(null);
                    }
                }
            }

            Load(buildingBlockToSave);
            return(new LocalTemplate
            {
                Name = buildingBlockName,
                Description = buildingBlockToSave.Description,
                Object = buildingBlockToSave,
                Type = templateType,
                DatabaseType = templateDatabaseType
            });
        }
 private string renameFieldAfterImport(PopulationAnalysis populationAnalysis, PopulationAnalysisDerivedField field)
 {
     return(_entityTask.NewNameFor(field, populationAnalysis.AllFields.Select(x => x.Name), PKSimConstants.UI.Grouping));
 }