CmdRunnerMultiWorker ClassCleanCode C# Libraries v1.2.03 API
Executes multiple commands on a collection of remote servers using a telnet session.
Inheritance Hierarchy

OnlineSystem Object
  CleanCode.RemoteCommands CmdRunnerMultiWorker

Namespace: CleanCode.RemoteCommands
Assembly: CleanCode.RemoteCommands (in CleanCode.RemoteCommands.dll) Version: 1.2.3.0 (1.2.03)
Syntax

public class CmdRunnerMultiWorker
Remarks

Each command is managed by a CmdRunnerWorker object, which performs work in a background thread allowing your foreground GUI to continue interacting with a user. CmdRunnerWorker executes a single command on one or more remote systems then filters and formats that output per your specifications.

The command on a single server is executed by an instance of either TelnetExternalExec (which uses the external program Onlineplink) or TelnetLibExec (which uses an internal telnet library). Unless you invoke the UseExternalCmd  method, the latter is used. It is preferable and seems to work fine for Ethernet connections, but with servers communicating over GPRS it does not work reliably, hence the choice.

To use any ThreadWorker objects you need to have a ThreadManager which handles multiple background tasks for your application (say, for example, two to execute commands, one to do a ping check, one to get WMI information, etc.). While you may certainly use multiple CmdRunnerWorker objects, the CmdRunnerMultiWorker was designed to streamline the process of dealing with multiple remote commands.

Since CleanCode 0.9.07.

Examples

This instrumentation code is similar but not identical between CmdRunnerWorker and CmdRunnerMultiWorker To use this class you will need to define a callback routine to process results as they become available.
private void MyUpdater(string ip, string cmd, string msg)
{ . . . }
This method is then identified as a delegate to the CmdRunnerWorker.
CmdRunnerWorker.CmdRunnerUpdater cmdCallback =
    new CmdRunnerWorker.CmdRunnerUpdater(MyUpdater);
Next you instantiate an object with the necessary specifications then add as many commands as you need (compare to the CmdRunnerWorker's SetCmd(String, String, String) method).
cmdRunnerMultiWorker = new CmdRunnerMultiWorker(
    threadManager, cmdCallback, 21, 10,
    "login", "Password", @"bash[^$]*\$", "mylogin", "mypwd");
cmdRunnerMultiWorker.AddCmd("df",
    @".*?\n\S+\s+(\d+)(?:\s+\d+){2}\s+(\S+)", "{0} ({1})" );
cmdRunnerMultiWorker.AddCmd(. . .);
cmdRunnerMultiWorker.AddCmd(. . .);
Unlike with the singular CmdRunnerWorker, these methods that tailor behavior must not be executed until you have added all the commands above:
cmdRunnerMultiWorker.UseExternalCmd();
cmdRunnerMultiWorker.SetIpAddressList(ipList);
After you have prepared all of your ThreadWorker objects, you tell the ThreadManager to start them.
threadManager.Run();
cmdRunnerWorker.UpdateResults();
Finally, you will need to periodically poll for results with this method, which invokes your delegate as needed.
See Also