示例#1
0
        /// <summary>
        /// Instantiates a new MSBuild or MSBuildTaskHost process acting as a child node.
        /// </summary>
        internal bool CreateNode(HandshakeOptions hostContext, INodePacketFactory factory, INodePacketHandler handler, TaskHostConfiguration configuration)
        {
            ErrorUtilities.VerifyThrowArgumentNull(factory, "factory");
            ErrorUtilities.VerifyThrow(!_nodeIdToPacketFactory.ContainsKey((int)hostContext), "We should not already have a factory for this context!  Did we forget to call DisconnectFromHost somewhere?");

            if (AvailableNodes == 0)
            {
                ErrorUtilities.ThrowInternalError("All allowable nodes already created ({0}).", _nodeContexts.Count);
                return(false);
            }

            // Start the new process.  We pass in a node mode with a node number of 2, to indicate that we
            // want to start up an MSBuild task host node.
            string commandLineArgs = $" /nologo /nodemode:2 /nodereuse:{ComponentHost.BuildParameters.EnableNodeReuse} ";

            string msbuildLocation = GetMSBuildLocationFromHostContext(hostContext);

            // we couldn't even figure out the location we're trying to launch ... just go ahead and fail.
            if (msbuildLocation == null)
            {
                return(false);
            }

            CommunicationsUtilities.Trace("For a host context of {0}, spawning executable from {1}.", hostContext.ToString(), msbuildLocation ?? "MSBuild.exe");

            // Make it here.
            NodeContext context = GetNode
                                  (
                msbuildLocation,
                commandLineArgs,
                (int)hostContext,
                this,
                CommunicationsUtilities.GetHostHandshake(hostContext),
                CommunicationsUtilities.GetClientHandshake(hostContext),
                NodeContextTerminated
                                  );

            if (null != context)
            {
                _nodeContexts[hostContext] = context;

                // Start the asynchronous read.
                context.BeginAsyncPacketRead();

                _activeNodes.Add((int)hostContext);
                _noNodesActiveEvent.Reset();

                return(true);
            }

            return(false);
        }
 /// <summary>
 /// Magic number sent by the host to the client during the handshake.
 /// Derived from the binary timestamp to avoid mixing binary versions,
 /// Is64BitProcess to avoid mixing bitness, and enableNodeReuse to
 /// ensure that a /nr:false build doesn't reuse clients left over from
 /// a prior /nr:true build. The enableLowPriority flag is to ensure that
 /// a build with /low:false doesn't reuse clients left over for a prior
 /// /low:true build.
 /// </summary>
 /// <param name="enableNodeReuse">Is reuse of build nodes allowed?</param>
 /// <param name="enableLowPriority">Is the build running at low priority?</param>
 internal static long GetHostHandshake(bool enableNodeReuse, bool enableLowPriority)
 {
     CommunicationsUtilities.Trace("MSBUILDNODEHANDSHAKESALT=\"{0}\", msbuildDirectory=\"{1}\", enableNodeReuse={2}, enableLowPriority={3}", Traits.MSBuildNodeHandshakeSalt, BuildEnvironmentHelper.Instance.MSBuildToolsDirectory32, enableNodeReuse, enableLowPriority);
     return(CommunicationsUtilities.GetHostHandshake(CommunicationsUtilities.GetHandshakeOptions(taskHost: false, nodeReuse: enableNodeReuse, lowPriority: enableLowPriority, is64Bit: EnvironmentUtilities.Is64BitProcess)));
 }
 /// <summary>
 /// Returns the host handshake for this node endpoint
 /// </summary>
 protected override long GetHostHandshake()
 {
     return(CommunicationsUtilities.GetHostHandshake(CommunicationsUtilities.GetHandshakeOptions(taskHost: true)));
 }
        /// <summary>
        /// Returns the host handshake for this node endpoint
        /// </summary>
        protected override long GetHostHandshake()
        {
            long hostHandshake = CommunicationsUtilities.GetHostHandshake(CommunicationsUtilities.GetCurrentTaskHostContext());

            return(hostHandshake);
        }