internal bool ReleaseSlave(MOG_Command pCommand)
        {
            // Scan mActiveSlaves looking for one that matches this command
            // This way is safer just in case NetworkIDs get reset from a reconnect event
            for (int s = 0; s < mActiveSlaves.Count; s++)
            {
                MOG_Command pSlave = (MOG_Command)mActiveSlaves[s];

                // Check if this slave is working on something?
                if (pSlave.GetCommand() != null)
                {
                    // Check if the CommandID matches?
                    if (pSlave.GetCommand().GetCommandID() == pCommand.GetCommandID())
                    {
                        // Clear this slave's command
                        pSlave.SetCommand(null);
                        // Refresh the command's SetAssignedSlaveID
                        pCommand.SetAssignedSlaveID(pSlave.GetNetworkID());

                        // 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);

                        // Insert the slave at the top of mAvailableSlaves so it will be immeadiately reused
                        mAvailableSlaves.Insert(0, pSlave);
                        // Erase the slave from mActiveSlaves
                        mActiveSlaves.RemoveAt(s);

                        // Return the command that the slave was processing for reference
                        return(true);
                    }
                }
            }

            string message = String.Concat("Server could not release slave because it failed to locate the slave in mActiveSlaves\n",
                                           "Command:", pCommand.ToString(), "     NetworkID:", pCommand.GetNetworkID(), "     Asset:", pCommand.GetAssetFilename().GetOriginalFilename());

            MOG_Report.ReportMessage("Server", message, Environment.StackTrace, MOG_ALERT_LEVEL.ERROR);
            return(false);
        }
        internal bool Command_KillCommand(MOG_Command pCommand)
        {
            // Enumerate through all the jobs
            foreach (MOG_JobInfo job in mJobOrder)
            {
                if (job != null)
                {
                    // Attempt to remove the command from this job
                    job.KillCommand(pCommand.GetCommandID());
                }
            }

            // Check the active slaves to see if it is being processed?
            // Just in case the command we want to kill has already been tasked out to a slave
            for (int c = 0; c < mActiveSlaves.Count; c++)
            {
                // Check this slave's assigned command?
                MOG_Command activeSlave    = (MOG_Command)mActiveSlaves[c];
                MOG_Command pActiveCommand = activeSlave.GetCommand();
                if (pActiveCommand != null)
                {
                    // Checkif the CommandID matches?
                    if (pActiveCommand.GetCommandID() == pCommand.GetCommandID())
                    {
                        // Clear the command this slave is working on
                        activeSlave.SetCommand(null);

                        // Always kill the connection to this slave just in case it was hung by the command
                        MOG_ControllerSystem.ShutdownSlave(activeSlave.GetNetworkID());
                        break;
                    }
                }
            }

            // Always eat this command
            return(true);
        }
        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);
        }