0

command name can be APP_COMMAND_NAME as const

            Friend Module Program

Private CurrentString As String = String.Empty
Public Const APP_RUNNING As String = "Running"
Public Const APP_TITLE As String = "Console"
Public State_Output As String
Public State_List As List(Of String) = New List(Of String)
Private commandlist_ As Dictionary(Of String, Action)

Private State As String = String.Empty

Public APP_USER As String

Event Command_Run()

Sub Main()
    APP_USER = String.Empty
    Program.State_Output = "App is " & State.ToString & CStr(Program.APP_RUNNING)
    'Program.State_List = New List(Of String)

    Console.Title = APP_TITLE
    AddHandler Command_Run, AddressOf RunCommand
    Program.commandlist_ = New Dictionary(Of String, Action)
    Program.commandlist_.Add("Notepad", New Action(AddressOf Notepad))

    Console.Write(">>")
    'Program.CurrentString = Console.ReadLine()
    ' Console.WriteLine(CurrentString)

    State = Program.APP_RUNNING

    While State = Program.APP_RUNNING
        Console.Write("?")
        'Program.CurrentString = Program.State_Output
        Console.WriteLine(Program.CurrentString)
        'Program.CurrentString = String.Empty = Console.ReadLine
        RaiseEvent Command_Run()
    End While

    'Call Main()

End Sub
Private Sub Notepad()
    Dim proc As Process
    proc = Program.RetrieveProcessStatus(Process.Start("Notepad.exe"))
    Program.APP_USER = proc.MachineName
    Console.WriteLine("Running:" & "With" & Program.APP_USER & "Process:" & proc.ToString)
End Sub
Private Sub LoadStateList()

    If Not IsNothing(Program.State_List) Then
        Console.WriteLine("App State is loaded")
        Program.State_List = Nothing
        Program.State_List = New List(Of String)
        Program.State_List.Add(APP_RUNNING)
        Program.State_List.Add(Program.State_Output)
    Else
        Dim nullcept As New Exception("Cannot load null list")
        Console.WriteLine(nullcept.Message)
        Exit Sub
    End If

End Sub

Private Sub RunCommand()
    Program.LoadStateList()

    Select Case Program.State_List(0) = Program.APP_RUNNING
        Case True
            Console.WriteLine("Ready to run command")

        Case False
            Console.WriteLine("Command Run Failed")
    End Select

    Console.WriteLine("Enter CMD Name.")
    Program.CurrentString = Console.ReadLine

    For Each a As Action In Program.commandlist_.Values
        If Not IsNothing(Program.commandlist_(Program.CurrentString)) Then

            commandlist_(Program.CurrentString).Invoke()

        End If
    Next
End Sub

Function RetrieveProcessStatus(ByVal p As Process)
    Return p
End Function
2
Contributors
1
Reply
15
Views
3 Weeks
Discussion Span
Last Post by rproffitt
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.