hongji.li
2023-11-07 1a1ba3ad5ed9e4380185aa1ccad20204a0e5f115
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
Quintiq file version 2.0
#parent: #root
Method PTF_StartClient (
  String user,
  String password,
  String clienttype,
  String project,
  String view,
  String customargumentline,
  Number minstartclientdelayinsecond,
  Number maxstartclientdelayinsecond,
  String dataset,
  String datasetfolder,
  String datasetkind
) id:Method_LibPTF_pnlTestController_PTF_StartClient
{
  #keys: '[105690.0.145844532]'
  Body:
  [*
    // Construct the commandline for starting a Client with the parameters entered by user
    argument                 := "/autostart/license=ReadWrite";
    clientexecutable         := "";
    fullpathclientexecutable := "";
    
    if( project.Length() > 0 )
    {
      argument := argument + '/project="' + project + '"';
    }
    
    if( user.Length() > 0 )
    {
      argument := argument + '/user="' + user + '"';
    }
    
    if( password.Length() > 0 )
    {
      argument := argument + '/password="' + password + '"';
    }
    
    if( view.Length() > 0 )
    {
      argument := argument + '/view="' + view + '"';
    }
    
    // Replacement values to bypass batch file reserved words
    argument := argument.ReplaceAll( '/', '@' );
    
    // Dataset folder adjustment
    datasetfolder     := datasetfolder.TrimBoth();
    missingbeginslash := datasetfolder.SubString( 0, 1 ) <> "/"
    extraendslash     := datasetfolder.RestString( datasetfolder.Length() -1 ) = "/"
    if( missingbeginslash )
    {
      datasetfolder := "/" + datasetfolder;
    }
    if( extraendslash )
    {
      datasetfolder := datasetfolder.SubString( 0, datasetfolder.Length() - 1 );
    }
    
    selectdataset := '/selectdataset="' + datasetkind + ':' + datasetfolder + '/' + dataset + '"';
    argument      := argument + selectdataset;
    
    if( customargumentline.Length() > 0 )
    {
      customargs      := customargumentline.Tokenize( " " );
      customarguments := "";
    
      traverse( customargs, Elements, customarg )
      {
        customarguments := customarguments + customarg.TrimBoth();
      }
    
      argument := argument + customarguments;
    }
    
    if( clienttype = LibPTF_Util::ClientType_ThinClient() )
    {
      clientexecutable := LibPTF_Util::ExecutableName_ThinClient();
    }
    else if( clienttype = LibPTF_Util::ClientType_FatClient() )
    {
      clientexecutable := LibPTF_Util::ExecutableName_FatClient();
    }
    fullpathclientexecutable := '"' + this.PTF_GetClientExecutablePath() + clientexecutable + '"';
    
    // The following are replaced with some other values because they are
    // reserved words in the batch file when exectuted from command windows.
    // The corresponding batch file will make the necessary conversion when executes
    argument := argument.ReplaceAll( '=', '$' );
    argument := argument.ReplaceAll( ' ', '\%20' );
    argument := argument.ReplaceAll( '"', '#' );
    argument := argument.ReplaceAll( ">", "gtsign" );
    argument := argument.ReplaceAll( "<", "ltsign" );
    
    fullpathclientexecutable := fullpathclientexecutable.ReplaceAll( ' ', '\%20' );
    fullpathclientexecutable := fullpathclientexecutable.ReplaceAll( '"', '#' );
    
    // Get random delay between the start client delay range
    randomdelayinsecond := Number::Random( minstartclientdelayinsecond, maxstartclientdelayinsecond );
    
    
    command := 'cmd /c "' + this.PTF_GetBatchFileFullPathForKickStartClient() + '" '
               + argument
               + ',' + [String]randomdelayinsecond
               + ',' + fullpathclientexecutable;
    
    Application.ExecuteCommand( command );
  *]
}