public ItemScore ScoreItem(ResponseInfo studentResponse, IItemScorerCallback callbackReference)
        {
            IItemScorer itemScorerImpl;

            if (scoringEngines.TryGetValue(studentResponse.ItemFormat, out itemScorerImpl))
            {
                if (callbackReference == null)
                {
                    //This is synchronous scoring
                    return(InvokeSynchronousScoring(itemScorerImpl, studentResponse));
                }
                else
                {
                    // This is asynchronous scoring
                    return(InvokeAsynchronousScoring(itemScorerImpl, studentResponse, callbackReference));
                }
            }

            return(new ItemScore(-1, -1, ScoringStatus.NoScoringEngine, null, new ScoreRationale {
                Msg = "No scoring engine found for " + studentResponse.ItemFormat
            }, null, studentResponse.ContextToken));
        }
        private ItemScore InvokeAsynchronousScoring(IItemScorer scorerImpl, ResponseInfo studentResponse, IItemScorerCallback callbackReference)
        {
            // if the scorer supports async mode then let the item scorer server deal with async
            if (scorerImpl.GetScorerInfo(studentResponse.ItemFormat).SupportsAsyncMode)
            {
                return(scorerImpl.ScoreItem(studentResponse, callbackReference));
            }

            // if the scorer does not handle async mode then we need to handle it in our own thread queue
            if (threadPool.Enqueue(new AsyncScoringTask(scorerImpl, studentResponse, callbackReference)))
            {
                return(new ItemScore(-1, -1, ScoringStatus.WaitingForMachineScore, null, null, null, studentResponse.ContextToken));
            }

            // if we get here then the thread queue is filled (probably waiting on a bunch of scores to come back)
            return(new ItemScore(-1, -1, ScoringStatus.WaitingForMachineScore, null, new ScoreRationale()
            {
                Msg = "Cannot enqueue scoring task"
            }, null, studentResponse.ContextToken));
        }
 public AsyncScoringTask(IItemScorer scorer, ResponseInfo studentResponse, IItemScorerCallback callback) : base(null)
 {
     this.scorerImpl      = scorer;
     this.studentResponse = studentResponse;
     this.callback        = callback;
 }