Exemplo n.º 1
0
        /// <summary>
        /// manual tester deserialize
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Tester GetTester(string id)
        {
            Tester toReturn;

            try
            {
                toReturn = (from tester in TesterRoot.Elements()
                            where tester.Element("id").Value == id
                            select new Tester()
                {
                    ID = tester.Element("id").Value,
                    Email = tester.Element("Email").Value,
                    PhoneNumber = tester.Element("Phone").Value,
                    Name = new Name(tester.Element("name").Element("firstName").Value,
                                    tester.Element("name").Element("lastName").Value),
                    Address = new Address(tester.Element("Address").Element("City").Value,
                                          tester.Element("Address").Element("street").Value,
                                          tester.Element("Address").Element("bldNumber").Value),
                    BirthDay = DateTime.Parse(tester.Element("BirthDay").Value),
                    Sex = (from sex in (Gender[])Enum.GetValues(typeof(Gender))
                           where sex.ToString() == tester.Element("Gender").Value
                           select sex).FirstOrDefault(),
                    CheckEmail = bool.Parse(tester.Element("CheckEmail").Value),
                    AwaitingAdminReset = bool.Parse(tester.Element("AwaitingAdminReset").Value),
                    FirstLogIn = bool.Parse(tester.Element("FirstLogin").Value),
                    testingCarType = (from type in (VehicleType[])Enum.GetValues(typeof(VehicleType))
                                      where type.ToString() == tester.Element("VehicleType").Value
                                      select type).FirstOrDefault(),
                    MaxDistance = uint.Parse(tester.Element("MaxDistance").Value),
                    ExpYears = uint.Parse(tester.Element("ExpYears").Value),
                    MaxWeeklyTests = uint.Parse(tester.Element("MaxWeeklyTests").Value),
                }).FirstOrDefault();

                foreach (var item in toReturn.schedule.week)
                {
                    var DayElement  = TesterRoot.Elements().FirstOrDefault(T => T.Element("id").Value == id).Element("Schedule").Element(item.Key.ToString());
                    var stringArray = DayElement.Value.Split(',');
                    foreach (var hour in stringArray)
                    {
                        int h;
                        if (int.TryParse(hour, out h))
                        {
                            toReturn.schedule[item.Key, h] = true;
                        }
                    }
                }
                var testerElement = (from tester in TesterRoot.Elements()
                                     where tester.Element("id").Value == id
                                     select tester).FirstOrDefault();
                toReturn.notifications = (from Notification in testerElement.Elements("Notification").Elements()
                                          select new Notification
                {
                    Icon = (from icon in (MessageIcon[])Enum.GetValues(typeof(MessageIcon))
                            where icon.ToString() == Notification.Element("Icon").Value
                            select icon).FirstOrDefault(),
                    message = Notification.Element("Message").Value,
                    time = DateTime.Parse(Notification.Element("Time").Value)
                }).ToList();
            }
            catch
            {
                toReturn = null;
            }
            return(toReturn);
        }
Exemplo n.º 2
0
        /// <summary>
        /// manual trainee deserialize
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Trainee GetTrainee(string id)
        {
            Trainee toReturn;

            try
            {
                toReturn = (from trainee in TraineeRoot.Elements()
                            where trainee.Element("id").Value == id
                            select new Trainee()
                {
                    ID = trainee.Element("id").Value,
                    Email = trainee.Element("Email").Value,
                    PhoneNumber = trainee.Element("Phone").Value,
                    Name = new Name(trainee.Element("name").Element("firstName").Value,
                                    trainee.Element("name").Element("lastName").Value),
                    Address = new Address(trainee.Element("Address").Element("City").Value,
                                          trainee.Element("Address").Element("street").Value,
                                          trainee.Element("Address").Element("bldNumber").Value),
                    BirthDay = DateTime.Parse(trainee.Element("BirthDay").Value),
                    Sex = (from sex in (Gender[])Enum.GetValues(typeof(Gender))
                           where sex.ToString() == trainee.Element("Gender").Value
                           select sex).FirstOrDefault(),
                    CheckEmail = bool.Parse(trainee.Element("CheckEmail").Value),
                    AwaitingAdminReset = bool.Parse(trainee.Element("AwaitingAdminReset").Value),
                    FirstLogIn = bool.Parse(trainee.Element("FirstLogin").Value),
                    CurrentCarType = (from type in (VehicleType[])Enum.GetValues(typeof(VehicleType))
                                      where type.ToString() == trainee.Element("VehicleType").Value
                                      select type).FirstOrDefault(),
                }).FirstOrDefault();

                foreach (var item in toReturn.carTypeStats)
                {
                    var stats       = item.Value;
                    var TypeElement = TraineeRoot.Elements().FirstOrDefault(T => T.Element("id").Value == id).Element(item.Key.ToString());
                    stats.gearType = (from type in (GearType[])Enum.GetValues(typeof(GearType))
                                      where type.ToString() == TypeElement.Element("GearType").Value
                                      select type).FirstOrDefault();
                    stats.numOfLessons = int.Parse(TypeElement.Element("NumOfLessons").Value);
                    stats.numOfTest    = int.Parse(TypeElement.Element("NumOfTests").Value);
                    stats.teacherName  = new Name(TypeElement.Element("TeacherName").Element("FirstName").Value,
                                                  TypeElement.Element("TeacherName").Element("LastName").Value);
                    stats.passed     = bool.Parse(TypeElement.Element("Passed").Value);
                    stats.schoolName = TypeElement.Element("SchoolName").Value;
                }
                var traineeElement = (from trainee in TraineeRoot.Elements()
                                      where trainee.Element("id").Value == id
                                      select trainee).FirstOrDefault();
                toReturn.notifications = (from Notification in traineeElement.Elements("Notifications").Elements()
                                          select new Notification
                {
                    Icon = (from icon in (MessageIcon[])Enum.GetValues(typeof(MessageIcon))
                            where icon.ToString() == Notification.Element("Icon").Value
                            select icon).FirstOrDefault(),
                    message = Notification.Element("Message").Value,
                    time = DateTime.Parse(Notification.Element("Time").Value)
                }).ToList();
            }
            catch
            {
                toReturn = null;
            }
            return(toReturn);
        }