Example #1
0
        /// <summary>
        /// Main thread process which is responsible for processing the configuration
        /// and build requests. Currently we process all items fromeach of the Queue.
        /// If there is an exception then send it to the definitions. Let the remining
        /// Queue be processed then exit the thread
        /// </summary>
        private void ProcessorThreadProc()
        {
            WaitHandle[] waitHandles = { this.processorThreadExit, this.processorThreadResume };
            while (!this.processorThreadExited)
            {
                int handle = WaitHandle.WaitAny(waitHandles);
                switch (handle)
                {
                case 0:
                    // exit
                    this.processorThreadExited = true;
                    break;

                case 1:
                    // something to process
                    if (this.engineException != null)
                    {
                        foreach (RequestDefinition definition in this.definitions.Values)
                        {
                            definition.RaiseEngineException(this.engineException);
                        }

                        this.processorThreadExited = true;
                    }

                    // Process new configuration requests
                    if (this.newConfigurations != null && this.newConfigurations.Count > 0)
                    {
                        BuildRequestConfiguration config = null;
                        config = this.newConfigurations.Peek();
                        while (config != null)
                        {
                            int newConfigId = this.GetIdForUnresolvedConfiguration(config);
                            RequestDefinition definition = this[newConfigId];
                            definition.RaiseOnNewConfigurationRequest(config);

                            lock (this.newConfigurations)
                            {
                                this.newConfigurations.Dequeue();
                            }

                            if (this.newConfigurations.Count > 0)
                            {
                                config = this.newConfigurations.Peek();
                            }
                            else
                            {
                                config = null;
                            }
                        }
                    }

                    // Process new build requests
                    if (this.newRequests != null && this.newRequests.Count > 0)
                    {
                        BuildRequest request = null;
                        request = this.newRequests.Peek();
                        while (request != null)
                        {
                            RequestDefinition definition = this[request.ConfigurationId];
                            definition.RaiseOnNewBuildRequest(request);

                            lock (this.newRequests)
                            {
                                this.newRequests.Dequeue();
                            }

                            if (this.newRequests.Count > 0)
                            {
                                request = this.newRequests.Peek();
                            }
                            else
                            {
                                request = null;
                            }
                        }
                    }

                    // Process results for completed requests
                    if (this.newResults != null && this.newResults.Count > 0)
                    {
                        ResultFromEngine result = null;
                        result = this.newResults.Peek();
                        while (result != null)
                        {
                            RequestDefinition definition = this[result.Request.ConfigurationId];
                            definition.RaiseOnBuildRequestCompleted(result.Request, result.Result);

                            lock (this.newResults)
                            {
                                this.newResults.Dequeue();
                            }

                            if (this.newResults.Count > 0)
                            {
                                result = this.newResults.Peek();
                            }
                            else
                            {
                                result = null;
                            }
                        }
                    }

                    break;

                default:
                    // Unknown event
                    this.processorThreadExited = true;
                    throw new InvalidOperationException("Unknown wait signal received by the ProcessorThread");
                }
            }
        }