1- using System . Collections . Generic ;
1+ using System . Collections . Generic ;
22using System . IO ;
3- using System . Reflection ;
43using MoBi . Assets ;
54using MoBi . Core . Exceptions ;
65using MoBi . Core . Serialization . Xml . Services ;
76using OSPSuite . Core . Domain . Builder ;
87using OSPSuite . Core . Domain . Services ;
9- using OSPSuite . Core . Qualification ;
108using OSPSuite . Core . Services ;
119using OSPSuite . Utility ;
1210using OSPSuite . Utility . Extensions ;
13- using Module = OSPSuite . Core . Domain . Module ;
1411
1512namespace MoBi . Core . Services
1613{
17- public interface IPKSimStarter
14+ public interface IPKSimStarter : IPKSimSnapshotConverter
1815 {
1916 void StartPopulationSimulationWithSimulationFile ( string simulationFilePath ) ;
2017 void StartWithWorkingJournalFile ( string journalFilePath ) ;
2118 IBuildingBlock CreateProfileExpression ( ExpressionType expressionType ) ;
2219 IBuildingBlock CreateIndividual ( ) ;
2320 IReadOnlyList < ExpressionParameterValueUpdate > UpdateExpressionProfileFromDatabase ( ExpressionProfileBuildingBlock expressionProfile ) ;
24- Module LoadModuleFromSnapshot ( string serializedSnapshot ) ;
25-
26- /// <summary>
27- /// Recreates the PKSim module from the snapshot.
28- /// If any of the PK-Sim building blocks should have markdown exported it will be done during the module rebuild.
29- /// </summary>
30- /// <param name="serializedSnapshot">The PK-Sim project snapshot</param>
31- /// <param name="qualificationConfiguration">
32- /// The configuration containing any building block inputs that should have report
33- /// markdown exported while the module is rebuilt in PK-Sim
34- /// </param>
35- /// <returns>A module and any input mappings that were exported</returns>
36- ( Module module , InputMapping [ ] inputMappings ) LoadModuleFromSnapshotAndExportInputs ( string serializedSnapshot , QualificationConfiguration qualificationConfiguration ) ;
37-
38- /// <summary>
39- /// Recreates a PK-Sim expression profile from the base64 encoded <paramref name="serializedSnapshot" />.
40- /// </summary>
41- /// <returns>The expression profile building block, as created in Pk-Sim</returns>
42- ExpressionProfileBuildingBlock LoadExpressionProfileFromSnapshot ( string serializedSnapshot ) ;
43-
44- /// <summary>
45- /// Recreates a PK-Sim individual from the base64 encoded <paramref name="serializedSnapshot" />.
46- /// </summary>
47- /// <returns>The individual building block, as created in Pk-Sim</returns>
48- IndividualBuildingBlock LoadIndividualFromSnapshot ( string serializedSnapshot ) ;
4921 }
5022
51- public class PKSimStarter : IPKSimStarter
23+ /// <summary>
24+ /// Desktop PK-Sim integration. In addition to the snapshot exchange (reflecting into
25+ /// <c>PKSim.Starter.SnapshotExchange</c> in the installed PK-Sim's PKSim.Starter.dll) it can launch
26+ /// the PK-Sim executable and create building blocks through the PK-Sim UI starter.
27+ /// </summary>
28+ public class PKSimStarter : PKSimSnapshotConverterBase , IPKSimStarter
5229 {
5330 private const string CREATE_INDIVIDUAL_ENZYME_EXPRESSION_PROFILE = "CreateIndividualEnzymeExpressionProfile" ;
5431 private const string CREATE_BINDING_PARTNER_EXPRESSION_PROFILE = "CreateBindingPartnerExpressionProfile" ;
5532 private const string CREATE_TRANSPORTER_EXPRESSION_PROFILE = "CreateTransporterExpressionProfile" ;
5633 private const string CREATE_INDIVIDUAL = "CreateIndividual" ;
57- private const string CREATE_MODULE = "CreateModule" ;
58- private const string CREATE_MODULE_AND_EXPORT_INPUTS = "CreateModuleAndExportInputs" ;
59- private const string CREATE_INDIVIDUAL_BUILDING_BLOCK = "CreateIndividualBuildingBlock" ;
60- private const string CREATE_EXPRESSION_PROFILE_BUILDING_BLOCK = "CreateExpressionProfileBuildingBlock" ;
6134 private const string GET_EXPRESSION_DATABASE_QUERY = "GetExpressionDatabaseQuery" ;
6235 private const string PKSIM_UI_STARTER_EXPRESSION_PROFILE_CREATOR = "PKSim.Starter.ExpressionProfileCreator" ;
6336 private const string PKSIM_UI_STARTER_INDIVIDUAL_CREATOR = "PKSim.Starter.IndividualCreator" ;
@@ -68,9 +41,6 @@ public class PKSimStarter : IPKSimStarter
6841 private readonly IApplicationSettings _applicationSettings ;
6942 private readonly IStartableProcessFactory _startableProcessFactory ;
7043 private readonly ICloneManagerForBuildingBlock _cloneManager ;
71- private readonly IMoBiProjectRetriever _projectRetriever ;
72- private readonly IXmlSerializationService _serializationService ;
73- private readonly IPKSimAssemblyLoader _pkSimLoader ;
7444
7545 public PKSimStarter ( IMoBiConfiguration configuration ,
7646 IApplicationSettings applicationSettings ,
@@ -79,17 +49,17 @@ public PKSimStarter(IMoBiConfiguration configuration,
7949 IXmlSerializationService serializationService ,
8050 IMoBiProjectRetriever projectRetriever ,
8151 IPKSimAssemblyLoader pkSimLoader )
52+ : base ( pkSimLoader , serializationService , projectRetriever )
8253 {
8354 _configuration = configuration ;
8455 _applicationSettings = applicationSettings ;
8556 _startableProcessFactory = startableProcessFactory ;
8657 _cloneManager = cloneManager ;
87- _serializationService = serializationService ;
88- _projectRetriever = projectRetriever ;
89- _pkSimLoader = pkSimLoader ;
9058 _pkSimLoader . InitializePath ( retrievePKSimAssemblyPath ( ) ) ;
9159 }
9260
61+ protected override string SnapshotExchangeType => PKSIM_UI_STARTER_SNAPSHOT_EXCHANGE ;
62+
9363 public void StartPopulationSimulationWithSimulationFile ( string simulationFilePath )
9464 {
9565 startPKSimWithFile ( simulationFilePath , AppConstants . PKSim . PopulationSimulationArgument ) ;
@@ -138,42 +108,6 @@ public IReadOnlyList<ExpressionParameterValueUpdate> UpdateExpressionProfileFrom
138108 return _pkSimLoader . ExecuteMethod ( PKSIM_UI_STARTER_EXPRESSION_PROFILE_CREATOR , GET_EXPRESSION_DATABASE_QUERY , [ expressionProfile ] ) as List < ExpressionParameterValueUpdate > ;
139109 }
140110
141- public Module LoadModuleFromSnapshot ( string serializedSnapshot )
142- {
143- var element = _pkSimLoader . ExecuteMethod ( PKSIM_UI_STARTER_SNAPSHOT_EXCHANGE , CREATE_MODULE , [ serializedSnapshot ] ) as string ;
144-
145- // all object exchanges should be done using serialization to ensure that objects are recreated in MoBi.
146- return _serializationService . Deserialize < Module > ( element , _projectRetriever . Current ) ;
147- }
148-
149- public ( Module module , InputMapping [ ] inputMappings ) LoadModuleFromSnapshotAndExportInputs ( string serializedSnapshot , QualificationConfiguration qualificationConfiguration )
150- {
151- var tuple = _pkSimLoader . ExecuteMethod ( PKSIM_UI_STARTER_SNAPSHOT_EXCHANGE , CREATE_MODULE_AND_EXPORT_INPUTS , [ serializedSnapshot , qualificationConfiguration ] ) ;
152-
153- var ( element , mappings ) = tuple as ( string element , InputMapping [ ] mappings ) ? ?? ( null , null ) ;
154-
155- // all object exchanges should be done using serialization to ensure that objects are recreated in MoBi.
156- var module = _serializationService . Deserialize < Module > ( element , _projectRetriever . Current ) ;
157-
158- return ( module , mappings ) ;
159- }
160-
161- public ExpressionProfileBuildingBlock LoadExpressionProfileFromSnapshot ( string serializedSnapshot )
162- {
163- var pkml = _pkSimLoader . ExecuteMethod ( PKSIM_UI_STARTER_SNAPSHOT_EXCHANGE , CREATE_EXPRESSION_PROFILE_BUILDING_BLOCK , [ serializedSnapshot ] ) as string ;
164-
165- // all object exchanges should be done using serialization to ensure that objects are recreated in MoBi.
166- return _serializationService . Deserialize < ExpressionProfileBuildingBlock > ( pkml , _projectRetriever . Current ) ;
167- }
168-
169- public IndividualBuildingBlock LoadIndividualFromSnapshot ( string serializedSnapshot )
170- {
171- var pkml = _pkSimLoader . ExecuteMethod ( PKSIM_UI_STARTER_SNAPSHOT_EXCHANGE , CREATE_INDIVIDUAL_BUILDING_BLOCK , [ serializedSnapshot ] ) as string ;
172-
173- // all object exchanges should be done using serialization to ensure that objects are recreated in MoBi.
174- return _serializationService . Deserialize < IndividualBuildingBlock > ( pkml , _projectRetriever . Current ) ;
175- }
176-
177111 private void startPKSimWithFile ( string filePathToStart , string option )
178112 {
179113 var pkSimPath = retrievePKSimExecutablePath ( ) ;
@@ -198,7 +132,7 @@ private string retrievePKSimExecutablePath()
198132 {
199133 var prioritizedPath = prioritizedPKSimPath ( ) ;
200134
201- if ( ! FileHelper . FileExists ( prioritizedPath ) )
135+ if ( ! FileHelper . FileExists ( prioritizedPath ) )
202136 throw new MoBiException ( AppConstants . PKSim . NotInstalled ) ;
203137
204138 return prioritizedPath ;
0 commit comments