static Faculty.Faculty TestCreateFaculty(string name) { var faculty = new Faculty.Faculty(name); faculty.Add(TestCreateGroup(faculty, 152001, 1520100)); faculty.Add(TestCreateGroup(faculty, 152002, 1520200)); faculty.Add(TestCreateGroup(faculty, 152003, 1520300)); faculty.Add(TestCreateGroup(faculty, 152004, 1520400)); faculty.Add(TestCreateGroup(faculty, 152005, 1520500)); return faculty; }
public static Faculty.Faculty LoadFacultyFromXML(FileStream stream) { try { var reader = new XmlTextReader(stream); string name = string.Empty; var path = string.Empty; while (reader.Read()) { switch (reader.Name) { case "name": name = reader.ReadString(); break; case "groups": if (reader.AttributeCount >= 1) path = reader.GetAttribute("path"); break; } } var faculty = new Faculty.Faculty(name); 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); LoadGroupFromXML(intream, faculty); intream.Close(); } } return faculty; } 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); } }