コード例 #1
0
        private void Serialize(string path, int disciplineId)
        {
            var discipline    = this.storage.GetDiscipline(disciplineId);
            var disciplineDto = new DisciplineDto
            {
                Name     = discipline.Name,
                Chapters = this.storage.GetChapters(item => item.DisciplineRef == discipline.Id)
                           .Select(chapter => new ChapterDto
                {
                    Name   = chapter.Name,
                    Topics = this.storage.GetTopics(item => item.ChapterRef == chapter.Id)
                             .OrderBy(item => item.SortOrder)
                             .Select(topic => new TopicDto
                    {
                        Name           = topic.Name,
                        TestCourseName = topic.TestCourseRef == null ?
                                         string.Empty :
                                         string.Format("{0}-Test_{1}", storage.GetCourse((int)topic.TestCourseRef).Name, (int)topic.TestCourseRef),
                        TestTopicTypeRef = topic.TestTopicTypeRef,
                        TheoryCourseName = topic.TheoryCourseRef == null ?
                                           string.Empty :
                                           string.Format("{0}-Theory_{1}", storage.GetCourse((int)topic.TheoryCourseRef).Name, (int)topic.TheoryCourseRef),
                        TheoryTopicTypeRef = topic.TheoryTopicTypeRef
                    }).ToList()
                }).ToList()
            };

            Stream writer     = new FileStream(path, FileMode.Create);
            var    serializer = new XmlSerializer(disciplineDto.GetType());

            serializer.Serialize(writer, disciplineDto);
            writer.Close();
        }
コード例 #2
0
        private void Serialize(string path, int disciplineId)
        {
            var discipline = this.storage.GetDiscipline(disciplineId);
            var disciplineDto = new DisciplineDto
            {
                Name = discipline.Name,
                Chapters = this.storage.GetChapters(item => item.DisciplineRef == discipline.Id)
                    .Select(chapter => new ChapterDto
                    {
                        Name = chapter.Name,
                        Topics = this.storage.GetTopics(item => item.ChapterRef == chapter.Id)
                            .OrderBy(item => item.SortOrder)
                            .Select(topic => new TopicDto
                                {
                                    Name = topic.Name,
                                    TestCourseName = topic.TestCourseRef == null ?
                                                                         string.Empty :
                                                                         string.Format("{0}-Test_{1}", storage.GetCourse((int)topic.TestCourseRef).Name, (int)topic.TestCourseRef),
                                    TestTopicTypeRef = topic.TestTopicTypeRef,
                                    TheoryCourseName = topic.TheoryCourseRef == null ?
                                                                         string.Empty :
                                                                         string.Format("{0}-Theory_{1}", storage.GetCourse((int)topic.TheoryCourseRef).Name, (int)topic.TheoryCourseRef),
                                    TheoryTopicTypeRef = topic.TheoryTopicTypeRef
                                }).ToList()
                    }).ToList()
            };

            Stream writer = new FileStream(path, FileMode.Create);
            var serializer = new XmlSerializer(disciplineDto.GetType());
            serializer.Serialize(writer, disciplineDto);
            writer.Close();
        }