Пример #1
0
        //process next MovesQueue item
        private void step()
        {
            if (adjacencyPairQueue.Count > 0)
            {
                AdjacencyPair p = adjacencyPairQueue.Dequeue();

                p.enqueueRecursively(MovesQueue);
            }

            if (MovesQueue.Count > 0)
            {
                Type t = typeof(Conversation);//necessary for invoke for some reason

                MovesQueueItem p = MovesQueue.Dequeue();


                //loop makes array of types from the paramaters
                //(necessary for the getmethod function in order to differentiate between overloaded methods)

                Type[] paramaterTypes = new Type[p.paramaters.Length];

                for (int i = 0; i < p.paramaters.Length; i++)
                {
                    //if an exception is ever thrown here it might be becuse the name or paramaters of a production rule was wrong
                    paramaterTypes[i] = p.paramaters[i].GetType();
                }

                //search for correct method
                MethodInfo methodInfo = t.GetMethod(p.methodToCall, paramaterTypes);

                /*INVOKE THE METHOD*/
                try
                {
                    /*The following if statement determines whether the method produces output or not
                     * methods producing output need to enqueue string return values onto the output buffer
                     * this is determined by the fact that only middlelayer functions take a PairParamaters as paramater
                     */
                    //this if statement used to be a hack to determine if it was a terminal symbol (which had output) or  a rule (which would just be processed)
                    //if (paramaterTypes[0] == typeof(PairParamaters))
                    //    methodInfo.Invoke(this/*utteranceGenerator*/, p.paramaters);
                    //else
                    outputQueue.Enqueue(new Turn(((PairParamaters)p.paramaters[0]).initiatingSpeaker, (string)methodInfo.Invoke(this /*utteranceGenerator*/, p.paramaters)));
                }
                catch (Exception e)
                {
                    outputQueue.Enqueue(new Turn("Exception thrown in reflection invoke of " + p.methodToCall));
                    if (e.InnerException != null)
                    {
                        string err = e.InnerException.Message; //get the inner exception
                        throw;                                 //rethrow the exception
                    }
                }
            }
        }