public async Task RunAsync(IndividualSimulation individualSimulation)
        {
            _progressUpdater = _progressManager.Create();
            _progressUpdater.Initialize(100, PKSimConstants.UI.Calculating);
            _simModelManager.SimulationProgress += simulationProgress;
            //make sure that thread methods always catch and handle any exception,
            //otherwise we risk unplanned application termination
            var begin = SystemTime.UtcNow();

            try
            {
                _eventPublisher.PublishEvent(new SimulationRunStartedEvent());
                await runSimulation(individualSimulation, exportAll : false, raiseEvents : true, checkForNegativeValues : true);
            }
            catch (Exception ex)
            {
                _exceptionManager.LogException(ex);
                terminated();
            }
            finally
            {
                var end       = SystemTime.UtcNow();
                var timeSpent = end - begin;
                _eventPublisher.PublishEvent(new SimulationRunFinishedEvent(individualSimulation, timeSpent));
            }
        }
        public async Task RunAsync(PopulationSimulation populationSimulation)
        {
            _progressUpdater = _progressManager.Create();
            _progressUpdater.Initialize(populationSimulation.NumberOfItems, PKSimConstants.UI.Calculating);
            _populationRunner.NumberOfCoresToUse = _userSettings.MaximumNumberOfCoresToUse;

            //make sure that thread methods always catch and handle any exception,
            //otherwise we risk unplanned application termination
            var begin = SystemTime.UtcNow();

            try
            {
                var populationData      = _populationExporter.CreatePopulationDataFor(populationSimulation);
                var modelCoreSimulation = _modelCoreSimulationMapper.MapFrom(populationSimulation, shouldCloneModel: false);
                _simulationPersistableUpdater.UpdatePersistableFromSettings(populationSimulation);

                _eventPublisher.PublishEvent(new SimulationRunStartedEvent());
                var populationRunResults = await _populationRunner.RunPopulationAsync(modelCoreSimulation, populationData, populationSimulation.AgingData.ToDataTable());

                _simulationResultsSynchronizer.Synchronize(populationSimulation, populationRunResults.Results);
                _populationSimulationAnalysisSynchronizer.UpdateAnalysesDefinedIn(populationSimulation);
                _eventPublisher.PublishEvent(new SimulationResultsUpdatedEvent(populationSimulation));
            }
            catch (OperationCanceledException)
            {
                simulationTerminated();
            }
            catch (Exception ex)
            {
                _exceptionManager.LogException(ex);
                simulationTerminated();
            }
            finally
            {
                var end       = SystemTime.UtcNow();
                var timeSpent = end - begin;
                _eventPublisher.PublishEvent(new SimulationRunFinishedEvent(populationSimulation, timeSpent));
            }
        }
Exemple #3
0
        private void actionCompleted(RunWorkerCompletedEventArgs runWorkerCompletedEventArgs)
        {
            //close the presenter when the action is completed
            if (_presenter != null)
            {
                _presenter.Close();
            }

            _action    = null;
            _presenter = null;
            if (runWorkerCompletedEventArgs.Error != null)
            {
                _success = false;
                _exceptionManager.LogException(runWorkerCompletedEventArgs.Error);
            }
            else
            {
                _success = !runWorkerCompletedEventArgs.Cancelled;
            }

            HeavyWorkedFinished(this, new HeavyWorkEventArgs(_success));
        }
Exemple #4
0
 public void RollBackTo(int state)
 {
     try
     {
         publishEvent(new RollBackStartedEvent());
         var rollBackCommand = CreateRollBackCommandTo(state);
         if (rollBackCommand.IsEmpty())
         {
             return;
         }
         _currentState = state;
         rollBackCommand.Execute(_executionContext);
         addToHistory(rollBackCommand, _currentState);
     }
     catch (Exception e)
     {
         _exceptionManager.LogException(e);
     }
     finally
     {
         publishEvent(new RollBackFinishedEvent());
     }
 }