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 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 InvokeSynchronousScoring(IItemScorer scorerImpl, ResponseInfo studentResponse)
 {
     return(scorerImpl.ScoreItem(studentResponse, null));
 }
 public AsyncScoringTask(IItemScorer scorer, ResponseInfo studentResponse, IItemScorerCallback callback) : base(null)
 {
     this.scorerImpl      = scorer;
     this.studentResponse = studentResponse;
     this.callback        = callback;
 }
示例#5
0
        public void ReadXml(XmlReader reader)
        {
            // <ItemScoreRequest>
            reader.MoveToContent();

            // "callbackUrl"
            if (reader.MoveToAttribute("callbackUrl"))
            {
                CallbackUrl = reader.ReadContentAsString();
            }

            // <ResponseInfo>
            reader.ReadToFollowing("ResponseInfo");

            // "itemIdentifier"
            string itemIdentifier = null;

            if (reader.MoveToAttribute("itemIdentifier"))
            {
                itemIdentifier = reader.ReadContentAsString();
            }

            // "itemFormat"
            string itemFormat = null;

            if (reader.MoveToAttribute("itemFormat"))
            {
                itemFormat = reader.ReadContentAsString();
            }

            // <StudentResponse>
            string studentResponse            = null;
            bool   studentResponseIsEncrypted = false;

            if (reader.Name == "StudentResponse" || reader.ReadToFollowing("StudentResponse"))
            {
                if (reader.MoveToAttribute("encrypted"))
                {
                    Boolean.TryParse(reader.ReadContentAsString(), out studentResponseIsEncrypted);
                }

                reader.MoveToElement();

                studentResponse = reader.ReadElementContentAsString();
            }

            // <Rubric>
            object            rubric            = null;
            RubricContentType rubricContentType = RubricContentType.Uri;
            bool canCache        = true;
            bool rubricEncrypted = false;

            if (reader.Name == "Rubric" || reader.ReadToFollowing("Rubric"))
            {
                reader.MoveToAttribute("type");
                string rubricType = reader.ReadContentAsString();

                if (reader.MoveToAttribute("cancache"))
                {
                    Boolean.TryParse(reader.ReadContentAsString(), out canCache);
                }

                if (reader.MoveToAttribute("encrypted"))
                {
                    Boolean.TryParse(reader.ReadContentAsString(), out rubricEncrypted);
                }

                reader.MoveToElement();

                rubricContentType = rubricType == "Data" ? RubricContentType.ContentString : RubricContentType.Uri;
                rubric            = reader.ReadElementContentAsString(); // Reading the rubric contents

                // We can safely convert to Uri only if the rubric is not encrypted. If it is, then you have to keep it as a string till someone can decrypt it
                if (!rubricEncrypted && rubricContentType == RubricContentType.Uri)
                {
                    rubric = new Uri((string)rubric);
                }
            }

            // Now the optional stuff

            // <ContextToken>
            string contextToken = null;

            if (reader.Name == "ContextToken")
            {
                contextToken = reader.ReadElementContentAsString();
            }

            // <IncomingBindings>
            List <VarBinding> incomingBindings = new List <VarBinding>();

            if (reader.Name == "IncomingBindings")
            {
                XmlReader bindingsReader = reader.ReadSubtree();
                while (bindingsReader.ReadToFollowing("Binding"))
                {
                    string name  = bindingsReader.MoveToAttribute("name") ? bindingsReader.ReadContentAsString() : null;
                    string type  = bindingsReader.MoveToAttribute("type") ? bindingsReader.ReadContentAsString() : null;
                    string value = bindingsReader.MoveToAttribute("value") ? bindingsReader.ReadContentAsString() : null;

                    if (!String.IsNullOrEmpty(name) && !String.IsNullOrEmpty(type) && !String.IsNullOrEmpty(value))
                    {
                        incomingBindings.Add(new VarBinding()
                        {
                            Name = name, Type = type, Value = value
                        });
                    }
                }
                bindingsReader.Close();
                reader.Read();  // move past the </IncomingBindings
            }

            // <OutgoingBindings>
            List <VarBinding> outgoingBindings = new List <VarBinding>();

            if (reader.Name == "OutgoingBindings")
            {
                XmlReader bindingsReader = reader.ReadSubtree();
                while (bindingsReader.ReadToFollowing("Binding"))
                {
                    string name = bindingsReader.MoveToAttribute("name") ? bindingsReader.ReadContentAsString() : null;
                    if (!String.IsNullOrEmpty(name))
                    {
                        outgoingBindings.Add(new VarBinding()
                        {
                            Name = name, Type = String.Empty, Value = String.Empty
                        });
                    }
                }
                bindingsReader.Close();
            }

            ResponseInfo = new ResponseInfo(itemFormat, itemIdentifier, studentResponse, rubric, rubricContentType, contextToken, canCache);
            ResponseInfo.IsStudentResponseEncrypted = studentResponseIsEncrypted;
            ResponseInfo.IsRubricEncrypted          = rubricEncrypted;
            ResponseInfo.IncomingBindings           = incomingBindings;
            ResponseInfo.OutgoingBindings           = outgoingBindings;
        }
示例#6
0
 public ItemScoreRequest(ResponseInfo responseInfo)
 {
     ResponseInfo = responseInfo;
 }