-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRscript.vb
More file actions
196 lines (175 loc) · 8.79 KB
/
Rscript.vb
File metadata and controls
196 lines (175 loc) · 8.79 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
Imports System.Runtime.CompilerServices
Imports System.Text
Imports Microsoft.VisualBasic.CommandLine
Imports Microsoft.VisualBasic.CommandLine.InteropService
Imports Microsoft.VisualBasic.ApplicationServices
' Microsoft VisualBasic CommandLine Code AutoGenerator
' assembly: ..\App\Rscript.exe
'
' //
' // R# scripting host
' //
' // VERSION: 1.99.7675.37247
' // ASSEMBLY: Rscript, Version=1.99.7675.37247, Culture=neutral, PublicKeyToken=null
' // COPYRIGHT: Copyright (c) SMRUCC genomics 2020
' // GUID: 16d477b1-e7fb-41eb-9b61-7ea75c5d2939
' // BUILT: 1/4/2021 8:17:02 AM
' //
'
'
' < Rscript.CLI >
'
'
' SYNOPSIS
' Rscript command [/argument argument-value...] [/@set environment-variable=value...]
'
' All of the command that available in this program has been list below:
'
' --build: build R# package
' --check: Verify a packed R# package is damaged or not?
' --slave: Create a R# cluster node for run background or parallel task. This IPC command will
' run a R# script file that specified by the ``/exec`` argument, and then post back the
' result data json to the specific master listener.
'
'
' ----------------------------------------------------------------------------------------------------
'
' 1. You can using "Rscript ??<commandName>" for getting more details command help.
' 2. Using command "Rscript /CLI.dev [---echo]" for CLI pipeline development.
' 3. Using command "Rscript /i" for enter interactive console mode.
Namespace CLI
''' <summary>
''' Rscript.CLI
''' </summary>
'''
Public Class Rscript : Inherits InteropService
Public Const App$ = "Rscript.exe"
Sub New(App$)
MyBase._executableAssembly = App$
End Sub
''' <summary>
''' Create an internal CLI pipeline invoker from a given environment path.
''' </summary>
''' <param name="directory">A directory path that contains the target application</param>
''' <returns></returns>
<MethodImpl(MethodImplOptions.AggressiveInlining)>
Public Shared Function FromEnvironment(directory As String) As Rscript
Return New Rscript(App:=directory & "/" & Rscript.App)
End Function
''' <summary>
''' ```bash
''' --build [/src <folder, default=./> /save <Rpackage.zip>]
''' ```
''' build R# package
''' </summary>
'''
''' <param name="src"> A folder path that contains the R source files and meta data files of the target R package,
''' a folder that exists in this folder path which is named 'R' is required!
''' </param>
Public Function Compile(Optional src As String = "./", Optional save As String = "") As Integer
Dim cli = GetCompileCommandLine(src:=src, save:=save, internal_pipelineMode:=True)
Dim proc As IIORedirectAbstract = RunDotNetApp(cli)
Return proc.Run()
End Function
Public Function GetCompileCommandLine(Optional src As String = "./", Optional save As String = "", Optional internal_pipelineMode As Boolean = True) As String
Dim CLI As New StringBuilder("--build")
Call CLI.Append(" ")
If Not src.StringEmpty Then
Call CLI.Append("/src " & """" & src & """ ")
End If
If Not save.StringEmpty Then
Call CLI.Append("/save " & """" & save & """ ")
End If
Call CLI.Append($"/@set --internal_pipeline={internal_pipelineMode.ToString.ToUpper()} ")
Return CLI.ToString()
End Function
''' <summary>
''' ```bash
''' --check --target <package.zip>
''' ```
''' Verify a packed R# package is damaged or not?
''' </summary>
'''
Public Function Check(target As String) As Integer
Dim cli = GetCheckCommandLine(target:=target, internal_pipelineMode:=True)
Dim proc As IIORedirectAbstract = RunDotNetApp(cli)
Return proc.Run()
End Function
Public Function GetCheckCommandLine(target As String, Optional internal_pipelineMode As Boolean = True) As String
Dim CLI As New StringBuilder("--check")
Call CLI.Append(" ")
Call CLI.Append("--target " & """" & target & """ ")
Call CLI.Append($"/@set --internal_pipeline={internal_pipelineMode.ToString.ToUpper()} ")
Return CLI.ToString()
End Function
''' <summary>
''' ```bash
''' --slave /exec <script.R> /args <json_base64> /request-id <request_id> /PORT=<port_number> [/timeout=<timeout in ms, default=1000> /retry=<retry_times, default=5> /MASTER=<ip, default=localhost> /entry=<function_name, default=NULL>]
''' ```
''' Create a R# cluster node for run background or parallel task. This IPC command will run a R# script file that specified by the ``/exec`` argument, and then post back the result data json to the specific master listener.
''' </summary>
'''
''' <param name="exec"> a specific R# script for run
''' </param>
''' <param name="args"> The base64 text of the input arguments for running current R# script file, this is a json encoded text of the arguments. the json object should be a collection of [key => value[]] pairs.
''' </param>
''' <param name="entry"> the entry function name, by default is running the script from the begining to ends.
''' </param>
''' <param name="request_id"> the unique id for identify current slave progress in the master node when invoke post data callback.
''' </param>
''' <param name="MASTER"> the ip address of the master node, by default this parameter value is ``localhost``.
''' </param>
''' <param name="PORT"> the port number for master node listen to this callback post data.
''' </param>
''' <param name="retry"> How many times that this cluster node should retry to send callback data if the TCP request timeout.
''' </param>
Public Function slaveMode(exec As String,
args As String,
request_id As String,
PORT As String,
Optional timeout As String = "1000",
Optional retry As String = "5",
Optional master As String = "localhost",
Optional entry As String = "NULL") As Integer
Dim cli = GetslaveModeCommandLine(exec:=exec,
args:=args,
request_id:=request_id,
PORT:=PORT,
timeout:=timeout,
retry:=retry,
master:=master,
entry:=entry, internal_pipelineMode:=True)
Dim proc As IIORedirectAbstract = RunDotNetApp(cli)
Return proc.Run()
End Function
Public Function GetslaveModeCommandLine(exec As String,
args As String,
request_id As String,
PORT As String,
Optional timeout As String = "1000",
Optional retry As String = "5",
Optional master As String = "localhost",
Optional entry As String = "NULL", Optional internal_pipelineMode As Boolean = True) As String
Dim CLI As New StringBuilder("--slave")
Call CLI.Append(" ")
Call CLI.Append("/exec " & """" & exec & """ ")
Call CLI.Append("/args " & """" & args & """ ")
Call CLI.Append("/request-id " & """" & request_id & """ ")
Call CLI.Append("/PORT " & """" & PORT & """ ")
If Not timeout.StringEmpty Then
Call CLI.Append("/timeout " & """" & timeout & """ ")
End If
If Not retry.StringEmpty Then
Call CLI.Append("/retry " & """" & retry & """ ")
End If
If Not master.StringEmpty Then
Call CLI.Append("/master " & """" & master & """ ")
End If
If Not entry.StringEmpty Then
Call CLI.Append("/entry " & """" & entry & """ ")
End If
Call CLI.Append($"/@set --internal_pipeline={internal_pipelineMode.ToString.ToUpper()} ")
Return CLI.ToString()
End Function
End Class
End Namespace