static public ExamGrades getMockExamGrades(int id)
        {
            ExamGrades examGrades = new ExamGrades();

            examGrades.ExamId    = "TestID" + id;
            examGrades.ExamTitle = "TestTitle" + id;
            examGrades.Grade     = random.Next(100, 500);
            examGrades.Status    = examGrades.Grade <= 4.0 ? "BE" : "NB";
            examGrades.Semester  = random.NextDouble() > 0.5 ? "20141" : "20142";
            examGrades.Attempts  = random.Next(1, 3);

            // Random date
            DateTime start     = new DateTime(2014, 1, 1);
            int      range     = 300;
            DateTime randomDay = start.AddDays(random.Next(range));

            examGrades.ExamDate = randomDay.ToString().Substring(0, 10);

            examGrades.G100 = random.Next(0, 12);
            examGrades.G130 = random.Next(0, 12);
            examGrades.G170 = random.Next(0, 12);
            examGrades.G200 = random.Next(0, 12);
            examGrades.G230 = random.Next(0, 12);
            examGrades.G270 = random.Next(0, 12);
            examGrades.G300 = random.Next(0, 12);
            examGrades.G330 = random.Next(0, 12);
            examGrades.G370 = random.Next(0, 12);
            examGrades.G400 = random.Next(0, 12);
            examGrades.G430 = random.Next(0, 12);
            examGrades.G470 = random.Next(0, 12);
            examGrades.G500 = random.Next(0, 12);

            examGrades.Participants += examGrades.G100;
            examGrades.Participants += examGrades.G130;
            examGrades.Participants += examGrades.G170;
            examGrades.Participants += examGrades.G200;
            examGrades.Participants += examGrades.G230;
            examGrades.Participants += examGrades.G270;
            examGrades.Participants += examGrades.G300;
            examGrades.Participants += examGrades.G330;
            examGrades.Participants += examGrades.G370;
            examGrades.Participants += examGrades.G400;
            examGrades.Participants += examGrades.G430;
            examGrades.Participants += examGrades.G470;
            examGrades.Participants += examGrades.G500;

            return(examGrades);
        }
Esempio n. 2
0
        static public List <ExamGrades> responseToExamGrades(WebResponse response)
        {
            List <ExamGrades> examGrades = new List <ExamGrades>();
            var    encoding = ASCIIEncoding.ASCII;
            string responseText;

            using (var reader = new System.IO.StreamReader(response.GetResponseStream(), encoding))
            {
                responseText = reader.ReadToEnd();
            }
            using (XmlReader reader = XmlReader.Create(new StringReader(responseText)))
            {
                while (reader.Read())
                {
                    // getDataXMLReturn contains cdata
                    if (reader.NodeType == XmlNodeType.Element && reader.Name == "getDataXMLReturn")
                    {
                        string gradesResponse = reader.ReadInnerXml();
                        // Decode encoded cdata
                        gradesResponse = HttpUtility.HtmlDecode(gradesResponse);
                        // Create xml
                        XmlDocument gradesResponseXml = new XmlDocument();
                        gradesResponseXml.LoadXml(gradesResponse);
                        // Select relevant nodes
                        XmlNode node = gradesResponseXml.SelectSingleNode("//es");

                        // Transform
                        string e = applyXlst(node).ToString();

                        // Deserialize
                        ExamGrades examGradesObj = null;
                        // Construct an instance of the XmlSerializer with the type
                        // of object that is being deserialized.
                        XmlSerializer serializer = new XmlSerializer(typeof(ExamGrades));
                        // Call the Deserialize method and cast to the object type.

                        gradesResponseXml.LoadXml(e);
                        XmlNodeList examNodes = gradesResponseXml.SelectNodes("//exam");
                        foreach (XmlNode asd in examNodes)
                        {
                            examGradesObj = (ExamGrades)serializer.Deserialize(new StringReader(asd.OuterXml));
                            examGrades.Add(examGradesObj);
                        }
                    }
                }
            }
            return(examGrades);
        }