| 1 |
#Region "Microsoft.VisualBasic::3144cbda496e0193f901526dfec42493, Microsoft.VisualBasic.Core\CommandLine\Interpreters\Interpreter.vb"
|
| 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 |
#End Region
|
| 53 |
|
| 54 |
Imports System.Reflection
|
| 55 |
Imports System.Runtime.CompilerServices
|
| 56 |
Imports System.Text
|
| 57 |
Imports Microsoft.VisualBasic.ApplicationServices.Debugging
|
| 58 |
Imports Microsoft.VisualBasic.CommandLine.ManView
|
| 59 |
Imports Microsoft.VisualBasic.CommandLine.Reflection
|
| 60 |
Imports Microsoft.VisualBasic.CommandLine.Reflection.EntryPoints
|
| 61 |
Imports Microsoft.VisualBasic.ComponentModel.Settings
|
| 62 |
Imports Microsoft.VisualBasic.Language
|
| 63 |
Imports Microsoft.VisualBasic.Language.UnixBash
|
| 64 |
Imports Microsoft.VisualBasic.Linq.Extensions
|
| 65 |
Imports Microsoft.VisualBasic.Serialization.JSON
|
| 66 |
Imports Microsoft.VisualBasic.Text
|
| 67 |
Imports Microsoft.VisualBasic.Text.Levenshtein
|
| 68 |
Imports VB = Microsoft.VisualBasic.CommandLine.InteropService.SharedORM.VisualBasic
|
| 69 |
|
| 70 |
#Const NET_45 = 0
|
| 71 |
|
| 72 |
Namespace CommandLine
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
<[Namespace]("Interpreter")> Public Class Interpreter
|
| 83 |
|
| 84 |
Implements IDisposable
|
| 85 |
Implements IDictionary(Of String, APIEntryPoint)
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
Protected Friend __API_table As New Dictionary(Of String, APIEntryPoint)
|
| 91 |
Protected __rootNamespace$
|
| 92 |
|
| 93 |
#Region "Optional delegates"
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
Public Property ExecuteFile As ExecuteFile
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
Public Property ExecuteEmptyCli As ExecuteEmptyCLI
|
| 108 |
Public Property ExecuteNotFound As ExecuteNotFound
|
| 109 |
#End Region
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
| 119 |
Public Function ToDictionary() As Dictionary(Of String, APIEntryPoint)
|
| 120 |
Return __API_table
|
| 121 |
End Function
|
| 122 |
|
| 123 |
Public Overrides Function ToString() As String
|
| 124 |
Return "CLI://" & __rootNamespace
|
| 125 |
End Function
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
Public Overridable Function Execute(args As CommandLine) As Integer
|
| 134 |
If Not args.IsNullOrEmpty Then
|
| 135 |
Dim i As Integer = apiInvoke(args.Name.ToLower, {args}, args.Parameters)
|
| 136 |
#If DEBUG Then
|
| 137 |
|
| 138 |
#Else
|
| 139 |
If Stack.TextEquals("Main") Then
|
| 140 |
If DebuggerArgs.AutoPaused Then
|
| 141 |
Call Pause()
|
| 142 |
End If
|
| 143 |
End If
|
| 144 |
#End If
|
| 145 |
Return i
|
| 146 |
Else
|
| 147 |
Return __executeEmpty()
|
| 148 |
End If
|
| 149 |
End Function
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
Private Function __executeEmpty() As Integer
|
| 157 |
If Not ExecuteEmptyCli Is Nothing Then
|
| 158 |
Try
|
| 159 |
Return _ExecuteEmptyCli()
|
| 160 |
Catch ex As Exception
|
| 161 |
Call App.LogException(ex)
|
| 162 |
Call ex.PrintException
|
| 163 |
End Try
|
| 164 |
|
| 165 |
Return -100
|
| 166 |
Else
|
| 167 |
|
| 168 |
Return Help("")
|
| 169 |
End If
|
| 170 |
End Function
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
Private Function apiInvoke(commandName$, argvs As Object(), help_argvs$()) As Integer
|
| 180 |
Dim CLI As CommandLine = DirectCast(argvs(Scan0), CommandLine)
|
| 181 |
|
| 182 |
If __API_table.ContainsKey(commandName) Then _
|
| 183 |
Return __API_table(commandName).Execute(argvs)
|
| 184 |
|
| 185 |
If "??vars".TextEquals(commandName) Then
|
| 186 |
Dim vars = App.GetAppVariables
|
| 187 |
|
| 188 |
Call Console.WriteLine()
|
| 189 |
Call Console.WriteLine(PS1.Fedora12.ToString)
|
| 190 |
Call Console.WriteLine()
|
| 191 |
Call Console.WriteLine($"Print environment variables for {GetType(App).FullName}:")
|
| 192 |
Call Console.WriteLine(ConfigEngine.Prints(vars))
|
| 193 |
|
| 194 |
Return 0
|
| 195 |
|
| 196 |
ElseIf "??history".TextEquals(commandName) Then
|
| 197 |
|
| 198 |
Dim logs$ = (App.LogErrDIR.ParentPath & "/.shells.log")
|
| 199 |
|
| 200 |
With DirectCast(argvs(Scan0), CommandLine)
|
| 201 |
If .Parameters.IsNullOrEmpty Then
|
| 202 |
Call Console.WriteLine()
|
| 203 |
Call logs.ReadAllText.EchoLine
|
| 204 |
Call Console.WriteLine()
|
| 205 |
Else
|
| 206 |
With .ParameterList.First
|
| 207 |
Select Case .Name.ToLower
|
| 208 |
Case "/clear"
|
| 209 |
Call New Byte() {}.FlushStream(logs)
|
| 210 |
Case "/search"
|
| 211 |
|
| 212 |
Dim term$ = .Value
|
| 213 |
|
| 214 |
Call Console.WriteLine()
|
| 215 |
Call logs.IterateAllLines _
|
| 216 |
.Where(Function(line)
|
| 217 |
Return InStr(line, term, CompareMethod.Text) > 0
|
| 218 |
End Function) _
|
| 219 |
.JoinBy(vbCrLf) _
|
| 220 |
.EchoLine
|
| 221 |
Call Console.WriteLine()
|
| 222 |
|
| 223 |
Case Else
|
| 224 |
Console.WriteLine("Unknown command!")
|
| 225 |
End Select
|
| 226 |
End With
|
| 227 |
End If
|
| 228 |
End With
|
| 229 |
|
| 230 |
Return 0
|
| 231 |
|
| 232 |
ElseIf String.Equals(commandName, "?") OrElse commandName = "??" OrElse commandName.TextEquals("--help") Then
|
| 233 |
If help_argvs.IsNullOrEmpty Then
|
| 234 |
Return Help("")
|
| 235 |
Else
|
| 236 |
Return Help(help_argvs.First)
|
| 237 |
End If
|
| 238 |
|
| 239 |
ElseIf InStr(commandName, "??") = 1 Then
|
| 240 |
commandName = Mid(commandName, 3)
|
| 241 |
Return Help(commandName)
|
| 242 |
|
| 243 |
ElseIf String.Equals(commandName, "~") Then
|
| 244 |
|
| 245 |
Call Console.WriteLine(App.ExecutablePath)
|
| 246 |
|
| 247 |
Return 0
|
| 248 |
|
| 249 |
ElseIf String.Equals(commandName, "man") Then
|
| 250 |
|
| 251 |
Dim doc As String = SDKdocs()
|
| 252 |
Dim output$ = CLI("/out") Or "./"
|
| 253 |
|
| 254 |
If Not CLI.GetBoolean("--file") Then
|
| 255 |
If CLI.GetBoolean("--print") Then
|
| 256 |
Call Console.WriteLine(doc)
|
| 257 |
Else
|
| 258 |
Call SDKManual.LaunchManual(CLI:=Me)
|
| 259 |
End If
|
| 260 |
Else
|
| 261 |
|
| 262 |
End If
|
| 263 |
|
| 264 |
Return doc.SaveTo($"{output}/{App.AssemblyName}.md", Encoding.UTF8).CLICode
|
| 265 |
|
| 266 |
ElseIf String.Equals(commandName, "/linux-bash", StringComparison.OrdinalIgnoreCase) Then
|
| 267 |
Return BashShell()
|
| 268 |
|
| 269 |
ElseIf String.Equals(commandName, "/CLI.dev", StringComparison.OrdinalIgnoreCase) Then
|
| 270 |
Dim namespace$ = CLI("/namespace") Or "CLI"
|
| 271 |
Dim vb$ = New VB(App:=Me, [namespace]:=[namespace]).GetSourceCode
|
| 272 |
|
| 273 |
If CLI.IsTrue("---echo") Then
|
| 274 |
Console.WriteLine(vb)
|
| 275 |
Return 0
|
| 276 |
Else
|
| 277 |
Dim sourcefile$ = $"{App.HOME}/{Type.Assembly.CodeBase.BaseName}.vb"
|
| 278 |
Return vb _
|
| 279 |
.SaveTo(sourcefile, Encodings.UTF8WithoutBOM.CodePage) _
|
| 280 |
.CLICode
|
| 281 |
End If
|
| 282 |
|
| 283 |
Else
|
| 284 |
|
| 285 |
If (commandName.FileExists OrElse commandName.DirectoryExists) AndAlso Not Me.ExecuteFile Is Nothing Then
|
| 286 |
Try
|
| 287 |
App.InputFile = commandName
|
| 288 |
Return ExecuteFile()(path:=commandName, args:=DirectCast(argvs(Scan0), CommandLine))
|
| 289 |
Catch ex As Exception
|
| 290 |
ex = New Exception("Execute file failure!", ex)
|
| 291 |
ex = New Exception(argvs(Scan0).ToString, ex)
|
| 292 |
Call App.LogException(ex)
|
| 293 |
Call ex.PrintException
|
| 294 |
End Try
|
| 295 |
|
| 296 |
Return -120
|
| 297 |
ElseIf Not ExecuteNotFound Is Nothing Then
|
| 298 |
Try
|
| 299 |
Return ExecuteNotFound()(DirectCast(argvs(Scan0), CommandLine))
|
| 300 |
Catch ex As Exception
|
| 301 |
ex = New Exception("Execute not found failure!", ex)
|
| 302 |
ex = New Exception(argvs(Scan0).ToString, ex)
|
| 303 |
Call App.LogException(ex)
|
| 304 |
Call ex.PrintException
|
| 305 |
End Try
|
| 306 |
|
| 307 |
Return -1000
|
| 308 |
Else
|
| 309 |
Dim list$() = Me.ListingRelated(commandName)
|
| 310 |
|
| 311 |
If list.IsNullOrEmpty Then
|
| 312 |
|
| 313 |
Call Console.WriteLine(BAD_COMMAND_NAME, commandName)
|
| 314 |
Call Console.WriteLine()
|
| 315 |
Call Console.WriteLine(PS1.Fedora12.ToString & " " & DirectCast(argvs(Scan0), CommandLine).ToString)
|
| 316 |
|
| 317 |
Else
|
| 318 |
Call listingCommands(list, commandName)
|
| 319 |
End If
|
| 320 |
End If
|
| 321 |
End If
|
| 322 |
|
| 323 |
Return -1
|
| 324 |
End Function
|
| 325 |
|
| 326 |
Const BAD_COMMAND_NAME$ = "Bad command, no such a command named ""{0}"", ? for command list or ""man"" for all of the commandline detail informations."
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
| 335 |
Public Function SDKdocs() As String
|
| 336 |
Return Me.MarkdownDoc
|
| 337 |
End Function
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
Public Function Execute(CommandLineArgs As String()) As Integer
|
| 348 |
Dim CommandName As String = CommandLineArgs.First
|
| 349 |
Dim argvs As String() = CommandLineArgs.Skip(1).ToArray
|
| 350 |
Dim i As Integer = apiInvoke(CommandName, argvs, help_argvs:=argvs)
|
| 351 |
|
| 352 |
#If DEBUG Then
|
| 353 |
If Not App.GetVariable("pause.disable").ParseBoolean = True Then
|
| 354 |
Call Pause()
|
| 355 |
End If
|
| 356 |
#Else
|
| 357 |
If Stack.TextEquals("Main") Then
|
| 358 |
If AutoPaused Then
|
| 359 |
Call Pause()
|
| 360 |
End If
|
| 361 |
End If
|
| 362 |
#End If
|
| 363 |
Return i
|
| 364 |
End Function
|
| 365 |
|
| 366 |
Public Function Execute(CommandName As String, args As String()) As Integer
|
| 367 |
Return apiInvoke(CommandName.ToLower, args, help_argvs:=args)
|
| 368 |
End Function
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
Public Sub AddCommand(Command As APIEntryPoint)
|
| 376 |
Dim key$ = Command.Name.ToLower
|
| 377 |
|
| 378 |
If Not __API_table.ContainsKey(key) Then
|
| 379 |
Call __API_table.Add(key, Command)
|
| 380 |
End If
|
| 381 |
End Sub
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
<ExportAPI("?", Usage:="? [CommandName]", Info:="Show Application help", Example:="? example_commandName")>
|
| 391 |
Public Function Help(CommandName As String) As Integer
|
| 392 |
If String.IsNullOrEmpty(CommandName) Then
|
| 393 |
|
| 394 |
Call Console.WriteLine(HelpSummary(False))
|
| 395 |
Else
|
| 396 |
|
| 397 |
Call PrintCommandHelp(CommandName)
|
| 398 |
End If
|
| 399 |
|
| 400 |
Return 0
|
| 401 |
End Function
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
Public ReadOnly Property ListCommandInfo As EntryPoints.APIEntryPoint()
|
| 410 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
| 411 |
Get
|
| 412 |
Return __API_table.Values.ToArray
|
| 413 |
End Get
|
| 414 |
End Property
|
| 415 |
|
| 416 |
Public ReadOnly Property Stack As String
|
| 417 |
Public ReadOnly Property Info As [Namespace]
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
Sub New(type As Type, <CallerMemberName> Optional caller As String = Nothing)
|
| 427 |
For Each cInfo As APIEntryPoint In __getsAllCommands(type, False)
|
| 428 |
If __API_table.ContainsKey(cInfo.Name.ToLower) Then
|
| 429 |
Throw New Exception(cInfo.Name & " is duplicated with other command!")
|
| 430 |
Else
|
| 431 |
Call __API_table.Add(cInfo.Name.ToLower, cInfo)
|
| 432 |
End If
|
| 433 |
Next
|
| 434 |
|
| 435 |
Me.__rootNamespace = type.Namespace
|
| 436 |
Me._Stack = caller
|
| 437 |
Me._Type = type
|
| 438 |
Me._Info = type.NamespaceEntry(True)
|
| 439 |
End Sub
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
Public ReadOnly Property Type As Type
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
Protected Overridable Function __getsAllCommands(Type As Type, Optional [Throw] As Boolean = True) As List(Of EntryPoints.APIEntryPoint)
|
| 454 |
Return GetAllCommands(Type, [Throw])
|
| 455 |
End Function
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
Public Shared Function GetAllCommands(type As Type, Optional [Throw] As Boolean = True) As List(Of EntryPoints.APIEntryPoint)
|
| 464 |
If type Is Nothing Then
|
| 465 |
Return New List(Of APIEntryPoint)
|
| 466 |
End If
|
| 467 |
|
| 468 |
Dim methods As MethodInfo() = type.GetMethods(BindingFlags.Public Or BindingFlags.Static)
|
| 469 |
Dim commandAttribute As Type = GetType(ExportAPIAttribute)
|
| 470 |
Dim commandsInfo = LinqAPI.MakeList(Of APIEntryPoint) <=
|
| 471 |
_
|
| 472 |
From methodInfo As MethodInfo
|
| 473 |
In methods
|
| 474 |
Let commandInfo As APIEntryPoint =
|
| 475 |
getAPI(methodInfo, commandAttribute, [Throw])
|
| 476 |
Where Not commandInfo Is Nothing
|
| 477 |
Select commandInfo
|
| 478 |
Order By commandInfo.Name Ascending
|
| 479 |
|
| 480 |
Return commandsInfo
|
| 481 |
End Function
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
Private Shared Function getAPI(methodInfo As MethodInfo, commandAttribute As Type, [throw] As Boolean) As APIEntryPoint
|
| 491 |
Dim cmdAttr As ExportAPIAttribute = Nothing
|
| 492 |
Dim commandInfo As APIEntryPoint
|
| 493 |
|
| 494 |
Try
|
| 495 |
Dim attrs As Object() = methodInfo.GetCustomAttributes(commandAttribute, False)
|
| 496 |
If attrs.IsNullOrEmpty Then
|
| 497 |
Return Nothing
|
| 498 |
End If
|
| 499 |
|
| 500 |
cmdAttr = DirectCast(attrs(0), ExportAPIAttribute)
|
| 501 |
commandInfo = New APIEntryPoint(cmdAttr, methodInfo, [throw])
|
| 502 |
If cmdAttr.Info.StringEmpty Then
|
| 503 |
cmdAttr.Info = methodInfo.Description
|
| 504 |
End If
|
| 505 |
If cmdAttr.Usage.StringEmpty Then
|
| 506 |
cmdAttr.Usage = methodInfo.Usage
|
| 507 |
End If
|
| 508 |
If cmdAttr.Example.StringEmpty Then
|
| 509 |
cmdAttr.Example = methodInfo.ExampleInfo
|
| 510 |
End If
|
| 511 |
|
| 512 |
Return commandInfo
|
| 513 |
Catch ex As Exception
|
| 514 |
If Not cmdAttr Is Nothing Then
|
| 515 |
ex = New Exception("This command API can not be imports: " & cmdAttr.GetJson, ex)
|
| 516 |
ex = New Exception(CheckNotice, ex)
|
| 517 |
End If
|
| 518 |
Call App.LogException(New Exception(methodInfo.FullName(True), ex))
|
| 519 |
Call ex.PrintException
|
| 520 |
|
| 521 |
Return Nothing
|
| 522 |
End Try
|
| 523 |
End Function
|
| 524 |
|
| 525 |
Const CheckNotice As String = "Please checks for the export api definition on your CLI interface function."
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
| 535 |
Public Shared Function CreateEmptyCLIObject() As Interpreter
|
| 536 |
Return New Interpreter(GetType(Interpreter))
|
| 537 |
End Function
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
| 547 |
<ExportAPI("CreateObject")>
|
| 548 |
Public Shared Function CreateInstance(type As Type) As Interpreter
|
| 549 |
Return New Interpreter(type)
|
| 550 |
End Function
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
| 560 |
Public Shared Function CreateInstance(Of T As Class)() As Interpreter
|
| 561 |
Return New Interpreter(type:=GetType(Type))
|
| 562 |
End Function
|
| 563 |
|
| 564 |
#If NET_40 = 0 Then
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
<ExportAPI("rundll")>
|
| 575 |
Public Shared Function CreateInstance(assmPath As String) As Interpreter
|
| 576 |
Dim assembly As Assembly = Assembly.LoadFrom(assmPath)
|
| 577 |
Dim dllMain As Type = GetType(RunDllEntryPoint)
|
| 578 |
Dim main As Type = LinqAPI.DefaultFirst(Of Type) _
|
| 579 |
_
|
| 580 |
() <= From [mod] As Type
|
| 581 |
In assembly.DefinedTypes
|
| 582 |
Let attributes As Object() = [mod].GetCustomAttributes(dllMain, inherit:=False)
|
| 583 |
Where Not attributes Is Nothing AndAlso
|
| 584 |
attributes.Length = 1
|
| 585 |
Select [mod]
|
| 586 |
|
| 587 |
If main Is Nothing Then
|
| 588 |
Return Nothing
|
| 589 |
Else
|
| 590 |
Return New Interpreter(main)
|
| 591 |
End If
|
| 592 |
End Function
|
| 593 |
#End If
|
| 594 |
|
| 595 |
#Region "IDisposable Support"
|
| 596 |
Private disposedValue As Boolean
|
| 597 |
|
| 598 |
|
| 599 |
Protected Sub Dispose(disposing As Boolean)
|
| 600 |
If Not Me.disposedValue Then
|
| 601 |
If disposing Then
|
| 602 |
|
| 603 |
End If
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
End If
|
| 608 |
Me.disposedValue = True
|
| 609 |
End Sub
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
Public Sub Dispose() Implements IDisposable.Dispose
|
| 620 |
|
| 621 |
Dispose(True)
|
| 622 |
GC.SuppressFinalize(Me)
|
| 623 |
End Sub
|
| 624 |
#End Region
|
| 625 |
|
| 626 |
#Region "Implements System.Collections.Generic.IReadOnlyDictionary(Of String, CommandInfo)"
|
| 627 |
|
| 628 |
Public Iterator Function GetEnumerator() As IEnumerator(Of KeyValuePair(Of String, EntryPoints.APIEntryPoint)) Implements IEnumerable(Of KeyValuePair(Of String, EntryPoints.APIEntryPoint)).GetEnumerator
|
| 629 |
For Each key As String In Me.__API_table.Keys
|
| 630 |
Yield New KeyValuePair(Of String, EntryPoints.APIEntryPoint)(key, Me.__API_table(key))
|
| 631 |
Next
|
| 632 |
End Function
|
| 633 |
|
| 634 |
Public Iterator Function GetEnumerator1() As IEnumerator Implements IEnumerable.GetEnumerator
|
| 635 |
Yield Me.GetEnumerator
|
| 636 |
End Function
|
| 637 |
|
| 638 |
Public Sub Add(item As KeyValuePair(Of String, EntryPoints.APIEntryPoint)) Implements ICollection(Of KeyValuePair(Of String, EntryPoints.APIEntryPoint)).Add
|
| 639 |
Call __API_table.Add(item.Key, item.Value)
|
| 640 |
End Sub
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
Public Sub Clear() Implements ICollection(Of KeyValuePair(Of String, EntryPoints.APIEntryPoint)).Clear
|
| 647 |
Call __API_table.Clear()
|
| 648 |
End Sub
|
| 649 |
|
| 650 |
Public Function Contains(item As KeyValuePair(Of String, EntryPoints.APIEntryPoint)) As Boolean Implements ICollection(Of KeyValuePair(Of String, EntryPoints.APIEntryPoint)).Contains
|
| 651 |
Return __API_table.Contains(item)
|
| 652 |
End Function
|
| 653 |
|
| 654 |
Public Sub CopyTo(array() As KeyValuePair(Of String, EntryPoints.APIEntryPoint), arrayIndex As Integer) Implements ICollection(Of KeyValuePair(Of String, EntryPoints.APIEntryPoint)).CopyTo
|
| 655 |
Call __API_table.ToArray.CopyTo(array, arrayIndex)
|
| 656 |
End Sub
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
Public ReadOnly Property Count As Integer Implements ICollection(Of KeyValuePair(Of String, EntryPoints.APIEntryPoint)).Count
|
| 665 |
Get
|
| 666 |
Return Me.__API_table.Count
|
| 667 |
End Get
|
| 668 |
End Property
|
| 669 |
|
| 670 |
Public ReadOnly Property IsReadOnly As Boolean Implements ICollection(Of KeyValuePair(Of String, EntryPoints.APIEntryPoint)).IsReadOnly
|
| 671 |
Get
|
| 672 |
Return False
|
| 673 |
End Get
|
| 674 |
End Property
|
| 675 |
|
| 676 |
Public Function Remove(item As KeyValuePair(Of String, EntryPoints.APIEntryPoint)) As Boolean Implements ICollection(Of KeyValuePair(Of String, EntryPoints.APIEntryPoint)).Remove
|
| 677 |
Return __API_table.Remove(item.Key)
|
| 678 |
End Function
|
| 679 |
|
| 680 |
Public Sub Add(key As String, value As EntryPoints.APIEntryPoint) Implements IDictionary(Of String, EntryPoints.APIEntryPoint).Add
|
| 681 |
Call __API_table.Add(key, value)
|
| 682 |
End Sub
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
Public Function ExistsCommand(CommandName As String) As Boolean Implements IDictionary(Of String, EntryPoints.APIEntryPoint).ContainsKey
|
| 691 |
Return Me.__API_table.ContainsKey(CommandName.ToLower)
|
| 692 |
End Function
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
Default Public Overloads Property Item(key As String) As EntryPoints.APIEntryPoint Implements IDictionary(Of String, EntryPoints.APIEntryPoint).Item
|
| 700 |
Get
|
| 701 |
Return Me.__API_table(key)
|
| 702 |
End Get
|
| 703 |
Set(value As EntryPoints.APIEntryPoint)
|
| 704 |
|
| 705 |
End Set
|
| 706 |
End Property
|
| 707 |
|
| 708 |
Public Function GetPossibleCommand(name As Value(Of String)) As APIEntryPoint
|
| 709 |
Dim commands = ListingRelated(name)
|
| 710 |
|
| 711 |
If commands.Length = 0 Then
|
| 712 |
Return Nothing
|
| 713 |
Else
|
| 714 |
Return __API_table(commands.First.ToLower)
|
| 715 |
End If
|
| 716 |
End Function
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
Public Function ListingRelated(query$) As String()
|
| 724 |
Dim key As New LevenshteinString(query.ToLower)
|
| 725 |
Dim LQuery = From x As String
|
| 726 |
In __API_table.Keys.AsParallel
|
| 727 |
Let compare = key Like x
|
| 728 |
Where Not compare Is Nothing AndAlso
|
| 729 |
compare.Score > 0.3
|
| 730 |
Select compare.Score,
|
| 731 |
x
|
| 732 |
Order By Score Descending
|
| 733 |
|
| 734 |
Dim levenshteins = LQuery _
|
| 735 |
.Select(Function(x) x.x) _
|
| 736 |
.AsList
|
| 737 |
|
| 738 |
levenshteins += __API_table _
|
| 739 |
.Keys _
|
| 740 |
.Where(Function(s)
|
| 741 |
Return InStr(s, query, CompareMethod.Text) > 0 OrElse
|
| 742 |
InStr(query, s, CompareMethod.Text) > 0
|
| 743 |
End Function)
|
| 744 |
|
| 745 |
Return levenshteins _
|
| 746 |
.Distinct _
|
| 747 |
.Select(Function(name)
|
| 748 |
Return __API_table(name).Name
|
| 749 |
End Function) _
|
| 750 |
.ToArray
|
| 751 |
End Function
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
Public ReadOnly Property APINameList As ICollection(Of String) Implements IDictionary(Of String, EntryPoints.APIEntryPoint).Keys
|
| 761 |
Get
|
| 762 |
Return Me.__API_table.Keys
|
| 763 |
End Get
|
| 764 |
End Property
|
| 765 |
|
| 766 |
Public Function Remove(CommandName As String) As Boolean Implements IDictionary(Of String, EntryPoints.APIEntryPoint).Remove
|
| 767 |
Return __API_table.Remove(CommandName)
|
| 768 |
End Function
|
| 769 |
|
| 770 |
Public Function TryGetValue(key As String, ByRef value As EntryPoints.APIEntryPoint) As Boolean Implements IDictionary(Of String, EntryPoints.APIEntryPoint).TryGetValue
|
| 771 |
Return Me.__API_table.TryGetValue(key, value)
|
| 772 |
End Function
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
Public ReadOnly Property APIList As ICollection(Of EntryPoints.APIEntryPoint) Implements IDictionary(Of String, EntryPoints.APIEntryPoint).Values
|
| 779 |
Get
|
| 780 |
Return Me.__API_table.Values
|
| 781 |
End Get
|
| 782 |
End Property
|
| 783 |
#End Region
|
| 784 |
End Class
|
| 785 |
End Namespace
|