internal bool AssignToSlave(MOG_Command pCommand) { MOG_Command pSlave = null; // Always make sure that the AssignedSlaveID is cleared just in case we fail pCommand.SetAssignedSlaveID(0); // Check if this is an exclusive command? if (pCommand.IsExclusiveCommand()) { // Check if this exclusive command is already actively getting processed? if (CheckExclusiveCommands(pCommand)) { // Don't assign this exclusive command because there is already another one being processed return(false); } } // Identify a valid slave based on the mValidSlaves? if (pCommand.GetValidSlaves().Length > 0) { // Look for a valid slave by scanning mAvailableSlaves for (int s = 0; s < mAvailableSlaves.Count; s++) { // Is this slave's name specified in mValidSlaves? pSlave = (MOG_Command)mAvailableSlaves[s]; if (pSlave != null) { if (IsSlaveListed(pSlave.GetComputerName(), pCommand.GetValidSlaves())) { break; } } // Indicate that this slave wasn't listed in mValidSlaves pSlave = null; } // No available valid slave found? if (pSlave == null) { // Request a new slave respecting this command's valid slaves RequestNewSlave(pCommand); // Bail out since we need to wait for a slave to become available return(false); } } else { // Check if we have run out of available slaves? if (mAvailableSlaves.Count == 0) { // Request a new slave? RequestNewSlave(pCommand); // Bail out here because there were no slaves and it can take some time before any requested slaves will be launched return(false); } // Since mValidSlaves was blank, get the first slave in the list pSlave = (MOG_Command)mAvailableSlaves[0]; } // Did we actually locate a valid available slave? if (pSlave != null) { // Send the command to the available slave if (mServerCommandManager.SendToConnection(pSlave.GetNetworkID(), pCommand)) { // Assign the Slave's NetworkID within the command so we will know who is working on this command pCommand.SetAssignedSlaveID(pSlave.GetNetworkID()); // Stick this command into the RegisteredSlave's command pSlave.SetCommand(pCommand); // Add the slave to mActiveSlaves mActiveSlaves.Add(pSlave); // Remove the top slave from mAvailableSlaves mAvailableSlaves.Remove(pSlave); // Send out needed Notify command MOG_Command pNotify = MOG_CommandFactory.Setup_NotifyActiveConnection(pSlave); mServerCommandManager.SendToActiveTab("Connections", pNotify); pNotify = MOG_CommandFactory.Setup_NotifyActiveCommand(pCommand); mServerCommandManager.SendToActiveTab("Connections", pNotify); return(true); } } return(false); }