コード例 #1
0
ファイル: TestSerialiser.cs プロジェクト: lidbit/ATS
        public void TestToXml(string id)
        {
            Test            t         = null;
            List <Question> questions = new List <Question>();

            questions = QuestionDAL.GetQuestions(Int32.Parse(id));

            t = TestDAL.GetTest(Int32.Parse(id));
            if (t != null)
            {
                XmlTextWriter xw = new XmlTextWriter(@"" + Directory.GetCurrentDirectory() + "Test_" + id.ToString(), System.Text.Encoding.UTF8);
                xw.WriteStartDocument();

                xw.WriteStartElement("Test");

                xw.WriteElementString("TestID", t.Id.ToString());
                xw.WriteElementString("Name", t.Name);
                xw.WriteElementString("Type", t.TestType);
                xw.WriteElementString("Timelimit", t.TimeLimit.ToString());

                xw.WriteStartElement("Questions");

                foreach (Question q in questions)
                {
                    xw.WriteElementString("QuestionID", q.Id.ToString());
                    xw.WriteElementString("Question", q.Quest);
                    xw.WriteElementString("Answer", q.Answer);
                }

                xw.WriteEndElement();
                // end Test element
                xw.WriteEndElement();
            }
        }
コード例 #2
0
ファイル: TestImporterExporter.cs プロジェクト: lidbit/ATS
        public static void exportTest(Test t)
        {
            Test            _test     = TestDAL.GetTest(t.Id);
            List <Question> questions = new List <Question>();

            questions = QuestionDAL.GetQuestions(t.Id);


            XmlTextWriter textWriter = new XmlTextWriter("test_" + _test.Id + ".xml", null);

            textWriter.WriteStartDocument();

            textWriter.WriteStartElement("Test");

            textWriter.WriteElementString("ID", _test.Id.ToString());   // <-- These are new
            textWriter.WriteElementString("Name", _test.Name);
            textWriter.WriteElementString("Type", _test.TestType);
            textWriter.WriteElementString("TimeLimit", _test.TimeLimit.ToString());
            textWriter.WriteElementString("NumberOfQuestions", questions.Count.ToString());

            textWriter.WriteStartElement("Questions");
            foreach (Question q in questions)
            {
                textWriter.WriteStartElement("Question");

                textWriter.WriteElementString("Ask", q.Quest);
                textWriter.WriteElementString("Get", q.Answer);

                textWriter.WriteEndElement();
            }
            textWriter.WriteEndElement();
            textWriter.WriteEndElement();
            textWriter.WriteEndDocument();
            textWriter.Close();
        }
コード例 #3
0
        public string GetQuestions(int testid)
        {
            List <Question> questions = new List <Question>();

            questions = QuestionDAL.GetQuestions(testid);
            return(JsonConvert.SerializeObject(questions));
        }
コード例 #4
0
 public static List <Question> GetQuestions(int testid, int userId)
 {
     return(QuestionDAL.GetQuestions(testid, userId));
 }
コード例 #5
0
 public List <Question> getAllQuestions()
 {
     return(QuestionDAL.GetQuestions());
 }