public static void importPlan(XDocument doc, List<ActType> actTypeList, Mission mission) { foreach (XElement activity in doc.Descendants("Activity")) { int idType = Int32.Parse(activity.Parent.Parent.Attribute("ID").Value); ActType actType = actTypeList[idType - 1]; int d = Int32.Parse(activity.Element("Day").Element("nDay").Value); Day day = new Day(d); Day checkDay = mission.checkDayList(day); if (checkDay == null) { mission.addDay(day); } else { day = checkDay; } int timeslotBegin = Int32.Parse(activity.Element("timeSlot").Element("start").Value); int timeslotEnd = Int32.Parse(activity.Element("timeSlot").Element("end").Value); TimeSlot timeSlot = new TimeSlot(timeslotBegin, timeslotEnd); string locName = activity.Element("Location").Element("Name").Value; int x = Int32.Parse(activity.Descendants("X").FirstOrDefault().Value); int y = Int32.Parse(activity.Descendants("Y").FirstOrDefault().Value); Location location = new Location(locName, new Position(x, y)); Location checkLocation = mission.checkLocationList(location); if (checkLocation == null) { mission.addLocation(location); } else { location = checkLocation; } List<Astronaut> astrList = new List<Astronaut>(); foreach (XElement astronaut in activity.Descendants("Astronaut")) { string astroName = astronaut.Element("Name").Value; Astronaut member = new Astronaut(astroName); Astronaut checkMember = mission.checkAstronaut(member); if (checkMember == null) { mission.addAstronaut(member); } else { member = checkMember; } astrList.Add(member); } string Desc = activity.Element("Desc").Value; Activity act = new Activity(actType, day, timeSlot, location, astrList, Desc); act.update(); } }
public static Mission loadFile(string generalFile, string activityFile) { //exemple generalFile = "generalInfo.xml"; activityFile = "defaultPlan.xml"; XDocument generalInfo = XDocument.Load(generalFile); List<ActType> actTypeList = createActTypeList(generalInfo); XDocument activityPlan = XDocument.Load(activityFile); Mission mission = new Mission(); ActType actTypeTree = new ActType("Activity tree", 0); actTypeTree.addChild(actTypeList[0]); //Living actTypeTree.addChild(actTypeList[7]); //Science actTypeTree.addChild(actTypeList[15]);//Maintenance actTypeTree.addChild(actTypeList[23]);//Communication actTypeTree.addChild(actTypeList[26]);//Repair actTypeTree.addChild(actTypeList[34]);//Emergency mission.setActTypeTree(actTypeTree); importPlan(activityPlan, actTypeList, mission); return mission; }