CleanCode.Threading ThreadWorker
CleanCode.RemoteCommands CmdRunnerWorker
Namespace: CleanCode.RemoteCommands
Assembly: CleanCode.RemoteCommands (in CleanCode.RemoteCommands.dll) Version: 1.2.3.0 (1.2.03)
public class CmdRunnerWorker : ThreadWorker
CmdRunnerWorker is an implementation of the abstract ThreadWorker class, 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 plink) 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 separate CmdRunnerMultiWorker was designed to streamline the process of dealing with multiple remote commands.
See the remarks for ThreadManager for a comprehensive discussion of how to wire up and use ThreadWorkers.
Since CleanCode 0.9.07.
private void MyUpdater(string ip, string cmd, string msg) { . . . }
CmdRunnerWorker.CmdRunnerUpdater cmdCallback =
new CmdRunnerWorker.CmdRunnerUpdater(MyUpdater);
cmdRunnerWorker = new CmdRunnerWorker( cmdCallback, 21, 10, "login", "Password", @"bash[^$]*\$", "mylogin", "mypwd"); threadManager.Add(cmdRunnerWorker); cmdRunnerWorker.UseExternalCmd(); cmdRunnerWorker.SetIpAddressList(ipList); cmdRunnerWorker.SetCmd("df", @".*?\n\S+\s+(\d+)(?:\s+\d+){2}\s+(\S+)", "{0} ({1})" );
threadManager.Run();
cmdRunnerWorker.UpdateResults();