Beispiel #1
0
        private static IRarController GetController(string pipeName, Handshake handshake)
        {
            Type rarControllerType = Type.GetType(RarControllerName);

            Func <string, int?, int?, int, bool, NamedPipeServerStream> streamFactory    = NamedPipeUtil.CreateNamedPipeServer;
            Func <Handshake, NamedPipeServerStream, int, bool>          validateCallback = NamedPipeUtil.ValidateHandshake;
            IRarController controller = Activator.CreateInstance(rarControllerType, pipeName, handshake, streamFactory, validateCallback, null) as IRarController;

            ErrorUtilities.VerifyThrow(controller != null, ResourceUtilities.GetResourceString("RarControllerReflectionError"), RarControllerName);
            return(controller);
        }
Beispiel #2
0
        public NodeEngineShutdownReason Run(bool nodeReuse, bool lowPriority, out Exception shutdownException, CancellationToken cancellationToken = default)
        {
            shutdownException = null;
            using CancellationTokenSource cts = new CancellationTokenSource();
            string    pipeName  = CommunicationsUtilities.GetRarPipeName(nodeReuse, lowPriority);
            Handshake handshake = NodeProviderOutOfProc.GetHandshake(enableNodeReuse: nodeReuse,
                                                                     enableLowPriority: lowPriority, specialNode: true);

            IRarController controller = GetController(pipeName, handshake);

            Task <int> rarTask = controller.StartAsync(cts.Token);

            Task <NodeEngineShutdownReason> msBuildShutdown = RunShutdownCheckAsync(handshake, cts.Token);

            // Timeout for node, limits lifetime of node to 1 hour
            cts.CancelAfter(NodeShutdownTimeout);
            int index;

            try
            {
                // Wait for any of these tasks to finish:
                // - rarTask can timeout (default is 15 minutes)
                // - msBuildShutdown ends when it receives command to shutdown
                // - node lifetime expires
                index = Task.WaitAny(new Task[] { msBuildShutdown, rarTask }, cts.Token);
            }
            catch (OperationCanceledException e)
            {
                shutdownException = e;
                return(NodeEngineShutdownReason.Error);
            }

            cts.Cancel();

            if (index == 0)
            {
                // We know that the task completed, so we can get Result without waiting for it.
                return(msBuildShutdown.Result);
            }
            else
            {
                // RAR task can only exit with connection error or timeout
                return(NodeEngineShutdownReason.ConnectionFailed);
            }
        }