Esempio n. 1
0
 static Group TestCreateGroup(Faculty faculty, int numberGroup, int studentID)
 {
     var group = new Group(faculty, numberGroup);
     var st = TestCreateStudent(group, studentID);
     foreach (var student in st)
     {
         group.Add(student);
     }
     return group;
 }
Esempio n. 2
0
 static Student[] TestCreateStudent(Group group, int studentID)
 {
     var result = new Student[10];
     result[0] = new Student("Ivanov", "Ivan", "I.", Sex.Male, group, studentID++, "01.01.1960");
     result[1] = new Student("Ivanov", "Cyril", "I.", Sex.Male, group, studentID++, "01.01.1960");
     result[2] = new Student("Petrov", "Ivan", "I.", Sex.Male, group, studentID++, "02.01.1960");
     result[3] = new Student("Sidorov", "Ivan", "I.", Sex.Male, group, studentID++, "03.01.1960");
     result[4] = new Student("Ivanov", "Oleg", "I.", Sex.Male, group, studentID++, "04.01.1960");
     result[5] = new Student("Ivanov", "Anna", "I.", Sex.Female, group, studentID++, "06.01.1960");
     result[6] = new Student("Ivanov", "Ivan", "V.", Sex.Male, group, studentID++, "07.01.1960");
     result[7] = new Student("Kozlov", "Ivan", "I.", Sex.Male, group, studentID++, "10.01.1960");
     result[8] = new Student("Ivanov", "Arman", "I.", Sex.Male, group, studentID++, "12.01.1960");
     result[9] = new Student("Bugaev", "Ivan", "K.", Sex.Male, group, studentID, "20.01.1960");
     return result;
 }
Esempio n. 3
0
File: XML.cs Progetto: Raumo0/Labs
 public static Group LoadGroupFromXML(FileStream stream, Faculty.Faculty faculty)
 {
     try
     {
         var reader = new XmlTextReader(stream);
         int groupNumber = 0;
         var path = string.Empty;
         while (reader.Read())
         {
             switch (reader.Name)
             {
                 case "groupNumber":
                     groupNumber = int.Parse(reader.ReadString());
                     break;
                 case "students":
                     if (reader.AttributeCount >= 1)
                         path = reader.GetAttribute("path");
                     break;
             }
         }
         var group = new Group(faculty, groupNumber);
         if (faculty != null)
             faculty.Add(group);
         if (!string.IsNullOrWhiteSpace(path))
         {
             var dir = new DirectoryInfo(path);
             var files = dir.GetFiles(@"*.xml");
             foreach (var file in files)
             {
                 var intream = file.Open(FileMode.Open);
                 LoadStudentFromXML(intream, group);
                 intream.Close();
             }
         }
         return group;
     }
     catch (ArgumentNullException exception)
     {
         throw new ArgumentNullException(exception.Source);
     }
     catch (XmlException exception)
     {
         throw new XmlException(exception.Source);
     }
     catch (InvalidOperationException exception)
     {
         throw new InvalidOperationException(exception.Source);
     }
     catch(FileNotFoundException exception)
     {
         throw new FileNotFoundException(exception.Source);
     }
     catch (DirectoryNotFoundException exception)
     {
         throw new DirectoryNotFoundException(exception.Source);
     }
 }
Esempio n. 4
0
File: XML.cs Progetto: Raumo0/Labs
 public static XElement XMLElementGroup(Group group)
 {
     if (group == null)
         throw new ArgumentNullException("group");
     var element = new XElement("group");
     element.Add(new XElement("groupNumber", group.GroupNumber));
     element.Add(new XElement("faculty", group.Faculty.Name));
     if (group.Leader != null)
         element.Add(XMLElementStudent(group.Leader));
     return element;
 }
Esempio n. 5
0
File: XML.cs Progetto: Raumo0/Labs
 public static void SaveGroupToXML(string path, Group group)
 {
     if (string.IsNullOrWhiteSpace(path))
         throw new ArgumentOutOfRangeException("path");
     if (path.LastIndexOf(@".xml") <= 0)
         path += "group_" + group.GroupNumber + ".xml";
     using (var stream = new FileStream(path, FileMode.Create))
     {
         SaveGroupToXML(stream, group);
     }
 }
Esempio n. 6
0
File: XML.cs Progetto: Raumo0/Labs
 public static void SaveGroupToXML(FileStream stream, Group group)
 {
     if (stream == null)
         throw new ArgumentNullException("stream");
     if (group == null)
         throw new ArgumentNullException("group");
     try
     {
         var path = stream.Name;
         var index = path.LastIndexOfAny(new[] { '\\' });
         if (index >= 0)
             path = path.Substring(0, index);
         path += @"\group_" + group.GroupNumber + @"\";
         var element = XMLElementGroup(group);
         element.Add(new XElement("students", new XAttribute("path", path)));
         var document = new XDocument(new XDeclaration("1.0", "utf-8", "yes"), element);
         document.Save(stream);
         Directory.CreateDirectory(path);
         foreach (var student in group)
             SaveStudentToXML(path, student);
     }
     catch (ArgumentNullException exception)
     {
         throw new ArgumentNullException(exception.Source);
     }
     catch(DirectoryNotFoundException exception)
     {
         throw new DirectoryNotFoundException(exception.Source);
     }
     catch (ArgumentException exception)
     {
         throw new ArgumentException(exception.Source);
     }
 }
Esempio n. 7
0
File: XML.cs Progetto: Raumo0/Labs
 public static Student LoadStudentFromXML(string path, Group group)
 {
     if (string.IsNullOrWhiteSpace(path))
         throw new ArgumentOutOfRangeException("path");
     using (var stream = new FileStream(path, FileMode.Create))
     {
         return LoadStudentFromXML(stream, group);
     }
 }
Esempio n. 8
0
File: XML.cs Progetto: Raumo0/Labs
 public static Student LoadStudentFromXML(FileStream stream, Group group)
 {
     try
     {
         var reader = new XmlTextReader(stream);
         var firstName = string.Empty;
         var middleName = string.Empty;
         var lastName = string.Empty;
         Sex sex = Sex.Male;
         var dateOfBirth = string.Empty;
         var studentID = string.Empty;
         var leader = false;
         while (reader.Read())
         {
             switch (reader.Name)
             {
                 case "student":
                     if (reader.AttributeCount >= 1)
                         leader = bool.Parse(reader.GetAttribute("leader"));
                     break;
                 case "firstName":
                     firstName = reader.ReadString();
                     break;
                 case "middleName":
                     middleName = reader.ReadString();
                     break;
                 case "lastName":
                     lastName = reader.ReadString();
                     break;
                 case "sex":
                     Enum.TryParse(reader.ReadString(), out sex);
                     break;
                 case "dateOfBirth":
                     dateOfBirth = reader.ReadString();
                     break;
                 case "id":
                     studentID = reader.ReadString();
                     break;
             }
         }
         var student = new Student(lastName, firstName, middleName, sex, group, int.Parse(studentID), dateOfBirth);
         if (group != null)
         {
             group.Add(student);
             if (leader)
                 group.SetLeader(student);
         }
         return student;
     }
     catch (ArgumentNullException exception)
     {
         throw new ArgumentNullException(exception.Source);
     }
     catch (XmlException exception)
     {
         throw new XmlException(exception.Source);
     }
     catch (InvalidOperationException exception)
     {
         throw new InvalidOperationException(exception.Source);
     }
 }
Esempio n. 9
0
 static Group TestCreateGroup(Faculty.Faculty faculty, int numberGroup, int studentID)
 {
     var group = new Group(faculty, numberGroup);
     group.AddStudents(TestCreateStudent(group, studentID));
     return group;
 }