1 #Region "Microsoft.VisualBasic::aa9a6c158df2b0f6ff46e52ef7b79e28, Microsoft.VisualBasic.Core\ApplicationServices\Parallel\MMFProtocol\WorkFlow.vb"
2
3     ' Author:
4     
5     '       asuka (amethyst.asuka@gcmodeller.org)
6     '       xie (genetics@smrucc.org)
7     '       xieguigang (xie.guigang@live.com)
8     
9     ' Copyright (c) 2018 GPL3 Licensed
10     
11     
12     ' GNU GENERAL PUBLIC LICENSE (GPL3)
13     
14     
15     ' This program is free software: you can redistribute it and/or modify
16     ' it under the terms of the GNU General Public License as published by
17     ' the Free Software Foundation, either version 3 of the License, or
18     ' (at your option) any later version.
19     
20     ' This program is distributed in the hope that it will be useful,
21     ' but WITHOUT ANY WARRANTY; without even the implied warranty of
22     ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23     ' GNU General Public License for more details.
24     
25     ' You should have received a copy of the GNU General Public License
26     ' along with this program. If not, see <http://www.gnu.org/licenses/>.
27
28
29
30     ' /********************************************************************************/
31
32     ' Summaries:
33
34     '     Module WorkFlow
35     
36     '         Function: FolkProc
37     
38     
39     ' /********************************************************************************/
40
41 #End Region
42
43 Imports System.Runtime.CompilerServices
44 Imports Microsoft.VisualBasic.CommandLine
45 Imports Microsoft.VisualBasic.Parallel.MMFProtocol.MapStream
46 Imports Microsoft.VisualBasic.SecurityString
47
48 Namespace Parallel.MMFProtocol
49
50     Public Module WorkFlow
51
52         Const map As String = "/std_map"
53
54         ''' <summary>
55         ''' 创建出一个子进程,然后按照命令行参数<paramref name="CLI"/>执行制定的命令,同时通过内存映射传递复杂参数,最后结束后通过内存映射传递回数据
56         ''' 主要是通过内存映射减少数据IO的时间,加快计算流程
57         ''' </summary>
58         ''' <typeparam name="TIn"></typeparam>
59         ''' <typeparam name="TOut"></typeparam>
60         ''' <param name="exe"></param>
61         ''' <param name="CLI"></param>
62         ''' <param name="[in]"></param>
63         ''' <param name="writer"></param>
64         ''' <param name="reader"></param>
65         ''' <returns></returns>
66         <Extension>
67         Public Function FolkProc(Of TIn, TOut)(exe As String,
68                                                CLI As String,
69                                                [in] As TIn,
70                                                writer As Func(Of TIn, Byte()),
71                                                reader As Func(Of Byte(), TOut)) As TOut
72             Dim data As Byte() = writer([in])
73             Dim uid As String = (Now.ToString & [in].ToString & CLI).GetMd5Hash
74             Dim socket As New MSWriter(uid, data.Length + 1024)
75             CLI = CLI & $" {map} {uid}"
76             socket.WriteStream(data)
77             Dim IO As New IORedirectFile(exe, CLI)
78             Call IO.Run()
79             data = socket.Read.byteData
80             Dim obj As TOut = reader(data)
81             Return obj
82         End Function
83     End Module
84 End Namespace