internal static bool RunOnRemoteClients(string requestType, Func<RemoteRequest, bool> whatToRun)
{
List<Process> processes = ExistingProcesses;
if (processes.Count == 0)
return false;
// REVIEW: Need to see if trying this many ports causes performance problems
int maxPort = kStartingPort + processes.Count * 4;
// Based on the requested project, decide if we need to start a new one or use the
// one we already have.
Hashtable channelConfiguration = new Hashtable();
channelConfiguration["name"] = "FW Process Remote Request"; // name is need to make connection unique
int processesToBeChecked = processes.Count;
for (int port = kStartingPort; processesToBeChecked > 0 && port < maxPort; port++)
{
TcpChannel chan = new TcpChannel(channelConfiguration, null, null);
try
{
// Create a channel for communicating w/ the process.
ChannelServices.RegisterChannel(chan, false);
if (s_servicePort == port)
continue; // no need to check our service port
// Create an instance of the remote object
RemoteRequest requestor = CreateRequestor(port, requestType);
if (requestor == null)
continue;
// Let the delegate do whatever it needs to with the RemoteRequest
if (whatToRun(requestor))
return true; // The delegate got what it needed
processesToBeChecked--;
}
catch
{
// The process is most likely not listening on the specified port. In
// which case we want to ignore the error and try the next port.
}
finally
{
ChannelServices.UnregisterChannel(chan);
}
}
return false;
}