Beispiel #1
0
 private static void generatePeopleForList(List<Person> list, int numberToGenerate, bool areHackers = false)
 {
     for (var index = 0; index < numberToGenerate; ++index)
     {
         var male = Utils.flipCoin();
         if (areHackers)
             male = !male || !Utils.flipCoin();
         var person =
             new Person(
                 male
                     ? maleNames[Utils.random.Next(maleNames.Length)]
                     : femaleNames[Utils.random.Next(femaleNames.Length)],
                 surnames[Utils.random.Next(surnames.Length)], male, areHackers, UsernameGenerator.getName());
         list.Add(person);
         all.Add(person);
     }
 }
Beispiel #2
0
 public static Person loadPersonFromFile(string path)
 {
     try
     {
         using (var fileStream = new FileStream(path, FileMode.Open))
         {
             var rdr = XmlReader.Create(fileStream, new XmlReaderSettings());
             while (rdr.Name != "Person")
                 rdr.Read();
             string str1;
             var lName = str1 = "unknown";
             var fName = str1;
             var handle = str1;
             var male = true;
             var isHacker = false;
             if (rdr.MoveToAttribute("id"))
                 rdr.ReadContentAsString();
             if (rdr.MoveToAttribute("handle"))
                 handle = rdr.ReadContentAsString();
             if (rdr.MoveToAttribute("firstName"))
                 fName = rdr.ReadContentAsString();
             if (rdr.MoveToAttribute("lastName"))
                 lName = rdr.ReadContentAsString();
             if (rdr.MoveToAttribute("isMale"))
                 male = rdr.ReadContentAsBoolean();
             if (rdr.MoveToAttribute("isHacker"))
                 isHacker = rdr.ReadContentAsBoolean();
             var person = new Person(fName, lName, male, isHacker, handle);
             rdr.Read();
             while (!(rdr.Name == "Person") || rdr.IsStartElement())
             {
                 switch (rdr.Name)
                 {
                     case "Degrees":
                         var list = new List<Degree>();
                         rdr.Read();
                         while (!(rdr.Name == "Degrees") || rdr.IsStartElement())
                         {
                             if (rdr.Name == "Degree")
                             {
                                 string str2;
                                 var uniName = str2 = "UNKNOWN";
                                 var num1 = 3.0;
                                 if (rdr.MoveToAttribute("uni"))
                                     uniName = rdr.ReadContentAsString();
                                 if (rdr.MoveToAttribute("gpa"))
                                     num1 = rdr.ReadContentAsDouble();
                                 var num2 = (int) rdr.MoveToContent();
                                 var degree = new Degree(rdr.ReadElementContentAsString(), uniName, (float) num1);
                                 list.Add(degree);
                             }
                             rdr.Read();
                         }
                         if (list.Count > 0)
                         {
                             person.degrees = list;
                         }
                         break;
                     case "Birthplace":
                         string name = null;
                         if (rdr.MoveToAttribute("name"))
                             name = rdr.ReadContentAsString();
                         if (name == null)
                             name = WorldLocationLoader.getRandomLocation().name;
                         person.birthplace = WorldLocationLoader.getClosestOrCreate(name);
                         break;
                     case "DOB":
                         var cultureInfo = new CultureInfo("en-au");
                         var num = (int) rdr.MoveToContent();
                         var dateTime = DateTime.Parse(rdr.ReadElementContentAsString(), cultureInfo);
                         if (dateTime.Hour == 0 && dateTime.Second == 0)
                         {
                             var timeSpan = TimeSpan.FromHours(Utils.random.NextDouble()*23.99);
                             dateTime += timeSpan;
                         }
                         person.DateOfBirth = dateTime;
                         break;
                     case "Medical":
                         person.medicalRecord = MedicalRecord.Load(rdr, person.birthplace, person.DateOfBirth);
                         break;
                 }
                 rdr.Read();
             }
             return person;
         }
     }
     catch (FileNotFoundException ex)
     {
         return null;
     }
 }
 private void addFileForPerson(Person p)
 {
     entries.files.Add(getFileForPerson(p));
 }
 public FileMedicalRecord(Person p)
 {
     Firstname = p.firstName;
     Lastname = p.lastName;
     IsMale = p.isMale;
     record = MedicalRecordToReport(p.medicalRecord);
     DOB = p.medicalRecord.DateofBirth;
 }
 private FileEntry getFileForPerson(Person p)
 {
     var fileEntry = new FileEntry();
     fileEntry.name = convertNameToFileNameStart(p.FullName);
     var num = 0;
     while (entries.searchForFile(fileEntry.name) != null)
     {
         if (num == 0)
             fileEntry.name = fileEntry.name.Substring(0, fileEntry.name.Length - 1) + num;
         else
             fileEntry.name += "1";
         ++num;
     }
     var str = p.FullName + "\n--------------------\n";
     for (var index = 0; index < p.degrees.Count; ++index)
         str = str + p.degrees[index].name + "\n" + p.degrees[index].uni + "\n" + p.degrees[index].GPA +
               "\n--------------------";
     fileEntry.data = str;
     return fileEntry;
 }