예제 #1
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;
        }
예제 #2
0
 public ResponseInfo(string itemFormat, string itemID, string studentResponse, Object rubric, RubricContentType contentType, string contextToken, bool allowRubricCaching)
 {
     this.ItemFormat      = itemFormat;
     this.ItemIdentifier  = itemID;
     this.StudentResponse = studentResponse;
     this.Rubric          = rubric;
     this.ContentType     = contentType;
     this.ContextToken    = contextToken;
     this.CanCacheRubric  = allowRubricCaching;
 }