Esempio n. 1
0
        public void LoadMappers(string xml, DatabaseConnection connection, RepoContainer repository)
        {
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xml);

            XmlNode prefixes = doc.GetElementsByTagName("namespacePrefixes")[0];
            string dataLayerPrefix = prefixes.Attributes.GetNamedItem("dataLayer").Value;
            string domainPrefix = prefixes.Attributes.GetNamedItem("domain").Value;

            foreach (XmlNode mapping in doc.GetElementsByTagName("mapping"))
            {
                string mapperName = mapping.Attributes.GetNamedItem("mapper").Value;
                string domainClassName = mapping.Attributes.GetNamedItem("model").Value;

                object mapper = this.ConstructMapper(dataLayerPrefix, mapperName, connection);

                Type domainType = Type.GetType("{0}.{1}, {2}".FormatWith(domainPrefix, domainClassName, "DomainLayer"));

                this.AddMapper(mapper, domainType, repository);
            }
        }
Esempio n. 2
0
 static SchoolService()
 {
     SchoolService.connection = new DatabaseConnection("Server=(localdb)\\v11.0; Integrated Security=true; Database=VIS; MultipleActiveResultSets=true;");
     SchoolService.repo = RepoContainer.Instance;
     SchoolService.InitMappers(SchoolService.connection, SchoolService.repo);
 }
Esempio n. 3
0
        private static void InitMappers(DatabaseConnection connection, RepoContainer repository)
        {
            string gradeXml = HostingEnvironment.MapPath("~/xml");

            SqlPersonMapper personMapper = new SqlPersonMapper(connection);
            SqlTeachingHourMapper teachingHourMapper = new SqlTeachingHourMapper(connection);
            SqlScheduleMapper scheduleMapper = new SqlScheduleMapper(connection, teachingHourMapper);
            SqlAbsenceMapper absenceMapper = new SqlAbsenceMapper(connection, personMapper, teachingHourMapper);
            SqlTestMapper testMapper = new SqlTestMapper(connection);
            SqlSubjectMapper subjectMapper = new SqlSubjectMapper(connection, absenceMapper, scheduleMapper, testMapper);
            SqlClassMapper classMapper = new SqlClassMapper(connection, personMapper);
            SqlGradeMapper gradeMapper = new SqlGradeMapper(connection);
            SqlSupplementMapper supplementMapper = new SqlSupplementMapper(connection, teachingHourMapper, scheduleMapper, personMapper);

            personMapper.SubjectRepository = subjectMapper; // break object cycle
            personMapper.ClassRepository = classMapper;
            testMapper.GradeRepository = gradeMapper;

            repository.TeachingHour = teachingHourMapper;
            repository.Schedule = scheduleMapper;
            repository.Person = personMapper;
            repository.Absence = absenceMapper;
            repository.Subject = subjectMapper;
            repository.Class = classMapper;
            repository.Test = testMapper;
            repository.Grade = gradeMapper;
            repository.Supplement = supplementMapper;
        }
Esempio n. 4
0
 private object ConstructMapper(string namespacePrefix, string mapperName, DatabaseConnection connection)
 {
     Type mapperType = Type.GetType("{0}.{1}".FormatWith(namespacePrefix, mapperName));
     ConstructorInfo info = mapperType.GetConstructor(new Type[] { typeof(DatabaseConnection) });
     return info.Invoke(new object[] { connection });
 }