Esempio n. 1
0
        private void exportSimulationToFile(Simulation simulation, string moBiFile)
        {
            _lazyLoadTask.Load(simulation);
            if (simulation.IsImported)
            {
                throw new PKSimException(PKSimConstants.Error.CannotExportAnImportedSimulation);
            }

            var configuration  = _buildConfigurationTask.CreateFor(simulation, shouldValidate: true, createAgingDataInSimulation: false);
            var moBiSimulation = _simulationMapper.MapFrom(simulation, configuration, shouldCloneModel: false);

            updateObserverForAllFlag(moBiSimulation);
            updateRepresentationInfo(moBiSimulation);
            updateFormulaIdIn(moBiSimulation);

            var simulationTransfer = new SimulationTransfer
            {
                Simulation  = moBiSimulation,
                JournalPath = _journalRetriever.JournalFullPath
            };

            var currentProject = _projectRetriever.CurrentProject;

            if (currentProject != null)
            {
                simulationTransfer.AllObservedData = simulation.UsedObservedData.Select(o => currentProject.ObservedDataBy(o.Id)).ToList();
                simulationTransfer.Favorites       = currentProject.Favorites;
            }

            _simulationPersistor.Save(simulationTransfer, moBiFile);
        }
        private void loadSimulationFromFileInProject(string fileName)
        {
            var project = _context.CurrentProject;

            if (project == null)
            {
                return;
            }

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

            SimulationTransfer simulationTransfer = null;

            _heavyWorkManager.Start(() => simulationTransfer = LoadSimulationTransferDataFromFile(fileName));
            if (simulationTransfer == null)
            {
                return;
            }

            _context.AddToHistory(addSimulationTransferToProject(simulationTransfer));
            loadJournalIfNotLoadedAlready(project, simulationTransfer.JournalPath);
            notifyProjectLoaded();
        }
Esempio n. 3
0
 protected override void Context()
 {
     base.Context();
     _simulationTransfer = new SimulationTransfer {
         Simulation = _simulation
     };
 }
Esempio n. 4
0
        protected override void Context()
        {
            base.Context();
            _project                      = A.Fake <IMoBiProject>();
            _simulationTransfer           = A.Fake <SimulationTransfer>();
            _simulationTransfer.Favorites = new Favorites {
                "Fav1", "Fav2"
            };
            _simulation = A.Fake <IMoBiSimulation>();
            _simulationTransfer.Simulation = _simulation;
            _newBuildingBlock      = A.Fake <IPassiveTransportBuildingBlock>();
            _existingBuildingBlock = A.Fake <IMoBiReactionBuildingBlock>().WithId("Existing");
            _existingBBInfo        = new ReactionBuildingBlockInfo()
            {
                BuildingBlock = _existingBuildingBlock, TemplateBuildingBlockId = "Existing"
            };
            _newBBInfo = new PassiveTransportBuildingBlockInfo()
            {
                BuildingBlock = _newBuildingBlock, TemplateBuildingBlockId = "New"
            };

            A.CallTo(() => _project.ReactionBlockCollection).Returns(new[] { _existingBuildingBlock });
            var moBiBuildConfiguration = A.Fake <IMoBiBuildConfiguration>();

            A.CallTo(() => _simulation.MoBiBuildConfiguration).Returns(moBiBuildConfiguration);
            A.CallTo(() => moBiBuildConfiguration.AllBuildingBlockInfos()).Returns(new IBuildingBlockInfo[] { _existingBBInfo, _newBBInfo });
            moBiBuildConfiguration.ReactionsInfo         = _existingBBInfo;
            moBiBuildConfiguration.PassiveTransportsInfo = _newBBInfo;
            A.CallTo(() => _dialogCreator.AskForFileToOpen(AppConstants.Dialog.LoadSimulation, Constants.Filter.PKML_FILE_FILTER, Constants.DirectoryKey.MODEL_PART, null, null)).Returns("File");
            A.CallTo(() => _serializationTask.Load <SimulationTransfer>(A <string> ._, A <bool> ._)).Returns(_simulationTransfer);
            A.CallTo(() => _context.CurrentProject).Returns(_project);
            A.CallTo(() => _nameCorrector.CorrectName(A <IEnumerable <IPassiveTransportBuildingBlock> > ._, _newBuildingBlock)).Returns(true);
        }
        public void SaveSimulation(Simulation simulation, string fileName)
        {
            var simulationTransfer = new SimulationTransfer {
                Simulation = simulation.CoreSimulation
            };

            _simulationPersistor.Save(simulationTransfer, fileName);
        }
        protected override void Context()
        {
            base.Context();
            var simTransfer = new SimulationTransfer();

            _individualSimulation = A.Fake <IndividualSimulation>();
            A.CallTo(() => _simulationTransferLoader.Load(_pkmlFile)).Returns(simTransfer);
            A.CallTo(() => _simulationFactory.CreateBasedOn <IndividualSimulation>(simTransfer.Simulation)).Returns(_individualSimulation);
        }
Esempio n. 7
0
        protected override void Context()
        {
            base.Context();
            A.CallTo(() => _simulationPersister.Save(A <SimulationTransfer> ._, A <string> ._))
            .Invokes(x => _simulationTransfer = x.GetArgument <SimulationTransfer>(0));

            A.CallTo(() => _favoriteRepository.Favorites).Returns(new Favorites {
                "A", "B"
            });
        }
Esempio n. 8
0
 protected override void Context()
 {
     _pkmlFile            = "file";
     _project             = new PKSimProject();
     _simulationPersister = A.Fake <ISimulationPersistor>();
     _projectRetriever    = A.Fake <IProjectRetriever>();
     _journalTask         = A.Fake <IJournalTask>();
     sut = new SimulationTransferLoader(_simulationPersister, _projectRetriever, _journalTask);
     _simulationTransfer = new SimulationTransfer();
     A.CallTo(() => _projectRetriever.CurrentProject).Returns(_project);
     A.CallTo(() => _simulationPersister.Load(_pkmlFile, A <IWithIdRepository> ._)).Returns(_simulationTransfer);
 }
 protected override void Context()
 {
     base.Context();
     _dataRepository                     = new DataRepository("Id");
     _newDataRepository                  = new DataRepository("New");
     _simulationTransfer                 = new SimulationTransfer();
     _simulationTransfer.Simulation      = _simulation;
     _simulationTransfer.AllObservedData = new List <DataRepository> {
         _dataRepository, _newDataRepository
     };
     _project.AddObservedData(_dataRepository);
 }
Esempio n. 10
0
 protected override void Context()
 {
     base.Context();
     _fileName                      = "filename";
     _simulationTransfer            = A.Fake <SimulationTransfer>();
     _simulationTransfer.Simulation = A.Fake <IMoBiSimulation>().WithName("Sim");
     A.CallTo(_dialogCreator).WithReturnType <string>().Returns(_fileName);
     A.CallTo(() => _serializationTask.Load <SimulationTransfer>(_fileName, false))
     .Throws(() => new CannotConvertConcentrationToAmountException("object"))
     .Once()
     .Then.Returns(_simulationTransfer);
 }
Esempio n. 11
0
        public ICommand AddSimulationToProject(SimulationTransfer simulationTransfer)
        {
            var project = _context.CurrentProject;

            project.Favorites.AddFavorites(simulationTransfer.Favorites);
            var simulation  = simulationTransfer.Simulation.DowncastTo <IMoBiSimulation>();
            var loadCommand = createLoadCommand(simulation);

            addSimulationToProject(simulation, loadCommand, shouldCloneSimulation: !project.IsEmpty);
            addObservedDataToProject(simulationTransfer.AllObservedData, loadCommand);
            return(loadCommand.Run(_context));
        }
        public ICommand AddSimulationToProject(SimulationTransfer simulationTransfer)
        {
            var project = _context.CurrentProject;

            project.Favorites.AddFavorites(simulationTransfer.Favorites);
            var simulation  = simulationTransfer.Simulation.DowncastTo <IMoBiSimulation>();
            var loadCommand = createLoadCommand(simulation);

            //We always clone the simulation from Transfer as it may be loaded twice
            addSimulationToProject(simulation, loadCommand, shouldCloneSimulation: true);
            addObservedDataToProject(simulationTransfer.AllObservedData, loadCommand);
            return(loadCommand.Run(_context));
        }
Esempio n. 13
0
 protected override void Context()
 {
     _pkmlFile             = "file";
     _project              = new PKSimProject();
     _dimensionFactory     = A.Fake <IDimensionFactory>();
     _objectBaseFactory    = A.Fake <IObjectBaseFactory>();
     _simulationPersister  = A.Fake <ISimulationPersistor>();
     _projectRetriever     = A.Fake <IProjectRetriever>();
     _journalTask          = A.Fake <IJournalTask>();
     _cloneManagerForModel = A.Fake <ICloneManagerForModel>();
     sut = new SimulationTransferLoader(_dimensionFactory, _objectBaseFactory, _simulationPersister, _projectRetriever, _journalTask, _cloneManagerForModel);
     _simulationTransfer = new SimulationTransfer();
     A.CallTo(() => _projectRetriever.CurrentProject).Returns(_project);
     A.CallTo(() => _simulationPersister.Load(_pkmlFile, _dimensionFactory, _objectBaseFactory, A <IWithIdRepository> ._, _cloneManagerForModel)).Returns(_simulationTransfer);
 }
Esempio n. 14
0
        public void SendSimulationToPKSim(IMoBiSimulation simulation)
        {
            var simulationTransfer = new SimulationTransfer
            {
                Simulation      = simulation,
                PkmlVersion     = Constants.PKML_VERSION,
                AllObservedData = Enumerable.Empty <DataRepository>().ToList(),
                Favorites       = _favoriteRepository.Favorites,
                JournalPath     = _journalRetriever.JournalFullPath
            };

            var fileName = FileHelper.GenerateTemporaryFileName();

            fileName = Path.ChangeExtension(fileName, Constants.Filter.PKML_EXTENSION);
            _simulationPersister.Save(simulationTransfer, fileName);
            _pkSimStarter.StartPopulationSimulationWithSimulationFile(fileName);
        }
Esempio n. 15
0
        protected override void Context()
        {
            base.Context();
            _sim           = A.Fake <Simulation>();
            _fileName      = "toto";
            _observedData1 = new DataRepository();
            A.CallTo(() => _sim.UsedObservedData).Returns(new[] { new UsedObservedData {
                                                                      Id = "OBS"
                                                                  } });
            A.CallTo(() => _sim.IsImported).Returns(false);
            A.CallTo(() => _simulationPersistor.Save(A <SimulationTransfer> ._, _fileName))
            .Invokes(x => _simulationTransfer = x.GetArgument <SimulationTransfer>(0));

            A.CallTo(() => _projectRetriever.CurrentProject.Favorites).Returns(new Favorites {
                "FAV1"
            });
            A.CallTo(() => _projectRetriever.CurrentProject.ObservedDataBy("OBS")).Returns(_observedData1);
        }
Esempio n. 16
0
        public void should_return_a_simulation_transfer_containing_a_valid_simulation_and_license()
        {
            var x1 = new SimulationTransfer {
                Simulation = _simulation
            };

            x1.Favorites.Add("F1");
            x1.Favorites.Add("F2");
            _simulationPersistor.Save(x1, _filePath);
            File.Exists(_filePath).ShouldBeTrue();

            var deserializationObjectBaseRepository = IoC.Resolve <IWithIdRepository>();

            var x2 = _simulationPersistor.Load(_filePath, deserializationObjectBaseRepository);

            AssertForSpecs.AreEqualSimulationTransfer(x1, x2);

            x2.Id.ShouldBeEqualTo(x1.Id);
        }
Esempio n. 17
0
 protected override void Context()
 {
     base.Context();
     _fileName                      = "filename";
     _simulationTransfer            = A.Fake <SimulationTransfer>();
     _simulationTransfer.Simulation = A.Fake <IMoBiSimulation>().WithName("Sim");
     A.CallTo(_dialogCreator).WithReturnType <string>().Returns(_fileName);
     A.CallTo(() => _serializationTask.Load <SimulationTransfer>(_fileName, false))
     .Invokes(() =>
     {
         //makes sure that the exception is raised once only so that the second time is successful
         if (_exceptionRaised)
         {
             return;
         }
         _exceptionRaised = true;
         throw new CannotConvertConcentrationToAmountException("object");
     })
     .Returns(_simulationTransfer);
 }
Esempio n. 18
0
 public override void GlobalContext()
 {
     base.GlobalContext();
     _simulation = LoadPKML <SimulationTransfer>("run", ReactionDimensionMode.ConcentrationBased);
 }
 public void Visit(SimulationTransfer simulationTransfer)
 {
     Visit(simulationTransfer.Simulation);
     _converted = true;
 }
Esempio n. 20
0
 public void Visit(SimulationTransfer simulationTransfer)
 {
     Visit((IMoBiSimulation)simulationTransfer.Simulation);
     simulationTransfer.AllObservedData.Each(_dimensionConverter.ConvertDimensionIn);
     _converted = true;
 }
Esempio n. 21
0
 public void Visit(SimulationTransfer objToVisit)
 {
     Visit(objToVisit.Simulation);
     _converted = true;
 }
 public void Visit(SimulationTransfer simulationTransfer)
 {
     Visit(simulationTransfer.Simulation);
 }
Esempio n. 23
0
 protected override void Because()
 {
     _result = sut.Load(_pkmlFile);
 }
Esempio n. 24
0
 public override void GlobalContext()
 {
     base.GlobalContext();
     _simulationTransfer = LoadPKML <SimulationTransfer>("523_Export_S1");
 }
Esempio n. 25
0
 private static bool shouldLoadJournal(IProject project, SimulationTransfer simulationTransfer)
 {
     return(project != null &&
            string.IsNullOrEmpty(project.JournalPath) &&
            !string.IsNullOrEmpty(simulationTransfer.JournalPath));
 }
Esempio n. 26
0
        public void LoadSimulation(string simulationfileName)
        {
            var simulationFile = DomainHelperForSpecs.DataFilePathFor($"{simulationfileName}.pkml");

            _simulationTransfer = sut.Load(simulationFile);
        }
 private ICommand addSimulationTransferToProject(SimulationTransfer simulationTransfer)
 {
     return(_simulationLoader.AddSimulationToProject(simulationTransfer));
 }