Example #1
0
        /// <summary>
        /// Make sure a node in the requested context exists.
        /// </summary>
        internal bool AcquireAndSetUpHost(TaskHostContext hostContext, INodePacketFactory factory, INodePacketHandler handler, TaskHostConfiguration configuration)
        {
            NodeContext context = null;
            bool        nodeCreationSucceeded = false;

            if (!(_nodeContexts.TryGetValue(hostContext, out context)))
            {
                nodeCreationSucceeded = CreateNode(hostContext, factory, handler, configuration);
            }
            else
            {
                // node already exists, so "creation" automatically succeeded
                nodeCreationSucceeded = true;
            }

            if (nodeCreationSucceeded)
            {
                context = _nodeContexts[hostContext];
                _nodeIdToPacketFactory[(int)hostContext] = factory;
                _nodeIdToPacketHandler[(int)hostContext] = handler;

                // Configure the node.
                context.SendData(configuration);
                return(true);
            }

            return(false);
        }
 public void RegisterPacketHandler(NodePacketType packetType, NodePacketFactoryMethod factory, INodePacketHandler handler)
 {
     throw new NotImplementedException();
 }
Example #3
0
 /// <summary>
 /// Registers a packet handler.  Not used in the in-proc node.
 /// </summary>
 public void RegisterPacketHandler(NodePacketType packetType, NodePacketFactoryMethod factory, INodePacketHandler handler)
 {
     // Not used
     ErrorUtilities.ThrowInternalErrorUnreachable();
 }
 /// <summary>
 /// Registers the specified handler for a particular packet type.
 /// </summary>
 /// <param name="packetType">The packet type.</param>
 /// <param name="factory">The factory for packets of the specified type.</param>
 /// <param name="handler">The handler to be called when packets of the specified type are received.</param>
 public void RegisterPacketHandler(NodePacketType packetType, NodePacketFactoryMethod factory, INodePacketHandler handler)
 {
     _packetFactory.RegisterPacketHandler(packetType, factory, handler);
 }
Example #5
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public PacketFactoryRecord(INodePacketHandler handler, NodePacketFactoryMethod factoryMethod)
 {
     _handler = handler;
     _factoryMethod = factoryMethod;
 }
 /// <summary>
 /// Registers a packet handler.  Not used in the in-proc node.
 /// </summary>
 public void RegisterPacketHandler(NodePacketType packetType, NodePacketFactoryMethod factory, INodePacketHandler handler)
 {
     // Not used
     ErrorUtilities.ThrowInternalErrorUnreachable();
 }
 /// <summary>
 /// Registers the specified handler for a particular packet type.
 /// </summary>
 /// <param name="packetType">The packet type.</param>
 /// <param name="factory">The factory for packets of the specified type.</param>
 /// <param name="handler">The handler to be called when packets of the specified type are received.</param>
 public void RegisterPacketHandler(NodePacketType packetType, NodePacketFactoryMethod factory, INodePacketHandler handler)
 {
     throw new NotSupportedException("not used");
 }
Example #8
0
 public void RegisterPacketHandler(NodePacketType packetType, NodePacketFactoryMethod factory, INodePacketHandler handler)
 {
     _packetFactory.RegisterPacketHandler(packetType, factory, handler);
 }
        internal bool CreateNode(HandshakeOptions hostContext, INodePacketFactory factory, INodePacketHandler handler, TaskHostConfiguration configuration)
        {
            ErrorUtilities.VerifyThrowArgumentNull(factory, nameof(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} /low:{ComponentHost.BuildParameters.LowPriority} ";

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

            // There is always one task host per host context so we always create just 1 one task host node here.
            int nodeId = (int)hostContext;
            IList <NodeContext> nodeContexts = GetNodes(
                msbuildLocation,
                commandLineArgs,
                nodeId,
                this,
                new Handshake(hostContext),
                NodeContextCreated,
                NodeContextTerminated,
                1);

            return(nodeContexts.Count == 1);
        }
Example #10
0
 /// <summary>
 /// Not necessary for in-proc node - we don't serialize.
 /// </summary>
 public void RegisterPacketHandler(NodePacketType packetType, NodePacketFactoryMethod factory, INodePacketHandler handler)
 {
     // The in-proc node doesn't need to do this.
 }
Example #11
0
 /// <summary>
 /// Not necessary for in-proc node - we don't serialize.
 /// </summary>
 public void RegisterPacketHandler(NodePacketType packetType, NodePacketFactoryMethod factory, INodePacketHandler handler)
 {
     // The in-proc node doesn't need to do this.
 }
Example #12
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public PacketFactoryRecord(INodePacketHandler handler, NodePacketFactoryMethod factoryMethod)
 {
     _handler       = handler;
     _factoryMethod = factoryMethod;
 }
Example #13
0
 /// <summary>
 /// Registers a packet handler
 /// </summary>
 public void RegisterPacketHandler(NodePacketType packetType, NodePacketFactoryMethod factory, INodePacketHandler handler)
 {
     _packetFactories[packetType] = new PacketFactoryRecord(handler, factory);
 }
Example #14
0
        /// <summary>
        /// Instantiates a new MSBuild or MSBuildTaskHost process acting as a child node.
        /// </summary>
        internal bool CreateNode(TaskHostContext 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 ";
            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.GetTaskHostHostHandshake(hostContext),
                CommunicationsUtilities.GetTaskHostClientHandshake(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>
        /// Make sure a node in the requested context exists.  
        /// </summary>
        internal bool AcquireAndSetUpHost(TaskHostContext hostContext, INodePacketFactory factory, INodePacketHandler handler, TaskHostConfiguration configuration)
        {
            NodeContext context = null;
            bool nodeCreationSucceeded = false;

            if (!(_nodeContexts.TryGetValue(hostContext, out context)))
            {
                nodeCreationSucceeded = CreateNode(hostContext, factory, handler, configuration);
            }
            else
            {
                // node already exists, so "creation" automatically succeeded
                nodeCreationSucceeded = true;
            }

            if (nodeCreationSucceeded)
            {
                context = _nodeContexts[hostContext];
                _nodeIdToPacketFactory[(int)hostContext] = factory;
                _nodeIdToPacketHandler[(int)hostContext] = handler;

                // Configure the node.
                context.SendData(configuration);
                return true;
            }

            return false;
        }
Example #16
0
 /// <summary>
 /// Registers the specified handler for a particular packet type.
 /// </summary>
 /// <param name="packetType">The packet type.</param>
 /// <param name="factory">The factory for packets of the specified type.</param>
 /// <param name="handler">The handler to be called when packets of the specified type are received.</param>
 public void RegisterPacketHandler(NodePacketType packetType, NodePacketFactoryMethod factory, INodePacketHandler handler)
 {
     throw new NotSupportedException("not used");
 }
        /// <summary>
        /// Instantiates a new MSBuild or MSBuildTaskHost process acting as a child node.
        /// </summary>
        internal bool CreateNode(TaskHostContext 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 ";
            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.GetTaskHostHostHandshake(hostContext),
                                        CommunicationsUtilities.GetTaskHostClientHandshake(hostContext),
                                        NodeContextTerminated
                                    );

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

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

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

                return true;
            }

            return false;
        }
 public void RegisterPacketHandler(NodePacketType packetType, NodePacketFactoryMethod factory, INodePacketHandler handler)
 {
     throw new NotImplementedException();
 }
Example #19
0
 /// <summary>
 /// Registers a packet handler
 /// </summary>
 public void RegisterPacketHandler(NodePacketType packetType, NodePacketFactoryMethod factory, INodePacketHandler handler)
 {
     _packetFactories[packetType] = new PacketFactoryRecord(handler, factory);
 }