| 1 | #Region "Microsoft.VisualBasic::6fb2ed20b45a699c4c701e22d8e822c5, Microsoft.VisualBasic.Core\CommandLine\Reflection\Attributes\ExportAPI.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 | ' Class LastUpdatedAttribute |
| 35 | ' |
| 36 | ' Constructor: (+2 Overloads) Sub New |
| 37 | ' Function: ToString |
| 38 | ' |
| 39 | ' Class ExportAPIAttribute |
| 40 | ' |
| 41 | ' Properties: Example, Info, Name, Type, Usage |
| 42 | ' |
| 43 | ' Constructor: (+1 Overloads) Sub New |
| 44 | ' Function: __printView, __printViewHTML, GenerateHtmlDoc, PrintView, ToString |
| 45 | ' |
| 46 | ' Interface IExportAPI |
| 47 | ' |
| 48 | ' Properties: Example, Info, Name, Usage |
| 49 | ' |
| 50 | ' |
| 51 | ' /********************************************************************************/ |
| 52 | |
| 53 | #End Region |
| 54 | |
| 55 | Imports System.Text |
| 56 | Imports Microsoft.VisualBasic.Scripting.MetaData |
| 57 | |
| 58 | Namespace CommandLine.Reflection |
| 59 | |
| 60 | <AttributeUsage(AttributeTargets.Method, AllowMultiple:=False, Inherited:=True)> |
| 61 | Public Class LastUpdatedAttribute : Inherits Attribute |
| 62 | |
| 63 | Public ReadOnly [Date] As Date |
| 64 | |
| 65 | Sub New([date] As String) |
| 66 | Me.Date = Date.Parse([date]) |
| 67 | End Sub |
| 68 | |
| 69 | Sub New(yy%, mm%, dd%, H%, M%, S%) |
| 70 | Me.Date = New Date(yy, mm, dd, H, M, S) |
| 71 | End Sub |
| 72 | |
| 73 | Public Overrides Function ToString() As String |
| 74 | Return [Date].ToString |
| 75 | End Function |
| 76 | End Class |
| 77 | |
| 78 | ''' <summary> |
| 79 | ''' A command object that with a specific name.(一个具有特定名称命令执行对象) |
| 80 | ''' </summary> |
| 81 | ''' <remarks></remarks> |
| 82 | <AttributeUsage(AttributeTargets.Method, AllowMultiple:=False, Inherited:=True)> |
| 83 | Public Class ExportAPIAttribute : Inherits Attribute |
| 84 | Implements IExportAPI |
| 85 | |
| 86 | ''' <summary> |
| 87 | ''' The name of the commandline object.(这个命令的名称) |
| 88 | ''' </summary> |
| 89 | ''' <value></value> |
| 90 | ''' <returns></returns> |
| 91 | ''' <remarks></remarks> |
| 92 | Public ReadOnly Property Name As String Implements IExportAPI.Name |
| 93 | ''' <summary> |
| 94 | ''' Something detail of help information.(详细的帮助信息) |
| 95 | ''' </summary> |
| 96 | ''' <value></value> |
| 97 | ''' <returns></returns> |
| 98 | ''' <remarks></remarks> |
| 99 | Public Property Info As String Implements IExportAPI.Info |
| 100 | ''' <summary> |
| 101 | ''' The usage of this command.(这个命令的用法,本属性仅仅是一个助记符,当用户没有编写任何的使用方法信息的时候才会使用本属性的值) |
| 102 | ''' </summary> |
| 103 | ''' <value></value> |
| 104 | ''' <returns></returns> |
| 105 | ''' <remarks></remarks> |
| 106 | Public Property Usage As String Implements IExportAPI.Usage |
| 107 | ''' <summary> |
| 108 | ''' A example that to useing this command. |
| 109 | ''' (对这个命令的使用示例,本属性仅仅是一个助记符,当用户没有编写任何示例信息的时候才会使用本属性的值, |
| 110 | ''' 在编写帮助示例的时候,需要编写出包括命令开关名称的完整的例子) |
| 111 | ''' </summary> |
| 112 | ''' <value></value> |
| 113 | ''' <returns></returns> |
| 114 | ''' <remarks></remarks> |
| 115 | Public Property Example As String Implements IExportAPI.Example |
| 116 | |
| 117 | ''' <summary> |
| 118 | ''' You are going to define a available export api for you application to another language or scripting program environment. |
| 119 | ''' (定义一个命令行程序之中可以使用的命令) |
| 120 | ''' </summary> |
| 121 | ''' <param name="Name">The name of the commandline object or you define the exported API name here.(这个命令的名称)</param> |
| 122 | ''' <remarks></remarks> |
| 123 | Sub New(<Parameter("Command.Name", "The name of the commandline object.")> Name As String) |
| 124 | _Name = Name |
| 125 | End Sub |
| 126 | |
| 127 | Public Overrides Function ToString() As String |
| 128 | Return Name |
| 129 | End Function |
| 130 | |
| 131 | Public Function PrintView(HTML As Boolean) As String |
| 132 | If HTML Then |
| 133 | Return __printViewHTML() |
| 134 | Else |
| 135 | Return __printView() |
| 136 | End If |
| 137 | End Function |
| 138 | |
| 139 | Private Function __printView() |
| 140 | Dim sbr As StringBuilder = New StringBuilder(1024) |
| 141 | Call sbr.AppendLine($"{NameOf(Name)} = ""{Name}""") |
| 142 | Call sbr.AppendLine($"{NameOf(Info)} = ""{Info}""") |
| 143 | Call sbr.AppendLine($"{NameOf(Usage)} = ""{Usage}""") |
| 144 | Call sbr.AppendLine($"{NameOf(Example)} = ""{Example}""") |
| 145 | |
| 146 | Return sbr.ToString |
| 147 | End Function |
| 148 | |
| 149 | Private Function __printViewHTML() As String |
| 150 | Return ExportAPIAttribute.GenerateHtmlDoc(Me, "", "") |
| 151 | End Function |
| 152 | |
| 153 | Public Shared Function GenerateHtmlDoc(Command As IExportAPI, addNode As String, addValue As String) As String |
| 154 | Dim add As String = If(Not String.IsNullOrEmpty(addValue), $" <tr> |
| 155 | <td>{addNode}</td> |
| 156 | <td>{addValue}</td> |
| 157 | </tr>", "") |
| 158 | |
| 159 | Return $"<p>Help for ""{Command.Name}"":</p> |
| 160 | <table frame=""hsides""> |
| 161 | <tr> |
| 162 | <th>DocNode</th> |
| 163 | <th>Content Text</th> |
| 164 | <th><a href=""#""><strong><font size=3>[↑]</font></strong></a></th> |
| 165 | </tr> |
| 166 | <tr> |
| 167 | <td><strong>{NameOf(Name)}</strong></td> |
| 168 | <td><strong><a name=""{Command.Name}"">{Command.Name}</a></strong></td> |
| 169 | </tr> |
| 170 | <tr> |
| 171 | <td>{NameOf(Info)}</td> |
| 172 | <td>{Command.Info}</td> |
| 173 | </tr> |
| 174 | <tr> |
| 175 | <td>{NameOf(Usage)}</td> |
| 176 | <td>{Command.Usage}</td> |
| 177 | </tr> |
| 178 | <tr> |
| 179 | <td>{NameOf(Example)}</td> |
| 180 | <td>{Command.Example}</td> |
| 181 | </tr> |
| 182 | {add} |
| 183 | </table>" |
| 184 | End Function |
| 185 | |
| 186 | Public Shared ReadOnly Property Type As Type = GetType(ExportAPIAttribute) |
| 187 | End Class |
| 188 | |
| 189 | Public Interface IExportAPI |
| 190 | |
| 191 | ''' <summary> |
| 192 | ''' The name of the commandline object.(这个命令的名称) |
| 193 | ''' </summary> |
| 194 | ''' <value></value> |
| 195 | ''' <returns></returns> |
| 196 | ''' <remarks></remarks> |
| 197 | ReadOnly Property Name As String |
| 198 | ''' <summary> |
| 199 | ''' Something detail of help information.(详细的帮助信息) |
| 200 | ''' </summary> |
| 201 | ''' <value></value> |
| 202 | ''' <returns></returns> |
| 203 | ''' <remarks></remarks> |
| 204 | ReadOnly Property Info As String |
| 205 | ''' <summary> |
| 206 | ''' The usage of this command.(这个命令的用法,本属性仅仅是一个助记符,当用户没有编写任何的使用方法信息的时候才会使用本属性的值) |
| 207 | ''' </summary> |
| 208 | ''' <value></value> |
| 209 | ''' <returns></returns> |
| 210 | ''' <remarks></remarks> |
| 211 | ReadOnly Property Usage As String |
| 212 | ''' <summary> |
| 213 | ''' A example that to useing this command.(对这个命令的使用示例,本属性仅仅是一个助记符,当用户没有编写任何示例信息的时候才会使用本属性的值) |
| 214 | ''' </summary> |
| 215 | ''' <value></value> |
| 216 | ''' <returns></returns> |
| 217 | ''' <remarks></remarks> |
| 218 | ReadOnly Property Example As String |
| 219 | End Interface |
| 220 | End Namespace |